- work on actions
[enigma2.git] / mytest.py
1 from enigma import *
2 from tools import *
3
4
5 import sys
6 import time
7
8 from screens import *
9 from skin import applyGUIskin
10
11 # A screen is a function which instanciates all components of a screen into a temporary component.
12 # Thus, the global stuff is a screen, too.
13 # In a screen, components can either be instanciated from the class-tree, cloned (copied) or
14 # "linked" from the instance tree.
15 # A screen itself lives as the container of the components, so a screen is a component, too.
16
17 # we thus have one (static) hierarchy of screens (classes, not instances)
18 # and one with the instanciated components itself (both global and dynamic)
19
20 def dump(dir, p = ""):
21         if isinstance(dir, dict):
22                 for (entry, val) in dir.items():
23                         dump(val, p + "/" + entry)
24         print p + ":" + str(dir.__class__)
25
26 # defined components
27 components = {}
28
29 # do global
30 doGlobal(components)
31
32 # display
33
34 class OutputDevice:
35         def create(self, screen): pass
36
37 # display: HTML
38
39 class HTMLOutputDevice(OutputDevice):
40         def create(self, comp):
41                 print comp.produceHTML()
42
43 html = HTMLOutputDevice()
44
45 class GUIOutputDevice(OutputDevice):
46         parent = None
47         def create(self, comp):
48                 comp.createGUIScreen(self.parent)
49
50 class Session:
51         def __init__(self):
52                 self.desktop = None
53                 self.delayTimer = eTimer()
54                 self.delayTimer.timeout.get().append(self.processDelay)
55                 
56                 self.currentDialog = None
57                 
58                 self.dialogStack = [ ]
59         
60         def processDelay(self):
61                 self.execEnd()
62                 self.currentDialog.doClose()
63                 
64                 del self.currentDialog
65                 del self.currentWindow
66                 
67                 if len(self.dialogStack):
68                         (self.currentDialog, self.currentWindow) = self.dialogStack.pop()
69                         self.execBegin()
70                         
71         def execBegin(self):
72                         self.currentDialog.execBegin()
73                         self.currentWindow.show()
74                 
75         def execEnd(self):
76                         self.currentDialog.execEnd()
77                         self.currentWindow.hide()
78         
79         def create(self, screen, arguments):
80                 return screen(self, *arguments)
81         
82         def open(self, screen, *arguments):
83                 if self.currentDialog:
84                         self.dialogStack.append((self.currentDialog, self.currentWindow))
85                         self.execEnd()
86                 
87                 self.currentDialog = self.create(screen, arguments)
88                 
89                 if self.desktop != None:
90                         self.currentWindow = eWindow(self.desktop)
91
92                         gui = GUIOutputDevice()
93                         gui.parent = self.currentWindow
94                         gui.create(self.currentDialog)
95
96                         applyGUIskin(self.currentDialog, self.currentWindow, None, self.currentDialog.skinName)
97
98                         self.execBegin()
99                 else:
100                         self.currentWindow = None
101
102         def keyEvent(self, code):
103 #               print "code " + str(code)
104                 if code == 32:
105                         self.currentDialog["okbutton"].instance.push()
106
107                 if code == 33:
108                         self.currentDialog["channelSwitcher"].instance.push()
109                 
110                 if code >= 0x30 and code <= 0x39:
111                         try:
112                                 self.currentDialog["menu"].instance.moveSelection(code - 0x31)
113                         except:
114                                 self.currentDialog["list"].instance.moveSelection(code - 0x31)
115
116         def close(self):
117                 self.delayTimer.start(0, 1)
118
119 def runScreenTest():
120         session = Session()
121         session.desktop = getDesktop()
122         
123         session.nav = pNavigation()
124         
125         session.open(infoBar)
126
127         CONNECT(keyPressedSignal(), session.keyEvent)
128         
129         runMainloop()
130         
131         return 0
132
133 import keymapparser
134 keymapparser.readKeymap()
135
136 # first, setup a screen
137 runScreenTest()
138
139 # now, run the mainloop