Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: self-closing window with wxPython

Reply
Thread Tools

Re: self-closing window with wxPython

 
 
Philip Semanchuk
Guest
Posts: n/a
 
      09-17-2010

On Sep 17, 2010, at 12:05 PM, Jabba Laci wrote:

> Hi,
>
> I'd like to create a simple alarm application that shows an alarm
> window. The application should shut down automatically after 5
> seconds. The problem is the following:
> * If I keep the mouse outside of the window, the application keeps
> running. Somehow self.Destroy() is not taken into account.
> * If the mouse is over the window and I keep moving it, the window closes.
>
> I'm using Ubuntu Linux with wxPython 2.8. Below you can find what I have so far.


Hi Laszlo,
It's difficult to help without a complete working example. But I have a few suggestions.

1) Why not call self.parent.Close()? It seems a bit more polite than ..Destroy().

2) I saw this in the documentation for Destroy() -- "Frames and dialogs are not destroyed immediately when this function is called -- they are added to a list of windows to be deleted on idle time, when all the window's events have been processed." That might be consistent with what you're seeing. The window you're trying to destroy has no events in its queue. WHen you move the mouse over it, the window processes those mouse events and then wx realizes, "Hey, this window has processed all of its events, and it's on the list of windows to be destroyed. I'd better get rid of it."

If you're interested in experimenting, find a non-mouse way to force that window to process an event and I'll bet that would have the same effect as moving the mouse over it.

3) Both the wxPython and wxWidgets mailing lists are probably better places to ask for help on wxPython.


Good luck
Philip



>
> ==========
>
> class MyThread(threading.Thread):
> def __init__(self, parent):
> self.parent = parent
> threading.Thread.__init__(self)
>
> def run(self):
> print time.time() # appears on stdout
> time.sleep(5)
> print time.time() # appears on stdout
>
> self.parent.Destroy() # ??? doesn't work if the mouse is
> outside of the application window
>
> class Alarm(wx.Frame):
> def __init__(self, title, *args):
> wx.Frame.__init__(self, None, -1, title, pos=(0, 0),
> size=(800, 600), *args)
>
> self.sleepThread = MyThread(self)
> self.sleepThread.start()
>
> self.Bind(wx.EVT_CLOSE, self.on_close)
>
> def on_close(self, event):
> self.Destroy()
>
> ==========
>
> To call it:
>
> class Main(wx.PySimpleApp):
> def OnInit(self):
> self.frame = alarm.Alarm("Alarm 0.1")
> self.SetTopWindow(self.frame)
> self.SetExitOnFrameDelete(True)
> self.frame.Show()
> return True
>
> a = Main()
> a.MainLoop()
>
> =====
> --
> http://mail.python.org/mailman/listinfo/python-list


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wxPython: How can I get window's HANDLE in wxPython. Leo Lee Python 3 07-17-2008 02:10 AM
[wxPython-users] Web based applications are possible with wxPython? Ruben Charles Python 6 10-25-2005 09:41 PM
wxPython - wx package (new style wxPython?) Logan Python 5 12-11-2003 04:12 PM
[PY GUI] interest function in python GUI(wxpython,pyqt) program.wxpython,pyqt ulysses Python 4 10-22-2003 03:28 PM
wxPython looses function "wxPython.wx.miscc" Anand Python 1 07-23-2003 01:59 AM



Advertisments