Permalink
Browse files

button event handling sorted out for firefox, safari, IE. they are di…

…fferent button numbers - standardise them all

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@1249 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
1 parent e62599b commit 933740d0f6133e30eba7a08e3e65bb6b733bc67f lkcl committed Aug 18, 2009
View
5 examples/toggle/Toggle.py
@@ -24,7 +24,7 @@ def onModuleLoad(self):
self.image_down = Image("./images/logo.png")
self.image_down3 = Image("./images/logo.png")
self.toggle = ToggleButton(self.image_up, self.image_down, self)
- self.toggle2 = ToggleButton("up", "down")
+ self.toggle2 = ToggleButton("up", "down", getattr(self, "onToggleUD"))
self.push = PushButton(self.image_up3, self.image_down3)
self.vpanel = VerticalPanel()
@@ -42,6 +42,9 @@ def onModuleLoad(self):
RootPanel().add(self.vpanel)
self.i = False
+ def onToggleUD(self, sender):
+ self.label.setText(" Toggle2 isdown: "+str(self.toggle2.isDown()))
+
def onClick(self, sender):
if sender == self.button:
if self.i:
View
10 library/__mozilla__/pyjamas/DOM.py
@@ -24,13 +24,13 @@ def compare(elem1, elem2):
def eventGetButton(evt):
JS("""
- var button = evt.button;
- if(button == 0) {
- return 1;
- } else if (button == 1) {
+ var button = evt.which;
+ if(button == 2) {
return 4;
+ } else if (button == 3) {
+ return 2;
} else {
- return button;
+ return button || 0;
}
""")
View
22 library/__safari__/pyjamas/DOM.py
@@ -79,3 +79,25 @@ def getAbsoluteTop(elem):
}
return top;
""")
+
+def eventGetButton(evt):
+ JS("""
+ var button = evt.which;
+ if(button == 2) {
+ return 4;
+ } else if (button == 3) {
+ return 2;
+ } else {
+ return button || 0;
+ }
+ """)
+
+def buttonClick(elem):
+ JS("""
+ var evt = $doc.createEvent('MouseEvents');
+ evt.initMouseEvent('click', true, true, null, 1, 0,
+ 0, 0, 0, false, false, false, false, 0, null);
+
+ elem.dispatchEvent(evt);
+ """)
+
View
9 library/pyjamas/ui/CustomButton.py
@@ -181,6 +181,10 @@ def __init__(self, upImageText = None, downImageText=None, listener = None,
**kwargs):
"""Constructor for CustomButton."""
+ if not kwargs.has_key('StyleName'): kwargs['StyleName']=self.STYLENAME_DEFAULT
+
+ ButtonBase.__init__(self, Focus.createFocusable(), **kwargs)
+
self.curFace = None # The button's current face.
self.curFaceElement = None # No "undefined" anymore
self.up = None # Face for up.
@@ -204,7 +208,7 @@ def __init__(self, upImageText = None, downImageText=None, listener = None,
# TODO: pyjslib.isinstance
if downImageText is None and listener is None:
- handler = upImageText
+ listener = upImageText
upImageText = None
if upImageText and isinstance(upImageText, str):
@@ -233,9 +237,6 @@ def __init__(self, upImageText = None, downImageText=None, listener = None,
# set the face UP
#self.setCurrentFace(self.getUpFace())
- if not kwargs.has_key('StyleName'): kwargs['StyleName']=self.STYLENAME_DEFAULT
-
- ButtonBase.__init__(self, Focus.createFocusable(), **kwargs)
self.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS
| Event.KEYEVENTS)
if listener: self.addClickListener(listener)
View
4 library/pyjamas/ui/Event.py
@@ -16,8 +16,8 @@
This module contains flags and integer values used by the event system.
"""
-BUTTON_LEFT = 0
-BUTTON_MIDDLE = 1
+BUTTON_LEFT = 1
+BUTTON_MIDDLE = 4
BUTTON_RIGHT = 2
ONBLUR = 0x01000

0 comments on commit 933740d

Please sign in to comment.