473,320 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Don't understand wxPython event handling

Hello list,

could somebody point me to a good reference about wxPython event handling?
I have seen many examples but which one is the best. Waht are the advantages
and disadvantages?

Can you also have a short look at the example below and give me some
comments, please?

Example:
I have implemented (or copied from somewhere) one event in two flavours.
Both work, but which one is the best? Or does anybody have a better
implementation.

EVT_NEXT_PAGE_ID = wxNewId()

def EVT_NEXT_PAGE( win, func ):
"""Your documentation here"""
win.Connect( -1, -1, EVT_NEXT_PAGE_ID, func )

class showNextPageEvent(wxPyEvent):
def __init__(self, windowID):
wxPyEvent.__init__(self)
self.SetEventType(EVT_NEXT_PAGE_ID)
or

EVT_NEXT_PAGE_TYPE = wxNewEventType()

def EVT_NEXT_PAGE( window, function ):
"""Your documentation here"""
window.Connect( -1, -1, EVT_NEXT_PAGE_TYPE, function )

class showNextPageEvent(wxPyCommandEvent):
eventType = EVT_NEXT_PAGE_TYPE
def __init__(self, windowID):
wxPyCommandEvent.__init__(self, self.eventType, windowID)
def Clone( self ):
self.__class__( self.GetId() )
Thank you

Robert
Jul 18 '05 #1
3 2852
I also have anouther question:

which is the better way to register to events:
eventManager.Register(self.OnPageDone,EVT_PAGE_DON E,self.pageContainer)

or

EVT_PAGE_DONE(self, self.OnPageDone)
Jul 18 '05 #2
Robert wrote:
Hello list,

could somebody point me to a good reference about wxPython event handling?
I have seen many examples but which one is the best. Waht are the advantages
and disadvantages?
http://wiki.wxpython.org/index.cgi/RecipesEvents
http://wxwidgets.org/manuals/2.5.1/w...goverview.html
The wxPython demo
etc.

Can you also have a short look at the example below and give me some
comments, please?

Example:
I have implemented (or copied from somewhere) one event in two flavours.
Both work, but which one is the best? Or does anybody have a better
implementation.

EVT_NEXT_PAGE_ID = wxNewId()
wxNewId is meant for window/menuItem/toolbarItem IDs. wxNewEventType
should be used for, uh, new eventTypes ;-)


def EVT_NEXT_PAGE( win, func ):
"""Your documentation here"""
win.Connect( -1, -1, EVT_NEXT_PAGE_ID, func )

class showNextPageEvent(wxPyEvent):
def __init__(self, windowID):
wxPyEvent.__init__(self)
self.SetEventType(EVT_NEXT_PAGE_ID)


This is fine (or deriving from wxPyCommandEvent if you want the event to
propgate to parent windows,) but even better is to use the newevent
module in the wxPython library. It contains functions that generate on
the fly an event class and binder function similar to the above for you,
but it will help your code to be future proof in case things change in
future releases.

import wx.lib.newevent
showNextPageEvent, EVT_NEXT_PAGE = wx.lib.newevent.NewEvent()

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

Jul 18 '05 #3
Robert wrote:
I also have anouther question:

which is the better way to register to events:
eventManager.Register(self.OnPageDone,EVT_PAGE_DON E,self.pageContainer)

or

EVT_PAGE_DONE(self, self.OnPageDone)


Short answer: It depends.

Long answer: The eventManager sits on top of a Publish/Subscribe
framework (Observer design pattern) so it is useful if you want to have
lots of handlers for a specific event and/or if you want your handlers
to be loosly coupled with the windows where the event was generated. If
you put your handlers in the same class as the window that generated the
event (or a parent window) then using the simpler form is just fine.

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

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Grant Edwards | last post by:
I've decided to learn wxPython, and I'm afraid I just don't grok the whole "id" thing where you have to pull unique integers out of your, er, the air and then use those to refer to objects: ...
8
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the...
12
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. ...
3
by: johncee | last post by:
Greetings, I created a base class that has a datagrid. I've made it generic as possible so that any derived classes pass some info to the base constructor (including a SQL select stmt) &...
5
by: Richard Grant | last post by:
Hi, I need to "save" in a variable the event handler sub of a control's event, then perform some process, and finally "restore" the originally saved event handler. Example in pseudo-code: 1)...
4
by: reggiestyles | last post by:
Hi, I've got a question about prototype and event handling. I've got several div's (dynamic number) on a page that I want to set as active or inactive (basically, I'm using scriptaculous'...
4
by: StepanM | last post by:
Problem with event handling in FireFox. I have two controls on HTML page: ListBox and TextBox (<selectand <input>). Both controls have event "onchange" and functions for this event (e.g....
5
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create...
5
by: Thierry | last post by:
Hello fellow pythonists, I'm a relatively new python developer, and I try to adjust my understanding about "how things works" to python, but I have hit a block, that I cannot understand. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.