add chinese support
This commit is contained in:
@@ -66,7 +66,10 @@ def get_extra_depending():
|
||||
for g in ri_data.Group.dict.values():
|
||||
if g.install != 'no':
|
||||
l.extend([ p for p in g.mandatory ])
|
||||
l.extend([ p[0] for p in g.optional if p[1] == 'yes' ])
|
||||
if g.selection == 'manual':
|
||||
l.extend([ p[0] for p in g.optional if p[1] == 'yes' ])
|
||||
else:
|
||||
l.extend([ p[0] for p in g.optional ])
|
||||
|
||||
set1 = set(l)
|
||||
set2 = set(set1)
|
||||
|
||||
@@ -8,6 +8,8 @@ import ri_cmd
|
||||
import ri_widget
|
||||
|
||||
var_dict={}
|
||||
# language should be all lower case letters
|
||||
language='english'
|
||||
|
||||
def init(base_w):
|
||||
''' base_w - base widget instance '''
|
||||
@@ -17,7 +19,9 @@ def init(base_w):
|
||||
# grid management for root_window
|
||||
root_window.columnconfigure(0, weight=1)
|
||||
root_window.rowconfigure(0, weight=1)
|
||||
|
||||
root_window.geometry("%sx%s+0+0" %(root_window.winfo_screenwidth(),root_window.winfo_screenheight()))
|
||||
root_window.title(translate_text('Linx'))
|
||||
|
||||
# bind WM_DELETE_WINDOW
|
||||
root_window.protocol("WM_DELETE_WINDOW", root_window.quit)
|
||||
@@ -28,6 +32,12 @@ def quit():
|
||||
''' exit root window '''
|
||||
root_window.quit()
|
||||
|
||||
def set_step_info(s):
|
||||
''' set some information in base widget '''
|
||||
# set step name which will be shown on base widget column 1 row 0
|
||||
title = translate_text(s)
|
||||
var_dict['main.step_name'].set(title)
|
||||
|
||||
def create_widget(w):
|
||||
''' w - widget instance '''
|
||||
|
||||
@@ -35,8 +45,7 @@ def create_widget(w):
|
||||
|
||||
# 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)
|
||||
set_step_info(w.name)
|
||||
|
||||
import os.path
|
||||
|
||||
@@ -44,6 +53,14 @@ class MyImage:
|
||||
''' MyImage - a dummy class to hold Image variable '''
|
||||
count = 0
|
||||
|
||||
def translate_text(txt):
|
||||
''' multi-language support, translate t if needed '''
|
||||
key = txt.lower()
|
||||
if key in ri_widget.Text.dict.keys() and (txt[0] == '#' or language != 'english'):
|
||||
return getattr(ri_widget.Text.dict[key], language)
|
||||
else:
|
||||
return txt
|
||||
|
||||
def modify_attributes(attr_dict):
|
||||
''' modify values in attr_dict to suit Tk usage '''
|
||||
for a in attr_dict.keys():
|
||||
@@ -59,7 +76,9 @@ def modify_attributes(attr_dict):
|
||||
attr_dict[a] = getattr(sys.modules["ri_cmd"], attr_dict[a])
|
||||
elif a == "textvariable" or a == "listvariable" or a == 'variable':
|
||||
attr_dict[a] = var_dict[attr_dict[a]]
|
||||
|
||||
elif a == "text":
|
||||
attr_dict[a] = translate_text(attr_dict[a])
|
||||
|
||||
def create_widget_sub(w, p_win):
|
||||
'''
|
||||
w - widget instance
|
||||
@@ -143,7 +162,7 @@ def create_message_box(w):
|
||||
''' display MessageBox
|
||||
w - MessageBox instance'''
|
||||
disp = getattr(tkMessageBox, "show%s" %(w.tp))
|
||||
disp(w.title, w.message)
|
||||
disp(translate_text(w.title), translate_text(w.message))
|
||||
|
||||
def create_top_window(w):
|
||||
''' display TopWindow
|
||||
@@ -243,7 +262,9 @@ class SoftwarePackageWindow():
|
||||
win.columnconfigure(0, weight=1)
|
||||
win.rowconfigure(1, weight=1)
|
||||
win.rowconfigure(4, weight=1)
|
||||
Tkinter.Label(win, text='Mandatory').grid(column=0, row=0)
|
||||
|
||||
text_mdt = translate_text('Mandatory')
|
||||
Tkinter.Label(win, text=text_mdt).grid(column=0, row=0)
|
||||
cnv1 = Tkinter.Canvas(win)
|
||||
hs1 = Tkinter.Scrollbar(win, orient='horizontal')
|
||||
hs1.configure(command=cnv1.xview)
|
||||
@@ -265,9 +286,11 @@ class SoftwarePackageWindow():
|
||||
for i in range(len(self.group.mandatory)):
|
||||
Tkinter.Label(fr1, text=self.group.mandatory[i]).grid(column=i%5, row=i/5, sticky='NWES')
|
||||
|
||||
Tkinter.Label(win, text='Optional').grid(column=0, row=3)
|
||||
text_opt = translate_text('Optional')
|
||||
Tkinter.Label(win, text=text_opt).grid(column=0, row=3)
|
||||
self.selection = Tkinter.StringVar(value=self.group.selection)
|
||||
chk_sa = Tkinter.Checkbutton(win, text='Select all', command=self.select_all, variable=self.selection, onvalue='all', offvalue='manual')
|
||||
text_sal = translate_text('Select all')
|
||||
chk_sa = Tkinter.Checkbutton(win, text=text_sal, command=self.select_all, variable=self.selection, onvalue='all', offvalue='manual')
|
||||
chk_sa.grid(column=1, row=3)
|
||||
if self.group.selection == 'all':
|
||||
chk_sa.select()
|
||||
|
||||
@@ -197,7 +197,7 @@ def dependency_list_init():
|
||||
ri_dep.resolve_recursive_depending()
|
||||
ri_dep.construct_depended()
|
||||
dep_dict = ri_dep.get_extra_depending()
|
||||
l = [ k.ljust(15) + ': ' + ' '.join(dep_dict[k]) for k in dep_dict.keys()]
|
||||
l = [ k.ljust(20) + ': ' + ' '.join(dep_dict[k]) for k in dep_dict.keys()]
|
||||
display.var_dict['dependency.list'].set(value=tuple(l))
|
||||
|
||||
def service_construct(w):
|
||||
|
||||
@@ -169,6 +169,22 @@ class Sequence:
|
||||
Sequence.current_sequence.current_step += 1
|
||||
return Sequence.current_sequence.steps[Sequence.current_sequence.current_step]
|
||||
|
||||
class Text:
|
||||
''' implement text in interface.xml '''
|
||||
dict={}
|
||||
|
||||
def __init__(self, xml_node):
|
||||
for n in xml_node.childNodes:
|
||||
if n.nodeType == n.ELEMENT_NODE:
|
||||
if n.nodeName == 'English': self.english = n.firstChild.data
|
||||
elif n.nodeName == 'Chinese': self.chinese = n.firstChild.data
|
||||
|
||||
if 'key' in xml_node.attributes.keys():
|
||||
self.key = xml_node.attributes['key'].value
|
||||
else:
|
||||
self.key = self.english
|
||||
Text.dict[self.key.lower()] = self
|
||||
|
||||
def construct(xml_root):
|
||||
''' construct Widget's static members'''
|
||||
for n in xml_root.childNodes:
|
||||
@@ -177,6 +193,7 @@ def construct(xml_root):
|
||||
elif n.nodeName == "message_box": MessageBox(n)
|
||||
elif n.nodeName == "top_window": TopWindow(n)
|
||||
elif n.nodeName == "sequence": Sequence(n)
|
||||
elif n.nodeName == "text": Text(n)
|
||||
|
||||
def init_display(bw):
|
||||
''' base widget name'''
|
||||
|
||||
@@ -10,10 +10,10 @@ from xml.dom import minidom
|
||||
import os.path
|
||||
|
||||
def print_usages():
|
||||
print 'Usages: %s [-b|--begin step_name] [interface_xml_file] [install_xml_file]' %sys.argv[0]
|
||||
print 'Usages: %s [-b|--begin step_name] [-l|--language language] [interface_xml_file] [install_xml_file]' %sys.argv[0]
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "b:", ["begin=",])
|
||||
opts, args = getopt.getopt(sys.argv[1:], "b:l:", ["begin=","language="])
|
||||
except getopt.GetoptError:
|
||||
print_usages()
|
||||
sys.exit(1)
|
||||
@@ -22,6 +22,8 @@ begin_step=None
|
||||
for opt, arg in opts:
|
||||
if opt in ('-b', '--begin'):
|
||||
begin_step = arg
|
||||
elif opt in ('-l', '--language'):
|
||||
ri_tk.language = arg.lower()
|
||||
|
||||
if len(args) == 0:
|
||||
itf_xml = "../xml/interface_t.xml"
|
||||
|
||||
Reference in New Issue
Block a user