~gladex/gladex/0.4

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
101
102
#!/usr/bin/env python

import sys
import os
import inspect
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
from py_compile import compile
gpath = os.path.split(__file__)[0]
if gpath == "": gpath = "."
compile(gpath+"/"+"{CALLBACKS_FILE_TITLE_EXT}")
import {CALLBACKS_FILE_TITLE} as callbacks


class holder:
{I}def __init__(self, cn, tree):
{I}{I}self.cn = cn
{I}{I}self.wTree = tree
{I}def get_lambda(self):
{I}{I}return lambda cw, cd="": self.calls(self.cn, cw, cd)
{I}def calls(self, callname, callwidget, calldata=''):
{I}{I}func = dir(callbacks)
{I}{I}i=func.index(callname)
{I}{I}obj = getattr(callbacks, func[i])
{I}{I}obj(callwidget, calldata, self.wTree)


def get_callback_functions(handarray):
{I}working_directory=gpath+"/"
{I}sys.path.insert(0, working_directory)
{I}call_file_name = working_directory+"{CALLBACKS_FILE_TITLE_EXT}"
{I}callbacksmod = __import__(inspect.getmodulename(call_file_name))
{I}a=""
{I}funcs = dir(callbacksmod)
{I}for c in handarray:
{I}{I}if c in funcs: continue
{I}{I}else: a+="\ndef "+c+"(widget, data, wtree):\n\tprint \"function '"+c+"' not implmented\"\n\tpass\n"
{I}return a
#


gladefilepath = None
def get_handlers():
{I}global gladefilepath
{I}gladefile = open(gladefilepath,"r")
{I}handlerlines = []
{I}handlers = {}
{I}for line in gladefile.readlines():
{I}{I}line = line.strip()
{I}{I}if line[0:7] == '<signal':
{I}{I}{I}handlerlines.append(line)
{I}for item in handlerlines:
{I}{I}if item.find('handler=') >= 0:
{I}{I}{I}tail = item[item.find('handler=') +9:]
{I}{I}{I}handlers[tail[:tail.find('\"')]] = 0
{I}return handlers.keys()
#
class {CLASS_NAME}:
{I}def __init__(self):
{I}{I}global gladefilepath
{I}{I}self.gladefile = gpath+'/{GLADE_FILE_TITLE_EXT}'
{I}{I}gladefilepath = self.gladefile
{I}{I}self.checkcallbacks()
{I}{I}self.wTree = gtk.glade.XML(self.gladefile)
{I}{I}callbacks.init(self.wTree)
{I}{I}self.handarray = get_handlers()
{I}{I}self.wTree.signal_autoconnect(self.get_dictionary())
{I}def calls(self, callname, callwidget, calldata=''):
{I}{I}func = dir(callbacks)
{I}{I}i=func.index(callname)
{I}{I}obj = getattr(callbacks, func[i])
{I}{I}obj(callwidget, calldata, self.wTree)
{I}def checkcallbacks(self):
{I}{I}global callbacks
{I}{I}newcalls = get_callback_functions(get_handlers())
{I}{I}if newcalls != "":
{I}{I}{I}{I}self.callbacks_file= open(gpath+"/"+"{CALLBACKS_FILE_TITLE_EXT}","a")
{I}{I}{I}{I}self.callbacks_file.write(newcalls)
{I}{I}{I}{I}self.callbacks_file.close()
{I}{I}{I}{I}compile(gpath+"/"+"{CALLBACKS_FILE_TITLE_EXT}")
{I}{I}{I}{I}reload(callbacks)
{I}def get_dictionary(self):
{I}{I}indent = "{INDENT_STYLE}"
{I}{I}dic = {}
{I}{I}for hand in self.handarray:
{I}{I}{I}s = holder(hand, self.wTree)
{I}{I}{I}dic[hand] = s.get_lambda()
{I}{I}return dic
#

if __name__ == '__main__':
{I}someclass = {CLASS_NAME}()
{I}try:
{I}{I}gtk.main()
{I}except KeyboardInterrupt:
{I}{I}sys.exit(1)
#