add scrollbar processing

add mount init
decide to use top window to handle detour
This commit is contained in:
lizhi-rocky
2010-07-19 17:01:16 +08:00
parent df190f2bca
commit 3ef7daf59a
8 changed files with 109 additions and 34 deletions

View File

@@ -4,6 +4,7 @@
import ri_tk as display
import ri_seq
import ri_widget
import re
def quit():
''' correspond to quit button '''
@@ -37,3 +38,22 @@ def serial_no_init():
def serial_no_quit():
v = display.var_dict['serial_no.number'].get()
def mount_list_init():
''' initialize mount list '''
f = file('/proc/partitions', 'r')
pattern = re.compile(r'''
\s*\d+ # major dev number
\s*\d+ # minor dev number
\s*\d+ # blocks
\s*(\w+\d) # name
\s*$''', re.VERBOSE)
s = []
while True:
l = f.readline()
if not l:
break
res = pattern.search(l)
if res:
s.append(res.groups()[0])
display.var_dict['mount.list'].set(value='\n'.join(s))

View File

@@ -5,6 +5,7 @@ import Tkinter
import tkMessageBox
import sys
import ri_cmd
import ri_widget
var_dict={}
@@ -18,6 +19,8 @@ def init(base_w):
root_window.rowconfigure(0, weight=1)
root_window.geometry("%sx%s+0+0" %(root_window.winfo_screenwidth(),root_window.winfo_screenheight()))
# bind WM_DELETE_WINDOW
root_window.protocol("WM_DELETE_WINDOW", root_window.quit)
global base_widget
base_widget = create_widget_sub(base_w, root_window)
@@ -86,6 +89,22 @@ def create_widget_sub(w, p_win):
cf_func = getattr(w_win, cf[0])
cf_func( cf[1], weight=cf[2])
# handle scroll bar for sub_widgets
if 'action' in dir(w):
# ing for scrolling, ed for scrolled
for ing, ed in w.action.scrolls:
ing_win = w.dict[ing].tk_widget
ed_win = w.dict[ed].tk_widget
if ing_win['orient'] == 'vertical':
ed_cmd_name = 'yscrollcommand'
ing_cmd = getattr(ed_win, 'yview')
else:
ed_cmd_name = 'xscrollcommand'
ing_cmd = getattr(ed_win, 'xview')
ing_win.configure(command=ing_cmd)
ed_win[ed_cmd_name]=ing_win.set
# grid location
if 'grid_location' in dir(w):
w_win.grid(w.grid_location.dict)

View File

@@ -32,6 +32,10 @@ class Action:
self.dict={}
for a in xml_node.attributes.values():
self.dict[a.name] = a.value
self.scrolls = []
for node in xml_node.childNodes:
if node.nodeName == 'scroll':
self.scrolls.append((node.attributes['scrolling'].value, node.attributes['scrolled'].value))
class Widget:
''' implement widget in interface xml '''