add binding

add top window
add interface -> xml
This commit is contained in:
lizhi-rocky
2010-07-23 18:02:22 +08:00
parent 9a1bd8a5df
commit 602463a772
7 changed files with 169 additions and 36 deletions

View File

@@ -11,6 +11,7 @@ import re
def quit():
''' correspond to quit button '''
display.quit()
ri_data.to_xml()
def previous():
''' correspond to previous button '''
@@ -45,7 +46,21 @@ def mount_list_init():
''' initialize mount list '''
l = []
for m in ri_data.MountPoint.list:
# s = m.device.center(10) + m.directory.center(20) + m.filesystem.center(10)
s = m.device.ljust(10) + m.directory.ljust(20) + m.filesystem.ljust(10)
l.append(s)
display.var_dict['mount.list'].set(value=tuple([str(i) for i in l]))
def mount_list_quit():
''' mount list quit function, write mount information into xml file '''
s = display.var_dict['mount.list'].get()
if not s: return
tpl = eval(s)
for i in range(len(tpl)):
dev, dir, fs = tpl[i].split()
ri_data.MountPoint.list[i].directory = dir
ri_data.MountPoint.list[i].filesystem = fs
def mount_list_modify(*args):
''' modify an item in mount list '''
tw = ri_widget.TopWindow.dict['mount_list_modify']
tw.show()

View File

@@ -2,6 +2,12 @@
import re
import commands
from xml.dom import minidom
from xml.dom.ext import PrettyPrint
# xml file names
install_xml = '../../xml/install.xml'
config_xml = './config.xml'
def to_xml_attr(doc, node, cls, name):
''' This method is called by to_xml. Its function is to create an attribute, and set its value based on Network data member
@@ -217,7 +223,7 @@ doc - xml document instance
p_node - xml node (parent node)'''
mps = doc.createElement('mount-points')
for m in MountPoint.list:
mp = doc.createElement('mount-points')
mp = doc.createElement('mount-point')
dev_attr = doc.createAttribute('device')
dir_attr = doc.createAttribute('directory')
fs_attr = doc.createAttribute('file-system')
@@ -451,12 +457,6 @@ p_node - xml node (parent node)'''
srvs.appendChild(srv)
p_node.appendChild(srvs)
# xml file names
install_xml = '../../xml/install.xml'
config_xml = './config.xml'
from xml.dom import minidom
def init_from_xml():
''' init all classes in this module based input file (install xml) '''
xmldoc = minidom.parse(install_xml)

View File

@@ -109,6 +109,10 @@ def create_widget_sub(w, p_win):
if 'grid_location' in dir(w):
w_win.grid(w.grid_location.dict)
# handle bindings
for bd in w.bindings:
w_win.bind(bd[0], getattr(ri_cmd, bd[1]))
# save tk widget instance into w (widget instance)
setattr(w, 'tk_widget', w_win)
return w_win
@@ -135,6 +139,40 @@ def destroy_widget(w):
def create_message_box(w):
''' display MessageBox
w - widget instance'''
w - MessageBox instance'''
disp = getattr(tkMessageBox, "show%s" %(w.tp))
disp(w.title, w.message)
def create_top_window(w):
''' display TopWindow
w - TopWindow instance '''
tk_attr = dict(w.attr)
modify_attributes(tk_attr)
w_win = Tkinter.Toplevel(root_window, tk_attr)
for sub_w in w.widgets:
create_widget_sub(sub_w, w_win)
if 'grid_management' in dir(w):
for cf in w.grid_management.cf_list:
cf_func = getattr(w_win, cf[0])
cf_func(cf[1], weight=cf[2])
# save tk widget instance into w (TopWindow instance)
setattr(w, 'tk_widget', w_win)
# 'bind' it to root window
w_win.transient(root_window)
# grab all events into it
while True:
try:
w_win.grab_set()
except Tkinter.TclError:
pass
else:
break
w_win.wait_window()
return w_win

View File

@@ -50,6 +50,7 @@ class Widget:
self.attr = {}
self.widgets=[]
self.variables=[]
self.bindings = []
for node in xml_node.childNodes:
if node.nodeType == node.ELEMENT_NODE:
if node.nodeName == "grid_management":
@@ -67,6 +68,13 @@ class Widget:
"value" in node.attributes.keys() and node.attributes["value"].value or "" ))
elif node.nodeName == "action":
self.action = Action(node)
elif node.nodeName == 'binding':
if node.attributes['wrap'].value == 'single':
seq = '<'+node.attributes["sequence"].value+'>'
elif node.attributes['wrap'].value == 'double':
seq = '<<'+node.attributes["sequence"].value+'>>'
self.bindings.append((seq, \
node.attributes["function"].value))
def show(self):
Widget.current_widget = self
@@ -75,7 +83,7 @@ class Widget:
def hide(self):
display.destroy_widget(self)
class MessageBox():
class MessageBox:
''' implement dialog in interface.xml '''
dict={}
@@ -91,12 +99,37 @@ class MessageBox():
''' display dialog'''
display.create_message_box(self)
class TopWindow:
''' implement top_window in interface.xml - top_window corresponds to Toplevel in Tkinter '''
dict={}
def __init__(self, xml_node):
self.name = xml_node.attributes["name"].value
TopWindow.dict[self.name] = self
self.attr = {}
self.widgets = []
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 == "widget_attribute":
for a in node.attributes.values():
self.attr[a.name] = a.value
elif node.nodeName == "widget":
self.widgets.append(Widget(node))
def show(self):
display.create_top_window(self)
def hide(self):
display.destroy_top_window(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)
elif n.nodeName == "top_window": TopWindow(n)
def init_display(bw):
''' base widget name'''