How to implement PushEventHandler?

Can someone explain to a non-C++ and new-to-Python programmer how to implement the concept of PushEventHandler? Slowly, as if to a child, because every attempted explanation I've seen so far only seems to re-iterate exactly what it says in the wxWindows Reference (which I quite obviously don't understand).

Frankly, words with an Asterisk after* them, double colons :: and arrows just confuse me. Python is my first and only programming language/experience so far and I just don't have the background to understand this, I guess.

Actually, PushEventHandler may not even be the proper solution for my problem.

I'm trying to implement a simple interface similar to MS Outlook. Its a Frame containing a SplitWindow . The left-hand panel is narrow and holds a notebook (which will ultimately hold the icons to launch various modules). The right-hand panel is going to be the main work area.

My problem is that I would like to structure this program so that seperate scripts are used for each "module" the program launches. Each imported module is to contain the panel(s) to display, a menubar definition, and a toolbar definition, and all the event definitions for the menu. Obviously, when selected, I need to set the Main_Frame.MenuBar and ToolBar. What I can't manage is to get the menu items to trigger event handling in the imported module instead of just looking in the Main_Frame script.

I'm assuming the PushEventHandler function can solve this, but I don't understand the documentation well enough to implement it.

PushEventHandler(wxEvtHandler* handler)

Where does the command itself go? In the function that imports the script or in the script to be imported? And, what does "wxEvtHandler* handler" mean? Is it looking for
    the imported panel class name (i.e. Class imported (args) ),
    the instantiated panel class name (i.e. instantiated = imported() ),
    the imported script name,
    a global variable name,
    parent window name,
    parent frame name,
etc.?

Can someone translate this to something like:

FunctionCallingTheScript.PushEventHandler(InstantiatedNameOfMainFrameClass)

or whatever the correct implementation would be?
And, is that all there is to it, or do I have to prep something in the script-to-be-called, as well?

Rick Zoerner wrote:

Can someone explain to a non-C++ and new-to-Python programmer how to
implement the concept of PushEventHandler?

See below, you may not need it. IN any case, any kind of custom event handling is tricky, so don't be dismayed.

Frankly, words with an Asterisk after* them, double colons :: and
arrows just confuse me.

Have you read this?

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

It may help.

As a rule, you can just replace the :: and arrows => with ".", and pretend the * and & aren't there.

Actually, PushEventHandler may not even be the proper solution for my
problem.

I don't think it is.

Each imported module is to contain the panel(s) to display, a menubar
definition, and a toolbar definition, and all the event definitions
for the menu. Obviously, when selected, I need to set the
Main_Frame.MenuBar and ToolBar. What I can't manage is to get the
menu items to trigger event handling in the imported module instead
of just looking in the Main_Frame script.

What you need to do is pass the Main_Frame into your modules, and make sure you use that in your EVT* calls:

psuedo code example:

class MyNiftyPanel(wxPanel):
  def __init__(some stuff, MainFrame)
    some stuff
    
    EVT_MENU(MainFrame, ID_MENUID, self.Method)

Note that in most of the examples, teh first argument to EVT_MENU is "self" this is because it is most common for the menu to be constructed in the Frame __init__. What that parameter is is the Window that you want the event caught in.

I'm assuming the PushEventHandler function can solve this, but I
don't understand the documentation well enough to implement it.

PushEventHandler is pretty tricky (I don't think I've used it yet). As a rule you're only going to need that if you are making a custom control, so you need to manipulate the events in a custom way.

PushEventHandler(wxEvtHandler* handler)

Where does the command itself go? In the function that imports the
script or in the script to be imported? And, what does "wxEvtHandler*
handler" mean?

