Permalink
Browse files

#152 - added and fixed up Toggle at same time

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@901 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
1 parent 1284de5 commit 79e730581bb00aa29bee72b1ff3eea107431ba7c lkcl committed Jul 11, 2009
View
@@ -1,6 +1,11 @@
Changes made to Pyjamas since 0.5p1
-----------------------------------
+ * #152 - added buttonClick and fixed up CustomButton (see Toggle example)
+ at same time. EVENT.BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT had wrong
+ #defines as well: only CustomButton was using them which was why nobody
+ noticed.
+
* Allowed all widget constructors to take kwargs which will result
in the setXXXX method being called. Tuples as kwargs will result
in *args to the setXXXX method e.g.
@@ -60,7 +60,7 @@ def onClick(self, sender):
text = ">>>DOWN<<<"
if self.i: text = ">>>>UP<<<<"
self.i = not self.i
- self.label.setText(text+" isdown: "+self.toggle.isDown())
+ self.label.setText(text+" isdown: "+str(self.toggle.isDown()))
if __name__ == "__main__":
@@ -88,6 +88,11 @@ def init():
def addEventPreview(preview):
sEventPreviewStack.append(preview)
+def buttonClick(button):
+ JS("""
+ button.click();
+ """)
+
def appendChild(parent, child):
JS("""
parent.appendChild(child);
@@ -1,3 +1,14 @@
+def buttonClick(button):
+ JS("""
+ var doc = button.ownerDocument;
+ if (doc != null) {
+ var evt = doc.createEvent('MouseEvents');
+ evt.initMouseEvent('click', true, true, null, 0, 0,
+ 0, 0, 0, false, false, false, false, 0, null);
+ button.dispatchEvent(evt);
+ }
+ """)
+
def compare(elem1, elem2):
JS("""
if (!elem1 && !elem2) {
View
@@ -146,6 +146,12 @@ def appendChild(parent, child):
#print "appendChild", parent, child
parent.appendChild(child)
+def buttonClick(element):
+ evt = doc().createEvent('MouseEvents')
+ evt.initMouseEvent("click", True, True, wnd(), 1, 0, 0, 0, 0, False,
+ False, False, False, 0, element)
+ element.dispatchEvent(evt)
+
def compare(elem1, elem2):
return elem1.isSameNode(elem2)
@@ -13,8 +13,6 @@
# the License.
import sys
-if sys.platform not in ['mozilla', 'ie6', 'opera', 'oldmoz', 'safari']:
- from pyjamas.__pyjamas__ import doc, wnd
from pyjamas import DOM
from pyjamas.ui import Event
@@ -371,7 +369,6 @@ def onBrowserEvent(self, event):
self.isCapturing = False
self.onClickCancel()
-
ButtonBase.onBrowserEvent(self, event)
# Synthesize clicks based on keyboard events AFTER the normal
@@ -471,11 +468,7 @@ def onClick(self, sender=None):
# there is a good explanation about all the arguments of initMouseEvent
# at: https://developer.mozilla.org/En/DOM:event.initMouseEvent
- evt = doc().createEvent('MouseEvents')
- evt.initMouseEvent("click", true, true, wnd(), 1, 0, 0, 0, 0, false,
- false, false, false, 0, null)
-
- self.getElement().dispatchEvent(evt)
+ DOM.buttonClick(self.getElement())
self.allowClick = False
@@ -16,8 +16,8 @@
This module contains flags and integer values used by the event system.
"""
-BUTTON_LEFT = 1
-BUTTON_MIDDLE = 4
+BUTTON_LEFT = 0
+BUTTON_MIDDLE = 1
BUTTON_RIGHT = 2
ONBLUR = 0x01000

0 comments on commit 79e7305

Please sign in to comment.