self-closing window with wxPython

Discussion in 'Python' started by Jabba Laci, Sep 17, 2010.

  1. Jabba Laci

    Jabba Laci Guest

    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.

    Thanks,

    Laszlo

    ==========

    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()

    =====
     
    Jabba Laci, Sep 17, 2010
    #1
    1. Advertising

  2. Jabba Laci wrote:

    > I'd like to create a simple alarm application that shows an alarm
    > window. The application should shut down automatically after 5
    > seconds.


    Are you sure that's a good idea? What happens if the
    user gets distracted for 6 seconds and misses the
    alarm?

    --
    Greg
     
    Gregory Ewing, Sep 18, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    620
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    620
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    427
    Dan Sommers
    Jul 12, 2005
  4. =?Utf-8?B?Vk1J?=

    Closing popup window when closing parent window?

    =?Utf-8?B?Vk1J?=, Feb 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    677
    Thomas Hansen
    Feb 15, 2007
  5. Philip Semanchuk

    Re: self-closing window with wxPython

    Philip Semanchuk, Sep 17, 2010, in forum: Python
    Replies:
    0
    Views:
    1,030
    Philip Semanchuk
    Sep 17, 2010
Loading...

Share This Page