add scrollbar processing
add mount init decide to use top window to handle detour
This commit is contained in:
@@ -73,6 +73,8 @@ row 4 | quit previous next |
|
||||
How to connect different windows? There are 2 alternatives. One is using Ids. Every window has a id, my program just sorts windows according to Ids. For example, there are 3 windows with id 1, 2, and 3. Number 1 window will be first displayed, when user clicks "next", number 2 window will be displayed. It seems reasonable, right? If it did not have the following 2 drawbacks, I would not think about the second alternative: first, id is an inborn attribute to each window, you have to decide the install sequence at the same time or before you define the window; second it is a little hard to solve the "detour" problem. The install sequence is not a straight line, but has some side road, which is called "detour" by I. For example, when in partition dividing, there may or may not be some windows for RAID setup.
|
||||
Now comes the second alternative: using names. I admit and believe that human beings like string while computers like number. Each window has a name. The install/setup sequence will be defined separately like ["welcome", "serial number", "partition dividing", "package selecting"]. For detour problem, another sequence will be defined, and some button in main sequence will open the detour sequence.
|
||||
|
||||
I will just use top window to handle detour!
|
||||
|
||||
3.1.2 Curses
|
||||
I have investigated several choices: urwid, pycdk, and python+dialog. Some is a little complicated and error-prone: urwid. Some has few documents: pycdk. Finally, I chose python+dialog. It is simple, and workable. I like the demo.py in it very much. It demonstrates excellent programming skills.
|
||||
The curses interface will be simple and terse. It will only include the changing part in GUI interface(row 2).
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 '''
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<install>
|
||||
<serial-number>123456789012</serial-number>
|
||||
|
||||
<partition device="/dev/hda1" boot="no" type="primary" id="5" size="101MB"/>
|
||||
<partition device="/dev/hda2" boot="no" type="primary" id="5" size="101MB"/>
|
||||
<partition device="/dev/hda3" boot="no" type="primary" id="5" size="203MB"/>
|
||||
<partition device="/dev/hda4" boot="no" type="extended" id="5" size="9828MB"/>
|
||||
<partition device="/dev/hda5" boot="no" type="logic" id="5" size="203MB"/>
|
||||
<partition device="/dev/hda6" boot="no" type="logic" id="5" size="203MB"/>
|
||||
<partition device="/dev/hdb1" boot="no" type="primary" id="83" size="5004MB"/>
|
||||
<partition device="/dev/hdb2" boot="no" type="primary" id="82" size="800MB"/>
|
||||
<partition device="/dev/hdb3" boot="no" type="extended" id="5" size="4431MB"/>
|
||||
<partition device="/dev/hdb5" boot="no" type="logic" id="83" size="502MB"/>
|
||||
<partitions unit='sector'>
|
||||
<partition device="/dev/hda1" start='63' size='16450497' id='83'/>
|
||||
<partition device="/dev/hda2" start='16450560' size='4016250' id="5"/>
|
||||
<partition device='/dev/hda5' start='16450623' size='4016187' id='83'/>
|
||||
</partitions>
|
||||
|
||||
<raid raid-device="/dev/md0" raid-type="RAID0">
|
||||
<raw-device>/dev/hda1</raw-device>
|
||||
|
||||
@@ -20,24 +20,17 @@
|
||||
</define>
|
||||
|
||||
<define name="partitions">
|
||||
<oneOrMore>
|
||||
<element name="partition">
|
||||
<attribute name="device"/>
|
||||
<attribute name="boot">
|
||||
<ref name="mybool"/>
|
||||
</attribute>
|
||||
<attribute name="type">
|
||||
<choice>
|
||||
<value>primary</value>
|
||||
<value>extended</value>
|
||||
<value>logic</value>
|
||||
</choice>
|
||||
</attribute>
|
||||
<attribute name="id"/>
|
||||
<attribute name="start"/>
|
||||
<attribute name="end"/>
|
||||
</element>
|
||||
</oneOrMore>
|
||||
<element name='partitions'>
|
||||
<attribute name='unit'/>
|
||||
<oneOrMore>
|
||||
<element name='partition'>
|
||||
<attribute name='device'/>
|
||||
<attribute name='start'/>
|
||||
<attribute name='size'/>
|
||||
<attribute name='id'/>
|
||||
</element>
|
||||
</oneOrMore>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="raids">
|
||||
|
||||
@@ -80,6 +80,9 @@ on special cases -->
|
||||
<optional>
|
||||
<attribute name="textvariable"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="listvariable"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="orient">
|
||||
<choice>
|
||||
|
||||
@@ -205,23 +205,64 @@ row 4 | |
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<!--
|
||||
column 0 column 1 column 2
|
||||
____________________________________________________________
|
||||
row 0 | |
|
||||
row 1 | |
|
||||
row 2 | |
|
||||
| _________ __________________________ |
|
||||
| | | | | |
|
||||
| | | | | |
|
||||
| | text | | | |
|
||||
| | | | | |
|
||||
| | | | | |
|
||||
| |_________| | | |
|
||||
| |__________________________| |
|
||||
| |
|
||||
| |
|
||||
| |
|
||||
row 3 | |
|
||||
row 4 | |
|
||||
|____________________________________________________________|
|
||||
-->
|
||||
|
||||
<widget type='Frame' name='mount'>
|
||||
<grid_management rows='1' columns='3'>
|
||||
<grid_management rows='1' columns='2'>
|
||||
<configure row='0' weight='1'/>
|
||||
<configure column='0' weight='1'/>
|
||||
<configure column='1' weight='1'/>
|
||||
<configure column='2' weight='1'/>
|
||||
</grid_management>
|
||||
<grid_location row='2' column='0' columnspan='3' sticky='NSWE'/>
|
||||
|
||||
<variable name='mount.list' type='StringVar'/>
|
||||
|
||||
<action>
|
||||
<scroll scrolling='mount.scroll' scrolled='mount.list'/>
|
||||
</action>
|
||||
|
||||
<widget type='Text'>
|
||||
<widget_attribute width='40' height='15' state='disabled'/>
|
||||
<grid_location row='0' column='0'/>
|
||||
</widget>
|
||||
|
||||
<widget type='Listbox'>
|
||||
<widget_attribute width='40' height='15'/>
|
||||
<widget type='Frame'>
|
||||
<grid_management rows='1' columns='2'>
|
||||
<configure row='0' weight='1'/>
|
||||
<configure column='0' weight='1'/>
|
||||
</grid_management>
|
||||
<grid_location row='0' column='1' columnspan='2'/>
|
||||
|
||||
<widget type='Listbox' name='mount.list'>
|
||||
<widget_attribute width='40' height='15' listvariable='mount.list'/>
|
||||
<grid_location row='0' column='0'/>
|
||||
<action init='mount_list_init'/>
|
||||
</widget>
|
||||
|
||||
<widget type='Scrollbar' name='mount.scroll'>
|
||||
<widget_attribute orient='vertical'/>
|
||||
<grid_location row='0' column='1' sticky='NS'/>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
@@ -291,7 +332,6 @@ row 4 | |
|
||||
<sequence name='main'>
|
||||
<widget name='welcome'/>
|
||||
<widget name='serial_no'/>
|
||||
<widget name='partition'/>
|
||||
<widget name='mount'/>
|
||||
<widget name='network'/>
|
||||
</sequence>
|
||||
|
||||
Reference in New Issue
Block a user