Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DynamicMessage can't handle strings #193

Copy link
Copy link

Description

@DarkRedman
Issue body actions

Description

I prefered to use DynamicMessage instead of FormatCustomText because it's easier to set up.
so I added a DynamicMessage widget and update its value with a string, and I get an error that the g format code doesn't work with an str

ValueError: Unknown format code 'g' for object of type 'str'

Code

import progressbar, time

widgets = [
    progressbar.Percentage(),
    progressbar.Bar(),
    progressbar.DynamicMessage('user'),
]
with progressbar.ProgressBar(max_value=100, widgets=widgets) as bar:
    for i in range(100):
        bar.update(i, user='me')
        time.sleep(0.2)`

Versions

  • Python version: 3.7.3 (default, Mar 26 2019, 21:43:19)
    [GCC 8.2.1 20181127]
  • Python distribution/environment: CPython
  • Operating System: Antergos (Arch Linux)
  • Package version: 3.39.3

Solution

In order to fix it I changed the code of function call of DynamicMessage like this

def __call__(self, progress, data):
    val = data['dynamic_messages'][self.name]
    if val:
            if isinstance(val,str):
                return self.name + ': ' + '{:6s}'.format(val)
            else:
                return self.name + ': ' + '{:6.3g}'.format(val)
    else:
        return self.name + ': ' + 6 * '-'
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.