Automatically close user interruptable modal dialog ?

Hello,
My program should display download progress (user interruptable)
So if user gets bored he can stop downloading by pressing button.
Dialog also shouldn't wait for user keypress if download is complete
Below is my ugly solution with defects:
   - After dialog is closed program waits for some keypress.
How can i get rid of it?
Thanks in advance for any help.

cut here<<<<<<<<<<<<<<

from wxPython.wx import *
import wx
import time

···

#----------------------------------------------------------------------
class FetchUpgrade(wxDialog):
    def __init__(self,parent):
        wxDialog.__init__(self, parent, -1, "Example dialog", wxDefaultPosition, wxSize(350,200),wxRESIZE_BORDER | wxCAPTION | wxSYSTEM_MENU)
        self.infomessage=wxStaticText(self, -1, "progress indicator",pos=wxPoint(48, 24), size=wxSize(91, 13))
        self.progress= wxGauge(self, -1, 10, pos=wxPoint(32, 48), size=wxSize(248, 24),)
        self.cancel=wxButton(self, 1000, ' Stop ', pos=wxPoint(120, 80), size=wxSize(75, 23))
        EVT_BUTTON(self,1000,self.CancelButton)
    def CancelButton(self,evt):
        print "cancelling"
        self.Close()
    def ShowModal(self):
        wx.CallAfter(self.RunFetch)
        return wx.Dialog.ShowModal(self)
    def Show(self):
        wx.CallAfter(self.RunFetch)
        return wx.Dialog.Show(self)
    def RunFetch(self):
        for i in xrange(1,self.progress.GetRange()+1):
            time.sleep(0.1)
            self.progress.SetValue(i)
            print i
        self.Close()
