With -a key, fill empty keys in current section from other sections.

portnov [2008-09-24 06:47:36]
With -a key, fill empty keys in current section from other sections.
Filename
qwerty.conf
qwerty.py
diff --git a/qwerty.conf b/qwerty.conf
index b231b91..3d61957 100644
--- a/qwerty.conf
+++ b/qwerty.conf
@@ -1,94 +1,238 @@
-Section: Graphics
+DefaultSection: 3
+Section: Графика
 Icon: krita.png
+Order: 0

-Key: G
-Title: Gimp
-Icon: gimp.svg
-Class: gimp
-Command: gimp
+Key: V
+Icon: geeqie.png
+Title: Geeqie
+Class: geeqie
+Command: geeqie
+
+Key: C
+Icon: gcolor2/icon.png
+Title: GColor2
+Class: gcolor2
+Command: gcolor2
+
+Key: X
+Icon: xsane.xpm
+Title: XSane
+Class: xsane
+Command: xsane

 Key: F
-Title: F-Spot
 Icon: f-spot.svg
+Title: F-Spot
 Class: f-spot
 Command: f-spot

-Key: I
-Title: Inkscape
-Icon: inkscape.png
-Class: inkscape
-Command: inkscape
+Key: H
+Icon: hugin.png
+Title: Hugin
+Class: hugin
+Command: hugin

-Key: V
-Title: Geeqie
+Key: R
+Icon: rawstudio.png
+Title: Raw Studio
+Class: rawstudio
+Command: rawstudio
+
+Key: G
+Mods: Shift
 Icon: geeqie.png
+Title: Geeqie
 Class: geeqie
 Command: geeqie

+Key: W
+Icon: gwenview.png
+Title: Gwenview
+Class: Gwenview
+Command: gwenview
+
+Key: I
+Icon: inkscape.png
+Title: Inkscape
+Class: inkscape
+Command: inkscape
+
 Key: Q
-Title: QtPFSgui
 Icon: qtpfsgui.png
+Title: QtPFSgui
 Class: qtpfsgui
 Command: qtpfsgui

-Key: H
-Title: Hugin
-Icon: hugin.png
-Class: hugin
-Command: hugin
+Key: F
+Mods: Shift
+Icon: f-spot.svg
+Title: F-Spot
+Description: Фотоальбом АВ
+Class: f-spot
+Command: /home/portnov/bin/f-spot-mama
+
+Key: G
+Icon: gimp.svg
+Title: Gimp
+Description: Редактор растровой графики
+Class: gimp
+Command: gimp
+
+Key: A
+Icon: agave.svg
+Title: Agave
+Class: agave
+Command: agave

-Section: Internet
+Key: S
+Icon: gnome-specimen.png
+Title: Specimen
+Class: gnome-specimen
+Command: gnome-specimen
+
+Key: U
+Icon: ufraw.png
+Title: UFRaw
+Command: ufraw
+
+Section: Интернет
 Icon: applications-internet.png
+Order: 1
+
+Key: P
+Icon: pidgin.png
+Title: Pidgin
+Class: pidgin
+Command: pidgin

 Key: E
-Title: Epiphany
 Icon: gnome-web-browser.svg
+Title: Epiphany
 Class: epiphany-browser
 Command: epiphany

+Key: M
+Icon: icedove.png
+Title: Icedove
+Class: icedove
+Command: icedove
+
 Key: I
-Title: Iceweasel
 Icon: iceweasel.png
+Title: Iceweasel
 Class: Iceweasel-bin
 Command: iceweasel

-Key: M
-Title: Claws-mail
-Icon: claws-mail.png
-Class: claws-mail
-Command: claws-mail
-
 Key: L
-Title: Liferea
 Icon: liferea.png
-Class: liferea
+Title: Liferea
+Class: liferea-bin
 Command: liferea

-Key: P
-Title: Pidgin
-Icon: pidgin.png
-Class: pidgin
-Command: pidgin
-
-Section: Office
+Section: Офис
 Icon: abiword.png
+Order: 2

-Key: W
-Title: Writer
-Icon: ooo-writer.png
-Command: oowriter
+Key: G
+Icon: gnucash-icon.png
+Title: Gnucash
+Command: gnucash
+
+Key: V
+Icon: /usr/share/vym/icons/vym.png
+Title: Vym
+Class: vym
+Command: vym

 Key: C
-Title: Calc
 Icon: ooo-calc.png
+Title: Calc
 Command: oocalc

-Key: G
-Title: Gnucash
-Icon: gnucash-icon.png
-Command: gnucash
-
 Key: E
-Title: Gedit
 Icon: abiword.png
+Title: Gedit
+Class: Gedit
 Command: gedit
