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

Skip to content

Commit 4a68406

Browse files
committed
added Goekhan's apply patch to qt editor
svn path=/trunk/matplotlib/; revision=8091
1 parent cbd757c commit 4a68406

2 files changed

Lines changed: 74 additions & 51 deletions

File tree

lib/matplotlib/backends/qt4_editor/figureoptions.py

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -112,43 +112,46 @@ def figure_edit(axes, parent=None):
112112
datalist = [(general, "Axes", "")]
113113
if has_curve:
114114
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-
115+
116+
def apply_callback(data):
117+
"""This function will be called to apply changes"""
118+
if has_curve:
119+
general, curves = data
120+
else:
121+
general, = data
122+
123+
# Set / General
124+
title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale = general
125+
axes.set_xscale(xscale)
126+
axes.set_yscale(yscale)
127+
axes.set_title(title)
128+
axes.set_xlim(xmin, xmax)
129+
axes.set_xlabel(xlabel)
130+
axes.set_ylim(ymin, ymax)
131+
axes.set_ylabel(ylabel)
132+
133+
if has_curve:
134+
# Set / Curves
135+
for index, curve in enumerate(curves):
136+
line = linedict[curvelabels[index]]
137+
label, linestyle, linewidth, color, \
138+
marker, markersize, markerfacecolor, markeredgecolor = curve
139+
line.set_label(label)
140+
line.set_linestyle(linestyle)
141+
line.set_linewidth(linewidth)
142+
line.set_color(color)
143+
if marker is not 'none':
144+
line.set_marker(marker)
145+
line.set_markersize(markersize)
146+
line.set_markerfacecolor(markerfacecolor)
147+
line.set_markeredgecolor(markeredgecolor)
148+
149+
# Redraw
150+
figure = axes.get_figure()
151+
figure.canvas.draw()
152+
153+
data = formlayout.fedit(datalist, title="Figure options", parent=parent,
154+
icon=get_icon('qt4_editor_options.svg'), apply=apply_callback)
155+
if data is not None:
156+
apply_callback(data)
157+

lib/matplotlib/backends/qt4_editor/formlayout.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
OTHER DEALINGS IN THE SOFTWARE.
3434
"""
3535

36-
__version__ = '1.0.5'
36+
# History:
37+
# 1.0.7: added support for "Apply" button
38+
# 1.0.6: code cleaning
39+
40+
__version__ = '1.0.7'
3741
__license__ = __doc__
3842

3943
DEBUG = False
@@ -67,29 +71,29 @@ def __init__(self, parent=None):
6771
QPushButton.__init__(self, parent)
6872
self.setFixedSize(20, 20)
6973
self.setIconSize(QSize(12, 12))
70-
self.connect(self, SIGNAL("clicked()"), self.chooseColor)
74+
self.connect(self, SIGNAL("clicked()"), self.choose_color)
7175
self._color = QColor()
7276

73-
def chooseColor(self):
77+
def choose_color(self):
7478
rgba, valid = QColorDialog.getRgba(self._color.rgba(),
7579
self.parentWidget())
7680
if valid:
7781
color = QColor.fromRgba(rgba)
78-
self.setColor(color)
82+
self.set_color(color)
7983

80-
def color(self):
84+
def get_color(self):
8185
return self._color
8286

8387
@pyqtSignature("QColor")
84-
def setColor(self, color):
88+
def set_color(self, color):
8589
if color != self._color:
8690
self._color = color
8791
self.emit(SIGNAL("colorChanged(QColor)"), self._color)
8892
pixmap = QPixmap(self.iconSize())
8993
pixmap.fill(color)
9094
self.setIcon(QIcon(pixmap))
9195

92-
color = pyqtProperty("QColor", color, setColor)
96+
color = pyqtProperty("QColor", get_color, set_color)
9397

9498

9599
def text_to_qcolor(text):
@@ -369,8 +373,10 @@ def get(self):
369373
class FormDialog(QDialog):
370374
"""Form Dialog"""
371375
def __init__(self, data, title="", comment="",
372-
icon=None, parent=None):
376+
icon=None, parent=None, apply=None):
373377
super(FormDialog, self).__init__(parent)
378+
379+
self.apply_callback = apply
374380

375381
# Form
376382
if isinstance(data[0][0], (list, tuple)):
@@ -387,6 +393,9 @@ def __init__(self, data, title="", comment="",
387393

388394
# Button box
389395
bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
396+
if self.apply_callback is not None:
397+
apply_btn = bbox.addButton(QDialogButtonBox.Apply)
398+
self.connect(apply_btn, SIGNAL("clicked()"), self.apply)
390399
self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
391400
self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
392401
layout.addWidget(bbox)
@@ -406,17 +415,25 @@ def reject(self):
406415
self.data = None
407416
QDialog.reject(self)
408417

418+
def apply(self):
419+
self.apply_callback(self.formwidget.get())
420+
409421
def get(self):
410422
"""Return form result"""
411423
return self.data
412424

413425

414-
def fedit(data, title="", comment="", icon=None, parent=None):
426+
def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
415427
"""
416428
Create form dialog and return result
417429
(if Cancel button is pressed, return None)
418430
419431
data: datalist, datagroup
432+
title: string
433+
comment: string
434+
icon: QIcon instance
435+
parent: parent QWidget
436+
apply: apply callback (function)
420437
421438
datalist: list/tuple of (field_name, field_value)
422439
datagroup: list/tuple of (datalist *or* datagroup, title, comment)
@@ -440,7 +457,7 @@ def fedit(data, title="", comment="", icon=None, parent=None):
440457
if QApplication.startingUp():
441458
QApplication([])
442459

443-
dialog = FormDialog(data, title, comment, icon, parent)
460+
dialog = FormDialog(data, title, comment, icon, parent, apply)
444461
if dialog.exec_():
445462
return dialog.get()
446463

@@ -471,8 +488,11 @@ def create_datagroup_example():
471488

472489
#--------- datalist example
473490
datalist = create_datalist_example()
491+
def apply_test(data):
492+
print "data:", data
474493
print "result:", fedit(datalist, title="Example",
475-
comment="This is just an <b>example</b>.")
494+
comment="This is just an <b>example</b>.",
495+
apply=apply_test)
476496

477497
#--------- datagroup example
478498
datagroup = create_datagroup_example()

0 commit comments

Comments
 (0)