#----------------------------------------------------------------------
class Frame(wxFrame):
    def __init__(self,parent, title):
        wxFrame.__init__(self, None, -1, title, style= wxDEFAULT_FRAME_STYLE)
        self.FetchUpgrade=FetchUpgrade(self)
        self.FetchUpgrade.ShowModal()
        self.Destroy()
        dlg = wxMessageDialog(self, 'Upgrade Done!', 'A Message Box', wxOK | wxICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
#----------------------------------------------------------------------
class MyApp(wxApp):
    def OnInit(self):
        frame = Frame(self,'appname')
        frame.Show(true)
        return true
#----------------------------------------------------------------------
myapp = MyApp(0)
myapp.MainLoop()
  
--
Igor.
                     mailto:igor@tyumbit.ru

Igor Prischepoff wrote:

Hello,
My program should display download progress (user interruptable)
So if user gets bored he can stop downloading by pressing button.
Dialog also shouldn't wait for user keypress if download is complete
Below is my ugly solution with defects:
   - After dialog is closed program waits for some keypress.
How can i get rid of it?

A modal dialog can be closed simply by calling EndModal(resultCode). For example the default handler for the cancel button just calls EndModal(wxID_CANCEL).

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hello,
My program should display download progress (user interruptable)
So if user gets bored he can stop downloading by pressing button.
Dialog also shouldn't wait for user keypress if download is complete
Below is my ugly solution with defects:
   - After dialog is closed program waits for some keypress.
How can i get rid of it?

A modal dialog can be closed simply by calling EndModal(resultCode).
For example the default handler for the cancel button just calls
EndModal(wxID_CANCEL).

Thanks,Robin.
Didn't work for me. :frowning:
I've modified sample source with EndModal call.
Still - dialog closed,then _waits_ for something.
Until some keypress.
Here is modified sample.
Am i miss something?
And i've just discovered that my 'interrupt' button didn't react on mouse click
either. Something is very wrong here... May be all my concept with
implementing this downloading progress indicator with wxDialog is wrong?
Could someone point me to right direction?
Details:
win2k, python 2.2, wxPython 2.4.2 (non unicode) .

cut here <<<<<<<<<<<

from wxPython.wx import *
import wx
import time

···

#----------------------------------------------------------------------
class FetchUpgrade(wxDialog):
    def __init__(self,parent):
        wxDialog.__init__(self, parent, -1, "Example dialog", wxDefaultPosition, wxSize(350,200),wxRESIZE_BORDER | wxCAPTION | wxSYSTEM_MENU)
        self.infomessage=wxStaticText(self, -1, "progress indicator",pos=wxPoint(48, 24), size=wxSize(91, 13))
        self.progress= wxGauge(self, -1, 20, pos=wxPoint(32, 48), size=wxSize(248, 24),)
        self.cancel=wxButton(self, wxID_CANCEL, ' Stop ', pos=wxPoint(120, 80), size=wxSize(75, 23))
        EVT_BUTTON(self,wxID_CANCEL,self.CancelButton)
    def CancelButton(self,evt):
        print "cancelling"
        self.EndModal(wxID_CANCEL)
    def ShowModal(self):
        wx.CallAfter(self.RunFetch)
        return wx.Dialog.ShowModal(self)
    def Show(self):
        wx.CallAfter(self.RunFetch)
        return wx.Dialog.Show(self)
    def RunFetch(self):
        for i in xrange(1,self.progress.GetRange()+1):
            time.sleep(0.1)
            self.progress.SetValue(i)
            print i
        self.EndModal(wxID_CANCEL)
#----------------------------------------------------------------------
class Frame(wxFrame):
    def __init__(self,parent, title):
        wxFrame.__init__(self, None, -1, title, style= wxDEFAULT_FRAME_STYLE)
        self.FetchUpgrade=FetchUpgrade(self)
        self.FetchUpgrade.ShowModal()
        self.FetchUpgrade.Destroy()
        print "now proceed ..."
        dlg = wxMessageDialog(self, 'Upgrade Done!', 'A Message Box', wxOK | wxICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
#----------------------------------------------------------------------
class MyApp(wxApp):
    def OnInit(self):
        frame = Frame(self,'appname')
        frame.Show(true)
        return true
#----------------------------------------------------------------------
myapp = MyApp(0)
myapp.MainLoop()

--
Igor.
                         mailto:igor@tyumbit.ru

Igor Prischepoff wrote:

Hello,
My program should display download progress (user interruptable)
So if user gets bored he can stop downloading by pressing button.
Dialog also shouldn't wait for user keypress if download is complete
Below is my ugly solution with defects:
  - After dialog is closed program waits for some keypress.
How can i get rid of it?

> A modal dialog can be closed simply by calling EndModal(resultCode). > For example the default handler for the cancel button just calls > EndModal(wxID_CANCEL).
Thanks,Robin.
Didn't work for me. :frowning:
I've modified sample source with EndModal call.
Still - dialog closed,then _waits_ for something.
Until some keypress.
Here is modified sample.
Am i miss something?
And i've just discovered that my 'interrupt' button didn't react on mouse click
either. Something is very wrong here... May be all my concept with
implementing this downloading progress indicator with wxDialog is wrong?
Could someone point me to right direction?
Details:
win2k, python 2.2, wxPython 2.4.2 (non unicode) .

This has come up before, the return from ShowModal is delayed but I don't remember the reason for it. There is an easy workaround though, just show your main frame before running the dialogs. See attached.

dlgclose.py (1.96 KB)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

And i've just discovered that my 'interrupt' button didn't react on mouse

click

either. Something is very wrong here... May be all my concept with
implementing this downloading progress indicator with wxDialog is wrong?

It seems to me that putting your application functionality inside the
wxDialog-derived class is wrong. It should probably be in the frame class or
somewhere else. Then from there you can use wxProgressDialog to show
progress and do everything you want.

Or did I miss something?
-Rick King

I can explain my decision.
You see, it's upgrade function.
Before my application permits user to do something , it should check
"is there an upgrade available?". Then - if upgrade exists , app is going to
download upgrade and replace own files with new ones.And shutdown himself with warning -
"upgrade happens, please restart the app." So, showing upgrade dialog
after main frame is on the screen is too late i think.

···

--
Igor.
                         mailto:igor@tyumbit.ru