Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make a manageRootPanel function and add it into clickablerootpanel ex…

…ample

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@2276 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
commit e266d9cedc723ece23b2b2cea6d36c0381a26a12 1 parent df93f40
lkcl authored
View
31 examples/clickablerootpanel/ClickableRootPanel.py
@@ -1,6 +1,6 @@
import pyjd # this is dummy in pyjs.
-from pyjamas.ui.RootPanel import RootPanelCls, RootPanel
+from pyjamas.ui.RootPanel import RootPanelCls, RootPanel, manageRootPanel
from pyjamas.ui.Button import Button
from pyjamas.ui.FocusPanel import FocusPanel
from pyjamas.ui.KeyboardListener import KeyboardHandler
@@ -24,7 +24,9 @@ def __init__(self, Parent, *args, **kwargs):
def onClick(self, Sender):
self.focussed = not self.focussed
self.Parent.setFocus(self.focussed)
- self.add(HTML('focus: %s' % (self.focussed and 'yes' or 'no')))
+
+ txt = self.focussed and 'yes. now press keys' or 'no. keys fail now'
+ self.add(HTML('focus: %s' % txt))
def onKeyDown(self, sender, keyCode, modifiers = None):
self.add(HTML('keyDOWN: %d' % keyCode))
@@ -49,6 +51,23 @@ def marginset(fred):
panel = FocusPanel(Widget=h)
gp = RootPanelListener(panel, StyleName='rootstyle')
+ # as this is replacing the 'normal' usage of RootPanel(),
+ # it is necessary to add this in 'by hand' so that the
+ # window-close notification is 'hooked into', and so when
+ # the browser window is closed, cleanups (onDetach) will
+ # be triggered.
+ #
+ # calling manageRootPanel (with the default arg id=None)
+ # also has the advantage that RootPanel(id=None) will
+ # 'pick up' the above RootPanelListener instance, meaning
+ # that you don't need to have a silly global variable
+ # all over the place, you can just use the standard pyjamas
+ # API as normal.
+ #
+ # kinda cute.
+
+ manageRootPanel(gp)
+
info = """Click anywhere in the Root (grey) to activate key input;
click again to disable it. Note the focus highlighting
that occurs on the "Hello World" HTML box.
@@ -78,9 +97,9 @@ def marginset(fred):
<br /> <br />
"""
- gp.add(panel)
- gp.add(b)
- gp.add(bh)
- gp.add(HTML(info))
+ RootPanel().add(panel)
+ RootPanel().add(b)
+ RootPanel().add(bh)
+ RootPanel().add(HTML(info))
pyjd.run()
View
11 library/pyjamas/ui/RootPanel.py
@@ -45,11 +45,14 @@ def get(id=None):
if not element:
return None
+ manageRootPanel(RootPanelCls(element), id)
+
+def manageRootPanel(panel, id=None):
+
if len(rootPanels) < 1:
panelManager = RootPanelManager()
Window.addWindowCloseListener(panelManager)
- panel = RootPanelCls(element)
rootPanels[id] = panel
return panel
@@ -61,12 +64,6 @@ def __init__(self, Element=None, **kwargs):
AbsolutePanel.__init__(self, **kwargs)
self.onAttach()
- # although the "normal" way to use this module is with the
- # RootPanel() function (below), we need to (redundantly)
- # trigger adding of RootPanelCls instance to rootPanels in case
- # anyone bypasses use of get() by e.g. deriving from RootPanelCls
- get(Element)
-
def getBodyElement(self):
return doc().body
Please sign in to comment.
Something went wrong with that request. Please try again.