[Tkinter-discuss] Fwd: WxPython -> Tkinter

Guilherme Polo ggpolo at gmail.com
Wed Oct 29 12:18:21 CET 2008


---------- Forwarded message ----------
From: Guilherme Polo <ggpolo at gmail.com>
Date: Oct 29, 2008 9:16 AM
Subject: Re: [Tkinter-discuss] WxPython -> Tkinter
To: Olrik Lenstra <o.lenstra at gmail.com>
Cc: python-list at python.org


On 10/29/08, Olrik Lenstra <o.lenstra at gmail.com> wrote:
 > 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(self, 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(window, only_if_needed=False):
    window_disabler(window)

    try:
        return tk_yield(window, only_if_needed)
    finally:
        for widget, flags in disabled_wins.iteritems():
            ttk.Widget.state(widget, flags)
        disabled_wins.clear()


 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("safe_yield called recursively")

        return False

    inside_tkyield = True;

    window.update()
    window.update_idletasks()

    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.

[Forwarded because I sent to the wrong list first time]

 >  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(self, 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 at python.org
 > http://mail.python.org/mailman/listinfo/tkinter-discuss
 >
 >



 --
 -- Guilherme H. Polo Goncalves


-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list