5233d85e8324e168b3fe0decb604f692c764ce96
[enigma2.git] / mytest.py
1 from enigma import *
2
3 import sys
4 import time
5
6 from screens import *
7 from skin import applyGUIskin
8
9
10 def CONNECT(slot, fnc):
11         slot.get().append(fnc)
12
13 def DISCONNECT(slot, fnc):
14         slot.get().remove(fnc)
15
16 # A screen is a function which instanciates all components of a screen into a temporary component.
17 # Thus, the global stuff is a screen, too.
18 # In a screen, components can either be instanciated from the class-tree, cloned (copied) or
19 # "linked" from the instance tree.
20 # A screen itself lives as the container of the components, so a screen is a component, too.
21
22 # we thus have one (static) hierarchy of screens (classes, not instances)
23 # and one with the instanciated components itself (both global and dynamic)
24
25 def dump(dir, p = ""):
26         if isinstance(dir, dict):
27                 for (entry, val) in dir.items():
28                         dump(val, p + "/" + entry)
29         print p + ":" + str(dir.__class__)
30
31 # defined components
32 components = {}
33
34 # do global
35 screens["global"](components)
36
37 # test our screens
38 components["$001"] = screens["testDialog"]()
39
40 print "*** classes:"
41 dump(screens)
42
43 print "*** instances:"
44 dump(components)
45
46 # display
47
48 class OutputDevice:
49         def create(self, screen): pass
50
51 # display: HTML
52
53 class HTMLOutputDevice(OutputDevice):
54         def create(self, comp):
55                 print comp.produceHTML()
56
57 html = HTMLOutputDevice()
58
59 class GUIOutputDevice(OutputDevice):
60         parent = None
61         def create(self, comp):
62                 comp.createGUIScreen(self.parent)
63
64 class Session:
65         def __init__(self):
66                 self.desktop = None
67                 self.delayTimer = eTimer()
68                 self.delayTimer.timeout.get().append(self.processDelay)
69                 
70                 self.currentDialog = None
71         
72         def processDelay(self):
73                 self.currentDialog.close()
74                 if self.currentWindow != None:
75                         self.currentWindow.hide()
76                 
77                 del self.currentDialog
78                 del self.currentWindow
79                 
80                 self.open(screens["testDialog"]())
81
82         def open(self, screen):
83                 self.currentDialog = screen
84                 screen.session = self
85                 
86                 if self.desktop != None:
87                         self.currentWindow = wnd = eWindow(self.desktop)
88                         wnd.setTitle("Screen from python!")
89                         wnd.move(ePoint(300, 100))
90                         wnd.resize(eSize(300, 300))
91
92                         gui = GUIOutputDevice()
93                         gui.parent = wnd
94                         gui.create(self.currentDialog)
95
96                         applyGUIskin(self.currentDialog, None, screen.__class__.__name__)
97
98                         wnd.show()
99                 else:
100                         self.currentWindow = None
101
102         def keyEvent(self, code):
103                 print "code " + str(code)
104                 if code == 32:
105                         self.currentDialog.data["okbutton"]["instance"].push()
106                 
107                 if code >= 0x30 and code <= 0x39:
108                         self.currentDialog.data["menu"]["instance"].moveSelection(code - 0x31)
109
110         def close(self):
111                 self.delayTimer.start(0, 1)
112
113 def runScreenTest():
114         session = Session()
115         session.desktop = getDesktop()
116         
117         session.open(screens["clockDisplay"](components["clock"]))
118 #       session.open(screens["testDialog"]())
119
120         # simple reason for this helper function: we want to call the currently
121         # active "okbutton", even when we changed the dialog
122         #
123         # more complicated reason: we don't want to hold a reference.
124 #       def blub():
125 #               session.currentDialog.data["okbutton"]["instance"].push()       
126 #               session.currentDialog["okbutton"].setText("hello!")
127 #       
128 #       tmr = eTimer()
129 #       CONNECT(tmr.timeout, blub)
130 #       tmr.start(4000, 0)
131 #       
132         CONNECT(keyPressedSignal(), session.keyEvent)
133         
134         runMainloop()
135         
136         return 0
137
138
139 # first, setup a screen
140 runScreenTest()
141
142 # now, run the mainloop