summarylogtreecommitdiffstats
path: root/MyGTKMenu.py
blob: 1f3bf61dbe306f8bb403e3748cb37348f237d764 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import os.path, MenuMaker, Prophet




from MenuMaker import indent, writeFullMenu




menuFile = "~/.mygtkmenu.txt"




def _map(x) :
	for d, s in (("\'", "\""),) :
		x = x.replace(s, d)
	return x




class Sep(object) :
	def emit(self, level) :
		return ['%sSEPARATOR' % indent(level)]




class App(object) :
	def emit(self, level) :
		x = indent(level)
		cmd = self.app.execmd
		if self.app.terminal :
			cmd = MenuMaker.terminal.runCmd(cmd)
		return [
			'%sitem = %s' % (x, _map(self.app.name)),
			'%scmd = %s' % (x, cmd),
			'%sicon = NULL' % x,
			''
		]



class Menu(object) :
	def emit(self, level) :
		menu = ['%sSubmenu = %s' % (indent(level), _map(self.name)),
			'%sicon = NULL' % indent(level + 1),
			''
		]
		for x in self :
			menu += x.emit(level + 1)
		return menu




class Root(object) :
	def __init__(self, subs) :
		if writeFullMenu :
			subs = subs + [MenuMaker.Sep(), SysMenu()]
		super(Root, self).__init__(subs)
	def emit(self, level) :
		if writeFullMenu :
			menu = [
				'iconsize = 25'
			]
			for x in self :
				menu += x.emit(level)
			menu.append('')
			return menu
		else :
			menu = []
			for x in self :
				menu += x.emit(level)
			return menu




class SysMenu(MenuMaker.Menu) :
	name = "Session"
	def __init__(self) :
		subs = [
			X('item = Log Out'),
			X('cmd = killall X'),
			X('icon = NULL')
		]
		super(SysMenu, self).__init__(subs)
		self.align = MenuMaker.Entry.StickBottom


class X(MenuMaker.Entry) :
	def __init__(self, x) :
		super(X, self).__init__()
		self.align = MenuMaker.Entry.StickBottom
		self.x = x
	def emit(self, level) :
		return [indent(level) + self.x]