update python
authorFelix Domke <tmbinc@elitedvb.net>
Wed, 26 Jan 2005 01:15:38 +0000 (01:15 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Wed, 26 Jan 2005 01:15:38 +0000 (01:15 +0000)
mytest.py
screens.py
skin.py

index 54f0f86..c0967d7 100644 (file)
--- a/mytest.py
+++ b/mytest.py
@@ -59,19 +59,21 @@ class Session:
                self.desktop = None
                self.delayTimer = eTimer()
                self.delayTimer.timeout.get().append(self.processDelay)
+               
+               self.currentDialog = None
        
        def processDelay(self):
-               components[self.screenname].close()
+               self.currentDialog.close()
                if self.currentWindow != None:
                        self.currentWindow.hide()
                
-               del components[self.screenname]
+               del self.currentDialog
                del self.currentWindow
                
+               self.open(screens["testDialog"]())
 
-       def open(self, screenname, screen):
-               components[screenname] = screen
-               self.screenname = screenname
+       def open(self, screen):
+               self.currentDialog = screen
                screen.session = self
                
                if self.desktop != None:
@@ -82,9 +84,9 @@ class Session:
 
                        gui = GUIOutputDevice()
                        gui.parent = wnd
-                       gui.create(components["$002"])
+                       gui.create(self.currentDialog)
 
-                       applyGUIskin(components["$002"], None, "clockDialog")
+                       applyGUIskin(self.currentDialog, None, screen.__class__.__name__)
 
                        wnd.show()
                else:
@@ -97,21 +99,19 @@ def runScreenTest():
        session = Session()
        session.desktop = getDesktop()
        
-#      components["$002"] = screens["clockDisplay"](components["clock"])
-
-       session.open("$002", screens["clockDisplay"](components["clock"]))
+       session.open(screens["clockDisplay"](components["clock"]))
+#      session.open(screens["testDialog"]())
 
-       
+       # simple reason for this helper function: we want to call the currently
+       # active "okbutton", even when we changed the dialog
+       #
+       # more complicated reason: we don't want to hold a reference.
        def blub():
-#              x = components["$002"]
-               components["$002"].data["okbutton"]["instance"].push()
-#              dump(components)
-#              print "session, close screen " + str(sys.getrefcount(x))
-#              session.close()
-               
+               session.currentDialog.data["okbutton"]["instance"].push()
+       
        tmr = eTimer()
        tmr.timeout.get().append(blub)
-       tmr.start(4000, 1)
+       tmr.start(4000, 0)
        
        runMainloop()
        
index b68f669..f0b06bd 100644 (file)
@@ -15,14 +15,21 @@ class Screen(dict, HTMLSkin, GUISkin):
 class testDialog(Screen):
        def testDialogClick(self):
                print "test dialog clicked!"
-               self["title"].setText("bla")
+               if self.tries == 0:
+                       self["title"].setText("Hihi - no, this doesn't work!")
+               else:
+                       self["title"].setText("You tried it %d times without success now!" % self.tries )
+
+               self.tries += 1
 
        def __init__(self):
-               HTMLSkin.__init__(self, ("title", "okbutton"))
+               GUISkin.__init__(self)
                b = Button("ok")
                b.onClick = [ self.testDialogClick ]
                self["okbutton"] = b
                self["title"] = Header("Test Dialog - press ok to leave!")
+               
+               self.tries = 0
 
 # a clock display dialog
 class clockDisplay(Screen):
diff --git a/skin.py b/skin.py
index 5d482fd..ab5fa36 100644 (file)
--- a/skin.py
+++ b/skin.py
@@ -11,11 +11,21 @@ def dump(x, i=0):
                None
 
 dom = xml.dom.minidom.parseString(
-       "<screen name=\"clockDialog\" position=\"300,100\" size=\"300,300\"> \
-               <widget name=\"okbutton\" position=\"10,10\" size=\"280,40\" /> \
-               <widget name=\"theClock\" position=\"10,60\" size=\"280,50\" /> \
-               <widget name=\"title\" position=\"10,120\" size=\"280,50\" /> \
-       </screen>")
+       """
+       <skin>
+               <screen name="testDialog">
+                       <widget name="okbutton" position="10,10" size="280,40" />
+                       <widget name="title" position="10,120" size="280,50" />
+               </screen>
+               <screen name="clockDisplay" position="300,100" size="300,300">
+                       <widget name="okbutton" position="10,10" size="280,40" />
+                       <widget name="title" position="10,120" size="280,50" />
+                       <widget name="theClock" position="10,60" size="280,50" />
+               </screen>
+       </skin>
+""")
+
+
 
 def parsePosition(str):
        x, y = str.split(',')
@@ -43,14 +53,16 @@ def applyGUIskin(screen, skin, name):
        myscreen = None
        
        # first, find the corresponding screen element
-       screens = dom.getElementsByTagName("screen")
+       skin = dom.getElementsByTagName("skin")[0]
+       screens = skin.getElementsByTagName("screen")
+       del skin
        for x in screens:
                if x.getAttribute('name') == name:
                        myscreen = x
        
-       if myscreen == None:
-               print "no skin for screen " + name + " found!"
-               return;
+       assert myscreen != None, "no skin for screen " + name + " found!"
+       
+       print "ok, found screen.."
        
        # now walk all widgets
        for widget in myscreen.getElementsByTagName("widget"):