Skip to content

Commit

Permalink
add click override example
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Leighton committed Aug 18, 2010
1 parent 64dd190 commit d906964
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
Empty file.
61 changes: 61 additions & 0 deletions examples/clickoverride/Override.py
@@ -0,0 +1,61 @@
""" This example shows how to check in onBrowserEvent whether the
event targets a child, and if so refuse to handle it, so that
the child widget will be the only widget dealing with it.
see _event_targets_title() for details.
"""

import pyjd # dummy in pyjs

from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.HTML import HTML
from pyjamas.ui.ClickListener import ClickHandler
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui import Event
from pyjamas import log
from pyjamas import DOM

class Board(VerticalPanel, ClickHandler):
def __init__(self):
""" Standard initialiser.
"""
VerticalPanel.__init__(self)
ClickHandler.__init__(self)
self.addClickListener(self)
self.title=Text('Board')
self.title.setzIndex(100)
self.add(self.title)
self.setSize("100%", "50%")
self.setBorderWidth(1)

def onClick(self, sender):
log.writebr('Text'+str(sender))

def _event_targets_title(self, event):
target = DOM.eventGetTarget(event)
return target and DOM.isOrHasChild(self.title.getElement(), target)

def onBrowserEvent(self, event):
etype = DOM.eventGetType(event)
if etype == "click":
if self._event_targets_title(event):
return
ClickHandler.onBrowserEvent(self, event)


class Text(HTML, ClickHandler):
def __init__(self, text):
HTML.__init__(self, text)
ClickHandler.__init__(self, preventDefault=True)
self.addClickListener(self)

def onClick(self, sender):
log.writebr('Text'+str(sender))


if __name__ == "__main__":
pyjd.setup("./Override.html")
board = Board()
RootPanel().add(board)
pyjd.run()

9 changes: 1 addition & 8 deletions library/pyjamas/ui/__init__.py
Expand Up @@ -78,14 +78,7 @@ def __init__(self, **kwargs):


def applyValues(self, **kwargs): def applyValues(self, **kwargs):


if not kwargs: for (prop, args) in kwargs.items():
return
k = kwargs.keys()
l = len(k)
i = -1
while i < l-1:
i += 1
prop = k[i]
fn = getattr(self, "set%s" % prop, None) fn = getattr(self, "set%s" % prop, None)
if not fn: if not fn:
return return
Expand Down

0 comments on commit d906964

Please sign in to comment.