- skins are now loaded first and applied later
[enigma2.git] / mytest.py
1 from enigma import *
2 from tools import *
3
4 import Screens.InfoBar
5
6 import sys
7 import time
8
9 import ServiceReference
10
11 from Navigation import Navigation
12
13 from skin import readSkin, applyAllAttributes
14
15 # A screen is a function which instanciates all components of a screen into a temporary component.
16 # Thus, the global stuff is a screen, too.
17 # In a screen, components can either be instanciated from the class-tree, cloned (copied) or
18 # "linked" from the instance tree.
19 # A screen itself lives as the container of the components, so a screen is a component, too.
20
21 # we thus have one (static) hierarchy of screens (classes, not instances)
22 # and one with the instanciated components itself (both global and dynamic)
23
24 had = dict()
25
26 def dump(dir, p = ""):
27         if isinstance(dir, dict):
28                 for (entry, val) in dir.items():
29                         dump(val, p + "(dict)/" + entry)
30         if hasattr(dir, "__dict__"):
31                 for name, value in dir.__dict__.items():
32                         if not had.has_key(str(value)):
33                                 had[str(value)] = 1
34                                 dump(value, p + "/" + str(name))
35                         else:
36                                 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
37         else:
38                 print p + ":" + str(dir)
39
40 # + ":" + str(dir.__class__)
41
42 # display
43
44 class OutputDevice:
45         def create(self, screen): pass
46
47 # display: HTML
48
49 class HTMLOutputDevice(OutputDevice):
50         def create(self, comp):
51                 print comp.produceHTML()
52
53 html = HTMLOutputDevice()
54
55 class GUIOutputDevice(OutputDevice):
56         parent = None
57         def create(self, comp, desktop):
58                 comp.createGUIScreen(self.parent, desktop)
59
60 class Session:
61         def __init__(self):
62                 self.desktop = None
63                 self.delayTimer = eTimer()
64                 self.delayTimer.timeout.get().append(self.processDelay)
65                 
66                 self.currentDialog = None
67                 
68                 self.dialogStack = [ ]
69         
70         def processDelay(self):
71                 self.execEnd()
72                 
73                 if self.currentDialog.isTmp:
74                         self.currentDialog.doClose()
75                 
76                         print sys.getrefcount(self.currentDialog)
77                         del self.currentDialog.instance
78 #                       dump(self.currentDialog)
79                         del self.currentDialog
80                 
81                 self.popCurrent()
82                         
83         def execBegin(self):
84                         self.currentDialog.execBegin()
85                         self.currentDialog.instance.show()
86                 
87         def execEnd(self):
88                         self.currentDialog.execEnd()
89                         self.currentDialog.instance.hide()
90         
91         def create(self, screen, arguments):
92                 # creates an instance of 'screen' (which is a class)
93                 return screen(self, *arguments)
94         
95         def instantiateDialog(self, screen, *arguments):
96                 # create dialog
97                 dlg = self.create(screen, arguments)
98                 
99                 # read skin data
100                 readSkin(dlg, None, dlg.skinName, self.desktop)
101
102                 # create GUI view of this dialog
103                 assert self.desktop != None
104                 dlg.instance = eWindow(self.desktop)
105                 applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
106                 gui = GUIOutputDevice()
107                 gui.parent = dlg.instance
108                 gui.create(dlg, self.desktop)
109                 
110                 return dlg
111          
112         def pushCurrent(self):
113                 if self.currentDialog:
114                         self.dialogStack.append(self.currentDialog)
115                         self.execEnd()
116         
117         def popCurrent(self):
118                 if len(self.dialogStack):
119                         self.currentDialog = self.dialogStack.pop()
120                         self.execBegin()
121         
122         def execDialog(self, dialog):
123                 self.pushCurrent()
124                 self.currentDialog = dialog
125                 self.currentDialog.isTmp = False
126                 self.execBegin()
127
128         def open(self, screen, *arguments):
129                 self.pushCurrent()
130                 self.currentDialog = self.instantiateDialog(screen, *arguments)
131                 self.currentDialog.isTmp = True
132                 self.execBegin()
133
134         def keyEvent(self, code):
135                 print "code " + str(code)
136
137         def close(self):
138                 self.delayTimer.start(0, 1)
139
140
141 def runScreenTest():
142         session = Session()
143         session.desktop = getDesktop()
144         
145         session.nav = Navigation()
146         
147         session.open(Screens.InfoBar.InfoBar)
148
149         CONNECT(keyPressedSignal(), session.keyEvent)
150         
151         runMainloop()
152         
153         session.nav.shutdown()
154         
155         return 0
156
157 import keymapparser
158 keymapparser.readKeymap()
159 import skin
160 skin.loadSkin(getDesktop())
161
162 # first, setup a screen
163 runScreenTest()
164
165 # now, run the mainloop
166
167 #pt = eDebugClassPtr()
168 #eDebugClass.getDebug(pt, 12)
169 #p = pt.__deref__()
170 #print pt.x
171 #print p.x
172 #print "removing ptr..."
173 #pt = 0
174 #print "now"
175 #print "p is " + str(p)
176 #print p.x
177 #p = 0
178 #
179 #bla = eDebugClass()
180 #bla = eDebugClass(2)
181 #
182