7 def print_fig_prop(fig
):
8 for ind_ax
, ax
in enumerate(P
.figure(fig
).axes
):
9 print "*** Axe %d ***"%ind
_ax
10 print "Xmin : %g"%ax
.get_xlim()[0]
11 print "Xmax : %g"%ax
.get_xlim()[1]
12 print "Ymin : %g"%ax
.get_ylim()[0]
13 print "Ymax : %g"%ax
.get_ylim()[1]
14 print "Fontsize (X) : %g"%ax
.get_xticklabels()[0].get_fontsize()
15 print "Fontsize (Y) : %g"%ax
.get_yticklabels()[0].get_fontsize()
16 print "Title : " + ax
.title
.get_text()
17 print "Title fontsize : %g"%ax
.title
.get_fontsize()
18 print "X label : " + ax
.xaxis
.get_label().get_text()
19 print "X label fontsize : %g"%ax
.xaxis
.get_label().get_fontsize()
20 print "Y label : " + ax
.yaxis
.get_label().get_text()
21 print "Y label fontsize : %g"%ax
.yaxis
.get_label().get_fontsize()
23 for ind_line
, line
in enumerate(ax
.lines
):
24 print " *** Line %d ***"%ind
_line
25 print " Style : " + line
.get_linestyle()
26 print " Marker : " + line
.get_marker()
27 print " Line Width : %.1f"%line
.get_linewidth()
28 print " Color : " + line
.get_color()
29 for ind_im
, im
in enumerate(ax
.images
):
30 print " *** Image %d ***"%ind
_im
31 print " Colormap : " + im
.cmap
.name
32 print " Interpolation : " + im
.get_interpolation()
33 print " Extent : [%g, %g, %g, %g]"%(im
.get_extent()[0],im
.get_extent()[1],im
.get_extent()[2],im
.get_extent()[3], )
37 def row_activated(self
, treeview
):
38 model
, iter = treeview
.get_selection().get_selected()
39 type = model
.get_value(iter, 1)
40 self
.type_selected
= type
41 obj
= model
.get_value(iter,2)
42 self
.selected
= model
.get_value(iter,2)
43 self
.fig
= model
.get_value(iter, 3)
45 self
.display_line(obj
)
49 self
.display_image(obj
)
50 elif type == 'figure':
51 self
.display_figure(obj
)
53 self
.display_text(obj
)
55 def get_value(self
, obj
, name
):
56 if name
== 'linestyle':
57 return obj
.get_linestyle()
58 elif name
== 'marker':
59 return obj
.get_marker()
60 elif name
== 'linewidth':
61 return obj
.get_linewidth()
62 elif name
== 'linecolor':
63 return obj
.get_color()
65 return obj
.get_xlim()[0]
67 return obj
.get_xlim()[1]
69 return obj
.get_ylim()[0]
71 return obj
.get_ylim()[1]
73 return obj
.title
.get_text()
74 elif name
== 'titlefontsize':
75 return obj
.title
.get_fontsize()
76 elif name
== 'xlabel':
77 return obj
.xaxis
.get_label().get_text()
78 elif name
== 'ylabel':
79 return obj
.yaxis
.get_label().get_text()
80 elif name
== 'xfontsize':
81 return obj
.xaxis
.get_ticklabels()[0].get_fontsize()
82 elif name
== 'yfontsize':
83 return obj
.yaxis
.get_ticklabels()[0].get_fontsize()
84 elif name
== 'xlabelfontsize':
85 return obj
.xaxis
.get_label().get_fontsize()
86 elif name
== 'ylabelfontsize':
87 return obj
.yaxis
.get_label().get_fontsize()
88 elif name
== 'figwidth':
89 return obj
.window
.get_size()[0]
90 elif name
== 'figheight':
91 return obj
.window
.get_size()[1]
93 return obj
.get_position()[0]
95 return obj
.get_position()[1]
97 return obj
.get_position()[2]
98 elif name
== 'height':
99 return obj
.get_position()[3]
100 elif name
== 'xbegin':
101 return obj
.get_extent()[0]
103 return obj
.get_extent()[1]
104 elif name
== 'ybegin':
105 return obj
.get_extent()[2]
107 return obj
.get_extent()[3]
110 elif name
== 'interp':
111 return obj
.get_interpolation()
112 elif name
== 'label':
113 return obj
.get_label()
114 elif name
== 'textx':
115 return obj
.get_position()[0]
116 elif name
== 'texty':
117 return obj
.get_position()[1]
119 return obj
.get_text()
120 elif name
== 'textfontsize':
121 return obj
.get_fontsize()
122 elif name
== 'textrotation':
123 return obj
.get_rotation()
127 def set_value(self
, obj
, name
, value
):
128 if name
== 'linestyle':
129 obj
.set_linestyle(value
)
130 elif name
== 'marker':
131 obj
.set_marker(value
)
132 elif name
== 'linewidth':
133 obj
.set_linewidth(float(value
))
134 elif name
== 'linecolor':
136 elif name
== 'xmin' or name
== 'xmax':
137 obj
.set_xlim([float(self
.param
['xmin'].get_text()), float(self
.param
['xmax'].get_text())])
138 elif name
== 'ymin' or name
== 'ymax':
139 obj
.set_ylim([float(self
.param
['ymin'].get_text()), float(self
.param
['ymax'].get_text())])
140 elif name
== 'title':
141 obj
.title
.set_text(value
)
142 elif name
== 'titlefontsize':
143 obj
.title
.set_fontsize(float(value
))
144 elif name
== 'xlabel':
145 obj
.xaxis
.get_label().set_text(value
)
146 elif name
== 'ylabel':
147 obj
.yaxis
.get_label().set_text(value
)
148 elif name
== 'xfontsize':
149 for tick
in obj
.xaxis
.get_ticklabels():
150 tick
.set_fontsize(float(value
))
151 elif name
== 'yfontsize':
152 for tick
in obj
.yaxis
.get_ticklabels():
153 tick
.set_fontsize(float(value
))
154 elif name
== 'xlabelfontsize':
155 obj
.xaxis
.get_label().set_fontsize(float(value
))
156 elif name
== 'ylabelfontsize':
157 obj
.yaxis
.get_label().set_fontsize(float(value
))
158 elif name
== 'figwidth' or name
== 'figheight':
159 obj
.resize(int(self
.param
['figwidth'].get_text()),int(self
.param
['figheight'].get_text()) )
160 elif name
== 'xpos' or name
=='ypos' or name
== 'width' or name
== 'height':
161 a
= float(self
.param
['xpos'].get_text())
162 b
= float(self
.param
['ypos'].get_text())
163 c
= float(self
.param
['width'].get_text())
164 d
= float(self
.param
['height'].get_text())
165 obj
.set_position([a
,b
,c
,d
])
167 obj
.set_cmap(getattr(P
.cm
, value
))
168 elif name
== 'interp':
169 obj
.set_interpolation(value
)
170 elif name
== 'label':
172 elif name
== 'textx':
173 obj
.set_x(float(value
))
174 elif name
== 'texty':
175 obj
.set_y(float(value
))
178 elif name
== 'textfontsize':
179 obj
.set_fontsize(float(value
))
180 elif name
== 'textrotation':
181 obj
.set_rotation(float(value
))
183 def remove(self
, widget
):
184 self
.paramtable
.remove(widget
)
186 def add_param(self
, widget
, name
, title
, obj
):
190 tmp2
= gtk
.Label(title
)
194 default
= self
.get_value(obj
, name
)
197 self
.param
[name
] = gtk
.Entry(255)
198 self
.param
[name
].set_text(str(default
))
199 self
.param
[name
].connect("activate", self
.apply)
200 self
.param
[name
].show()
201 tmp
.pack_start(self
.param
[name
])
203 widget
.pack_start(tmp
, False)
205 def display_line(self
, line
):
206 self
.paramtable
.foreach(self
.remove
)
208 for name
in self
.param_lines_order
:
209 self
.add_param(self
.paramtable
, name
, self
.param_names
[name
], line
)
211 def display_axe(self
, ax
):
212 self
.paramtable
.foreach(self
.remove
)
214 for name
in self
.param_axe_order
:
215 self
.add_param(self
.paramtable
, name
, self
.param_names
[name
], ax
)
217 def display_figure(self
, figure
):
218 self
.paramtable
.foreach(self
.remove
)
220 for name
in self
.param_figure_order
:
221 self
.add_param(self
.paramtable
, name
, self
.param_names
[name
], figure
)
222 def display_text(self
, text
):
223 self
.paramtable
.foreach(self
.remove
)
225 for name
in self
.param_text_order
:
226 self
.add_param(self
.paramtable
, name
, self
.param_names
[name
], text
)
228 def display_image(self
, im
):
229 self
.paramtable
.foreach(self
.remove
)
231 for name
in self
.param_image_order
:
232 self
.add_param(self
.paramtable
, name
, self
.param_name
[name
], im
)
234 def apply(self
, widget
):
236 for name
, button
in self
.param
.items():
237 value
= button
.get_text()
238 self
.set_value(obj
, name
, value
)
241 self
.row_activated(self
.treeview
)
243 def delete(self
, widget
):
244 model
, iter = self
.treeview
.get_selection().get_selected()
245 if self
.type_selected
=='axe':
246 P
.delaxes(self
.selected
)
249 elif self
.type_selected
=='figure':
251 elif self
.type_selected
=='line':
252 axe
= model
.get_value(model
.iter_parent(iter), 2)
253 del axe
.lines
[model
.get_value(iter, 4)]
256 elif self
.type_selected
=='image':
257 axe
= model
.get_value(model
.iter_parent(iter), 2)
258 del axe
.images
[model
.get_value(iter, 4)]
261 elif self
.type_selected
=='text':
262 axe
= model
.get_value(model
.iter_parent(iter), 2)
263 del axe
.texts
[model
.get_value(iter, 4)]
266 self
.treestore
.remove(iter)
267 self
.paramtable
.foreach(self
.remove
)
270 def update(self
, widget
):
271 self
.window
.destroy()
274 def copy(self
, widget
):
275 model
, iter = self
.treeview
.get_selection().get_selected()
276 self
.wincopy
= gtk
.Window(gtk
.WINDOW_TOPLEVEL
)
277 self
.wincopy
.set_transient_for(self
.window
)
278 self
.wincopy
.set_title('Copy ' + model
.get_value(iter, 0))
280 self
.wincopy
.add(vbox
)
281 scroll
= gtk
.ScrolledWindow()
282 vbox
.pack_start(scroll
)
283 treeview
= gtk
.TreeView(model
)
284 renderer
= gtk
.CellRendererText()
285 column
= gtk
.TreeViewColumn('Object ID', renderer
, text
=0)
286 treeview
.set_headers_visible(False)
287 treeview
.append_column(column
)
292 vbox
.pack_start(hbox
)
293 button
= gtk
.Button('Cancel')
294 button
.connect("clicked", self
.close_copy
)
296 hbox
.pack_start(button
)
297 button
= gtk
.Button('Copy')
298 button
.connect("clicked", self
.do_copy
)
300 hbox
.pack_start(button
)
304 if self
.type_selected
=='line':
307 def do_copy(self
, widget
):
309 def close_copy(self
, widget
):
310 self
.wincopy
.destroy()
315 self
.param_names
= {'label': 'Label',
316 'linestyle': 'Line style',
318 'linewidth': 'Line Width',
319 'linecolor': 'Line Color',
321 'interp': 'Interpolation',
323 'xpos': 'X position',
324 'ypos': 'Y position',
332 'titlefontsize': 'Title fontsize',
335 'xlabelfontsize': 'Fontsize (X label)',
336 'ylabelfontsize': 'Fontsize (Y label)',
337 'xfontsize': 'Fontsize (X ticks)',
338 'yfontsize': 'Fontsize (Y ticks)',
340 'figheight': 'Height',
341 'textx': 'X position',
342 'texty': 'Y position',
344 'textfontsize': 'Fontsize',
345 'textrotation': 'Rotation'}
347 self
.param_lines_order
= ['label', 'linestyle', 'linecolor', 'linewidth', 'marker']
348 self
.param_image_order
= ['label', 'cmap', 'interp']
349 self
.param_axe_order
= ['xpos', 'ypos', 'width', 'height',
350 'xmin', 'xmax', 'ymin', 'ymax',
351 'title', 'titlefontsize',
352 'xlabel', 'xlabelfontsize',
353 'ylabel', 'ylabelfontsize',
354 'xfontsize', 'yfontsize']
355 self
.param_figure_order
= ['figwidth', 'figheight']
356 self
.param_text_order
= ['textx', 'texty', 'text', 'textfontsize',
360 self
.window
= gtk
.Window(gtk
.WINDOW_TOPLEVEL
)
361 self
.window
.set_title('Graphics properties')
362 self
.window
.set_default_size(300, 400)
365 self
.paramtable
= gtk
.VBox()
366 self
.paramtable
.show()
367 self
.treestore
= gtk
.TreeStore(gobject
.TYPE_STRING
, str, object, int, int)
368 self
.treeview
= gtk
.TreeView(self
.treestore
)
369 self
.treeview
.set_headers_visible(False)
370 renderer
= gtk
.CellRendererText()
371 self
.column
= gtk
.TreeViewColumn('Object ID', renderer
, text
=0)
372 self
.treeview
.append_column(self
.column
)
373 for figure
in P
.matplotlib
._pylab
_helpers
.Gcf
.get_all_fig_managers():
375 iter_fig
= self
.treestore
.append(None, ['Figure %d'%fig, 'figure' ,figure
, fig
, fig
])
376 for ind_ax
, ax
in enumerate(P
.figure(fig
).axes
):
377 iter_ax
= self
.treestore
.append(iter_fig
, ['Axe %d'%ind
_ax
, 'axe' ,ax
, fig
, ind_ax
])
378 for ind_line
, line
in enumerate(ax
.lines
):
379 iter = self
.treestore
.append(iter_ax
, ['Line %d'%ind
_line
, 'line', line
, fig
, ind_line
])
380 for ind_im
, im
in enumerate(ax
.images
):
381 iter = self
.treestore
.append(iter_ax
, ['Image %d'%ind
_im
, 'image',im
, fig
, ind_im
])
382 for ind_text
, text
in enumerate(ax
.texts
):
383 iter = self
.treestore
.append(iter_ax
, ['Text %d'%ind
_text
, 'text', text
, fig
, ind_text
])
389 self
.treeview
.connect("cursor-changed", self
.row_activated
)
390 scroll
= gtk
.ScrolledWindow()
391 scroll
.set_policy(gtk
.POLICY_NEVER
, gtk
.POLICY_AUTOMATIC
)
392 scroll
.add(self
.treeview
)
394 hbox
.pack_start(scroll
)
396 viewport
= gtk
.Viewport()
397 viewport
.add(self
.paramtable
)
399 scroll
= gtk
.ScrolledWindow()
400 scroll
.set_policy(gtk
.POLICY_NEVER
, gtk
.POLICY_AUTOMATIC
)
403 hbox
.pack_start(scroll
)
406 button
= gtk
.Button('Update')
407 button
.connect("clicked", self
.update
)
409 bottom
.pack_start(button
)
410 button
= gtk
.Button('Copy')
411 button
.connect("clicked", self
.copy
)
413 bottom
.pack_start(button
)
414 button
= gtk
.Button('Delete')
415 button
.connect("clicked", self
.delete
)
417 bottom
.pack_start(button
)
419 button
= gtk
.Button('Apply')
420 button
.connect("clicked", self
.apply)
422 bottom
.pack_start(button
)
425 vbox
.pack_start(hbox
)
426 vbox
.pack_start(bottom
, False)
427 self
.window
.add(vbox
)