So in the code below, I'm binding some events to a text control in
wxPython. The way I've been doing it is demonstrated with the
Lame_Event_Widg et class. I want to factor out the repeating
patterns. Cool_Event_Widg et is my attempt at this. It pretty much
works, but I have a feeling there's a better way of doing this. Also,
I couldn't get the Cool_Text_Contr ol to override the on_text method.
How would I do that?
-------------
import textwrap, new
import wx
class Lame_Event_Widg et:
def bind_events(sel f):
self.Bind(wx.EV T_LEFT_DOWN, self.on_left_do wn)
self.Bind(wx.EV T_RIGHT_DOWN, self.on_right_d own)
self.Bind(wx.EV T_MIDDLE_DOWN, self.on_middle_ down)
self.Bind(wx.EV T_LEFT_UP, self.on_left_up )
self.Bind(wx.EV T_RIGHT_UP, self.on_right_u p)
self.Bind(wx.EV T_TEXT, self.on_text)
def on_left_down(se lf, e):
print "lame normal method: on_left_down"
e.Skip()
def on_right_down(s elf, e):
print "lame normal method: on_right_down"
e.Skip()
def on_middle_down( self, e):
print "lame normal method: on_middle_down"
e.Skip()
def on_left_up(self , e):
print "lame normal method: on_left_up"
e.Skip()
def on_right_up(sel f, e):
print "lame normal method: on_right_up"
e.Skip()
def on_text(self, e):
print "lame normal method: on_text"
e.Skip()
class Cool_Event_Widg et:
def bind_events(sel f):
method_names = textwrap.dedent (
"""
on_left_down, on_right_down, on_middle_down,
on_left_up, on_right_up, on_middle_up,
on_text"""
).replace("\n", "").split(" , ")
for name in method_names:
event_name = name.partition( "_")[2]
event_name = "wx.EVT_" + event_name.uppe r()
exec("def " + name + "(self, e):\n" +
" print 'cool dynamic method: " + name + "'\n" +
" e.Skip()\n"
"self." + name + " = new.instancemet hod(" + name + ",
self, self.__class__) \n"
"self.Bind( " + event_name + ", self." + name + ")")
if __name__ == "__main__":
app = wx.App()
frame = wx.Frame(None)
panel = wx.Panel(frame)
sizer = wx.BoxSizer(wx. VERTICAL)
panel.SetSizer( sizer)
class Cool_Text_Contr ol(wx.TextCtrl, Cool_Event_Widg et):
def __init__(self, parent):
wx.TextCtrl.__i nit__(self, parent)
self.bind_event s()
def on_text(self, e):
print "modified text in Cool_Text_Contr ol"
class Lame_Text_Contr ol(wx.TextCtrl, Lame_Event_Widg et):
def __init__(self, parent):
wx.TextCtrl.__i nit__(self, parent)
self.bind_event s()
def on_text(self, e):
print "modified text in Lame_Text_Contr ol"
sizer.Add(Cool_ Text_Control(pa nel))
sizer.Add(Lame_ Text_Control(pa nel))
frame.Show()
app.MainLoop() 0 923 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stephen Gennard |
last post by:
Hello,
I having a problem dynamically invoking a static method that takes a
reference to a SByte*. If I do it directly it works just fine.
Anyone any ideas why?
I have include a example below...
--
|
by: MikeY |
last post by:
Hi Everyone,
Does anyone know where I can get my hands on a sample with source code of a
simple dynamic button control in C# Windows form. I am looking for a sample
that uses a class library that sets the properties send/passed from the main
windows form. I'm having problems with the class library, the button control
collection and my referencing it ie this.Control.Add(aControl);.
Any and all help is appreciated. Thanks in advance.
|
by: sleigh |
last post by:
Hello,
I'm building a web application that will build a dynamic form based
upon questions in a database. This form will have several different
sections that consist of a panel containing one to many questions.
To keep it simple, I'll describe the basics of what I'm trying to
design.
I've created a TextBox composite control that consists of a label for
|
by: Venus |
last post by:
Hello,
Thanks for your reply.
I understand that a control can be created dynamically in several ways:
1) using StringBuilder
2) using Controls.Add
3) using ASP PlaceHolder
But this is just for the controls and not for the form itself.
What I am trying to achieve is to create an entire form (including controls)
|
by: Leo J. Hart IV |
last post by:
OK, here's another question for the experts:
I am building a multi-step (3 steps actually) form using a panel for
each step and hiding/displaying the appropriate panel/panels depending
on which step you're on. This all works fine, but I ran into some
trouble when I started creating controls dynamically in my code-behind
file.
Each panel contains a table which is filled with various radio buttons,
text fields and the such which are...
| |
by: serge |
last post by:
How can I run a single SP by asking multiple sales question either
by using the logical operator AND for all the questions; or using
the logical operator OR for all the questions. So it's always
either AND or OR but never mixed together.
We can use Northwind database for my question, it is very similar
to the structure of the problem on the database I am working on.
IF(SELECT OBJECT_ID('REPORT')) IS NOT NULL
DROP TABLE REPORT_SELECTION
|
by: toton |
last post by:
Hi,
I have little confusion about static memory allocation & dynamic
allocation for a cluss member.
I have class like
class Bar{
public:
explicit Bar(){
cout<<"bar default"<<endl;
}
|
by: mcgrew.michael |
last post by:
I hope this is the right group. I am very new to ASP so this is
probably a stupid question. I have some vbscript that query's AD and
populates a recordset. I know the recorset contains the information I
want by doing a Response.write. I am having problems dynamically
creating a drop down list from the data in the recordset. The drop down
is created but it is empty. Any help would be greatly appreciated. A
sample of the code:
<%
'On...
|
by: pjr |
last post by:
Using VS2005, I dynamically create an event delegate. Code follows question.
My method gets the event's parameters and passes them onto a common event handler. My delegate gets called when expected and in turn, calls my common event handler. However, once in the common event handler code, the "this pointer" is wrong and hence I can't access other class properties and methods.
Even if I invoke the dynamic method directly, the "this pointer" is...
|
by: pbd22 |
last post by:
Hi.
This is just a disaster management question.
I am using XMLHTTP for the dynamic loading of content in a very
crucial area of my web site. Same as an IFrame, but using XMLHTTP and
a DIV. I got the core of the javascript from here:
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm
I noticed in the demo that sometimes the content takes a long
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |