2010/7/14:
add some content in design some minor changes in python scripts
This commit is contained in:
@@ -16,9 +16,9 @@ def previous():
|
||||
if ri_widget.Widget.current_widget:
|
||||
ri_widget.Widget.current_widget.hide()
|
||||
|
||||
ri_widget.Widget.dict[wid_name].display()
|
||||
ri_widget.Widget.dict[wid_name].show()
|
||||
else:
|
||||
ri_widget.MessageBox.dict["previous"].display()
|
||||
ri_widget.MessageBox.dict["previous"].show()
|
||||
|
||||
def next():
|
||||
''' correspond to next button '''
|
||||
@@ -27,14 +27,13 @@ def next():
|
||||
if ri_widget.Widget.current_widget:
|
||||
ri_widget.Widget.current_widget.hide()
|
||||
|
||||
ri_widget.Widget.dict[wid_name].display()
|
||||
ri_widget.Widget.dict[wid_name].show()
|
||||
else:
|
||||
ri_widget.MessageBox.dict["next"].display()
|
||||
ri_widget.MessageBox.dict["next"].show()
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@ import sys
|
||||
import ri_cmd
|
||||
|
||||
var_dict={}
|
||||
widget_dict={}
|
||||
|
||||
def initialize(base_w):
|
||||
def init(base_w):
|
||||
''' base_w - base widget instance '''
|
||||
global root_window
|
||||
root_window = Tkinter.Tk()
|
||||
@@ -20,19 +19,20 @@ def initialize(base_w):
|
||||
root_window.geometry("%sx%s+0+0" %(root_window.winfo_screenwidth(),root_window.winfo_screenheight()))
|
||||
|
||||
global base_widget
|
||||
base_widget = display_widget_sub(base_w, root_window)
|
||||
base_widget = create_widget_sub(base_w, root_window)
|
||||
|
||||
def quit():
|
||||
''' exit root window '''
|
||||
root_window.quit()
|
||||
|
||||
def display_widget(w):
|
||||
def create_widget(w):
|
||||
''' w - widget instance '''
|
||||
global current_window
|
||||
setattr(w, 'tk_widget', display_widget_sub(w, base_widget))
|
||||
|
||||
create_widget_sub(w, base_widget)
|
||||
|
||||
# set step name
|
||||
if 'name' in dir(w):
|
||||
# set step name which will be shown on base widget column 1 row 0
|
||||
var_dict['main.step_name'].set(w.name)
|
||||
|
||||
class MyImage:
|
||||
@@ -54,21 +54,22 @@ def modify_attributes(attr_dict):
|
||||
elif a == "textvariable" or a == "listvariable":
|
||||
attr_dict[a] = var_dict[attr_dict[a]]
|
||||
|
||||
def display_widget_sub(w, p_win):
|
||||
def create_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)
|
||||
for v_n, v_t, v_v in w.variables:
|
||||
if not v_n in var_dict.keys():
|
||||
# if not yet in dict, create it
|
||||
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'])()
|
||||
|
||||
# change attr, if needed to suit tk
|
||||
tk_attr = dict(w.attr)
|
||||
modify_attributes(tk_attr)
|
||||
|
||||
@@ -76,9 +77,8 @@ def display_widget_sub(w, p_win):
|
||||
w_win = tk_func(p_win, tk_attr)
|
||||
|
||||
# display sub widgets
|
||||
if 'widgets' in dir(w):
|
||||
for sub_w in w.widgets:
|
||||
display_widget_sub(sub_w, w_win)
|
||||
for sub_w in w.widgets:
|
||||
create_widget_sub(sub_w, w_win)
|
||||
|
||||
# grid management
|
||||
if 'grid_management' in dir(w):
|
||||
@@ -90,8 +90,14 @@ def display_widget_sub(w, p_win):
|
||||
if 'grid_location' in dir(w):
|
||||
w_win.grid(w.grid_location.dict)
|
||||
|
||||
# save tk widget instance into w (widget instance)
|
||||
setattr(w, 'tk_widget', w_win)
|
||||
return w_win
|
||||
|
||||
# When creating widget, I have to create each sub widget.
|
||||
# while destroying a widget, only destroy one. Tk functions will
|
||||
# destroy all descendant.
|
||||
# so init is a little different from quit.
|
||||
def process_action_quit(w):
|
||||
''' process action quit '''
|
||||
if 'action' in dir(w) and 'quit' in w.action.dict:
|
||||
@@ -101,20 +107,14 @@ def process_action_quit(w):
|
||||
for sub_w in w.widgets:
|
||||
process_action_quit(sub_w)
|
||||
|
||||
def kill_widget(w):
|
||||
def destroy_widget(w):
|
||||
''' w - Widget instance '''
|
||||
# process action quit
|
||||
process_action_quit(w)
|
||||
|
||||
w.tk_widget.destroy()
|
||||
|
||||
#def display_entry(w):
|
||||
|
||||
#def display_listbox(w):
|
||||
|
||||
#def display_radiobutton(w):
|
||||
|
||||
def display_message_box(w):
|
||||
def create_message_box(w):
|
||||
''' display MessageBox
|
||||
w - widget instance'''
|
||||
disp = getattr(tkMessageBox, "show%s" %(w.tp))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import Tkinter
|
||||
import ri_tk as display
|
||||
|
||||
class GridManagement:
|
||||
@@ -42,95 +41,35 @@ class Widget:
|
||||
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.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])
|
||||
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)
|
||||
|
||||
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))
|
||||
|
||||
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:
|
||||
for a in attr_list[0].attributes.values():
|
||||
d[a.name] = a.value
|
||||
return d
|
||||
|
||||
def display(self):
|
||||
def show(self):
|
||||
Widget.current_widget = self
|
||||
display.display_widget(self)
|
||||
display.create_widget(self)
|
||||
|
||||
def hide(self):
|
||||
display.kill_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)
|
||||
display.destroy_widget(self)
|
||||
|
||||
class MessageBox():
|
||||
''' implement dialog in interface.xml '''
|
||||
@@ -142,22 +81,22 @@ class MessageBox():
|
||||
self.title = xml_node.attributes["title"].value
|
||||
self.message = xml_node.attributes["message"].value
|
||||
|
||||
def display(self):
|
||||
MessageBox.dict[self.name] = self
|
||||
|
||||
def show(self):
|
||||
''' display dialog'''
|
||||
display.display_message_box(self)
|
||||
display.create_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)
|
||||
|
||||
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'''
|
||||
base_w = Widget.dict[bw]
|
||||
display.initialize(base_w)
|
||||
display.init(Widget.dict[bw])
|
||||
|
||||
def mainloop():
|
||||
'''run message main loop '''
|
||||
|
||||
@@ -41,6 +41,6 @@ if begin_step is None:
|
||||
else:
|
||||
main_sequence.set_step(begin_step)
|
||||
|
||||
ri_widget.Widget.dict[begin_step].display()
|
||||
ri_widget.Widget.dict[begin_step].show()
|
||||
|
||||
ri_widget.mainloop()
|
||||
|
||||
Reference in New Issue
Block a user