1 """
2 class TemplatePlotGroupPanel
3 Panel for displaying preference maps and activity plot groups.
4
5 $Id: templateplotgrouppanel.py 11310 2010-07-27 16:56:14Z ceball $
6 """
7 __version__='$Revision: 11310 $'
8
9
10 import copy
11
12 from Tkinter import DISABLED, NORMAL
13 from tkFileDialog import asksaveasfilename
14
15 import param
16 from param import tk,normalize_path
17
18 import topo.command.pylabplot
19 from topo.plotting.plotgroup import TemplatePlotGroup
20
21 from plotgrouppanel import SheetPanel
22
23
24
25
26
27
28
29
30
31
32
33
34
35
37 """
38 Return the channels+names of the channels that have views.
39 """
40 available_channels = {}
41 for name,channel in plot.channels.items():
42 if plot.view_dict.has_key(channel):
43 available_channels[name]=channel
44 return available_channels
45
46
47
48
49
50
52
53 plotgroup_type = TemplatePlotGroup
54
55 strength_only = param.Boolean(default=False,doc="""If true, disables all but the Strength channel of each plot,
56 disabling all color coding for Strength/Hue/Confidence plots.""")
57
58
59
60
61
62
63
64
66
67
68 original_templates = self.plotgroup.plot_templates
69 self.plotgroup.plot_templates = copy.deepcopy(self.plotgroup.plot_templates)
70 if self.strength_only:
71 for name,template in self.plotgroup.plot_templates:
72 for c in ['Confidence','Hue']:
73 if c in template:
74 del template[c]
75 return original_templates
76
83
90
91
92
93 - def __init__(self,master,plotgroup,**params):
94
95 super(TemplatePlotGroupPanel,self).__init__(master,plotgroup,**params)
96
97 self.pack_param('strength_only',parent=self.control_frame_1,
98 on_set=self.redraw_plots,side='right')
99
100
101
102 if self.plotgroup.plot_immediately:
103 self.refresh_plots()
104 else:
105 self.redraw_plots()
106 self.display_labels()
107
108
109
110
111 self._sheet_menu.add_command(label="Save image as PNG",
112 command=self.__save_to_png)
113
114
115 self._sheet_menu.add_command(label="Save image as EPS",
116 command=self.__save_to_postscript)
117
118
119 self._unit_menu.add_command(label="Print info",
120 command=self.__print_info)
121
122
123
124 channel_menus={}
125 for chan in ['Strength','Hue','Confidence']:
126 newmenu = tk.Menu(self._canvas_menu, tearoff=0)
127 self._canvas_menu.add_cascade(menu=newmenu,label=chan+' channel', indexname=chan)
128
129
130 newmenu.add_command(label="Print matrix", command=lambda c=chan: self.__print_matrix(c))
131 newmenu.add_command(label="Plot with axis labels", command=lambda c=chan: self.__plot_matrix(c))
132 newmenu.add_command(label="Plot as 3D wireframe", command=lambda c=chan: self.__plot_matrix3d(c))
133 newmenu.add_command(label="Fourier transform", command=lambda c=chan: self.__fft(c))
134 newmenu.add_command(label="Histogram", command=lambda c=chan: self.__histogram(c))
135 newmenu.add_command(label="Gradient", command=lambda c=chan: self.__gradient(c))
136 channel_menus[chan]=newmenu
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
158 """
159 Make whichever of the SHC channels is present in the plot available on the menu.
160 """
161 super(TemplatePlotGroupPanel,self)._canvas_right_click(event_info,show_menu=False)
162
163 if 'plot' in event_info:
164 plot = event_info['plot']
165
166 available_channels =available_plot_channels(plot)
167
168 for channel in ('Strength','Hue','Confidence'):
169 if channel in available_channels:
170 self._canvas_menu.entryconfig(channel,
171 label="%s channel: %s" %
172 (channel,str(plot.channels[channel])),state=NORMAL)
173 else:
174 self._canvas_menu.entryconfig(channel,
175 label="%s channel: None" %
176 (channel),state=DISABLED)
177
178 self._canvas_menu.tk_popup(event_info['event'].x_root,
179 event_info['event'].y_root)
180
181
192
193
195 plot = self._right_click_info['plot']
196 canvas = self._right_click_info['event'].widget
197 filename = self.plotgroup.filesaver.filename(plot.label(),file_format="eps")
198 POSTSCRIPT_FILETYPES = [('Encapsulated PostScript images','*.eps'),
199 ('PostScript images','*.ps'),('All files','*')]
200 snapshot_name = asksaveasfilename(filetypes=POSTSCRIPT_FILETYPES,
201 initialdir=normalize_path(),
202 initialfile=filename)
203
204 if snapshot_name:
205 canvas.postscript(file=snapshot_name)
206
207
208 - def __fft(self,channel):
213
219
227
234
240
246
247
248
249
251 plot = self._right_click_info['plot']
252 (r,c),(x,y) = self._right_click_info['coords']
253 description ="%s %s, row %d, col %d at time %s: " % (plot.plot_src_name, plot.name, r, c, topo.sim.timestr())
254
255 channels_info = ""
256 if channel is None:
257 for channel,name in available_plot_channels(plot).items():
258 m=plot._get_matrix(channel)
259 channels_info+="%s:%f"%(name,m[r,c])
260 else:
261 m=plot._get_matrix(channel)
262 channels_info+="%s:%f"%(plot.channels[channel],m[r,c])
263
264 print "%s %s" % (description, channels_info)
265
266
267
268
269
271 """
272 Also print whatever other channels are there and have views.
273 """
274 plot = event_info['plot']
275 r,c = event_info['coords'][0]
276
277 info_string = basic_text
278
279 for channel,channel_name in available_plot_channels(plot).items():
280 info_string+=" %s: % 1.3f"%(channel_name,plot._get_matrix(channel)[r,c])
281
282 return info_string
283