From: <jd...@us...> - 2010-01-17 01:42:38
|
Revision: 8091 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8091&view=rev Author: jdh2358 Date: 2010-01-17 01:42:30 +0000 (Sun, 17 Jan 2010) Log Message: ----------- added Goekhan's apply patch to qt editor Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/qt4_editor/figureoptions.py trunk/matplotlib/lib/matplotlib/backends/qt4_editor/formlayout.py Modified: trunk/matplotlib/lib/matplotlib/backends/qt4_editor/figureoptions.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/qt4_editor/figureoptions.py 2010-01-16 23:14:50 UTC (rev 8090) +++ trunk/matplotlib/lib/matplotlib/backends/qt4_editor/figureoptions.py 2010-01-17 01:42:30 UTC (rev 8091) @@ -112,43 +112,46 @@ 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() - + + def apply_callback(data): + """This function will be called to apply changes""" + if has_curve: + general, curves = data + else: + general, = data + + # 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() + + data = formlayout.fedit(datalist, title="Figure options", parent=parent, + icon=get_icon('qt4_editor_options.svg'), apply=apply_callback) + if data is not None: + apply_callback(data) + Modified: trunk/matplotlib/lib/matplotlib/backends/qt4_editor/formlayout.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/qt4_editor/formlayout.py 2010-01-16 23:14:50 UTC (rev 8090) +++ trunk/matplotlib/lib/matplotlib/backends/qt4_editor/formlayout.py 2010-01-17 01:42:30 UTC (rev 8091) @@ -33,7 +33,11 @@ OTHER DEALINGS IN THE SOFTWARE. """ -__version__ = '1.0.5' +# History: +# 1.0.7: added support for "Apply" button +# 1.0.6: code cleaning + +__version__ = '1.0.7' __license__ = __doc__ DEBUG = False @@ -67,21 +71,21 @@ QPushButton.__init__(self, parent) self.setFixedSize(20, 20) self.setIconSize(QSize(12, 12)) - self.connect(self, SIGNAL("clicked()"), self.chooseColor) + self.connect(self, SIGNAL("clicked()"), self.choose_color) self._color = QColor() - def chooseColor(self): + def choose_color(self): rgba, valid = QColorDialog.getRgba(self._color.rgba(), self.parentWidget()) if valid: color = QColor.fromRgba(rgba) - self.setColor(color) + self.set_color(color) - def color(self): + def get_color(self): return self._color @pyqtSignature("QColor") - def setColor(self, color): + def set_color(self, color): if color != self._color: self._color = color self.emit(SIGNAL("colorChanged(QColor)"), self._color) @@ -89,7 +93,7 @@ pixmap.fill(color) self.setIcon(QIcon(pixmap)) - color = pyqtProperty("QColor", color, setColor) + color = pyqtProperty("QColor", get_color, set_color) def text_to_qcolor(text): @@ -369,8 +373,10 @@ class FormDialog(QDialog): """Form Dialog""" def __init__(self, data, title="", comment="", - icon=None, parent=None): + icon=None, parent=None, apply=None): super(FormDialog, self).__init__(parent) + + self.apply_callback = apply # Form if isinstance(data[0][0], (list, tuple)): @@ -387,6 +393,9 @@ # Button box bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + if self.apply_callback is not None: + apply_btn = bbox.addButton(QDialogButtonBox.Apply) + self.connect(apply_btn, SIGNAL("clicked()"), self.apply) self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()")) self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()")) layout.addWidget(bbox) @@ -406,17 +415,25 @@ self.data = None QDialog.reject(self) + def apply(self): + self.apply_callback(self.formwidget.get()) + def get(self): """Return form result""" return self.data -def fedit(data, title="", comment="", icon=None, parent=None): +def fedit(data, title="", comment="", icon=None, parent=None, apply=None): """ Create form dialog and return result (if Cancel button is pressed, return None) data: datalist, datagroup + title: string + comment: string + icon: QIcon instance + parent: parent QWidget + apply: apply callback (function) datalist: list/tuple of (field_name, field_value) datagroup: list/tuple of (datalist *or* datagroup, title, comment) @@ -440,7 +457,7 @@ if QApplication.startingUp(): QApplication([]) - dialog = FormDialog(data, title, comment, icon, parent) + dialog = FormDialog(data, title, comment, icon, parent, apply) if dialog.exec_(): return dialog.get() @@ -471,8 +488,11 @@ #--------- datalist example datalist = create_datalist_example() + def apply_test(data): + print "data:", data print "result:", fedit(datalist, title="Example", - comment="This is just an <b>example</b>.") + comment="This is just an <b>example</b>.", + apply=apply_test) #--------- datagroup example datagroup = create_datagroup_example() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |