From a5307ff8aa3456aa5bec285e7d94d8d7c014d131 Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Wed, 26 Jan 2005 01:15:38 +0000 Subject: [PATCH 1/1] update python --- mytest.py | 36 ++++++++++++++++++------------------ screens.py | 11 +++++++++-- skin.py | 30 +++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/mytest.py b/mytest.py index 54f0f862..c0967d78 100644 --- 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() diff --git a/screens.py b/screens.py index b68f669e..f0b06bda 100644 --- a/screens.py +++ b/screens.py @@ -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 5d482fdb..ab5fa369 100644 --- a/skin.py +++ b/skin.py @@ -11,11 +11,21 @@ def dump(x, i=0): None dom = xml.dom.minidom.parseString( - " \ - \ - \ - \ - ") + """ + + + + + + + + + + + +""") + + 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"): -- 2.30.2