1 """
2 PlotgroupPanels for displaying ProjectionSheet plotgroups.
3
4 $Id: projectionpanel.py 11310 2010-07-27 16:56:14Z ceball $
5 """
6 __version__='$Revision: 11310 $'
7
8
9 import ImageTk
10
11 from itertools import chain
12 from Tkinter import Canvas
13 from numpy import sometrue
14
15 import param
16
17 import topo
18 from topo.base.cf import CFProjection
19 from topo.base.projection import ProjectionSheet, Projection
20 from topo.misc.generatorsheet import GeneratorSheet
21
22 from templateplotgrouppanel import TemplatePlotGroupPanel
27 """
28 Comparison function for Plots.
29 It compares the precedence number first and then the src_name and name attributes.
30 """
31 if p1.src.precedence != p2.src.precedence:
32 return cmp(p1.src.precedence,p2.src.precedence)
33 else:
34 return cmp(p1,p2)
35
36
37 UNIT_PADDING = 1
42 """
43 Abstract base class for panels relating to ProjectionSheets.
44 """
45 __abstract = True
46
47 sheet_type = ProjectionSheet
48 projection_type = Projection
49
50 @classmethod
51 - def valid_context(cls):
52 """
53 Return True if there is at least one instance of
54 projection_type among all projections in the simulation.
55 """
56 for p in chain(*[sheet.projections().values()
57 for sheet in topo.sim.objects(cls.sheet_type).values()]):
58 if isinstance(p,cls.projection_type):
59 return True
60
61 return False
62
63
64 - def __init__(self,master,plotgroup,**params):
65 super(ProjectionSheetPanel,self).__init__(master,plotgroup,**params)
66
67 self.plotgroup.auto_refresh=False
68
69 self.pack_param('sheet',parent=self.control_frame_3,
70 on_modify=self.sheet_change,side='left',expand=1,
71 widget_options={'new_default':True,
72 'sort_fn_args':{'cmp':lambda x, y: cmp(-x.precedence,-y.precedence)}})
73
74
78
79
82
83
90
98
101
105
106
107 - def __init__(self,master,plotgroup,**params):
115
116
117
118
119
120
121
122
123
124
125
126
128
129
130
131
132
133
134
135
136
137 if 'sheet' in self.initial_args: self.sheet=self.initial_args['sheet']
138
139 for coord in ['x','y']:
140 self._tkvars[coord].set(self.initial_args.get(coord,0.0))
141
142 l,b,r,t = self.sheet.bounds.lbrt()
143
144
145 D=0.0000000001
146 bounds = {'x':(l,r-D),
147 'y':(b,t-D)}
148
149 inclusive_bounds = {'x':(True,False),
150 'y':(False,True)}
151
152 for coord in ['x','y']:
153 param_obj=self.get_parameter_object(coord)
154 param_obj.bounds = bounds[coord]
155 param_obj.inclusive_bounds = inclusive_bounds[coord]
156
157
158 if coord in self.representations:
159 w=self.representations[coord]['widget']
160 w.set_bounds(param_obj.bounds[0],param_obj.bounds[1],
161 inclusive_bounds=param_obj.inclusive_bounds)
162 w.tag_set()
163
164 self.initial_args = {}
165 super(UnitsPanel,self).sheet_change()
166
184
187 """
188 PlotGroupPanel for visualizing an array of bitmaps, such as for
189 a projection involving a matrix of units.
190 """
191
192 gui_desired_maximum_plot_height = param.Integer(default=5,bounds=(0,None),doc="""
193 Value to provide for PlotGroup.desired_maximum_plot_height for
194 PlotGroups opened by the GUI. Determines the initial, default
195 scaling for the PlotGroup.""")
196
198 self.redraw_plots()
199
205
206
208 """
209 CFProjectionPanel requires a 2D grid of plots.
210 """
211 plots=self.plotgroup.plots
212
213 self.zoomed_images = [ImageTk.PhotoImage(p.bitmap.image)
214 for p in plots]
215 old_canvases = self.canvases
216
217 self.canvases = [Canvas(self.plot_container,
218 width=image.width(),
219 height=image.height(),
220 borderwidth=1,highlightthickness=0,
221 relief='groove')
222 for image in self.zoomed_images]
223
224
225 for i,image,canvas in zip(range(len(self.zoomed_images)),
226 self.zoomed_images,self.canvases):
227 canvas.grid(row=i//self.plotgroup.proj_plotting_shape[1],
228 column=i%self.plotgroup.proj_plotting_shape[1],
229 padx=UNIT_PADDING,pady=UNIT_PADDING)
230 canvas.create_image(1,1,anchor='nw',image=image)
231
232
233
234 for c in old_canvases:
235 c.grid_forget()
236
237 self._add_canvas_bindings()
238
239
241 """Do not display labels for these plots."""
242 pass
243
268
271 - def __init__(self,master,plotgroup,**params):
272 super(ProjectionPanel,self).__init__(master,plotgroup,**params)
273 self.pack_param('projection',parent=self.control_frame_3,
274 on_modify=self.redraw_plots,side='left',expand=1,
275 widget_options={'sort_fn_args':{'cmp':cmp_projections},
276 'new_default':True})
277
278 self.pack_param('density',parent=self.control_frame_4)
279
280
284
288
289
293
294
300
301
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326 -class CFProjectionPanel(ProjectionPanel):
327 """
328 Panel for displaying CFProjections.
329 """
330
331 projection_type = CFProjection
332
333 - def __init__(self,master,plotgroup,**params):
336
339
340
341
342
343
344
345
346