e257f11a160c5a84e37599f10c808430080ddcda
[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 # display
38
39 class OutputDevice:
40         def create(self, screen): pass
41
42 # display: HTML
43
44 class HTMLOutputDevice(OutputDevice):
45         def create(self, comp):
46                 print comp.produceHTML()
47
48 html = HTMLOutputDevice()
49
50 class GUIOutputDevice(OutputDevice):
51         parent = None
52         def create(self, comp):
53                 comp.createGUIScreen(self.parent)
54
55 class Session:
56         def __init__(self):
57                 self.desktop = None
58                 self.delayTimer = eTimer()
59                 self.delayTimer.timeout.get().append(self.processDelay)
60                 
61                 self.currentDialog = None
62                 
63                 self.dialogStack = [ ]
64         
65         def processDelay(self):
66                 self.currentDialog.doClose()
67                 if self.currentWindow != None:
68                         self.currentWindow.hide()
69                 
70                 del self.currentDialog
71                 del self.currentWindow
72                 
73                 if len(self.dialogStack):
74                         (self.currentDialog, self.currentWindow) = self.dialogStack.pop()
75                         self.currentWindow.show()
76         
77         def open(self, screen):
78                 if self.currentDialog:
79                         self.dialogStack.append((self.currentDialog, self.currentWindow))
80                         self.currentWindow.hide()
81                 
82                 self.currentDialog = screen
83                 screen.session = self
84                 
85                 if self.desktop != None:
86                         self.currentWindow = wnd = eWindow(self.desktop)
87                         wnd.setTitle("Screen from python!")
88                         wnd.move(ePoint(300, 100))
89                         wnd.resize(eSize(300, 300))
90
91                         gui = GUIOutputDevice()
92                         gui.parent = wnd
93                         gui.create(self.currentDialog)
94
95                         applyGUIskin(self.currentDialog, None, screen.__class__.__name__)
96
97                         wnd.show()
98                 else:
99                         self.currentWindow = None
100
101         def keyEvent(self, code):
102 #               print "code " + str(code)
103                 if code == 32:
104                         self.currentDialog.data["okbutton"]["instance"].push()
105                 
106                 if code >= 0x30 and code <= 0x39:
107                         self.currentDialog.data["menu"]["instance"].moveSelection(code - 0x31)
108
109         def close(self):
110                 self.delayTimer.start(0, 1)
111
112 def runScreenTest():
113         session = Session()
114         session.desktop = getDesktop()
115         
116 #       session.open(screens["clockDisplay"](components["clock"]))
117         session.open(screens["testDialog"]())
118
119         # simple reason for this helper function: we want to call the currently
120         # active "okbutton", even when we changed the dialog
121         #
122         # more complicated reason: we don't want to hold a reference.
123 #       def blub():
124 #               session.currentDialog.data["okbutton"]["instance"].push()       
125 #               session.currentDialog["okbutton"].setText("hello!")
126 #       
127 #       tmr = eTimer()
128 #       CONNECT(tmr.timeout, blub)
129 #       tmr.start(4000, 0)
130 #       
131         CONNECT(keyPressedSignal(), session.keyEvent)
132         
133         runMainloop()
134         
135         return 0
136
137
138 # first, setup a screen
139 runScreenTest()
140
141 # now, run the mainloop