RE: [Pythoncard-users] what is the syntax for posting an event?
by Kevin Altis other posts by this author
Apr 22 2002 5:39PM messages near this date
[Pythoncard-users] added flatfileDatabase sample
|
[Pythoncard-users] bug in sound.py
> From: David Primmer
>
> > -----Original Message-----
> > From: Kevin Altis
> > > This has been covered before but it wasn't spelled out clearly
> enough
> > > for me. What do I need to do to post an event? How would I simulate
> > > someone selecting a checkable menu item?
> >
> > If you want to actually post an event with the existing framework, you
> > must
> > create a valid wxPython event object and then use wxPython's
> wxPostEvent
> > or
> > ProcessEvent. That isn't necessary for your needs as I'll show below.
>
> Actually, I would like to know how to do this. You sure you can't answer
> my question??? Please? ;-0
This is low-level wxPython stuff. wxPostEvent and ProcessEvent are not
wrapped in PythonCard, thus it is really a wxPython question. However, since
you want to see it, here is a short hack you can try in the shell with the
textEditor sample that will display the Find dialog.
I only initialized the minimal fields necessary in the event object, you'll
need to read up on wxEvent and wxCommandEvent if you want more. In
particular, I would guess you have to determine whether the checkmark is set
or not, which would sort of defeat the original idea of just posting an
event and not worrying about it. You can play around with events and report
back to the list.
You can't create a wxPython event without the id of the object, so we use
getMenuId to get that. Everything else are wxPython methods and classes.
> >> from wxPython import wx
> >> id = bg.menuBar.getMenuId('menuEditFind')
> >> mb = bg.GetMenuBar()
> >> mi = mb.FindItemById(id)
> >> mi.GetLabel()
'Find...'
> >> e = wx.wxCommandEvent(wx.wxEVT_COMMAND_MENU_SELECTED)
> >> e.SetId(id)
> >> e.SetEventObject(mi)
> >> wx.wxPostEvent(bg, e)
> > It won't work for your example below because you don't want to
> actually do
> > everything that is in on_menuViewPreviewBrowser_select.
>
> Actually, I do. I thought it would be easier to create the event in this
> case because unlike those file menu commands, my menu item needs to get
> checked. Toggling that check is what I wanted the event for. Seemed
> easier than looking up how to do setChecked. I was trying to program as
> if it were a macro but maybe that's just amateur stuff and I should call
> all the functions in that handler manually. I'm afraid I don't know how
> to program the pro way. So, if you say don't make events, then I won't.
Using the appropriate method is definitely easier than posting an event. At
some point, we'll wrap up the low-level event so you could do something
like:
postEvent(self.components.btn1, 'mouseClick')
While that looks simple, the underlying code probably won't be pleasant;
there are a lot of different types of events and a lot of attributes that
have to be initialized. There are a number of reasons to write that code
though, including the possibility of doing some UI unit testing. It isn't
high on my own priority list. I suppose I could do a simple version that
supports a limited set of events and then someone else can expand it to
include more components and event types.
ka
_______________________________________________
Pythoncard-users mailing list
Pythoncard-users@[...].net
https://lists.sourceforge.net/lists/listinfo/pythoncard-users
|