add save
[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
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 had = dict()
26
27 def dump(dir, p = ""):
28         if isinstance(dir, dict):
29                 for (entry, val) in dir.items():
30                         dump(val, p + "(dict)/" + entry)
31         if hasattr(dir, "__dict__"):
32                 for name, value in dir.__dict__.items():
33                         if not had.has_key(str(value)):
34                                 had[str(value)] = 1
35                                 dump(value, p + "/" + str(name))
36                         else:
37                                 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
38         else:
39                 print p + ":" + str(dir)
40
41 # + ":" + str(dir.__class__)
42
43 # display
44
45 class OutputDevice:
46         def create(self, screen): pass
47
48 # display: HTML
49
50 class HTMLOutputDevice(OutputDevice):
51         def create(self, comp):
52                 print comp.produceHTML()
53
54 html = HTMLOutputDevice()
55
56 class GUIOutputDevice(OutputDevice):
57         parent = None
58         def create(self, comp, desktop):
59                 comp.createGUIScreen(self.parent, desktop)
60
61 class Session:
62         def __init__(self):
63                 self.desktop = None
64                 self.delayTimer = eTimer()
65                 self.delayTimer.timeout.get().append(self.processDelay)
66                 
67                 self.currentDialog = None
68                 
69                 self.dialogStack = [ ]
70         
71         def processDelay(self):
72                 self.execEnd()
73                 
74                 if self.currentDialog.isTmp:
75                         self.currentDialog.doClose()
76                 
77                         print sys.getrefcount(self.currentDialog)
78                         del self.currentDialog.instance
79 #                       dump(self.currentDialog)
80                         del self.currentDialog
81                 
82                 self.popCurrent()
83                         
84         def execBegin(self):
85                         self.currentDialog.execBegin()
86                         self.currentDialog.instance.show()
87                 
88         def execEnd(self):
89                         self.currentDialog.execEnd()
90                         self.currentDialog.instance.hide()
91         
92         def create(self, screen, arguments):
93                 # creates an instance of 'screen' (which is a class)
94                 return screen(self, *arguments)
95         
96         def instantiateDialog(self, screen, *arguments):
97                 # create dialog
98                 dlg = self.create(screen, arguments)
99                 
100                 # read skin data
101                 readSkin(dlg, None, dlg.skinName, self.desktop)
102
103                 # create GUI view of this dialog
104                 assert self.desktop != None
105                 dlg.instance = eWindow(self.desktop)
106                 applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
107                 gui = GUIOutputDevice()
108                 gui.parent = dlg.instance
109                 gui.create(dlg, self.desktop)
110                 
111                 return dlg
112          
113         def pushCurrent(self):
114                 if self.currentDialog:
115                         self.dialogStack.append(self.currentDialog)
116                         self.execEnd()
117         
118         def popCurrent(self):
119                 if len(self.dialogStack):
120                         self.currentDialog = self.dialogStack.pop()
121                         self.execBegin()
122         
123         def execDialog(self, dialog):
124                 self.pushCurrent()
125                 self.currentDialog = dialog
126                 self.currentDialog.isTmp = False
127                 self.execBegin()
128
129         def open(self, screen, *arguments):
130                 self.pushCurrent()
131                 self.currentDialog = self.instantiateDialog(screen, *arguments)
132                 self.currentDialog.isTmp = True
133                 self.execBegin()
134
135         def keyEvent(self, code):
136                 print "code " + str(code)
137
138         def close(self):
139                 self.delayTimer.start(0, 1)
140
141
142 def runScreenTest():
143         session = Session()
144         session.desktop = getDesktop()
145         
146         session.nav = Navigation()
147         
148         session.open(Screens.InfoBar.InfoBar)
149
150         CONNECT(keyPressedSignal(), session.keyEvent)
151         
152         runMainloop()
153         
154         session.nav.shutdown()
155         
156         return 0
157
158 import keymapparser
159 keymapparser.readKeymap()
160 import skin
161 skin.loadSkin(getDesktop())
162
163 import Components.InputDevice
164 Components.InputDevice.InitInputDevices()
165
166 # first, setup a screen
167 runScreenTest()
168
169 # now, run the mainloop
170
171 #pt = eDebugClassPtr()
172 #eDebugClass.getDebug(pt, 12)
173 #p = pt.__deref__()
174 #print pt.x
175 #print p.x
176 #print "removing ptr..."
177 #pt = 0
178 #print "now"
179 #print "p is " + str(p)
180 #print p.x
181 #p = 0
182 #
183 #bla = eDebugClass()
184 #bla = eDebugClass(2)
185 #
186