Recognize 'Order' option for sections.

portnov [2008-08-27 07:53:46]
Recognize 'Order' option for sections.
Filename
qwerty.py
diff --git a/qwerty.py b/qwerty.py
index 0f9450c..d4c45ef 100755
--- a/qwerty.py
+++ b/qwerty.py
@@ -41,7 +41,7 @@ BUTTON_FILL = (0.9, 0.9, 0.9)
 BUTTON_FILL_RUNNING = (0.7, 0.7, 0.7)

 config_file = os.path.expanduser('~/.config/qwerty.conf')
-sections = []
+sections = {}
 speckeys = {}

 def find_icon(name):
@@ -234,6 +234,8 @@ def parse_config():
     global speckeys

     defsection = 0
+    ts = []
+    o = 0

     def parse_line(key,line):
         key = key + ": "
@@ -252,9 +254,16 @@ def parse_config():
         v = parse_line('Section',line)
         if v:
             S = Section(v)
-            sections.append(S)
+            S.order = o
+            o = (o+1) % 10
+            ts.append(S)
             context = SECTION
             continue
+
+        v = parse_line('Order', line)
+        if v:
+            S.order = int(v)
+            continue

         v = parse_line('Key',line)
         if v:
@@ -312,10 +321,11 @@ def parse_config():
             else:
                 raise SyntaxError, "Unexpected 'Command' key in config"
             continue
+    sections = dict([(s.order, s) for s in ts])

 def save_config():
     def write(key,value):
-        cf.write(key + ': ' + value + '\n')
+        cf.write(key + ': ' + str(value) + '\n')

     def writeln():
         cf.write('\n')
@@ -327,9 +337,10 @@ def save_config():
     cf = open(config_file, 'w')

     write('DefaultSection', str(defsection))
-    for S in sections:
+    for S in sections.values():
         write('Section', S.title)
         write('Icon', S.icon)
+        write('Order', S.order)
         writeln()
         for K in S.keys.values():
             write('Key', K.key)
@@ -403,8 +414,8 @@ class GUI(object):
         for btn in self.sbuttons:
             btn.connect("button-press-event",self.on_section)

-        for i,S in enumerate(sections):
-            btn = self.sbuttons[i]
+        for i,S in sections.iteritems():
+            btn = self.sbuttons[(i-1)%10]
             btn.set_label(S.title)
             btn.set_icon(S.icon)

@@ -579,6 +590,7 @@ class GUI(object):
         self.collect_windows()

         id = (int(k)-1)%10
+#         id = int(k)
         defsection = id

         for b in self.sbuttons:
@@ -589,7 +601,7 @@ class GUI(object):
         for b in self.sbuttons:
             b.queue_draw()

-        self.S = sections[id]
+        self.S = sections[int(k)]
         for b in self.buttons:
             btn = self.buttons[b]
             btn.clear()
ViewGit