updated on Sat Jan 14 12:12:45 UTC 2012
[aur-mirror.git] / menumaker-compiz / Compiz.py
blobfb19f9ceb492c6935ccd7c6590f9da37379f8494
1 import MenuMaker
6 from MenuMaker import indent, writeFullMenu
11 menuFile = "~/.config/compiz/deskmenu/menu.xml"
16 def _map(x) :
17 for d, s in (("&", "&"), ("\'", "\"")) :
18 x = x.replace(s, d)
19 return x
24 class Sep(object) :
25 def emit(self, level) :
26 return ['%s<separator/>' % indent(level)]
31 class App(object) :
32 def emit(self, level) :
33 x = indent(level)
34 xx = indent(level + 1)
35 cmd = self.app.execmd
36 if self.app.terminal :
37 cmd = MenuMaker.terminal.runCmd(cmd)
38 return [
39 '%s<item type="launcher">' % x,
40 '%s<name>%s</name>' % (x, _map(self.app.name)),
41 '%s<command>%s</command>' % (x, cmd),
42 '%s</item>' % x
47 class Menu(object) :
48 def emit(self, level) :
49 menu = ['%s<menu name="%s">' % (indent(level), _map(self.name))]
50 for x in self :
51 menu += x.emit(level + 1)
52 menu.append('%s</menu>' % indent(level))
53 return menu
56 class Root(object) :
57 def __init__(self, subs) :
58 if writeFullMenu :
59 subs = subs + [MenuMaker.Sep(), SysMenu()]
60 super(Root, self).__init__(subs)
61 def emit(self, level) :
62 if writeFullMenu :
63 menu = [
64 '<menu>'
66 for x in self :
67 menu += x.emit(level)
68 menu.append('</menu>')
69 return menu
70 else :
71 menu = []
72 for x in self :
73 menu += x.emit(level)
74 return menu
80 class SysMenu(MenuMaker.Menu) :
81 name = "Compiz"
82 def __init__(self) :
83 subs = [
84 X('<item type="launcher">'),
85 X(' <name>Edit Menu</name>'),
86 X(' <icon>gtk-edit</icon>'),
87 X(' <command>compiz-deskmenu-editor</command>'),
88 X('</item>'),
89 X('<item type="viewportlist"/>'),
90 X('<item type="reload"/>'),
91 MenuMaker.Sep(),
92 X('<item type="launcher">'),
93 X(' <name>Logout</name>'),
94 X(' <icon>gnome-session-logout</icon>'),
95 X(' <command>killall X</command>'),
96 X('</item>')
98 super(SysMenu, self).__init__(subs)
99 self.align = MenuMaker.Entry.StickBottom
104 class X(MenuMaker.Entry) :
105 def __init__(self, x) :
106 super(X, self).__init__()
107 self.align = MenuMaker.Entry.StickBottom
108 self.x = x
109 def emit(self, level) :
110 return [indent(level) + self.x]