ClickableRootPanel.py :  » Ajax » pyjamas » src » examples » clickablerootpanel » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » examples » clickablerootpanel » ClickableRootPanel.py
import pyjd # this is dummy in pyjs.

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
from pyjamas.ui.ClickListener import ClickHandler
from pyjamas.ui.HTML import HTML
from pyjamas import Window
from pyjamas import DOM
from __pyjamas__ import doc

class RootPanelListener(RootPanelCls, KeyboardHandler, ClickHandler):
    def __init__(self, Parent, *args, **kwargs):
        self.Parent = Parent
        self.focussed = False
        RootPanelCls.__init__(self, *args, **kwargs)
        ClickHandler.__init__(self)
        KeyboardHandler.__init__(self)

        self.addClickListener(self)
        self.addKeyboardListener(self)

    def onClick(self, Sender):
        self.focussed = not self.focussed
        self.Parent.setFocus(self.focussed)

        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))

def heightset(fred):
    DOM.setStyleAttribute(doc().body, 'height', '100%')

def marginset(fred):
    DOM.setStyleAttribute(doc().body, 'margin', '0px')

if __name__ == '__main__':

    pyjd.setup("public/ClickableRootPanel.html")

    bh = Button("Click me to set body height to 100%", heightset,
               StyleName='teststyle')
    b = Button("Click me to set body margin to 0", marginset,
               StyleName='teststyle')
    h = HTML("<b>Hello World</b> - watch for focus highlighting after click",
             StyleName='teststyle')

    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.
    <br /> <br />
    The CSS style has been set to 100% width
    and the margin to 100px.  Even though it is the "body" - root
    element, clicking outside the margin (indicated by the black border)
    will NOT activate key input.
    <br /><br />
    Note that many browsers screw up the sizes of the window when the
    margin is set as well as width or height to 100%, as evidenced by
    the black border being off the screen.  (Normally, you would add a
    WindowResize Listener which received the window size and then
    directly adjusted the CSS width and height of the body element
    to correct these problems (!) or, much better, add a SimplePanel
    on which the appropriate (100% width+height) CSS styles are set).
    <br /> <br />
    However that's not the issue: the point is that you <b>must</b>
    actually set the body to be 100% of the screen area in order to
    receive click events, and the above highlights why it is important
    to set margin and padding of body to 0 as well, and also to not
    set any borders.
    <br /> <br />
    Click the button to change the margin on the document "body" tag
    to zero, in order to test this out.  Note that the border may still
    be off the screen, even when the margin is zero.
    <br /> <br />
    """

    RootPanel().add(panel)
    RootPanel().add(b)
    RootPanel().add(bh)
    RootPanel().add(HTML(info))

    pyjd.run()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.