New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgets should overwrite by default #391

Closed
mpmc opened this Issue Feb 20, 2018 · 11 comments

Comments

Projects
None yet
2 participants
@mpmc
Contributor

mpmc commented Feb 20, 2018

If you use an after timer to refresh widget values. An example being..

    def device(self):
        """The device screen."""
        # Refresh timer (milliseconds).
        refresh = 5000
        # Widgets
        info_frame = {
            'title': '{}'.format(_('\u2605 Device Information')),
            'sticky': 'nesw',
            'stretch': 'both',
            'padding': (5, 5),
        }
        addr = {
            'title': 'Device address',
            'value': '{}'.format(_('Device address: Unknown')),
            'pos': (0, 0, 1),
            'sticky': 'nw',
            'stretch': 'none',
            'tip': '{}'.format(_('The current device address.')),
        }

        def show():
            # Display the widgets.
            print('updating..')
            with self.labelFrame(**info_frame):
                self.label(**addr)

            # Trigger update.
            self.after(refresh, self.queueFunction, show)

        # Reset all widgets and show the screen!
        self.removeAllWidgets()
        self.queueFunction(show)

the subsequent calls result in,

updating..
updating..
2018-02-20 09:22:46,495 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - pos:(0, 0, 1)
2018-02-20 09:22:46,496 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - sticky:nw
2018-02-20 09:22:46,496 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - stretch:none

Would it be possible to just update existing widgets by default if the title and position are the same?

@mpmc

This comment has been minimized.

Contributor

mpmc commented Feb 20, 2018

After a few more tests it appears that appJar won't update existing widgets at all in this way. Even If you remove the invalid arguments.

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 1, 2018

So, I've had a quick play, using the following code:

from appJar import gui 
from time import gmtime, strftime

def show():
    app.label("time here", strftime("%H:%M:%S", gmtime()))
    app.after(50, show)

with gui("timer", "200x200", font={'size':20}) as app:

    app.label("time here")
    app.queueFunction(show)

And it works as expected, the label is updating...

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 1, 2018

If I put it in a labelFrame, it still works as expected:

from appJar import gui 
from time import gmtime, strftime

def show():
    with app.labelFrame("TIMER"):
        app.label("time here", strftime("%H:%M:%S", gmtime()))
    app.after(50, show)

with gui("timer", "200x200", font={'size':20}) as app:
    with app.labelFrame("TIMER"):
        app.label("time here")
    app.queueFunction(show)
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 1, 2018

And, if I change the after call, it still works:

from appJar import gui 
from time import gmtime, strftime

def show():
    app.label("time here", strftime("%H:%M:%S", gmtime()))
    app.after(50, app.queueFunction, show)

with gui("timer", "200x200", font={'size':20}) as app:
    with app.labelFrame("TIMER"):
        app.label("time here")
    app.queueFunction(show)
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 1, 2018

Now, I think the use of queueFunction is slightly wrong, the label update should be queued, not the call to show:

from appJar import gui 
from time import gmtime, strftime

def show():
    app.queueFunction(app.label, "time here", strftime("%H:%M:%S", gmtime()))
    app.after(50, show)

with gui("timer", "200x200", font={'size':20}) as app:
    with app.labelFrame("TIMER"):
        app.label("time here")
    show()
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 1, 2018

But, as no extra threads are being created, it's not even necessary to use the function queue, as after should be safe in the main thread:

from appJar import gui 
from time import gmtime, strftime

def show():
    app.label("time here", strftime("%H:%M:%S", gmtime()))
    app.after(50, show)

with gui("timer", "200x200", font={'size':20}) as app:
    with app.labelFrame("TIMER"):
        app.label("time here")
    show()
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 1, 2018

Now, when I add in the extra parameters, I do get the same errors as you, but the label text is still being updated:

from appJar import gui 
from time import gmtime, strftime

def show():
    app.label("time here", strftime("%H:%M:%S", gmtime()), sticky='nw', stretch='none')
    app.after(50, show)

with gui("timer", "200x200", font={'size':20}) as app:
    with app.labelFrame("TIMER"):
        app.label("time here")
    show()
@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 1, 2018

Looking at the code, positional parameters (sticky, stretch, row, column, rowspan, colspan) are only processed when a new widget is being added, not when a widget is being updated. Which is probably right, as I don't know what the affect of trying to change them is, or if it's possible.

I think there might be a use case, for ignoring the positional parameters when updating/getting. But on the other hand, maybe we need to enforce some rules, and have the user provide the right parameters?

@mpmc

This comment has been minimized.

Contributor

mpmc commented Mar 1, 2018

OK I think I've figured out the problem..

Because I'm using nested methods and defining the label properties outside of the nested method, the label properties are not updated (kinda obvious now that I think about it :p).

Updating the label dictionary inside of the show method correctly updates the label. But the Invalid argument messages still end up spamming the log. I think warning once per run is fine but not every time.

jarvisteach added a commit that referenced this issue Mar 1, 2018

@jarvisteach

This comment has been minimized.

Owner

jarvisteach commented Mar 1, 2018

Hmm, OK - so join al the warnings into a single line, that sounds doable...

jarvisteach added a commit that referenced this issue Mar 1, 2018

@jarvisteach jarvisteach added this to the 1.0 milestone Mar 1, 2018

@jarvisteach jarvisteach closed this Mar 1, 2018

@mpmc

This comment has been minimized.

Contributor

mpmc commented Mar 1, 2018

Sorry, my mistake, I meant all warnings shouldn't repeat non-stop, separate lines are fine, but they should just output once.

So instead of

2018-02-20 09:22:46,495 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - pos:(0, 0, 1)
2018-02-20 09:22:46,496 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - sticky:nw
2018-02-20 09:22:46,496 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - stretch:none
2018-02-20 09:22:47,146 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - pos:(0, 0, 1)
2018-02-20 09:22:47,146 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - sticky:nw
2018-02-20 09:22:47,146 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - stretch:none

just

2018-02-20 09:22:46,495 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - pos:(0, 0, 1)
2018-02-20 09:22:46,496 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - sticky:nw
2018-02-20 09:22:46,496 appJar:ERROR [Line 393->7641/_configWidget]: Invalid argument for Label Device address - stretch:none

Or perhaps do a check to see if the widget (minus the value property) has changed, if so then warn, otherwise ignore the other arguments & update anyway?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment