+class Session:
+ def __init__(self):
+ self.desktop = None
+ self.delayTimer = eTimer()
+ self.delayTimer.timeout.get().append(self.processDelay)
+
+ self.currentDialog = None
+
+ self.dialogStack = [ ]
+
+ def processDelay(self):
+ self.execEnd()
+
+ callback = self.currentDialog.callback
+
+ retval = self.currentDialog.returnValue
+
+ if self.currentDialog.isTmp:
+ self.currentDialog.doClose()
+# dump(self.currentDialog)
+ del self.currentDialog
+ else:
+ del self.currentDialog.callback
+
+ self.popCurrent()
+ if callback is not None:
+ callback(*retval)
+
+ def execBegin(self):
+ c = self.currentDialog
+ c.execBegin()
+
+ # when execBegin opened a new dialog, don't bother showing the old one.
+ if c == self.currentDialog:
+ c.show()
+
+ def execEnd(self):
+ self.currentDialog.execEnd()
+ self.currentDialog.hide()
+
+ def create(self, screen, arguments):
+ # creates an instance of 'screen' (which is a class)
+ try:
+ return screen(self, *arguments)
+ except:
+ errstr = "Screen %s(%s): %s" % (str(screen), str(arguments), sys.exc_info()[0])
+ print errstr
+ traceback.print_exc(file=sys.stdout)
+ quitMainloop(5)
+
+
+ def instantiateDialog(self, screen, *arguments):
+ # create dialog
+
+ try:
+ dlg = self.create(screen, arguments)
+ except:
+ print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
+ print '-'*60
+ traceback.print_exc(file=sys.stdout)
+ quitMainloop(5)
+ print '-'*60
+
+ if dlg is None:
+ return
+
+ # read skin data
+ readSkin(dlg, None, dlg.skinName, self.desktop)
+
+ # create GUI view of this dialog
+ assert self.desktop != None
+
+ z = 0
+ for (key, value) in dlg.skinAttributes:
+ if key == "zPosition":
+ z = int(value)
+
+ dlg.instance = eWindow(self.desktop, z)
+ applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
+ gui = GUIOutputDevice()
+ gui.parent = dlg.instance
+ gui.create(dlg, self.desktop)
+
+ return dlg
+
+ def pushCurrent(self):
+ if self.currentDialog:
+ self.dialogStack.append(self.currentDialog)
+ self.execEnd()
+
+ def popCurrent(self):
+ if len(self.dialogStack):
+ self.currentDialog = self.dialogStack.pop()
+ self.execBegin()
+ else:
+ self.currentDialog = None
+
+ def execDialog(self, dialog):
+ self.pushCurrent()
+ self.currentDialog = dialog
+ self.currentDialog.isTmp = False
+ self.currentDialog.callback = None # would cause re-entrancy problems.
+ self.execBegin()
+
+ def openWithCallback(self, callback, screen, *arguments):
+ dlg = self.open(screen, *arguments)
+ dlg.callback = callback
+
+ def open(self, screen, *arguments):
+ self.pushCurrent()
+ dlg = self.currentDialog = self.instantiateDialog(screen, *arguments)
+ dlg.isTmp = True
+ dlg.callback = None
+ self.execBegin()
+ return dlg
+
+ def keyEvent(self, code):
+ print "code " + str(code)
+
+ def close(self, *retval):
+ self.currentDialog.returnValue = retval
+ self.delayTimer.start(0, 1)