Recognize SpecialKey's - w/o sections and icons.

portnov [2008-08-14 08:01:07]
Recognize SpecialKey's  - w/o sections and icons.
Filename
qwerty.py
diff --git a/qwerty.py b/qwerty.py
index 2b29a02..37f6aab 100755
--- a/qwerty.py
+++ b/qwerty.py
@@ -23,6 +23,7 @@ BUTTON_FILL_RUNNING = (0.7, 0.7, 0.7)

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

 def find_icon(name):
     if os.path.exists(name):
@@ -143,6 +144,7 @@ class Key(object):
 def parse_config():
     global sections
     global defsection
+    global speckeys

     defsection = 0

@@ -175,6 +177,13 @@ def parse_config():
             context = KEY
             continue

+        v = parse_line('SpecialKey', line)
+        if v:
+            K = Key(v)
+            speckeys[v] = K
+            context = KEY
+            continue
+
         v = parse_line('Hint',line)
         if v:
             if context == SECTION:
@@ -228,6 +237,7 @@ def save_config():

     global sections
     global defsection
+    global speckeys

     cf = open(config_file, 'w')

@@ -244,6 +254,12 @@ def save_config():
                 write('Class', K.cls)
             write('Command', K.command)
             writeln()
+
+    for K in speckeys.values():
+        write('SpecialKey', K.key)
+        write('Class', K.cls)
+        write('Command', K.command)
+
     cf.close()


@@ -402,10 +418,18 @@ class GUI(object):
         gtk.main_quit()

     def on_key(self,widget,event):
+        global speckeys
+
         if event.keyval == gtk.gdk.keyval_from_name("Escape"):
             self.exit()
             return

+        for k in speckeys:
+            if event.keyval == gtk.gdk.keyval_from_name(k):
+                self.do_special_button(speckeys[k])
+                self.exit()
+                return
+
         k = event.string.upper()
         if k in '1234567890':
             self.show_section(k)
@@ -440,6 +464,12 @@ class GUI(object):
 #         print wnd.id
         os.system("wmctrl -x -a %s" % cls)

+    def do_special_button(self,key):
+        if key.cls in self.by_class:
+            self.activate_window(key.cls)
+        else:
+            os.system(key.command + ' &')
+
     def on_button(self,widget,event=None):
         if widget.running:
 #             print "Activating", widget.label
ViewGit