1 column 1, row 0, display step name
2 variable
3 init and quit action
This commit is contained in:
lizhi-rocky
2010-07-13 16:53:14 +08:00
parent 5ed4600bf7
commit 732e5f1509
5 changed files with 125 additions and 25 deletions

View File

@@ -12,10 +12,9 @@ def quit():
def previous():
''' correspond to previous button '''
wid_name = ri_seq.previous()
print wid_name
if wid_name is not None:
if 'current_window' in dir(display):
display.kill_widget(display.current_window)
if ri_widget.Widget.current_widget:
ri_widget.Widget.current_widget.hide()
ri_widget.Widget.dict[wid_name].display()
else:
@@ -24,11 +23,18 @@ def previous():
def next():
''' correspond to next button '''
wid_name = ri_seq.next()
print wid_name
if wid_name is not None:
if 'current_window' in dir(display):
display.kill_widget(display.current_window)
if ri_widget.Widget.current_widget:
ri_widget.Widget.current_widget.hide()
ri_widget.Widget.dict[wid_name].display()
else:
ri_widget.MessageBox.dict["next"].display()
def serial_no_init():
print 'serial_no_init'
display.var_dict['serial_no.number'].set(value='123')
def serial_no_quit():
v = display.var_dict['serial_no.number'].get()
print v

View File

@@ -3,6 +3,12 @@
import Tkinter
import tkMessageBox
import sys
import ri_cmd
var_dict={}
widget_dict={}
def initialize(base_w):
''' base_w - base widget instance '''
global root_window
@@ -23,15 +29,52 @@ def quit():
def display_widget(w):
''' w - widget instance '''
global current_window
current_window = display_widget_sub(w, base_widget)
setattr(w, 'tk_widget', display_widget_sub(w, base_widget))
# set step name
if 'name' in dir(w):
var_dict['main.step_name'].set(w.name)
class MyImage:
''' MyImage - a dummy class to hold Image variable '''
count = 0
def modify_attributes(attr_dict):
''' modify values in attr_dict to suit Tk usage '''
for a in attr_dict.keys():
if a == 'image':
# I think there is a bug in Tkinter on Image processing
# I have to bypass it in the following way:
image_var = 'a' + str(MyImage.count)
setattr(MyImage, image_var, Tkinter.PhotoImage(file=attr_dict[a]))
MyImage.count += 1
attr_dict[a] = getattr(MyImage, image_var)
elif a == 'command':
attr_dict[a] = getattr(sys.modules["ri_cmd"], attr_dict[a])
elif a == "textvariable" or a == "listvariable":
attr_dict[a] = var_dict[attr_dict[a]]
def display_widget_sub(w, p_win):
'''
w - widget instance
p_win - Tk parent window '''
# name type and value
if "variables" in dir(w):
for v_n, v_t, v_v in w.variables:
if not v_n in var_dict.keys():
var_dict[v_n] = getattr(Tkinter, v_t)(value=v_v)
# process action init
if 'action' in dir(w) and 'init' in w.action.dict:
getattr(sys.modules['ri_cmd'], w.action.dict['init'])()
tk_attr = dict(w.attr)
modify_attributes(tk_attr)
tk_func = getattr(Tkinter, w.tp)
w_win = tk_func(p_win, w.attr)
w_win = tk_func(p_win, tk_attr)
# display sub widgets
if 'widgets' in dir(w):
for sub_w in w.widgets:
@@ -49,9 +92,21 @@ def display_widget_sub(w, p_win):
return w_win
def kill_widget(win):
''' win - Tk window instance '''
win.destroy()
def process_action_quit(w):
''' process action quit '''
if 'action' in dir(w) and 'quit' in w.action.dict:
getattr(sys.modules['ri_cmd'], w.action.dict['quit'])()
if 'widgets' in dir(w):
for sub_w in w.widgets:
process_action_quit(sub_w)
def kill_widget(w):
''' w - Widget instance '''
# process action quit
process_action_quit(w)
w.tk_widget.destroy()
#def display_entry(w):

View File

@@ -1,7 +1,6 @@
#!/usr/bin/python
import Tkinter
import sys
import ri_tk as display
class GridManagement:
@@ -28,12 +27,21 @@ class GridLocation:
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
self.tp = xml_node.attributes["type"].value
self.attr = self.widget_attribute(xml_node)
gm_list = [m for m in xml_node.childNodes
@@ -53,26 +61,36 @@ class Widget:
for w in w_list:
self.widgets.append(Widget(w))
v_list = [ v for v in xml_node.childNodes
if v.nodeType == v.ELEMENT_NODE and v.nodeName == "variable" ]
if v_list:
self.variables=[]
for v in v_list:
self.variables.append((v.attributes["name"].value, \
v.attributes["type"].value, \
"value" in v.attributes.keys() and v.attributes["value"].value or "" ))
act_list = [ a for a in xml_node.childNodes
if a.nodeType == a.ELEMENT_NODE and a.nodeName == "action" ]
if act_list:
self.action = Action(act_list[0])
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:
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
d[a.name] = a.value
return d
def display(self):
Widget.current_widget = self
display.display_widget(self)
def hide(self):
display.kill_widget(self)
class Label(Widget):
''' Label '''
def __init__(self, xml_node):