File: Toggle.py

package info (click to toggle)
pyjamas 0.7~%2Bpre2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,656 kB
  • ctags: 12,331
  • sloc: python: 74,493; php: 805; sh: 291; makefile: 59; xml: 9
file content (75 lines) | stat: -rw-r--r-- 2,646 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
""" testint our demo slider
"""
import pyjd # dummy in pyjs

from pyjamas.ui.Label      import Label
from pyjamas.ui.Button     import Button
from pyjamas.ui.ButtonBase import ButtonBase
from pyjamas.ui.RootPanel  import RootPanel
from pyjamas.ui.ToggleButton import ToggleButton
from pyjamas.ui.PushButton import PushButton
from pyjamas               import DOM
from pyjamas.ui.Image      import Image
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.HorizontalPanel import HorizontalPanel

class Toggle:
    def onModuleLoad(self):
        
        self.label = Label("Not set yet")
        
        self.button = Button("Probe button", self)
        self.image_up = Image("./images/logo.png")
        self.image_up3 = Image("./images/logo.png")
        self.image_down = Image("./images/logo.png")
        self.image_down3 = Image("./images/logo.png")
        self.toggle = ToggleButton(self.image_up, self.image_down, self)
        self.toggle2 = ToggleButton("up", "down", getattr(self, "onToggleUD"))
        self.push = PushButton(self.image_up3, self.image_down3)
        
        self.vpanel = VerticalPanel()
        self.togglePanel = HorizontalPanel()
        self.togglePanel.setSpacing(10)
        
        self.togglePanel.add(self.toggle)
        self.togglePanel.add(self.toggle2)
        self.togglePanel.add(self.push)
        
        self.vpanel.add(self.label)
        self.vpanel.add(self.button)
        self.vpanel.add(self.togglePanel)
        
        RootPanel().add(self.vpanel)
        self.i = False
        
    def onToggleUD(self, sender):
            self.label.setText(" Toggle2 isdown: "+str(self.toggle2.isDown()))

    def onClick(self, sender):
        if sender == self.button:
            if self.i: 
                self.i = False
                text = ">>>>UP<<<<"
                self.toggle.setCurrentFace(self.toggle.getUpFace())
            else:
                self.i = True
                text = ">>>DOWN<<<"
                self.toggle.setCurrentFace(self.toggle.getDownFace())
            #self.label.setText("self.toggle.style_name: "+
            #                    self.toggle.style_name+", self.toggle.getStyleName():"+
            #                    self.toggle.getStyleName()+" ")
            self.label.setText(text)
        elif sender == self.toggle:
            text = ">>>DOWN<<<"
            if self.i: text = ">>>>UP<<<<"
            self.i = not self.i
            self.label.setText(text+" isdown: "+str(self.toggle.isDown()))


if __name__ == "__main__":
    pyjd.setup("./public/Toggle.html")
    app = Toggle()
    app.onModuleLoad()
    pyjd.run()