Files
new_install/python/mine/ri_widget.py
lizhi-rocky 5ed4600bf7 ~~~
2010-07-12 17:35:16 +08:00

147 lines
4.5 KiB
Python

#!/usr/bin/python
import Tkinter
import sys
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 Widget:
''' implement widget in interface xml '''
current_widget=""
dict={}
def __init__(self, xml_node):
self.tp = xml_node.attributes["type"].value
self.attr = self.widget_attribute(xml_node)
gm_list = [m for m in xml_node.childNodes
if m.nodeType == m.ELEMENT_NODE and m.nodeName == "grid_management"]
if gm_list:
self.grid_management = GridManagement(gm_list[0])
gl_list = [l for l in xml_node.childNodes
if l.nodeType == l.ELEMENT_NODE and l.nodeName == "grid_location"]
if gl_list:
self.grid_location = GridLocation(gl_list[0])
w_list = [ w for w in xml_node.childNodes
if w.nodeType == w.ELEMENT_NODE and w.nodeName == "widget" ]
if w_list:
self.widgets=[]
for w in w_list:
self.widgets.append(Widget(w))
def widget_attribute(self, xml_node):
attr_list = [ a for a in xml_node.childNodes
if a.nodeType == a.ELEMENT_NODE and a.nodeName == "widget_attribute"]
d = {}
if attr_list:
for a in attr_list[0].attributes.values():
if a.name == 'image':
#d[a.name] = Tkinter.PhotoImage(file=a.value)
pass
elif a.name == 'command':
if not "ri_cmd" in sys.modules.keys():
import ri_cmd
d[a.name] = getattr(sys.modules["ri_cmd"], a.value)
else:
d[a.name] = a.value
return d
def display(self):
display.display_widget(self)
class Label(Widget):
''' Label '''
def __init__(self, xml_node):
Widget.__init__(self, xml_node)
class Button(Widget):
''' Button '''
def __init__(self, xml_node):
Widget.__init__(self, xml_node)
class Frame(Widget):
''' Frame '''
def __init__(self, xml_node):
Widget.__init__(self, xml_node)
class Entry(Widget):
''' Entry '''
def __init__(self, xml_node):
Widget.__init__(self, xml_node)
def display(self):
display_entry(self)
class Listbox(Widget):
''' Listbox '''
def __init__(self, xml_node):
Widget.__init__(self, xml_node)
#### need add scroll bar
def display(self):
display_listbox(self)
class Radiobutton(Widget):
''' Radiobutton '''
def __init__(self, xml_node):
Widget.__init__(self, xml_node)
### need add radios
def display(self):
display_radiobutton(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
def display(self):
''' display dialog'''
display.display_message_box(self)
def construct(xml_root):
''' construct Widget's static members'''
for w in xml_root.childNodes:
if w.nodeType == w.ELEMENT_NODE and w.nodeName == "widget" and "name" in w.attributes.keys():
Widget.dict[w.attributes["name"].value] = Widget(w)
elif w.nodeType == w.ELEMENT_NODE and w.nodeName == "message_box" and "name" in w.attributes.keys():
MessageBox.dict[w.attributes["name"].value] = MessageBox(w)
def init_display(bw):
''' base widget name'''
base_w = Widget.dict[bw]
display.initialize(base_w)
def mainloop():
'''run message main loop '''
display.root_window.mainloop()