Patch from Robb, among other things removes the unconditional event.Skip()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18614 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -34,7 +34,7 @@ This module is Python 2.1+ compatible.
|
|||||||
|
|
||||||
Author: Robb Shecter
|
Author: Robb Shecter
|
||||||
"""
|
"""
|
||||||
|
from wxPython import wx
|
||||||
import pubsub
|
import pubsub
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
@@ -86,7 +86,8 @@ class EventManager:
|
|||||||
if source is not None:
|
if source is not None:
|
||||||
id = source.GetId()
|
id = source.GetId()
|
||||||
if win is None:
|
if win is None:
|
||||||
win = source
|
# Some widgets do not function as their own windows.
|
||||||
|
win = self._determineWindow(source)
|
||||||
topic = (event, win, id)
|
topic = (event, win, id)
|
||||||
|
|
||||||
# Create an adapter from the PS system back to wxEvents, and
|
# Create an adapter from the PS system back to wxEvents, and
|
||||||
@@ -132,7 +133,7 @@ class EventManager:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Some aliases for Register
|
# Some aliases for Register, just for kicks
|
||||||
Bind = Register
|
Bind = Register
|
||||||
Subscribe = Register
|
Subscribe = Register
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ class EventManager:
|
|||||||
"""
|
"""
|
||||||
Deregister all events coming from the given window.
|
Deregister all events coming from the given window.
|
||||||
"""
|
"""
|
||||||
|
win = self._determineWindow(win)
|
||||||
topics = self.__getTopics(win)
|
topics = self.__getTopics(win)
|
||||||
if topics:
|
if topics:
|
||||||
for aTopic in topics:
|
for aTopic in topics:
|
||||||
@@ -206,12 +208,11 @@ class EventManager:
|
|||||||
"""
|
"""
|
||||||
A string rep of a window for debugging
|
A string rep of a window for debugging
|
||||||
"""
|
"""
|
||||||
from wxPython.wx import wxPyDeadObjectError
|
|
||||||
try:
|
try:
|
||||||
name = aWin.GetClassName()
|
name = aWin.GetClassName()
|
||||||
i = id(aWin)
|
i = id(aWin)
|
||||||
return '%s #%d' % (name, i)
|
return '%s #%d' % (name, i)
|
||||||
except wxPyDeadObjectError:
|
except wx.wxPyDeadObjectError:
|
||||||
return '(dead wxObject)'
|
return '(dead wxObject)'
|
||||||
|
|
||||||
|
|
||||||
@@ -257,8 +258,7 @@ class EventManager:
|
|||||||
|
|
||||||
|
|
||||||
def __isDeadWxObject(self, anObject):
|
def __isDeadWxObject(self, anObject):
|
||||||
from wxPython.wx import _wxPyDeadObject
|
return isinstance(anObject, wx._wxPyDeadObject)
|
||||||
return isinstance(anObject, _wxPyDeadObject)
|
|
||||||
|
|
||||||
|
|
||||||
def __isDeadTopic(self, aTopic):
|
def __isDeadTopic(self, aTopic):
|
||||||
@@ -276,6 +276,22 @@ class EventManager:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def _determineWindow(self, aComponent):
|
||||||
|
"""
|
||||||
|
Return the window that corresponds to this component.
|
||||||
|
A window is something that supports the Connect protocol.
|
||||||
|
Most things registered with the event manager are a window,
|
||||||
|
but there are apparently some exceptions. If more are
|
||||||
|
discovered, the implementation can be changed to a dictionary
|
||||||
|
lookup along the lines of class : function-to-get-window.
|
||||||
|
"""
|
||||||
|
if isinstance(aComponent, wx.wxMenuItem):
|
||||||
|
return aComponent.GetMenu()
|
||||||
|
else:
|
||||||
|
return aComponent
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# From here down is implementaion and support classes, although you may
|
# From here down is implementaion and support classes, although you may
|
||||||
# find some of them useful in other contexts.
|
# find some of them useful in other contexts.
|
||||||
@@ -351,11 +367,10 @@ class EventMacroInfo:
|
|||||||
|
|
||||||
class FakeWindow:
|
class FakeWindow:
|
||||||
"""
|
"""
|
||||||
Used internally by the EventMacroInfo class. The
|
Used internally by the EventMacroInfo class. The FakeWindow is
|
||||||
FakeWindow is the most important component of the
|
the most important component of the macro-info utility: it
|
||||||
macro-info utility: it implements the Connect()
|
implements the Connect() protocol of wxWindow, but instead of
|
||||||
protocol of wxWindow, but instead of registering
|
registering for events, it keeps track of what parameters were
|
||||||
for events, it keeps track of what parameters were
|
|
||||||
passed to it.
|
passed to it.
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -412,11 +427,10 @@ class EventAdapter:
|
|||||||
|
|
||||||
|
|
||||||
def Destroy(self):
|
def Destroy(self):
|
||||||
from wxPython.wx import wxPyDeadObjectError
|
|
||||||
try:
|
try:
|
||||||
if not self.disconnect():
|
if not self.disconnect():
|
||||||
print 'disconnect failed'
|
print 'disconnect failed'
|
||||||
except wxPyDeadObjectError:
|
except wx.wxPyDeadObjectError:
|
||||||
print 'disconnect failed: dead object' ##????
|
print 'disconnect failed: dead object' ##????
|
||||||
|
|
||||||
|
|
||||||
@@ -443,17 +457,14 @@ class MessageAdapter:
|
|||||||
given eventHandler.
|
given eventHandler.
|
||||||
"""
|
"""
|
||||||
self.eventHandler = eventHandler
|
self.eventHandler = eventHandler
|
||||||
pubsub.Publisher().subscribe(listener=self.notify, topic=(topicPattern,))
|
pubsub.Publisher().subscribe(listener=self.deliverEvent, topic=(topicPattern,))
|
||||||
|
|
||||||
|
def deliverEvent(self, message):
|
||||||
def notify(self, message):
|
|
||||||
event = message.data # Extract the wxEvent
|
event = message.data # Extract the wxEvent
|
||||||
self.eventHandler(event) # Perform the call as wxWindows would
|
self.eventHandler(event) # Perform the call as wxWindows would
|
||||||
##event.Skip(1) # Make sure Skip(1) wasn't set. ##????
|
|
||||||
|
|
||||||
|
|
||||||
def Destroy(self):
|
def Destroy(self):
|
||||||
pubsub.Publisher().unsubscribe(listener=self.notify)
|
pubsub.Publisher().unsubscribe(listener=self.deliverEvent)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
@@ -485,22 +496,22 @@ if __name__ == '__main__':
|
|||||||
# one event, and 3) Multiple events going to one listener.
|
# one event, and 3) Multiple events going to one listener.
|
||||||
#
|
#
|
||||||
|
|
||||||
def handleEvents(event):
|
def printEvent(event):
|
||||||
print event.GetClassName(), event.GetTimestamp()
|
print 'Name:',event.GetClassName(),'Timestamp',event.GetTimestamp()
|
||||||
|
|
||||||
def enableFrameEvents(event):
|
def enableFrameEvents(event):
|
||||||
# Turn the output of mouse events on and off
|
# Turn the output of mouse events on and off
|
||||||
if event.IsChecked():
|
if event.IsChecked():
|
||||||
print '\nEnabling mouse events...'
|
print '\nEnabling mouse events...'
|
||||||
eventManager.Register(handleEvents, EVT_MOTION, frame)
|
eventManager.Register(printEvent, EVT_MOTION, frame)
|
||||||
eventManager.Register(handleEvents, EVT_LEFT_DOWN, frame)
|
eventManager.Register(printEvent, EVT_LEFT_DOWN, frame)
|
||||||
else:
|
else:
|
||||||
print '\nDisabling mouse events...'
|
print '\nDisabling mouse events...'
|
||||||
eventManager.DeregisterWindow(frame)
|
eventManager.DeregisterWindow(frame)
|
||||||
|
|
||||||
# Send togglebutton events to both the on/off code as well
|
# Send togglebutton events to both the on/off code as well
|
||||||
# as the function that prints to stdout.
|
# as the function that prints to stdout.
|
||||||
eventManager.Register(handleEvents, EVT_TOGGLEBUTTON, button)
|
eventManager.Register(printEvent, EVT_TOGGLEBUTTON, button)
|
||||||
eventManager.Register(enableFrameEvents, EVT_TOGGLEBUTTON, button)
|
eventManager.Register(enableFrameEvents, EVT_TOGGLEBUTTON, button)
|
||||||
|
|
||||||
frame.CenterOnScreen()
|
frame.CenterOnScreen()
|
||||||
|
Reference in New Issue
Block a user