In C++, when a function is defined, you specify the type of the arguments, so this means that teh function is called with a wxEvtHandler object (actually a pointer to one, that's the * part, but that can be ignored in PYthon), so this function takes one argument, and it is a wxEvtHandler. Look in the reference to see what the heck that is, but you probably don't need it for this anyway.

By the way, until you really get comfortable reading the docs, you're best bet is to find an example, somewhere, that used the class or function you're trying to figure out. Look in the demo, look in the Wiki, then ask here. Note, a search on teh WIki for "wxEvtHandler" got me to this page:

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

Hey! I just noticed that that page is an answer to your question! It must have jsut been posted, so I guess I can excuse you for not finding it!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Rick Zoerner wrote:

Can someone explain to a non-C++ and new-to-Python programmer how to
implement the concept of PushEventHandler? Slowly, as if to a child,
because every attempted explanation I've seen so far only seems to
re-iterate exactly what it says in the wxWindows Reference (which I
quite obviously don't understand).

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

I'm trying to implement a simple interface similar to MS Outlook. Its
a Frame containing a SplitWindow . The left-hand panel is narrow and
holds a notebook (which will ultimately hold the icons to launch
various modules). The right-hand panel is going to be the main work
area.

My problem is that I would like to structure this program so that
seperate scripts are used for each "module" the program launches.
Each imported module is to contain the panel(s) to display, a menubar
definition, and a toolbar definition, and all the event definitions
for the menu. Obviously, when selected, I need to set the
Main_Frame.MenuBar and ToolBar. What I can't manage is to get the
menu items to trigger event handling in the imported module instead
of just looking in the Main_Frame script.

Menu events from the menubar (toolbar events too) are delivered to the frame, so they need to be caught there and then redirected to the module that has the current handlers. One way to solve that is to catch all menu events in a single handler in the main frame and then from that handler call some method in the current panel module that knows what to do with the event. The other way as you guessed is to use PushEventHandler. When you load the new menubar and toolbar for the new panel, you can also call frame's PushEventHandler (call PopEventHandler first to remove the old one if there is one,) with a new instance of a wxEvtHandler class that knows how to redirect those events to methods of your main panel class. In fact, since Python allows any callable object to be bound, the wxEvtHandler class can just call EVT_MENU using methods of the main panel itself, rather than self.

···

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

Thank You, Thank You, Thank You...

That was the best help in the most concise manner I think I've ever received. The explanation of why the docs always tell me to use "self" as the first parameter of EVT_MENU was, in particular, just the kind of thing I needed to know.

···

----- Original Message -----
  From: Chris Barker
  To: wxPython-users@lists.wxwindows.org
  Sent: Tuesday, December 23, 2003 9:14 AM
  Subject: Re: [wxPython-users] How to implement PushEventHandler?

  Rick Zoerner wrote:
  > Can someone explain to a non-C++ and new-to-Python programmer how to
  > implement the concept of PushEventHandler?

  See below, you may not need it. IN any case, any kind of custom event
  handling is tricky, so don't be dismayed.

  > Frankly, words with an Asterisk after* them, double colons :: and
  > arrows just confuse me.

  Have you read this?

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

  It may help.

  As a rule, you can just replace the :: and arrows => with ".", and
  pretend the * and & aren't there.

  > Actually, PushEventHandler may not even be the proper solution for my
  > problem.

  I don't think it is.

  > Each imported module is to contain the panel(s) to display, a menubar
  > definition, and a toolbar definition, and all the event definitions
  > for the menu. Obviously, when selected, I need to set the
  > Main_Frame.MenuBar and ToolBar. What I can't manage is to get the
  > menu items to trigger event handling in the imported module instead
  > of just looking in the Main_Frame script.

  What you need to do is pass the Main_Frame into your modules, and make
  sure you use that in your EVT* calls:

  psuedo code example:

  class MyNiftyPanel(wxPanel):
  def __init__(some stuff, MainFrame)
  some stuff

  EVT_MENU(MainFrame, ID_MENUID, self.Method)

  Note that in most of the examples, teh first argument to EVT_MENU is
  "self" this is because it is most common for the menu to be constructed
  in the Frame __init__. What that parameter is is the Window that you
  want the event caught in.

  > I'm assuming the PushEventHandler function can solve this, but I
  > don't understand the documentation well enough to implement it.

  PushEventHandler is pretty tricky (I don't think I've used it yet). As a
  rule you're only going to need that if you are making a custom control,
  so you need to manipulate the events in a custom way.

  > PushEventHandler(wxEvtHandler* handler)
  >
  > Where does the command itself go? In the function that imports the
  > script or in the script to be imported? And, what does "wxEvtHandler*
  > handler" mean?

  In C++, when a function is defined, you specify the type of the
  arguments, so this means that teh function is called with a wxEvtHandler
  object (actually a pointer to one, that's the * part, but that can be
  ignored in PYthon), so this function takes one argument, and it is a
  wxEvtHandler. Look in the reference to see what the heck that is, but
  you probably don't need it for this anyway.

  By the way, until you really get comfortable reading the docs, you're
  best bet is to find an example, somewhere, that used the class or
  function you're trying to figure out. Look in the demo, look in the
  Wiki, then ask here. Note, a search on teh WIki for "wxEvtHandler" got
  me to this page:

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

  Hey! I just noticed that that page is an answer to your question! It
  must have jsut been posted, so I guess I can excuse you for not finding it!

  -Chris

  --
  Christopher Barker, Ph.D.
  Oceanographer
                                       
  NOAA/OR&R/HAZMAT (206) 526-6959 voice
  7600 Sand Point Way NE (206) 526-6329 fax
  Seattle, WA 98115 (206) 526-6317 main reception

  Chris.Barker@noaa.gov

  ---------------------------------------------------------------------
  To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
  For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org