| Trees | Indices | Help |
|
|---|
|
|
1 """
2 Tk-based graphical user interface (GUI).
3
4 This package implements a Topographica GUI based on the Tk toolkit,
5 through the Tkinter interface to Python. The rest of Topographica
6 does not depend on this package or any module in it, and thus other
7 GUIs or other types of interfaces can also be used.
8
9 $Id: __init__.py 11264 2010-07-21 18:12:49Z ceball $
10 """
11 __version__='$Revision: 11264 $'
12
13 import sys
14 import os
15 import platform
16 import Tkinter
17
18 import param.tk
19
20 import topo
21
22 from topoconsole import TopoConsole,ControllableMenu
23
24 #### notes about tkgui ####
25 #
26 ## Geometry management
27 # In several places we use pack() when grid() would probably be
28 # simpler. Check you know which fits a task better rather than copying
29 # existing code.
30 #
31 ## Dialogs
32 # Don't know how to theme them (can't make them inherit from
33 # our own class, for instance). Consider making our own dialog
34 # boxes (subclass of Tkguiwindow) using transient and grab_set:
35 # http://thread.gmane.org/gmane.comp.python.tkinter/657/focus=659
36 #
37 ## Mainloop
38 # Because we don't call mainloop(), it's necessary to call
39 # update() or update_idletasks() sometimes. Also, I think that sometimes
40 # current graphics do not update properly (but I'm not sure - I don't
41 # have a specific example yet). Need to clean up all the scattered
42 # update() and update_idletasks()...
43 #
44 ## Window or Frame?
45 # Maybe one day everything (PlotGroupPanels, ParametersFrameWithApplys,
46 # ModelEditor, ...) will be Frames inside one master window (for
47 # e.g. a matlab-like workspace). Nobody's been worrying too much
48 # about whether something's a Frame or a window when they've been
49 # implementing things, so 'close' buttons, title methods, and so on
50 # are a bit of a mix. This needs to be cleaned up when we have a
51 # final window organization method in mind.
52
53
54 # When not using the GUI, Topographica does not ordinarily import any of
55 # the classes in the separate Topographica packages. For example, none
56 # of the pattern types in topo.patterns is imported in Topographica by
57 # default. But for the GUI, we want all such things to be available
58 # as lists from which the user can select. To do this, we import all
59 # pattern types and other such classes here. User-defined classes will
60 # also appear in the GUI menus if they are derived from any class
61 # derived from the one specified in each widget, and imported before
62 # the relevant GUI window starts.
63 from topo.coordmapper import *
64 from topo.ep import *
65 from topo.learningfn import *
66 from topo.transferfn import *
67 from topo.pattern import *
68 from topo.projection import *
69 from topo.responsefn import *
70 from topo.sheet import *
71
72
73
74 ##########
75 ### Which os is being used (for gui purposes)?
76 #
77 # system_plaform can be:
78 # "linux"
79 # "mac"
80 # "win"
81 # "unknown"
82 #
83 # If you are programming tkgui and need to do something special
84 # for some other platform (or to further distinguish the above
85 # platforms), please modify this code.
86 #
87 # Right now tkgui only needs to detect if the platform is linux (do I
88 # mean any kind of non-OS X unix*?) or mac, because there is some
89 # special-purpose code for both those two: the mac code below, and the
90 # menu-activating code in topoconsole. We might have some Windows-
91 # specific code for the window icons later on, too.
92 # * actually it's the window manager that's important, right?
93 # Does tkinter/tk itself give any useful information?
94 # What about root.tk.call("tk","windowingsystem")?
95
96 system_platform = 'unknown'
97 if platform.system()=='Linux':
98 system_platform = 'linux'
99 elif platform.system()=='Darwin' or platform.mac_ver()[0]:
100 system_platform = 'mac'
101 elif platform.system()=='Windows':
102 system_platform = 'win'
103 ##########
104
105
106
107 #
108 # Define up the right click (context menu) events. These variables can
109 # be appended or overridden in .topographicarc, if the user has some
110 # crazy input device.
111 #
112
113 if system_platform=='mac':
114 # if it's on the mac, these are the context-menu events
115 right_click_events = ['<Button-2>','<Control-Button-1>']
116 right_click_release_events = ['ButtonRelease-2', 'Control-ButtonRelease-1']
117 else:
118 # everywhere else (I think) it's Button-3
119 right_click_events = ['<Button-3>']
120 right_click_release_events = ['ButtonRelease-2']
121
122
123 global TK_SUPPORTS_DOCK
124 TK_SUPPORTS_DOCK = True
125
126
127 # CEBALERT: this function needs some cleaning up.
128 # Some stuff should be moved out to param.tk,
129 # which could also make this file much simpler.
130
131 # gets set to the TopoConsole instance created by start.
132 console = None
134 """
135 Start Tk and read in an options_database file (if present), then
136 open a TopoConsole.
137
138 Does nothing if the method has previously been called (i.e. the
139 module-level console variable is not None).
140
141 mainloop: If True, then the command-line is frozen while the GUI
142 is open. If False, then commands can be entered at the command-line
143 even while the GUI is operational. Default is False.
144 """
145 global console
146
147 ### Return immediately if console already set
148 # (console itself might have been destroyed but we still want to
149 # quit this function before starting another Tk instance, etc)
150 if console is not None: return
151
152 if banner: print 'Launching GUI'
153
154 # tcl equivalent of 'if not hasattr(wm,forget)' would be better
155 if system_platform=='mac' or Tkinter.TkVersion<8.5:
156 global TK_SUPPORTS_DOCK
157 TK_SUPPORTS_DOCK=False
158
159 param.tk.initialize()
160 param.tk.root.menubar = ControllableMenu(param.tk.root)
161 param.tk.root.configure(menu=param.tk.root.menubar)
162
163 # default,clam,alt,classic
164 try:
165 param.tk.root.tk.call("ttk::style","theme","use","classic")
166 except:
167 pass
168
169 # Try to read in options from an options_database file
170 # (see http://www.itworld.com/AppDev/1243/UIR000616regex/
171 # or p. 49 Grayson)
172 try:
173 options_database = os.path.join(sys.path[0],"topo","tkgui","options_database")
174 param.tk.root.option_readfile(options_database)
175 print "Read options database from",options_database
176 except Tkinter.TclError:
177 pass
178
179 console = TopoConsole(param.tk.root)
180
181 # Provide a way for other code to access the GUI when necessary
182 # CEBALERT: why is this import necessary? Need to cleanup this method.
183 import topo
184 topo.guimain=console
185
186
187 # This alows context menus to work on the Mac. Widget code should bind
188 # contextual menus to the virtual event <<right-click>>, not
189 # <Button-3>.
190 console.event_add('<<right-click>>',*right_click_events)
191 console.event_add('<<right-click-release>>',*right_click_release_events)
192
193 # GUI/threads:
194 # http://thread.gmane.org/gmane.comp.python.scientific.user/4153
195 # (inc. ipython info)
196 # (Also http://mail.python.org/pipermail/python-list/2000-January/021250.html)
197
198 # mainloop() freezes the commandline until the GUI window exits.
199 # Without this line the command-line remains responsive.
200 if mainloop: param.tk.root.mainloop()
201
202
203
204
205
206
207
208 #######################
209
210 if __name__ == '__main__':
211 start(mainloop=True)
212
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Thu Aug 5 14:59:56 2010 | http://epydoc.sourceforge.net |