wxPython issues

Josiah Carlson jcarlson at nospam.uci.edu
Sun Feb 1 19:10:37 EST 2004


>     #wxpython: do not use this
>     ????#wxYield()
>     #//wait for GUI to end with owerwrite dialog

wxYield only makes sense when called from the main thread.  The main 
thread should be the only thread that is handling GUI events.


What I would do is:
     def OnOverwriteDlg(self, event):
         print "OnOverwriteDlg"
         dlg = COverwriteDlg ()
         dlg.m_strInfo = g_strTitle
         g_nGuiResult = dlg.ShowModal()
         print g_nGuiResult
         return g_nGuiResult

Toss the semaphores, toss the worker threads, etc.  If saving takes so 
much time, then you can do what I describe farther down.


> How can I get, that in worker thread on "before" is waiting, until the
> dialog in mainthread is finished?

Why are you trying to use multiple threads to save files?


> wxYield, Semaphore, Mutex, ... is all a bit strange for me.
> Is there any website dedicated to this issues?

wxYield is normally used when programming a single-threaded application. 
  If your application can spend a long time on one task without 
returning, and you want to allow the GUI to update while it is 
processing, calling wxYield() is a good idea.

For example, you can have a status bar that reflects a percent complete, 
without requiring a second thread to do the processing.

     def LongRunningMethod(self, event):
         for i in xrange(101):
             self.SetStatusText("%s%% complete"%i)
             wxYield()
             time.sleep(.1)


wxMutex and wxSemaphore are really just ways of only allowing one thread 
(or some certain count) to modify some structure at one time.

def updateglobal_m(count, wxmutex):
     global counter
     for i in xrange(count):
         wxmutex.Lock()
         counter += 1
         wxmutex.Unlock()

def updateglobal_s(count, wxsemaphore):
     global counter
     for i in xrange(count):
         wxsemaphore.Wait()
         counter += 1
         wxsemaphore.Post()

The standard Python Semaphore and Mutex calls are very similar...

def updateglobal_pys(count, pysemaphore):
     global counter
     for i in xrange(count):
         pysemaphore.acquire()
         counter += 1
         pysemaphore.release()

But a Python mutex has a few different options that you can read about 
in the standard documentation.


> 2. I want to get a list icons from the windows shell folders and put
> it in the wxPython List control. How can I accomplish this?

I don't know how to get arbitrary icons from executables or dlls. 
Perhaps someone else can tell us.


> 3. 
>   menuAdd(self, pMenuFile, _("Exit") +"\tAlt+F4", _("Exit"),
> self.OnClose, wxID_CLOSE)

Change the above to:
menuAdd(self, pMenuFile, _("Exit") +"\tAlt+F4", _("Exit"), self.OnClose, 
wxNewId())

Then in the __init__ method use:
EVT_CLOSE(self, self.OnClose)



  - Josiah



More information about the Python-list mailing list