ControlDemo.py :  » Ajax » pyjamas » src » examples » controls » 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 » controls » ControlDemo.py

""" ControlDemo Example

    Bill Winder <wgwinder@gmail.com> added HorizontalSlider demo.
    Bill Winder <wgwinder@gmail.com> added AreaSlider demo.    
"""
import pyjd # dummy in pyjs
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.Label import Label
from pyjamas.ui.Controls import VerticalDemoSlider
from pyjamas.ui.Controls import VerticalDemoSlider2
from pyjamas.ui.Controls import HorizontalDemoSlider
from pyjamas.ui.Controls import HorizontalDemoSlider2
from pyjamas.ui.Controls import AreaDemoSlider
from pyjamas.ui.Controls import AreaDemoSlider2
from pyjamas.ui.Controls import InputControl
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui import HasAlignment

class SliderClass(VerticalPanel):
    def __init__(self, p2):
        VerticalPanel.__init__(self)

        self.setSpacing(10)
        if p2:
            self.b = VerticalDemoSlider2(0, 100)
        else:
            self.b = VerticalDemoSlider(0, 100)
        self.add(self.b)

        self.b.setWidth("20px")
        self.b.setHeight("100px")

        self.b.addControlValueListener(self)

        self.label = InputControl(0, 100)
        self.add(self.label)

        self.label.addControlValueListener(self)

    def onControlValueChanged(self, sender, old_value, new_value):
        if sender == self.label:
            self.b.setControlPos(new_value)
            self.b.setValue(new_value, 0)
        if sender == self.b:
            self.label.setControlPos(new_value)
            self.label.setValue(new_value, 0)

class HSliderClass(VerticalPanel):
    def __init__(self, p2):
        VerticalPanel.__init__(self)

        self.setSpacing(10)
        if p2:
            self.b = HorizontalDemoSlider2(0, 100)
        else:
            self.b = HorizontalDemoSlider(0, 100)
        self.add(self.b)

        self.b.setHeight("20px")
        self.b.setWidth("100px")

        self.b.addControlValueListener(self)

        self.label = InputControl(0, 100)
        self.add(self.label)

        self.label.addControlValueListener(self)

    def onControlValueChanged(self, sender, old_value, new_value):
        if sender == self.label:
            self.b.setControlPos(new_value)
            self.b.setValue(new_value, 0)
        if sender == self.b:
            self.label.setControlPos(new_value)
            self.label.setValue(new_value, 0)

class ASliderClass(VerticalPanel):
    def __init__(self, p2):
        VerticalPanel.__init__(self)

        self.setSpacing(10)
        if p2:
            self.b = AreaDemoSlider2((0,0), (100,100))
        else:
            self.b = AreaDemoSlider((0,0), (100,100))
        self.add(self.b)

        self.b.setHeight("100px")
        self.b.setWidth("100px")

        self.b.addControlValueListener(self)

        self.label_x = InputControl(0, 100)
        self.add(self.label_x)

        self.label_x.addControlValueListener(self)

        self.label_y = InputControl(0, 100)
        self.add(self.label_y)

        self.label_y.addControlValueListener(self)

    def onControlValueChanged(self, sender,old_value_xy , new_value_xy):

        #no use of old_values? (old_value_x,old_value_y)

        if (sender == self.label_x):

            self.b.setControlPos((new_value_xy,self.b.value_y))
            self.b.setValue((new_value_xy,self.b.value_y), 0)       

        elif (sender == self.label_y):

            self.b.setControlPos((self.b.value_x,new_value_xy))
            self.b.setValue((self.b.value_x,new_value_xy), 0)

        elif (sender == self.b):

            (new_value_x,new_value_y) = new_value_xy

            self.label_x.setControlPos(new_value_x)
            self.label_x.setValue(new_value_x, 0)

            self.label_y.setControlPos(new_value_y)
            self.label_y.setValue(new_value_y, 0)
class ControlDemo:
    def onModuleLoad(self):

        p = HorizontalPanel()
        p.setSpacing(10)
        p.setVerticalAlignment(HasAlignment.ALIGN_BOTTOM)

        sc = SliderClass(False)
        p.add(sc)
        sc = SliderClass(True)
        p.add(sc)
        sc = SliderClass(True)
        p.add(sc)

        sc = HSliderClass(False)
        p.add(sc)
        sc = HSliderClass(True)
        p.add(sc)

        sc = ASliderClass(False)
        p.add(sc)
        sc = ASliderClass(True)
        p.add(sc)    

        RootPanel().add(p)


if __name__ == '__main__':
    pyjd.setup("./public/ControlDemo.html")
    app = ControlDemo()
    app.onModuleLoad()
    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.