Posting events from worker thread to main thread is not working

Hello Chris,

thanks for your prompt reply.

(main thread)
    progressdlg, which i want to update
    EVT_BUTTON(self, 9999, self.OnUpdateProgress)
    def OnUpdateProgress ...
       print "updating"

Here you've connected a button event from a Button with an id of 9999 to your OnUpdateProgress() method

I see; it's surly not optimal; but I want to implement this application
from an original wxwindows app; and that was working.

(worker thread is created with import thread; as in wxpython thread example)
    def NotifyProgress(self):
        event = wxCommandEvent ()
        event.m_eventType = wxEVT_COMMAND_LISTBOX_SELECTED
        event.m_id = 9999
        wxPostEvent(self.m_pWndProgress, event)
        print "sending"

Here you are creating a custom CommandEvent, of the type:
wxEVT_COMMAND_LISTBOX_SELECTED

It was a typing mistake. It was from a testing source ...

and posting it to the window: self.m_pWndProgress

self.m_pWndProgress is valid, "sending" is shown, but never "updating"

you're not going to catch a wxEVT_COMMAND_LISTBOX_SELECTED event with an EVT_BUTTON call

of course

The easiest way to do this is to use wxCAllAfter(), but if that won't work for you, you should probably create your own custom event, and then bind it with your own custom event binding function, as per:

I want to use that event from different source files; that is another difficulty [for my spare experience :)] i don't know, how to achieve this :-

http://wiki.wxpython.org/index.cgi/CustomEventClasses

thanks, looks interesting.

the main interesting issue for me is, where the event "vanishes" and why;
and how to capture or monitoring this.

It's also possible to to what you seem to be trying to do, and create an event of an existing type, but it should be a button event, in this case, and I probably wouldn't do that. Clicking on a button is a different thing that whatever your thread is doing, even if you want them to call the same method.

I was aware of it; naturally it is not reasonable; but it shouldn't make no difference, i think.

Make sure you read:

http://wiki.wxpython.org/index.cgi/LongRunningTasks

As well.

Thank you very much for your effort.

···

scrutinizer@gmx.at wrote:

Hi all,

The attached program shows a frame with a panel and a wxTreeCtrl.

Drag and drop is enabled. A test is performed to see if the drop area is
valid. If not, a MessageDialog is displayed and nothing is updated. For this
sample program, all drops are treated as invalid.

The problem is that, under GTK (1 & 2), you cannot close the MessageDialog
with the mouse - you have to press Enter on the keyboard. MSW does not show
this problem.

I have included displaying a MessageDialog under normal circumstances as
well. This works correctly, so it is definitely connected with DnD.

Platform is wxPython 2.4.2.4 on Python 2.3.3. Any advice will be much
appreciated.

Frank Millman

fm22.py (2.54 KB)

Frank Millman wrote:

Hi all,

The attached program shows a frame with a panel and a wxTreeCtrl.

Drag and drop is enabled. A test is performed to see if the drop area is
valid. If not, a MessageDialog is displayed and nothing is updated. For this
sample program, all drops are treated as invalid.

The problem is that, under GTK (1 & 2), you cannot close the MessageDialog
with the mouse - you have to press Enter on the keyboard. MSW does not show
this problem.

I have included displaying a MessageDialog under normal circumstances as
well. This works correctly, so it is definitely connected with DnD.

The tree captures the mouse during the drag and so it can't be used within the dialog window until after the DnD has been completed. Using a wx.CallAfter to show the dialog takes care of the problem:

     def OnEndDrag(self,evt):
         wx.CallAfter(self.ShowDlg)

     def ShowDlg(self):
         dlg = wx.MessageDialog(self.panel, 'Not allowed',
             'Error', wx.OK | wx.ICON_ERROR)
         dlg.ShowModal()
         dlg.Destroy()

···

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