Skip to content
This repository
Browse code

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...
commit 933740d0f6133e30eba7a08e3e65bb6b733bc67f 1 parent e62599b
authored August 18, 2009
5  examples/toggle/Toggle.py
@@ -24,7 +24,7 @@ def onModuleLoad(self):
24 24
         self.image_down = Image("./images/logo.png")
25 25
         self.image_down3 = Image("./images/logo.png")
26 26
         self.toggle = ToggleButton(self.image_up, self.image_down, self)
27  
-        self.toggle2 = ToggleButton("up", "down")
  27
+        self.toggle2 = ToggleButton("up", "down", getattr(self, "onToggleUD"))
28 28
         self.push = PushButton(self.image_up3, self.image_down3)
29 29
         
30 30
         self.vpanel = VerticalPanel()
@@ -42,6 +42,9 @@ def onModuleLoad(self):
42 42
         RootPanel().add(self.vpanel)
43 43
         self.i = False
44 44
         
  45
+    def onToggleUD(self, sender):
  46
+            self.label.setText(" Toggle2 isdown: "+str(self.toggle2.isDown()))
  47
+
45 48
     def onClick(self, sender):
46 49
         if sender == self.button:
47 50
             if self.i: 
10  library/__mozilla__/pyjamas/DOM.py
@@ -24,13 +24,13 @@ def compare(elem1, elem2):
24 24
 
25 25
 def eventGetButton(evt):
26 26
     JS("""
27  
-    var button = evt.button;
28  
-    if(button == 0) {
29  
-        return 1;
30  
-    } else if (button == 1) {
  27
+    var button = evt.which;
  28
+    if(button == 2) {
31 29
         return 4;
  30
+    } else if (button == 3) {
  31
+        return 2;
32 32
     } else {
33  
-        return button;
  33
+        return button || 0;
34 34
     }
35 35
     """)
36 36
 
22  library/__safari__/pyjamas/DOM.py
@@ -79,3 +79,25 @@ def getAbsoluteTop(elem):
79 79
     }
80 80
     return top;
81 81
     """)
  82
+
  83
+def eventGetButton(evt):
  84
+    JS("""
  85
+    var button = evt.which;
  86
+    if(button == 2) {
  87
+        return 4;
  88
+    } else if (button == 3) {
  89
+        return 2;
  90
+    } else {
  91
+        return button || 0;
  92
+    }
  93
+    """)
  94
+
  95
+def buttonClick(elem):
  96
+    JS("""
  97
+        var evt = $doc.createEvent('MouseEvents');
  98
+        evt.initMouseEvent('click', true, true, null, 1, 0,
  99
+                    0, 0, 0, false, false, false, false, 0, null);
  100
+
  101
+        elem.dispatchEvent(evt);
  102
+    """)
  103
+
9  library/pyjamas/ui/CustomButton.py
@@ -181,6 +181,10 @@ def __init__(self, upImageText = None, downImageText=None, listener = None,
181 181
                        **kwargs):
182 182
         """Constructor for CustomButton."""
183 183
         
  184
+        if not kwargs.has_key('StyleName'): kwargs['StyleName']=self.STYLENAME_DEFAULT
  185
+        
  186
+        ButtonBase.__init__(self, Focus.createFocusable(), **kwargs)
  187
+
184 188
         self.curFace      = None # The button's current face.
185 189
         self.curFaceElement = None # No "undefined" anymore
186 190
         self.up           = None # Face for up.
@@ -204,7 +208,7 @@ def __init__(self, upImageText = None, downImageText=None, listener = None,
204 208
     
205 209
         # TODO: pyjslib.isinstance
206 210
         if downImageText is None and listener is None:
207  
-            handler = upImageText
  211
+            listener = upImageText
208 212
             upImageText = None
209 213
 
210 214
         if upImageText and isinstance(upImageText, str):
@@ -233,9 +237,6 @@ def __init__(self, upImageText = None, downImageText=None, listener = None,
233 237
         # set the face UP
234 238
         #self.setCurrentFace(self.getUpFace())
235 239
     
236  
-        if not kwargs.has_key('StyleName'): kwargs['StyleName']=self.STYLENAME_DEFAULT
237  
-        
238  
-        ButtonBase.__init__(self, Focus.createFocusable(), **kwargs)
239 240
         self.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS
240 241
                         | Event.KEYEVENTS)
241 242
         if listener: self.addClickListener(listener)
4  library/pyjamas/ui/Event.py
@@ -16,8 +16,8 @@
16 16
     This module contains flags and integer values used by the event system.
17 17
 """
18 18
 
19  
-BUTTON_LEFT   = 0
20  
-BUTTON_MIDDLE = 1
  19
+BUTTON_LEFT   = 1
  20
+BUTTON_MIDDLE = 4
21 21
 BUTTON_RIGHT  = 2
22 22
 
23 23
 ONBLUR        = 0x01000

0 notes on commit 933740d

Please sign in to comment.
Something went wrong with that request. Please try again.