Re: questions to anyone who uses wxPython

2006-07-20 Thread [EMAIL PROTECTED]

damacy wrote:
> hello. i'm using wxPython as my GUI package and whenever my program
> executes a long process which takes at least 2 or 3 seconds, the user
> interface gets corrupted while executing the progrocess during the
> period.

Hi Darnacy,

I had the same issue and used wxProcess to run the long process (in
this case a file copy) in a seperate process to the GUI

See src zip at :
http://www.latedecember.com/sites/software/LDBackup/

Thanks,
Davy Mitchell

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: questions to anyone who uses wxPython

2006-07-20 Thread Dermot Doran
Hi 
 
the "wxPython in Action" provides a very good explanation as to how to handle this sort of problem using a combination of pure Python threads and the wx.CallAfter function.  Also if you want more help on this you can join the wxPython mailing list via 
www.wxpython.org.
 
Here is a small example of what I'm talking about that uses a Queue object to get a background thread to await work from the main gui thread.  Note it is VERY important that all GUI updates are performed by the main thread in a wxPython program.

 
import wximport threadingimport Queue
class WorkerThread(threading.Thread):   def __init__(self, callBack):  threading.Thread.__init__(self)  self.callBack = callBack  self.work_queue = Queue.Queue()  self.setDaemon(True)  def run(self):
   wx.CallAfter(self.callBack, "Thread starting up...")  work_to_be_done = Truewhile work_to_be_done:   req = self.work_queue.get(True)   # Go and perform some long lasting task here!
   wx.CallAfter(self.callBack, "Sorry I was kind of busy just now!") def helloThere(self):   self.work_queue.put_nowait("This could be an object")  class MyFrame(
wx.Frame):  def __init__(self):  wx.Frame.__init__(self, None, -1, "Testing wxCallback and Python threads")self.worker_thread = WorkerThread(self.logMessage)panel = wx.Panel(self)
  test_btn = wx.Button(panel, -1, "Hello!")  self.log = wx.TextCtrl(panel, -1, "", style=wx.TE_MULTILINE|wx.TE_RICH2|wx.TE_READONLY)sizer = wx.BoxSizer(wx.VERTICAL)  sizer.Add(self.log
, 1, wx.EXPAND|wx.ALL, 5)  sizer.Add(test_btn, 0, wx.ALIGN_CENTER_HORIZONTAL)  panel.SetSizer(sizer)self.Bind(wx.EVT_BUTTON, self.onTestBtn, test_btn)  self.Bind(wx.EVT_CLOSE, self.onCloseWindow)

  self.worker_thread.start()   def onTestBtn(self, evt):  self.worker_thread.helloThere() def onCloseWindow(self, evt):  self.Destroy() def logMessage(self, msg):  self.log.AppendText
(msg)  self.log.AppendText("\n") if __name__ == '__main__': app = wx.PySimpleApp() frm = MyFrame() frm.Show() app.MainLoop()
 
Cheers!!
 
Dermot.
 
On 19 Jul 2006 22:52:09 -0700, Frank Millman <[EMAIL PROTECTED]> wrote:
damacy wrote:> hello. i'm using wxPython as my GUI package and whenever my program> executes a long process which takes at least 2 or 3 seconds, the user
> interface gets corrupted while executing the progrocess during the> period.>> i have tried the following lines of code...>> frame = mainwindow(None, -1, 'my program')> ...
> ...> frame.UpdateWindowUI()>> and it did not make any difference at all.>> could anyone help me?I don't really understand the question - what do you mean when you say
the user interface gets corrupted?Nevertheless, the following pointer may help -http://tinyurl.com/hj84lIt is an article in the wxPyWiki that discusses various ways of
handling longrunning tasks.HTHFrank Millman--http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: questions to anyone who uses wxPython

2006-07-19 Thread Frank Millman

damacy wrote:
> hello. i'm using wxPython as my GUI package and whenever my program
> executes a long process which takes at least 2 or 3 seconds, the user
> interface gets corrupted while executing the progrocess during the
> period.
>
> i have tried the following lines of code...
>
> frame = mainwindow(None, -1, 'my program')
> ...
> ...
> frame.UpdateWindowUI()
>
> and it did not make any difference at all.
>
> could anyone help me?

I don't really understand the question - what do you mean when you say
the user interface gets corrupted?

Nevertheless, the following pointer may help -

http://tinyurl.com/hj84l

It is an article in the wxPyWiki that discusses various ways of
handling longrunning tasks.

HTH

Frank Millman

-- 
http://mail.python.org/mailman/listinfo/python-list