Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a9e8ff

Browse files
committed
added qt4_editor dialog
svn path=/trunk/matplotlib/; revision=8064
1 parent 5e12fa5 commit 0a9e8ff

7 files changed

Lines changed: 711 additions & 0 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2010-01-03 Added Pierre's qt4 formlayout editor and toolbar button - JDH
2+
13
2009-12-31 Add support for using math text as marker symbols (Thanks to tcb)
24
- MGD
35

LICENSE/LICENSE_QT4_EDITOR

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Module creating PyQt4 form dialogs/layouts to edit various type of parameters
3+
4+
5+
formlayout License Agreement (MIT License)
6+
------------------------------------------
7+
8+
Copyright (c) 2009 Pierre Raybaut
9+
10+
Permission is hereby granted, free of charge, to any person
11+
obtaining a copy of this software and associated documentation
12+
files (the "Software"), to deal in the Software without
13+
restriction, including without limitation the rights to use,
14+
copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the
16+
Software is furnished to do so, subject to the following
17+
conditions:
18+
19+
The above copyright notice and this permission notice shall be
20+
included in all copies or substantial portions of the Software.
21+
22+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29+
OTHER DEALINGS IN THE SOFTWARE.
30+
"""

lib/matplotlib/backends/backend_qt4.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from matplotlib.figure import Figure
1313
from matplotlib.mathtext import MathTextParser
1414
from matplotlib.widgets import SubplotTool
15+
import matplotlib.backends.qt4_editor.figureoptions as figureoptions
1516

1617
try:
1718
from PyQt4 import QtCore, QtGui, Qt
@@ -330,10 +331,16 @@ def _init_toolbar(self):
330331
a = self.addAction(self._icon('subplots.png'), 'Subplots',
331332
self.configure_subplots)
332333
a.setToolTip('Configure subplots')
334+
335+
a = self.addAction(self._icon("qt4_editor_options.svg"),
336+
'Customize', self.edit_parameters)
337+
a.setToolTip('Edit curves line and axes parameters')
338+
333339
a = self.addAction(self._icon('filesave.svg'), 'Save',
334340
self.save_figure)
335341
a.setToolTip('Save the figure')
336342

343+
337344
self.buttons = {}
338345

339346
# Add the x,y location widget at the right side of the toolbar
@@ -352,6 +359,36 @@ def _init_toolbar(self):
352359
# reference holder for subplots_adjust window
353360
self.adj_window = None
354361

362+
def edit_parameters(self):
363+
allaxes = self.canvas.figure.get_axes()
364+
if len(allaxes) == 1:
365+
axes = allaxes[0]
366+
else:
367+
titles = []
368+
for axes in allaxes:
369+
title = axes.get_title()
370+
ylabel = axes.get_ylabel()
371+
if title:
372+
text = title
373+
if ylabel:
374+
text += ": "+ylabel
375+
text += " (%s)"
376+
elif ylabel:
377+
text = "%s (%s)" % ylabel
378+
else:
379+
text = "%s"
380+
titles.append(text % repr(axes))
381+
item, ok = QtGui.QInputDialog.getItem(self, 'Customize',
382+
'Select axes:', titles,
383+
0, False)
384+
if ok:
385+
axes = allaxes[titles.index(unicode(item))]
386+
else:
387+
return
388+
389+
figureoptions.figure_edit(axes, self)
390+
391+
355392
def dynamic_update( self ):
356393
self.canvas.draw()
357394

lib/matplotlib/backends/qt4_editor/__init__.py

Whitespace-only changes.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright © 2009 Pierre Raybaut
4+
# Licensed under the terms of the MIT License
5+
# see the mpl licenses directory for a copy of the license
6+
7+
"""Module that provides a GUI-based editor for matplotlib's figure options"""
8+
9+
import os.path as osp
10+
11+
import matplotlib.backends.qt4_editor.formlayout as formlayout
12+
from PyQt4.QtGui import QIcon
13+
14+
def get_icon(name):
15+
import matplotlib
16+
basedir = osp.join(matplotlib.rcParams['datapath'], 'images')
17+
return QIcon(osp.join(basedir, name))
18+
19+
LINESTYLES = {
20+
'-': 'Solid',
21+
'--': 'Dashed',
22+
'-.': 'DashDot',
23+
':': 'Dotted',
24+
'steps': 'Steps',
25+
'none': 'None',
26+
}
27+
28+
MARKERS = {
29+
'none': 'None',
30+
'o': 'circles',
31+
'^': 'triangle_up',
32+
'v': 'triangle_down',
33+
'<': 'triangle_left',
34+
'>': 'triangle_right',
35+
's': 'square',
36+
'+': 'plus',
37+
'x': 'cross',
38+
'*': 'star',
39+
'D': 'diamond',
40+
'd': 'thin_diamond',
41+
'1': 'tripod_down',
42+
'2': 'tripod_up',
43+
'3': 'tripod_left',
44+
'4': 'tripod_right',
45+
'h': 'hexagon',
46+
'H': 'rotated_hexagon',
47+
'p': 'pentagon',
48+
'|': 'vertical_line',
49+
'_': 'horizontal_line',
50+
'.': 'dots',
51+
}
52+
53+
COLORS = {'b': '#0000ff', 'g': '#00ff00', 'r': '#ff0000', 'c': '#ff00ff',
54+
'm': '#ff00ff', 'y': '#ffff00', 'k': '#000000', 'w': '#ffffff'}
55+
56+
def col2hex(color):
57+
"""Convert matplotlib color to hex"""
58+
return COLORS.get(color, color)
59+
60+
def figure_edit(axes, parent=None):
61+
"""Edit matplotlib figure options"""
62+
sep = (None, None) # separator
63+
64+
has_curve = len(axes.get_lines()) > 0
65+
66+
# Get / General
67+
xmin, xmax = axes.get_xlim()
68+
ymin, ymax = axes.get_ylim()
69+
general = [('Title', axes.get_title()),
70+
sep,
71+
(None, "<b>X-Axis</b>"),
72+
('Min', xmin), ('Max', xmax),
73+
('Label', axes.get_xlabel()),
74+
('Scale', [axes.get_xscale(), 'linear', 'log']),
75+
sep,
76+
(None, "<b>Y-Axis</b>"),
77+
('Min', ymin), ('Max', ymax),
78+
('Label', axes.get_ylabel()),
79+
('Scale', [axes.get_yscale(), 'linear', 'log'])
80+
]
81+
82+
if has_curve:
83+
# Get / Curves
84+
linedict = {}
85+
for line in axes.get_lines():
86+
label = line.get_label()
87+
if label == '_nolegend_':
88+
continue
89+
linedict[label] = line
90+
curves = []
91+
linestyles = LINESTYLES.items()
92+
markers = MARKERS.items()
93+
curvelabels = sorted(linedict.keys())
94+
for label in curvelabels:
95+
line = linedict[label]
96+
curvedata = [
97+
('Label', label),
98+
sep,
99+
(None, '<b>Line</b>'),
100+
('Style', [line.get_linestyle()] + linestyles),
101+
('Width', line.get_linewidth()),
102+
('Color', col2hex(line.get_color())),
103+
sep,
104+
(None, '<b>Marker</b>'),
105+
('Style', [line.get_marker()] + markers),
106+
('Size', line.get_markersize()),
107+
('Facecolor', col2hex(line.get_markerfacecolor())),
108+
('Edgecolor', col2hex(line.get_markeredgecolor())),
109+
]
110+
curves.append([curvedata, label, ""])
111+
112+
datalist = [(general, "Axes", "")]
113+
if has_curve:
114+
datalist.append((curves, "Curves", ""))
115+
result = formlayout.fedit(datalist, title="Figure options", parent=parent,
116+
icon=get_icon('qt4_editor_options.svg'))
117+
if result is None:
118+
return
119+
120+
if has_curve:
121+
general, curves = result
122+
else:
123+
general, = result
124+
125+
# Set / General
126+
title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale = general
127+
axes.set_xscale(xscale)
128+
axes.set_yscale(yscale)
129+
axes.set_title(title)
130+
axes.set_xlim(xmin, xmax)
131+
axes.set_xlabel(xlabel)
132+
axes.set_ylim(ymin, ymax)
133+
axes.set_ylabel(ylabel)
134+
135+
if has_curve:
136+
# Set / Curves
137+
for index, curve in enumerate(curves):
138+
line = linedict[curvelabels[index]]
139+
label, linestyle, linewidth, color, \
140+
marker, markersize, markerfacecolor, markeredgecolor = curve
141+
line.set_label(label)
142+
line.set_linestyle(linestyle)
143+
line.set_linewidth(linewidth)
144+
line.set_color(color)
145+
if marker is not 'none':
146+
line.set_marker(marker)
147+
line.set_markersize(markersize)
148+
line.set_markerfacecolor(markerfacecolor)
149+
line.set_markeredgecolor(markeredgecolor)
150+
151+
# Redraw
152+
figure = axes.get_figure()
153+
figure.canvas.draw()
154+

0 commit comments

Comments
 (0)