Skip to content

Commit

Permalink
added qt4_editor dialog
Browse files Browse the repository at this point in the history
svn path=/trunk/matplotlib/; revision=8064
  • Loading branch information
jdh2358 committed Jan 3, 2010
1 parent 5e12fa5 commit 0a9e8ff
Show file tree
Hide file tree
Showing 7 changed files with 711 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2010-01-03 Added Pierre's qt4 formlayout editor and toolbar button - JDH

2009-12-31 Add support for using math text as marker symbols (Thanks to tcb)
- MGD

Expand Down
30 changes: 30 additions & 0 deletions LICENSE/LICENSE_QT4_EDITOR
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

Module creating PyQt4 form dialogs/layouts to edit various type of parameters


formlayout License Agreement (MIT License)
------------------------------------------

Copyright (c) 2009 Pierre Raybaut

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"""
37 changes: 37 additions & 0 deletions lib/matplotlib/backends/backend_qt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from matplotlib.figure import Figure
from matplotlib.mathtext import MathTextParser
from matplotlib.widgets import SubplotTool
import matplotlib.backends.qt4_editor.figureoptions as figureoptions

try:
from PyQt4 import QtCore, QtGui, Qt
Expand Down Expand Up @@ -330,10 +331,16 @@ def _init_toolbar(self):
a = self.addAction(self._icon('subplots.png'), 'Subplots',
self.configure_subplots)
a.setToolTip('Configure subplots')

a = self.addAction(self._icon("qt4_editor_options.svg"),
'Customize', self.edit_parameters)
a.setToolTip('Edit curves line and axes parameters')

a = self.addAction(self._icon('filesave.svg'), 'Save',
self.save_figure)
a.setToolTip('Save the figure')


self.buttons = {}

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

def edit_parameters(self):
allaxes = self.canvas.figure.get_axes()
if len(allaxes) == 1:
axes = allaxes[0]
else:
titles = []
for axes in allaxes:
title = axes.get_title()
ylabel = axes.get_ylabel()
if title:
text = title
if ylabel:
text += ": "+ylabel
text += " (%s)"
elif ylabel:
text = "%s (%s)" % ylabel
else:
text = "%s"
titles.append(text % repr(axes))
item, ok = QtGui.QInputDialog.getItem(self, 'Customize',
'Select axes:', titles,
0, False)
if ok:
axes = allaxes[titles.index(unicode(item))]
else:
return

figureoptions.figure_edit(axes, self)


def dynamic_update( self ):
self.canvas.draw()

Expand Down
Empty file.
154 changes: 154 additions & 0 deletions lib/matplotlib/backends/qt4_editor/figureoptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2009 Pierre Raybaut
# Licensed under the terms of the MIT License
# see the mpl licenses directory for a copy of the license

"""Module that provides a GUI-based editor for matplotlib's figure options"""

import os.path as osp

import matplotlib.backends.qt4_editor.formlayout as formlayout
from PyQt4.QtGui import QIcon

def get_icon(name):
import matplotlib
basedir = osp.join(matplotlib.rcParams['datapath'], 'images')
return QIcon(osp.join(basedir, name))

LINESTYLES = {
'-': 'Solid',
'--': 'Dashed',
'-.': 'DashDot',
':': 'Dotted',
'steps': 'Steps',
'none': 'None',
}

MARKERS = {
'none': 'None',
'o': 'circles',
'^': 'triangle_up',
'v': 'triangle_down',
'<': 'triangle_left',
'>': 'triangle_right',
's': 'square',
'+': 'plus',
'x': 'cross',
'*': 'star',
'D': 'diamond',
'd': 'thin_diamond',
'1': 'tripod_down',
'2': 'tripod_up',
'3': 'tripod_left',
'4': 'tripod_right',
'h': 'hexagon',
'H': 'rotated_hexagon',
'p': 'pentagon',
'|': 'vertical_line',
'_': 'horizontal_line',
'.': 'dots',
}

COLORS = {'b': '#0000ff', 'g': '#00ff00', 'r': '#ff0000', 'c': '#ff00ff',
'm': '#ff00ff', 'y': '#ffff00', 'k': '#000000', 'w': '#ffffff'}

def col2hex(color):
"""Convert matplotlib color to hex"""
return COLORS.get(color, color)

def figure_edit(axes, parent=None):
"""Edit matplotlib figure options"""
sep = (None, None) # separator

has_curve = len(axes.get_lines()) > 0

# Get / General
xmin, xmax = axes.get_xlim()
ymin, ymax = axes.get_ylim()
general = [('Title', axes.get_title()),
sep,
(None, "<b>X-Axis</b>"),
('Min', xmin), ('Max', xmax),
('Label', axes.get_xlabel()),
('Scale', [axes.get_xscale(), 'linear', 'log']),
sep,
(None, "<b>Y-Axis</b>"),
('Min', ymin), ('Max', ymax),
('Label', axes.get_ylabel()),
('Scale', [axes.get_yscale(), 'linear', 'log'])
]

if has_curve:
# Get / Curves
linedict = {}
for line in axes.get_lines():
label = line.get_label()
if label == '_nolegend_':
continue
linedict[label] = line
curves = []
linestyles = LINESTYLES.items()
markers = MARKERS.items()
curvelabels = sorted(linedict.keys())
for label in curvelabels:
line = linedict[label]
curvedata = [
('Label', label),
sep,
(None, '<b>Line</b>'),
('Style', [line.get_linestyle()] + linestyles),
('Width', line.get_linewidth()),
('Color', col2hex(line.get_color())),
sep,
(None, '<b>Marker</b>'),
('Style', [line.get_marker()] + markers),
('Size', line.get_markersize()),
('Facecolor', col2hex(line.get_markerfacecolor())),
('Edgecolor', col2hex(line.get_markeredgecolor())),
]
curves.append([curvedata, label, ""])

datalist = [(general, "Axes", "")]
if has_curve:
datalist.append((curves, "Curves", ""))
result = formlayout.fedit(datalist, title="Figure options", parent=parent,
icon=get_icon('qt4_editor_options.svg'))
if result is None:
return

if has_curve:
general, curves = result
else:
general, = result

# Set / General
title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale = general
axes.set_xscale(xscale)
axes.set_yscale(yscale)
axes.set_title(title)
axes.set_xlim(xmin, xmax)
axes.set_xlabel(xlabel)
axes.set_ylim(ymin, ymax)
axes.set_ylabel(ylabel)

if has_curve:
# Set / Curves
for index, curve in enumerate(curves):
line = linedict[curvelabels[index]]
label, linestyle, linewidth, color, \
marker, markersize, markerfacecolor, markeredgecolor = curve
line.set_label(label)
line.set_linestyle(linestyle)
line.set_linewidth(linewidth)
line.set_color(color)
if marker is not 'none':
line.set_marker(marker)
line.set_markersize(markersize)
line.set_markerfacecolor(markerfacecolor)
line.set_markeredgecolor(markeredgecolor)

# Redraw
figure = axes.get_figure()
figure.canvas.draw()

Loading

0 comments on commit 0a9e8ff

Please sign in to comment.