#!/usr/bin/python import ri_tk as display class GridManagement: ''' implement grid management ''' def __init__(self, xml_node): self.cf_list=[] for cf in xml_node.childNodes: if cf.nodeType != cf.ELEMENT_NODE or cf.nodeName != "configure": continue if "row" in cf.attributes.keys(): cf_func = "rowconfigure" n = cf.attributes["row"].value elif "column" in cf.attributes.keys(): cf_func = "columnconfigure" n = cf.attributes["column"].value else: continue self.cf_list.append((cf_func, n, cf.attributes["weight"].value)) class GridLocation: ''' implement grid_location in interface xml ''' def __init__(self, xml_node): self.dict={} for a in xml_node.attributes.values(): self.dict[a.name] = a.value class Action: ''' implement action in interface xml ''' def __init__(self, xml_node): self.dict={} for a in xml_node.attributes.values(): self.dict[a.name] = a.value class Widget: ''' implement widget in interface xml ''' current_widget="" dict={} def __init__(self, xml_node): if 'name' in xml_node.attributes.keys(): self.name = xml_node.attributes["name"].value Widget.dict[self.name] = self self.tp = xml_node.attributes["type"].value self.attr = {} self.widgets=[] self.variables=[] for node in xml_node.childNodes: if node.nodeType == node.ELEMENT_NODE: if node.nodeName == "grid_management": self.grid_management = GridManagement(node) elif node.nodeName == "grid_location": self.grid_location = GridLocation(node) elif node.nodeName == "widget_attribute": for a in node.attributes.values(): self.attr[a.name] = a.value elif node.nodeName == "widget": self.widgets.append(Widget(node)) elif node.nodeName == "variable": self.variables.append((node.attributes["name"].value, \ node.attributes["type"].value, \ "value" in node.attributes.keys() and node.attributes["value"].value or "" )) elif node.nodeName == "action": self.action = Action(node) def show(self): Widget.current_widget = self display.create_widget(self) def hide(self): display.destroy_widget(self) class MessageBox(): ''' implement dialog in interface.xml ''' dict={} def __init__(self, xml_node): self.name = xml_node.attributes["name"].value self.tp = xml_node.attributes["type"].value self.title = xml_node.attributes["title"].value self.message = xml_node.attributes["message"].value MessageBox.dict[self.name] = self def show(self): ''' display dialog''' display.create_message_box(self) def construct(xml_root): ''' construct Widget's static members''' for n in xml_root.childNodes: if n.nodeType == n.ELEMENT_NODE: if n.nodeName == "widget": Widget(n) elif n.nodeName == "message_box": MessageBox(n) def init_display(bw): ''' base widget name''' display.init(Widget.dict[bw]) def mainloop(): '''run message main loop ''' display.root_window.mainloop()