Hi, I'm trying to add a progress indicator to my little script (which
isn't really an app at all... it never calls app.MainLoop())
It works great, except it doesn't let the user cancel because the main
event pump isn't pumping. I tried calling app.ProcessEvent(), but
that just throws an exception.
Is there a way I can make the progress indicator interactive without
creating a reall application?
Thanks!
# allow some simple interaction
app = wx.PySimpleApp()
#.....
count = 0
dlg = wx.ProgressDialog("Progress", "Uploading data to NeuroInfo",
maximum = len(lines),
parent=None, style = wx.PD_CAN_ABORT |
wx.PD_APP_MODAL)
for row in reader:
rowDict = dict(zip(header,row))
if not dry_run:
newID = ni.neuroinfo.createNewInstance(ni_sess,
"NeuroNames2000", rowDict)
else:
pprint.pprint(rowDict)
count += 1 #app.ProcessEvent()
keepGoing = dlg.Update(count, rowDict["Abbrev"])
if not keepGoing:
break
when you create the app object you are creating a real application. The fact that you don't call MainLoop() means that you don't have the evens handled properly. Why would you want that? Why not calling app.MainLoop() ?
You have to understand that a GUI is a event driven system, events get generated, events get dispatched, the MainLoop is there to dispatch the events... is there to help you!
···
On Wed, 9 Feb 2005 16:14:46 -0500, James Carroll <mrmaple@gmail.com> wrote:
Hi, I'm trying to add a progress indicator to my little script (which
isn't really an app at all... it never calls app.MainLoop())
It works great, except it doesn't let the user cancel because the main
event pump isn't pumping. I tried calling app.ProcessEvent(), but
that just throws an exception.
Is there a way I can make the progress indicator interactive without
creating a reall application?
It would save me the time of creating a real app, creating a
background thread for the process, and then managing the cross-thread
events to have the thread (non-gui thread) communicate with the
progress dialog in the gui thread... Overkill for a ten minute
script.
Thanks,
-Jim
···
On Thu, 10 Feb 2005 10:25:27 +0200, Peter Damoc <pdamoc@gmx.net> wrote:
On Wed, 9 Feb 2005 16:14:46 -0500, James Carroll <mrmaple@gmail.com> wrote:
> Hi, I'm trying to add a progress indicator to my little script (which
> isn't really an app at all... it never calls app.MainLoop())
>
> It works great, except it doesn't let the user cancel because the main
> event pump isn't pumping. I tried calling app.ProcessEvent(), but
> that just throws an exception.
>
> Is there a way I can make the progress indicator interactive without
> creating a reall application?
>
when you create the app object you are creating a real application. The fact that you don't call MainLoop() means that you don't have the evens handled properly. Why would you want that? Why not calling app.MainLoop() ?
You have to understand that a GUI is a event driven system, events get generated, events get dispatched, the MainLoop is there to dispatch the events... is there to help you!
It would save me the time of creating a real app, creating a
background thread for the process, and then managing the
cross-thread events to have the thread (non-gui thread)
communicate with the progress dialog in the gui thread...
Overkill for a ten minute script.