Re: [Tkinter-discuss] WxPython -> Tkinter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guilherme Polo

    Re: [Tkinter-discuss] WxPython -> Tkinter

    On 10/29/08, Olrik Lenstra <o.lenstra@gmai l.comwrote:
    Hello everyone,
    >
    A while ago I joined the Tutor mailing list, and they helped me out with a
    question regarding wxPython.
    Now however, I have tried a program in Tkinter and I would like to see if
    there is a similar command to "wx.SafeYield(s elf, True)".
    It will be a combination of commands, not a single one. Initially I
    considered this as "probably without solution", since tcl acquired a
    yield command just in the 8.6a3 release, but then I looked at
    wx.SafeYield code and apparently it is possible to replicate it.

    Here is an initial cut, it is very possible to contain something not
    equivalent to wx.SafeYield (besides it could be improved):


    import ttk

    inside_tkyield = False
    disabled_wins = {}

    def safe_yield(wind ow, only_if_needed= False):
    window_disabler (window)

    try:
    return tk_yield(window , only_if_needed)
    finally:
    for widget, flags in disabled_wins.i teritems():
    ttk.Widget.stat e(widget, flags)
    disabled_wins.c lear()


    def window_disabler (window):
    widgets = window.children .values()
    widgets.append( window)

    for widget in widgets:
    if widget.instate(['!disabled']):
    prev_flags = widget.state(['disabled'])
    disabled_wins[widget] = prev_flags


    def tk_yield(window , only_if_needed= False):
    # wx implements this differently based on the backend it is using
    global inside_tkyield
    if inside_tkyield:
    if not only_if_needed:
    raise RuntimeError("s afe_yield called recursively")

    return False

    inside_tkyield = True;

    window.update()
    window.update_i dletasks()

    inside_tkyield = False;

    return True


    Note that this depends on ttk widgets
    (http://pypi.python.org/pypi/pyttk) since it uses widget.state to
    disable and reenable the widgets. On windows the "wm" command supports
    disabling the entire window, so it is easier if you can use it.
    Below is a copy of the message to the tutor list.
    >
    Dear Mailing list,

    a while ago a few of you helped me solve an issue I had with a GUI / scan
    program that I made.
    The problem was that when I tried to move the frame it would hang until
    the
    scan was finished.
    To solve this I had to add "wx.SafeYield(s elf, True)" to the scan and the
    GUI wouldn't hang any more.
    Now I have redone the program and have written it with Tkinter instead of
    WxPython.

    So is there a similar command for Tkinter as there is for WxPython?

    Thanks in advance.
    Regards,
    Olrik
    >
    _______________ _______________ _______________ __
    Tkinter-discuss mailing list
    Tkinter-discuss@python. org

    >
    >

    --
    -- Guilherme H. Polo Goncalves
Working...