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