2f6cecfd40b0f8db6fde9b675f8b5446a78f18b7
[openblackhole/openblackhole-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 doGlobal(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, wnd, 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 == 33:
107                         self.currentDialog.data["channelSwitcher"]["instance"].push()
108                 
109                 if code >= 0x30 and code <= 0x39:
110                         try:
111                                 self.currentDialog.data["menu"]["instance"].moveSelection(code - 0x31)
112                         except:
113                                 self.currentDialog.data["list"]["instance"].moveSelection(code - 0x31)
114
115         def close(self):
116                 self.delayTimer.start(0, 1)
117
118 def runScreenTest():
119         session = Session()
120         session.desktop = getDesktop()
121         
122         session.open(infoBar())
123
124         CONNECT(keyPressedSignal(), session.keyEvent)
125         
126         runMainloop()
127         
128         return 0
129
130
131 # first, setup a screen
132 runScreenTest()
133
134 # now, run the mainloop