Files
new_install/python/mine/ri_widget.py
lizhi-rocky d1760bad48 10% work
complete most xml relax ng work.
work on real interface xml
work on python scripts for parsing interface xml
2010-07-08 11:52:50 +08:00

79 lines
2.8 KiB
Python

#!/usr/bin/python
import Tkinter
import sys
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 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)