]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/newevent.py
1 """Easy generation of new events classes and binder objects"""
3 __author__
= "Miki Tebeka <tebeka@cs.bgu.ac.il>"
7 #---------------------------------------------------------------------------
10 """Generate new (Event, Binder) tuple
11 e.g. MooEvent, EVT_MOO = NewEvent()
13 evttype
= wx
.NewEventType()
15 class _Event(wx
.PyEvent
):
16 def __init__(self
, **kw
):
17 wx
.PyEvent
.__init
__(self
)
18 self
.SetEventType(evttype
)
19 self
.__dict
__.update(kw
)
21 return _Event
, wx
.PyEventBinder(evttype
)
25 def NewCommandEvent():
26 """Generate new (CmdEvent, Binder) tuple
27 e.g. MooCmdEvent, EVT_MOO = NewCommandEvent()
29 evttype
= wx
.NewEventType()
31 class _Event(wx
.PyCommandEvent
):
32 def __init__(self
, id, **kw
):
33 wx
.PyCommandEvent
.__init
__(self
, evttype
, id)
34 self
.__dict
__.update(kw
)
36 return _Event
, wx
.PyEventBinder(evttype
, 1)
39 #---------------------------------------------------------------------------
42 """A little smoke test"""
43 from threading
import Thread
44 from time
import sleep
46 MooEvent
, EVT_MOO
= NewEvent()
47 GooEvent
, EVT_GOO
= NewCommandEvent()
53 wx
.PostEvent(win
, MooEvent(moo
=1))
57 wx
.PostEvent(win
, GooEvent(id, goo
=id))
62 class Frame(wx
.Frame
):
64 wx
.Frame
.__init
__(self
, None, -1, "MOO")
65 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
66 EVT_MOO(self
, self
.on_moo
)
67 b
= wx
.Button(self
, -1, "Generate MOO")
68 sizer
.Add(b
, 1, wx
.EXPAND
)
69 wx
.EVT_BUTTON(self
, b
.GetId(), self
.on_evt_click
)
70 b
= wx
.Button(self
, ID_CMD1
, "Generate GOO with %d" % ID_CMD1
)
71 sizer
.Add(b
, 1, wx
.EXPAND
)
72 wx
.EVT_BUTTON(self
, ID_CMD1
, self
.on_cmd_click
)
73 b
= wx
.Button(self
, ID_CMD2
, "Generate GOO with %d" % ID_CMD2
)
74 sizer
.Add(b
, 1, wx
.EXPAND
)
75 wx
.EVT_BUTTON(self
, ID_CMD2
, self
.on_cmd_click
)
77 EVT_GOO(self
, ID_CMD1
, self
.on_cmd1
)
78 EVT_GOO(self
, ID_CMD2
, self
.on_cmd2
)
81 self
.SetAutoLayout(True)
84 def on_evt_click(self
, e
):
85 t
= Thread(target
=evt_thr
, args
=(self
, ))
89 def on_cmd_click(self
, e
):
90 t
= Thread(target
=cmd_thr
, args
=(self
, e
.GetId()))
94 def show(self
, msg
, title
):
95 dlg
= wx
.MessageDialog(self
, msg
, title
, wx
.OK
)
100 self
.show("MOO = %s" % e
.moo
, "Got Moo")
102 def on_cmd1(self
, e
):
103 self
.show("goo = %s" % e
.goo
, "Got Goo (cmd1)")
105 def on_cmd2(self
, e
):
106 self
.show("goo = %s" % e
.goo
, "Got Goo (cmd2)")
109 app
= wx
.PySimpleApp()
114 if __name__
== "__main__":