6 def print_fig_prop(fig
):
7 for ind_ax
, ax
in enumerate(P
.figure(fig
).axes
):
8 print "*** Axe %d ***"%ind
_ax
9 print "Xmin : %g"%ax
.get_xlim()[0]
10 print "Xmax : %g"%ax
.get_xlim()[1]
11 print "Ymin : %g"%ax
.get_ylim()[0]
12 print "Ymax : %g"%ax
.get_ylim()[1]
13 print "Fontsize (X) : %g"%ax
.get_xticklabels()[0].get_fontsize()
14 print "Fontsize (Y) : %g"%ax
.get_yticklabels()[0].get_fontsize()
15 print "Title : " + ax
.title
.get_text()
16 print "Title fontsize : %g"%ax
.title
.get_fontsize()
17 print "X label : " + ax
.xaxis
.get_label().get_text()
18 print "X label fontsize : %g"%ax
.xaxis
.get_label().get_fontsize()
19 print "Y label : " + ax
.yaxis
.get_label().get_text()
20 print "Y label fontsize : %g"%ax
.yaxis
.get_label().get_fontsize()
22 for ind_line
, line
in enumerate(ax
.lines
):
23 print " *** Line %d ***"%ind
_line
24 print " Style : " + line
.get_linestyle()
25 print " Marker : " + line
.get_marker()
26 print " Line Width : %.1f"%line
.get_linewidth()
27 print " Color : " + line
.get_color()
28 for ind_im
, im
in enumerate(ax
.images
):
29 print " *** Image %d ***"%ind
_im
30 print " Colormap : " + im
.cmap
.name
31 print " Interpolation : " + im
.get_interpolation()
32 print " Extent : [%g, %g, %g, %g]"%(im
.get_extent()[0],im
.get_extent()[1],im
.get_extent()[2],im
.get_extent()[3], )
36 def row_activated(self
, treeview
):
37 model
, iter = treeview
.get_selection().get_selected()
38 type = model
.get_value(iter, 1)
39 self
.type_selected
= type
40 obj
= model
.get_value(iter,2)
41 self
.selected
= model
.get_value(iter,2)
42 self
.fig
= model
.get_value(iter, 3)
44 self
.display_line(obj
)
48 self
.display_image(obj
)
49 elif type == 'figure':
50 self
.display_figure(obj
)
52 self
.display_text(obj
)
53 ## if type != 'figure':
54 ## visi = obj.get_visible()
55 ## obj.set_visible(not(visi))
58 ## obj.set_visible(visi)
62 def get_value(self
, obj
, name
):
63 if name
== 'linestyle':
64 return obj
.get_linestyle()
65 elif name
== 'marker':
66 return obj
.get_marker()
67 elif name
== 'linewidth':
68 return obj
.get_linewidth()
70 return obj
.get_color()
72 return obj
.get_xlim()[0]
74 return obj
.get_xlim()[1]
76 return obj
.get_ylim()[0]
78 return obj
.get_ylim()[1]
80 return obj
.title
.get_text()
81 elif name
== 'titlefontsize':
82 return obj
.title
.get_fontsize()
83 elif name
== 'xlabel':
84 return obj
.xaxis
.get_label().get_text()
85 elif name
== 'ylabel':
86 return obj
.yaxis
.get_label().get_text()
87 elif name
== 'xfontsize':
88 return obj
.xaxis
.get_ticklabels()[0].get_fontsize()
89 elif name
== 'yfontsize':
90 return obj
.yaxis
.get_ticklabels()[0].get_fontsize()
91 elif name
== 'xlabelfontsize':
92 return obj
.xaxis
.get_label().get_fontsize()
93 elif name
== 'ylabelfontsize':
94 return obj
.yaxis
.get_label().get_fontsize()
95 elif name
== 'figwidth':
96 ## return obj.window.get_size()[0]
97 return obj
.get_figwidth()
98 elif name
== 'figheight':
99 ## return obj.window.get_size()[1]
100 return obj
.get_figheight()
102 return obj
.get_position()[0]
104 return obj
.get_position()[1]
105 elif name
== 'width':
106 return obj
.get_position()[2]
107 elif name
== 'height':
108 return obj
.get_position()[3]
109 elif name
== 'xbegin':
110 return obj
.get_extent()[0]
112 return obj
.get_extent()[1]
113 elif name
== 'ybegin':
114 return obj
.get_extent()[2]
116 return obj
.get_extent()[3]
119 elif name
== 'interp':
120 return obj
.get_interpolation()
121 elif name
== 'label':
122 return obj
.get_label()
123 elif name
== 'textx':
124 return obj
.get_position()[0]
125 elif name
== 'texty':
126 return obj
.get_position()[1]
128 return obj
.get_text()
129 elif name
== 'textfontsize':
130 return obj
.get_fontsize()
131 elif name
== 'textrotation':
132 return obj
.get_rotation()
133 elif name
== 'markersize':
134 return obj
.get_markersize()
135 elif name
== 'markerfacecolor':
136 return obj
.get_markerfacecolor()
137 elif name
== 'markeredgecolor':
138 return obj
.get_markeredgecolor()
139 elif name
== 'markeredgewidth':
140 return obj
.get_markeredgewidth()
143 def set_value(self
, obj
, name
, value
):
144 if name
== 'linestyle':
145 obj
.set_linestyle(value
)
146 elif name
== 'marker':
147 obj
.set_marker(value
)
148 elif name
== 'linewidth':
149 obj
.set_linewidth(float(value
))
150 elif name
== 'color':
152 elif name
== 'xmin' or name
== 'xmax':
153 obj
.set_xlim([float(self
.param
['xmin'].get_text()), float(self
.param
['xmax'].get_text())])
154 elif name
== 'ymin' or name
== 'ymax':
155 obj
.set_ylim([float(self
.param
['ymin'].get_text()), float(self
.param
['ymax'].get_text())])
156 elif name
== 'title':
157 obj
.title
.set_text(value
)
158 elif name
== 'titlefontsize':
159 obj
.title
.set_fontsize(float(value
))
160 elif name
== 'xlabel':
161 obj
.xaxis
.get_label().set_text(value
)
162 elif name
== 'ylabel':
163 obj
.yaxis
.get_label().set_text(value
)
164 elif name
== 'xfontsize':
165 for tick
in obj
.xaxis
.get_ticklabels():
166 tick
.set_fontsize(float(value
))
167 elif name
== 'yfontsize':
168 for tick
in obj
.yaxis
.get_ticklabels():
169 tick
.set_fontsize(float(value
))
170 elif name
== 'xlabelfontsize':
171 obj
.xaxis
.get_label().set_fontsize(float(value
))
172 elif name
== 'ylabelfontsize':
173 obj
.yaxis
.get_label().set_fontsize(float(value
))
174 ## elif name == 'figwidth' or name == 'figheight':
175 ## obj.resize(int(self.param['figwidth'].get_text()),int(self.param['figheight'].get_text()) )
176 elif name
== 'figwidth':
177 obj
.set_figwidth(float(value
))
178 elif name
== 'figheight':
179 obj
.set_figheight(float(value
))
180 elif name
== 'xpos' or name
=='ypos' or name
== 'width' or name
== 'height':
181 a
= float(self
.param
['xpos'].get_text())
182 b
= float(self
.param
['ypos'].get_text())
183 c
= float(self
.param
['width'].get_text())
184 d
= float(self
.param
['height'].get_text())
185 obj
.set_position([a
,b
,c
,d
])
187 obj
.set_cmap(getattr(P
.cm
, value
))
188 elif name
== 'interp':
189 obj
.set_interpolation(value
)
190 elif name
== 'label':
192 elif name
== 'textx':
193 obj
.set_x(float(value
))
194 elif name
== 'texty':
195 obj
.set_y(float(value
))
198 elif name
== 'textfontsize':
199 obj
.set_fontsize(float(value
))
200 elif name
== 'textrotation':
201 obj
.set_rotation(float(value
))
202 elif name
== 'markersize':
203 obj
.set_markersize(float(value
))
204 elif name
== 'markerfacecolor':
205 obj
.set_markerfacecolor(value
)
206 elif name
== 'markeredgecolor':
207 obj
.set_markeredgecolor(value
)
208 elif name
== 'markeredgewidth':
209 obj
.set_markeredgewidth(float(value
))
211 def remove(self
, widget
):
212 self
.paramtable
.remove(widget
)
214 def add_row(self
, name
, title
, obj
, line
):
215 tmp
= gtk
.Label(title
)
217 self
.paramtable
.attach(tmp
,0,1,line
,line
+1, yoptions
=gtk
.FILL
)
219 default
= self
.get_value(obj
, name
)
220 ## if default == None or default == 'None':
222 if not self
.param_treestore
.has_key(name
):
223 self
.param
[name
] = gtk
.Entry(255)
224 self
.param
[name
].set_text(str(default
))
225 self
.param
[name
].connect("activate", self
.apply)
227 self
.param
[name
] = gtk
.ComboBox(self
.param_treestore
[name
])
228 cell
= gtk
.CellRendererText()
229 self
.param
[name
].pack_start(cell
, True)
230 self
.param
[name
].add_attribute(cell
, 'text', 0)
232 while self
.param_treestore
[name
][ii
][0] != default
:
234 self
.param
[name
].set_active(ii
)
235 self
.param
[name
].connect("changed", self
.apply)
236 self
.param
[name
].show()
237 self
.paramtable
.attach(self
.param
[name
], 1, 2, line
, line
+1, yoptions
=gtk
.FILL
)
239 def display_line(self
, line
):
240 self
.paramtable
.foreach(self
.remove
)
242 self
.paramtable
.resize(2, len(self
.param_lines_order
))
243 for ii
, name
in enumerate(self
.param_lines_order
):
244 self
.add_row(name
, self
.param_names
[name
], line
, ii
)
246 def display_axe(self
, ax
):
247 self
.paramtable
.foreach(self
.remove
)
249 self
.paramtable
.resize(2, len(self
.param_axe_order
))
250 for ii
,name
in enumerate(self
.param_axe_order
):
251 self
.add_row(name
, self
.param_names
[name
], ax
, ii
)
253 def display_figure(self
, figure
):
254 self
.paramtable
.foreach(self
.remove
)
256 self
.paramtable
.resize(2, len(self
.param_figure_order
))
257 for ii
, name
in enumerate(self
.param_figure_order
):
258 self
.add_row(name
, self
.param_names
[name
], figure
, ii
)
260 def display_text(self
, text
):
261 self
.paramtable
.foreach(self
.remove
)
263 self
.paramtable
.resize(2, len(self
.param_text_order
))
264 for ii
, name
in enumerate(self
.param_text_order
):
265 self
.add_row(name
, self
.param_names
[name
], text
, ii
)
267 def display_image(self
, im
):
268 self
.paramtable
.foreach(self
.remove
)
270 self
.paramtable
.resize(2, len(self
.param_image_order
))
271 for ii
, name
in enumerate(self
.param_image_order
):
272 self
.add_row(name
, self
.param_names
[name
], im
, ii
)
274 def apply(self
, widget
):
276 for name
, button
in self
.param
.items():
277 if not self
.param_treestore
.has_key(name
):
278 value
= button
.get_text()
280 iter = button
.get_active_iter()
281 value
= self
.param_treestore
[name
].get_value(iter, 0)
282 self
.set_value(obj
, name
, value
)
285 self
.row_activated(self
.treeview
)
287 def save(self
, widget
):
288 model
, iter = self
.treeview
.get_selection().get_selected()
289 if self
.type_selected
== 'line':
290 line
= model
.get_value(iter,2)
291 x
= P
.transpose(P
.array([line
.get_xdata(), line
.get_ydata()]))
292 fileselection
= gtk
.FileSelection('Save ' + model
.get_value(iter,0) + ' data in...')
293 fileselection
.ok_button
.connect("clicked", self
.go_save
, fileselection
, x
)
294 fileselection
.cancel_button
.connect("clicked", lambda w
: fileselection
.destroy())
296 def go_save(self
, widget
, win
, data
):
297 name
= win
.get_filename()
301 def delete(self
, widget
):
302 model
, iter = self
.treeview
.get_selection().get_selected()
303 if self
.type_selected
=='axe':
304 P
.delaxes(self
.selected
)
307 elif self
.type_selected
=='figure':
309 elif self
.type_selected
=='line':
310 axe
= model
.get_value(model
.iter_parent(iter), 2)
311 del axe
.lines
[model
.get_value(iter, 4)]
314 elif self
.type_selected
=='image':
315 axe
= model
.get_value(model
.iter_parent(iter), 2)
316 del axe
.images
[model
.get_value(iter, 4)]
319 elif self
.type_selected
=='text':
320 axe
= model
.get_value(model
.iter_parent(iter), 2)
321 del axe
.texts
[model
.get_value(iter, 4)]
324 self
.treestore
.remove(iter)
325 self
.paramtable
.foreach(self
.remove
)
329 def update(self
, widget
):
330 self
.treestore
.clear()
331 for figure
in P
.matplotlib
._pylab
_helpers
.Gcf
.get_all_fig_managers():
333 iter_fig
= self
.treestore
.append(None, ['Figure %d'%fig, 'figure' ,P
.figure(fig
), fig
, fig
])
334 for ind_ax
, ax
in enumerate(P
.figure(fig
).axes
):
335 iter_ax
= self
.treestore
.append(iter_fig
, ['Axe %d'%ind
_ax
, 'axe' ,ax
, fig
, ind_ax
])
336 for ind_line
, line
in enumerate(ax
.lines
):
337 iter = self
.treestore
.append(iter_ax
, ['Line %d'%ind
_line
, 'line', line
, fig
, ind_line
])
338 for ind_im
, im
in enumerate(ax
.images
):
339 iter = self
.treestore
.append(iter_ax
, ['Image %d'%ind
_im
, 'image',im
, fig
, ind_im
])
340 for ind_text
, text
in enumerate(ax
.texts
):
341 iter = self
.treestore
.append(iter_ax
, ['Text %d'%ind
_text
, 'text', text
, fig
, ind_text
])
345 self
.window
.destroy()
347 def copy(self
, widget
):
348 model
, iter = self
.treeview
.get_selection().get_selected()
349 type_to_copy
= model
.get_value(iter, 1)
350 element_to_copy
= model
.get_value(iter, 2)
351 if type_to_copy
== 'figure':
353 self
.wincopy
= gtk
.Window(gtk
.WINDOW_TOPLEVEL
)
354 self
.wincopy
.set_transient_for(self
.window
)
355 self
.wincopy
.set_modal(True)
356 self
.wincopy
.set_title('Copy ' + model
.get_value(iter, 0) + ' to...')
357 self
.wincopy
.set_default_size(200,100)
359 self
.wincopy
.add(vbox
)
360 scroll
= gtk
.ScrolledWindow()
361 scroll
.set_policy(gtk
.POLICY_NEVER
, gtk
.POLICY_AUTOMATIC
)
362 vbox
.pack_start(scroll
)
363 model_filter
= model
.filter_new()
364 model_filter
.set_visible_func(self
.visible_model
, type_to_copy
)
365 self
.treeview_copy
= gtk
.TreeView(model_filter
)
366 renderer
= gtk
.CellRendererText()
367 column
= gtk
.TreeViewColumn('Object ID', renderer
, text
=0)
368 self
.treeview_copy
.set_headers_visible(False)
369 self
.treeview_copy
.append_column(column
)
370 self
.treeview_copy
.show()
371 scroll
.add(self
.treeview_copy
)
374 vbox
.pack_start(hbox
)
375 button
= gtk
.Button('Cancel')
376 button
.connect("clicked", self
.close_copy
)
378 hbox
.pack_start(button
)
379 button
= gtk
.Button('Copy')
380 button
.connect("clicked", self
.do_copy
, type_to_copy
, element_to_copy
)
382 hbox
.pack_start(button
)
387 def do_copy(self
, widget
, type, element
):
388 model_to
, iter_to
= self
.treeview_copy
.get_selection().get_selected()
389 dest
= model_to
.get_value(iter_to
, 2)
391 line
= P
.Line2D(element
.get_xdata(), element
.get_ydata(),
392 linewidth
=element
.get_linewidth(), linestyle
=element
.get_linestyle(),
393 color
=element
.get_color(), marker
=element
.get_marker())
395 elif type == 'image':
396 dest
.images
.append(element
)
398 dest
.text(element
.get_position()[0], element
.get_position()[1],
399 element
.get_text(), fontsize
=element
.get_fontsize())
400 self
.close_copy(None)
403 def close_copy(self
, widget
):
404 self
.wincopy
.destroy()
406 def visible_model(self
, model
, iter, data
):
407 type = model
.get_value(iter, 1)
414 if type == 'figure' or type == 'axe':
419 def end_of_program(self
, widget
, data
=None):
420 if P
.backends
.backend
[:3]=='GTK':
421 self
.window
.destroy()
428 marker_types
= ['.', ',', 'o', '^', 'v', '<', '>', 's', '+', 'x',
429 'D', 'd', '1', '2', '3', '4', 'h', 'H',
430 'p', '|', '_', 'None']
431 marker_treestore
= gtk
.TreeStore(str)
432 for marker
in marker_types
:
433 marker_treestore
.append(None, [marker
])
434 line_types
= ['-', '--', '-.', ':', 'steps', 'None']
435 line_treestore
= gtk
.TreeStore(str)
436 [line_treestore
.append(None, [ii
]) for ii
in line_types
]
437 self
.param_names
= {'label': 'Label',
438 'linestyle': 'Line style',
440 'markersize': 'Marker Size',
441 'markerfacecolor': 'Marker Face Color',
442 'markeredgecolor': 'Marker Edge Color',
443 'markeredgewidth': 'Marker Edge Width',
444 'linewidth': 'Line Width',
447 'interp': 'Interpolation',
449 'xpos': 'X position',
450 'ypos': 'Y position',
458 'titlefontsize': 'Title fontsize',
461 'xlabelfontsize': 'Fontsize (X label)',
462 'ylabelfontsize': 'Fontsize (Y label)',
463 'xfontsize': 'Fontsize (X ticks)',
464 'yfontsize': 'Fontsize (Y ticks)',
466 'figheight': 'Height',
467 'textx': 'X position',
468 'texty': 'Y position',
470 'textfontsize': 'Fontsize',
471 'textrotation': 'Rotation'}
473 self
.param_lines_order
= ['label', 'linestyle', 'color', 'linewidth',
474 'marker', 'markersize', 'markerfacecolor', 'markeredgecolor', 'markeredgewidth']
475 self
.param_image_order
= ['label', 'cmap', 'interp']
476 self
.param_axe_order
= ['xpos', 'ypos', 'width', 'height',
477 'xmin', 'xmax', 'ymin', 'ymax',
478 'title', 'titlefontsize',
479 'xlabel', 'xlabelfontsize',
480 'ylabel', 'ylabelfontsize',
481 'xfontsize', 'yfontsize']
482 self
.param_figure_order
= ['figwidth', 'figheight']
483 self
.param_text_order
= ['textx', 'texty', 'text', 'textfontsize',
484 'color', 'textrotation']
485 self
.param_treestore
= {'marker': marker_treestore
,
486 'linestyle': line_treestore
}
488 self
.window
= gtk
.Window(gtk
.WINDOW_TOPLEVEL
)
489 self
.window
.set_title('Graphics properties')
490 self
.window
.set_default_size(300, 400)
491 self
.window
.connect("delete_event", self
.end_of_program
)
492 self
.window
.connect("destroy", self
.end_of_program
)
495 self
.paramtable
= gtk
.Table()
496 self
.paramtable
.show()
497 self
.treestore
= gtk
.TreeStore(gobject
.TYPE_STRING
, str, object, int, int)
498 self
.treeview
= gtk
.TreeView(self
.treestore
)
499 self
.treeview
.set_headers_visible(False)
500 renderer
= gtk
.CellRendererText()
501 self
.column
= gtk
.TreeViewColumn('Object ID', renderer
, text
=0)
502 self
.treeview
.append_column(self
.column
)
504 self
.treeview
.connect("cursor-changed", self
.row_activated
)
505 scroll
= gtk
.ScrolledWindow()
506 scroll
.set_policy(gtk
.POLICY_NEVER
, gtk
.POLICY_AUTOMATIC
)
507 scroll
.add(self
.treeview
)
510 hbox
.pack_start(scroll
)
512 viewport
= gtk
.Viewport()
513 viewport
.add(self
.paramtable
)
515 scroll
= gtk
.ScrolledWindow()
516 scroll
.set_policy(gtk
.POLICY_NEVER
, gtk
.POLICY_AUTOMATIC
)
519 hbox
.pack_start(scroll
)
522 button
= gtk
.Button('Update')
523 button
.connect("clicked", self
.update
)
525 bottom
.pack_start(button
)
526 button
= gtk
.Button('Copy')
527 button
.connect("clicked", self
.copy
)
529 bottom
.pack_start(button
)
530 button
= gtk
.Button('Delete')
531 button
.connect("clicked", self
.delete
)
533 bottom
.pack_start(button
)
535 button
= gtk
.Button('Save data')
536 button
.connect("clicked", self
.save
)
538 bottom
.pack_start(button
)
540 button
= gtk
.Button('Apply')
541 button
.connect("clicked", self
.apply)
543 bottom
.pack_start(button
)
546 vbox
.pack_start(hbox
)
547 vbox
.pack_start(bottom
, False)
548 self
.window
.add(vbox
)