merge ri_seq into ri_widget

change image file location in interface.xml, and change python file to use relative file location for it.
This commit is contained in:
lizhi-rocky
2010-08-02 10:28:35 +08:00
parent 2a3dc6b0bb
commit 62e5b2b075
8 changed files with 63 additions and 25 deletions

View File

@@ -2,7 +2,6 @@
''' handle gui button related commands.'''
import ri_tk as display
import ri_seq
import ri_widget
import ri_data
@@ -14,15 +13,15 @@ def quit():
''' correspond to quit button '''
# maybe a quit in current widget, so call widget.hide()
# get current widget, call its quit()
q, t = ri_seq.Sequence.current()
q, t = ri_widget.Sequence.current()
ri_widget.Widget.dict[t].hide()
display.quit()
ri_data.to_xml()
def previous():
''' correspond to previous button '''
q, t = ri_seq.Sequence.current()
wid_name = ri_seq.previous()
q, t = ri_widget.Sequence.current()
wid_name = ri_widget.Sequence.previous()
if wid_name is not None:
ri_widget.Widget.dict[t].hide()
@@ -32,8 +31,8 @@ def previous():
def next():
''' correspond to next button '''
q, t = ri_seq.Sequence.current()
wid_name = ri_seq.next()
q, t = ri_widget.Sequence.current()
wid_name = ri_widget.Sequence.next()
if wid_name is not None:
ri_widget.Widget.dict[t].hide()

View File

@@ -20,7 +20,18 @@ class Sequence:
@staticmethod
def current():
return (Sequence.current_sequence, Sequence.current_sequence.steps[Sequence.current_sequence.current_step])
@staticmethod
def previous():
if Sequence.current_sequence.current_step:
Sequence.current_sequence.current_step -= 1
return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]
@staticmethod
def next():
if Sequence.current_sequence.current_step < len(Sequence.current_sequence.steps)-1:
Sequence.current_sequence.current_step += 1
return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]
def construct(xml_root):
''' construct Sequence's static members'''
@@ -28,12 +39,4 @@ def construct(xml_root):
if s.nodeType == s.ELEMENT_NODE and s.nodeName == "sequence":
Sequence.dict[s.attributes["name"].value] = Sequence(s)
def previous():
if Sequence.current_sequence.current_step:
Sequence.current_sequence.current_step -= 1
return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]
def next():
if Sequence.current_sequence.current_step < len(Sequence.current_sequence.steps)-1:
Sequence.current_sequence.current_step += 1
return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]

View File

@@ -38,6 +38,8 @@ def create_widget(w):
# set step name which will be shown on base widget column 1 row 0
var_dict['main.step_name'].set(w.name)
import os.path
class MyImage:
''' MyImage - a dummy class to hold Image variable '''
count = 0
@@ -49,7 +51,8 @@ def modify_attributes(attr_dict):
# 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]))
drt = os.path.join(os.path.dirname(__file__), '../data')
setattr(MyImage, image_var, Tkinter.PhotoImage(file=os.path.join(drt, attr_dict[a])))
MyImage.count += 1
attr_dict[a] = getattr(MyImage, image_var)
elif a == 'command':

View File

@@ -135,13 +135,48 @@ class TopWindow:
def hide(self):
display.destroy_top_window(self)
class Sequence:
''' implement sequence in interface xml'''
dict={}
def __init__(self, xml_node):
self.steps = [ s.attributes["name"].value for s in xml_node.childNodes
if s.nodeType == s.ELEMENT_NODE and s.nodeName == "widget" ]
self.current_step = 0
Sequence.dict[xml_node.attributes["name"].value] = self
def set_current_step(self, st):
''' set current step based on input step name'''
self.current_step = self.steps.index(st)
@staticmethod
def set_current_sequence(name):
Sequence.current_sequence = Sequence.dict[name]
@staticmethod
def current():
return (Sequence.current_sequence, Sequence.current_sequence.steps[Sequence.current_sequence.current_step])
@staticmethod
def previous():
if Sequence.current_sequence.current_step:
Sequence.current_sequence.current_step -= 1
return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]
@staticmethod
def next():
if Sequence.current_sequence.current_step < len(Sequence.current_sequence.steps)-1:
Sequence.current_sequence.current_step += 1
return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]
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)
elif n.nodeName == "top_window": TopWindow(n)
elif n.nodeName == "sequence": Sequence(n)
def init_display(bw):
''' base widget name'''

View File

@@ -2,7 +2,6 @@
import ri_widget
import ri_tk
import ri_seq
import ri_data
import sys
@@ -24,11 +23,11 @@ for opt, arg in opts:
begin_step = arg
if len(args) == 0:
itf_xml = "../../xml/interface_t.xml"
ins_xml = "../../xml/install.xml"
itf_xml = "../xml/interface_t.xml"
ins_xml = "../xml/install.xml"
elif len(args) == 1:
itf_xml = args[0]
ins_xml = "../../xml/install.xml"
ins_xml = "../xml/install.xml"
else:
itf_xml = args[0]
ins_xml = args[1]
@@ -39,14 +38,13 @@ ri_data.init_from_xml()
#ri_data.init()
ri_widget.construct(xmldoc.firstChild)
ri_seq.construct(xmldoc.firstChild)
base_widget_name = xmldoc.firstChild.attributes["base_widget"].value
ri_widget.init_display(base_widget_name)
main_sequence_name = xmldoc.firstChild.attributes["sequence"].value
ri_seq.Sequence.set_current_sequence(main_sequence_name)
main_sequence = ri_seq.Sequence.dict[main_sequence_name]
ri_widget.Sequence.set_current_sequence(main_sequence_name)
main_sequence = ri_widget.Sequence.dict[main_sequence_name]
if begin_step is None:
begin_step = main_sequence.steps[0]