473,883 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_I D = wxNewId()

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

class showNextPageEve nt(wxPyEvent):
def __init__(self, windowID):
wxPyEvent.__ini t__(self)
self.SetEventTy pe(EVT_NEXT_PAG E_ID)
or

EVT_NEXT_PAGE_T YPE = wxNewEventType( )

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

class showNextPageEve nt(wxPyCommandE vent):
eventType = EVT_NEXT_PAGE_T YPE
def __init__(self, windowID):
wxPyCommandEven t.__init__(self , self.eventType, windowID)
def Clone( self ):
self.__class__( self.GetId() )
Thank you

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

which is the better way to register to events:
eventManager.Re gister(self.OnP ageDone,EVT_PAG E_DONE,self.pag eContainer)

or

EVT_PAGE_DONE(s elf, 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_I D = 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_I D, func )

class showNextPageEve nt(wxPyEvent):
def __init__(self, windowID):
wxPyEvent.__ini t__(self)
self.SetEventTy pe(EVT_NEXT_PAG E_ID)


This is fine (or deriving from wxPyCommandEven t 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
showNextPageEve nt, 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.Re gister(self.OnP ageDone,EVT_PAG E_DONE,self.pag eContainer)

or

EVT_PAGE_DONE(s elf, 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
3440
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: From whe wxPython wiki examples: self.button =wxButton(self, 10, "Save", wxPoint(200, 325)) EVT_BUTTON(self, 10, self.OnClick)
8
2835
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 boxes and saving to the database at the end with the 'Submit' command button. Is it possible to save the changes as the checkboxes are clicked? I suppose I'd need to write some dynamic ASP event handling at the same time as creating the checkboxes......
12
4157
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. However in vb.net you get continual messages (even setting the system modal property). Firstly, are these two assumptions right and if so what is the approved
3
1478
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) & through the base class, any db table can be displayed/maintained in the grid. I've made some of the base class' event-handling subs overridable and in some of the derived classes using the base, the subs are being overridden:
5
1899
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) Save cmbMyCombo's event handler for SelectedIndexChange event. 2) Assign a temporary event handler sub to cmbMyCombo's for its SelectedIndexChange event.
4
2099
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' Effects to set Opacity to 1 for the active div and 0.5 for the inactive ones). Using prototype's event handling, I can see two ways to get this done:
4
3933
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. select_onchange and text_onchage). If I select item in ListBox, than I enter text in TextBox, and than I finally select other item in ListBox, then both events fires simultaneously (it can be checked up, if in both functions write a corresponding "alert",...
5
4305
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 delegate: public class DelegateEx {
5
2608
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 needed to output unicode datas back from a web service, and could not get back unicode/multibyte text before applying an hack that I don't understand (thank you google) I have realized an wxPython simple application, that takes the input
0
11160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10422
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9588
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7978
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5807
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6007
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4622
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4230
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3241
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.