+
+Key: A
+Icon: abiword.png
+Title: Abiword
+Class: abiword
+Command: abiword
+
+Key: K
+Icon: kontact.png
+Title: Kontact
+Class: kontact
+Command: kontact
+
+Key: W
+Icon: ooo-writer.png
+Title: Writer
+Command: oowriter
+
+Key: L
+Icon: lyx.png
+Title: Lyx
+Class: lyx
+Command: lyx
+
+Key: J
+Icon: gjots.png
+Title: GJots
+Class: gjots2
+Command: gjots2
+
+Section: Музыка
+Icon: rhythmbox.png
+Order: 3
+
+Key: R
+Icon: rhythmbox.png
+Title: Rhythmbox
+Class: rhythmbox
+Command: rhythmbox
+
+Section: Игры
+Icon: gnome-klotski.png
+Order: 4
+
+Key: R
+Icon: gnome-iagno.png
+Title: Reversi
+Class: iagno
+Command: iagno
+
+Key: M
+Icon: gnome-mines.png
+Title: Mines
+Class: gnomine
+Command: gnomine
+
+Key: D
+Icon: kdiamond.png
+Title: KDiamond
+Class: kdiamond
+Command: kdiamond
+
+Key: W
+Icon: warzone2100.svg
+Title: Warzone2100
+Command: warzone2100
+
+Key: N
+Icon: nexuiz48x48.png
+Title: Nexuiz
+Command: nexuiz
+
+Section: X11
+Icon: gnome-xterm.png
+Order: 6
+
+Key: X
+Icon: /usr/share/icons/Tango/scalable/devices/mouse.svg
+Title: X2X
+Command: x2x -from :0 -west -to laptop:0
+
diff --git a/qwerty.py b/qwerty.py
index 5668dde..c4db872 100755
--- a/qwerty.py
+++ b/qwerty.py
@@ -6,6 +6,7 @@ import os
 import re
 from getopt import getopt
 import time
+from copy import copy

 from Xlib import X,display,Xatom
 import Xlib.protocol.event
@@ -55,7 +56,10 @@ speckeys = {}

 def help():
     print """Synopsis:
-qwerty.py [-c | --config /path/to/config] [-f] [-g | --geometry geometry] [-d] [-h | --help]
+qwerty.py [-a] [-c | --config /path/to/config] [-f] [-g | --geometry geometry] [-d] [-h | --help]
+
+-a
+    Fill empty keys with keys from other sections

 -c | --config /path/to/config
     Use specified config file instead of ~/.config/qwerty.conf
@@ -258,6 +262,7 @@ class Key(object):
     def __init__(self,key):
         self.key = key
         self.mods = []
+        self.do_not_write = False

     def __repr__(self):
         return "<Key %s: %s>" % (self.key, self.title)
@@ -268,9 +273,12 @@ def parse_cmdline():
     fullscreen = True
     decorate = True
     geometry = ''
+    fill_empty = False

-    opts,args = getopt(sys.argv[1:], 'c:g:fdh',['config=','geometry=','help'])
+    opts,args = getopt(sys.argv[1:], 'ac:g:fdh',['config=','geometry=','help'])
     for k,v in opts:
+        if k == '-a':
+            fill_empty = True
         if k == '-c' or k == '--config':
             config_file = v
         if k == '-g' or k == '--geometry':
@@ -286,11 +294,28 @@ def parse_cmdline():
     if fullscreen:
         decorate = False

-    return fullscreen, geometry, decorate
+    return fill_empty, fullscreen, geometry, decorate


 def dict_from_keylist(keys):
-        return dict([((k.key,tuple(k.mods)), k) for k in keys])
+    return dict([((k.key,tuple(k.mods)), k) for k in keys])
+
+def update_keydict(sections, kd):
+    def get_first_key(sections, key):
+        for n in sorted(sections):
+            s = sections[n]
+            if not s.keydict:
+                continue
+            if (key, ()) in s.keydict:
+                return s.keydict[key, ()]
+
+    for l in ALPHABET:
+        if not (l, ()) in kd:
+            k = get_first_key(sections, l)
+            if k:
+                k1 = copy(k)
+                k1.do_not_write = True
+                kd[l, ()] = k1

 def parse_mods(s):
     r = []
@@ -303,7 +328,7 @@ def parse_mods(s):
         r.append(ALT)
     return r

-def parse_config():
+def parse_config(fill_empty):
     global sections
     global defsection
     global speckeys
@@ -415,6 +440,11 @@ def parse_config():
     for s in sections.values():
         s.keydict = dict_from_keylist(s.keys)

+    if fill_empty:
+        for s in sections.values():
+            update_keydict(sections, s.keydict)
+
+
 def mods_str(ms):
     r = ''
     if SHIFT in ms:
@@ -446,6 +476,8 @@ def save_config():
         writeln()

         for K in S.keydict.values():
+            if K.do_not_write:
+                continue
             write('Key', K.key)
             if K.mods:
                 write('Mods', mods_str(K.mods))
@@ -565,7 +597,7 @@ class KeyEditDialog(object):
         self.hide()

 class GUI(object):
-    def __init__(self):
+    def __init__(self, fullscreen, geometry, decorate):
         global sections

         self.buttons = {}
@@ -578,7 +610,7 @@ class GUI(object):
         self.window.connect('key-press-event', self.on_key)
         self.window.connect('key-release-event', self.key_released)

-        self.fullscreen,geometry,decorate = parse_cmdline()
+        self.fullscreen = fullscreen
         if self.fullscreen:
             self.window.fullscreen()
             self.width, self.height = self.window.get_screen().get_width(), self.window.get_screen().get_height()
@@ -931,8 +963,9 @@ class GUI(object):
                   btn.mark_running(K.cls)
         self.refresh()

-parse_config()
+fill_empty, fullscreen, geometry, decorate = parse_cmdline()
+parse_config(fill_empty)

-g = GUI()
+g = GUI(fullscreen, geometry, decorate)
 g.show_section(defsection+1,[])
 gtk.main()
ViewGit