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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# Copyright 2004, 2005, 2006 Jeff Epler <jepler@unpythonic.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
import Tkinter
__all__ = 'makecommand makevar makebool makewidget start'.split()
class _Emptyclass: pass
def newinstance(klass):
value = _Emptyclass()
value.__class__ = klass
return value
# Tkinter.py rev 65400 introduces a change which makes Menu.delete blow
# chunks. Until this is resolved, monkeypatch it
def delete(self, index1, index2=None):
self.tk.call(self._w, 'delete', index1, index2)
Tkinter.Menu.delete = delete
class TclCommands:
def __init__(self, master):
for k, v in self.__class__.__dict__.items():
if k.startswith("__") and k.endswith("__"): continue
makecommand(master, v.__name__, v)
setattr(self, k, v)
class Variables:
def __init__(self, master, *variables):
for (name, klass) in variables:
setattr(self, name, makevar(master, name, klass))
class Widgets:
def __init__(self, master, *widgets):
for (name, klass, path) in widgets:
setattr(self, name, makewidget(master, klass, path))
def makecommand(master, name, func, subst=None, needcleanup=0):
f = Tkinter.CallWrapper(func, subst, master).__call__
master.tk.createcommand(name, f)
if needcleanup:
if master._tclCommands is None:
master._tclCommands = []
master._tclCommands.append(name)
return name
def makevar(master, name, klass, *default):
self = newinstance(klass)
self._master = master
self._tk = master.tk
self._name = name
if default:
self.set(default[0])
else:
self.set(self._default)
return self
def makebool(master, name, *default):
return makevar(master, name, Tkinter.BooleanVar, *default)
def makeint(master, name, *default):
return makevar(master, name, Tkinter.IntVar, *default)
def makefloat(master, name, *default):
return makevar(master, name, Tkinter.DoubleVar, *default)
def makestring(master, name, *default):
return makevar(master, name, Tkinter.StringVar, *default)
def makewidget(master, klass, path):
path = str(path)
self = newinstance(klass)
if self._tclCommands is None:
self._tclCommands = []
if path[0] == '.':
if master._w == '.': self._name = path[1:]
else: self._name = path[len(master._w)+1:]
self._w = path
else:
self._name = path
if master._w == '.': self._w = '.' + path
else: self._w = master._w + '.' + path
self.children = {}
master.children[self._name] = self
self.master = master
self.tk = master.tk
return self
def find_prefix(f):
s = os.path.join(f, "share")
if os.path.exists(s): return f
if f == "/" or f == '': raise RuntimeError, "Share directory not found"
return find_prefix(os.path.dirname(f))
PREFIX = "@prefix@"
SHARE = os.path.join(PREFIX, "share", "axis")
tcl_libdir = os.path.join(SHARE, "tcl")
def source_lib_tcl(r, f):
r.tk.call("source", os.path.join(tcl_libdir, f))
def start(r):
r.tk.call("set", "imagedir", os.path.join(SHARE, "images"))
r.tk.call("lappend", "auto_path", os.path.join(tcl_libdir, "bwidget"))
r.tk.call("lappend", "auto_path", "/usr/lib")
source_lib_tcl(r, "accel.tcl")
source_lib_tcl(r, "support.tcl")
source_lib_tcl(r, "combobox.tcl")
source_lib_tcl(r, "dialog.tcl")
source_lib_tcl(r, "rb.tcl"); r.tk.call("rb::install")
source_lib_tcl(r, "cb.tcl"); r.tk.call("cb::install")
r.tk.call("package", "require", "BWidget", "1.7")
r.tk.call("namespace", "import", "combobox::combobox")
# vim:ts=8:sts=4:et:
|