Skip to content

Commit bd245ef

Browse files
committed
qt4_compat and qt4_editor: more pyqt/pyside fixes
1 parent 5f287e1 commit bd245ef

File tree

2 files changed

+52
-51
lines changed

2 files changed

+52
-51
lines changed

lib/matplotlib/backends/qt4_compat.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,20 @@ def prepare_pyqt4():
5252
__version__ = QtCore.PYQT_VERSION_STR
5353

5454
# Use new getSaveFileNameAndFilter()
55-
_getSaveFileName = lambda self, msg, start, filters, \
56-
selectedFilter : \
57-
QtGui.QFileDialog.getSaveFileNameAndFilter( \
58-
self, msg, start, filters, selectedFilter)[0]
59-
60-
55+
_get_save = QtGui.QFileDialog.getSaveFileNameAndFilter
6156

6257
elif QT_API == QT_API_PYSIDE:
6358
from PySide import QtCore, QtGui, __version__, __version_info__
6459
if __version_info__ < (1,0,3):
6560
raise ImportError(
6661
"Matplotlib backend_qt4 and backend_qt4agg require PySide >=1.0.3")
6762

63+
_get_save = QtGui.QFileDialog.getSaveFileName
64+
6865
else:
6966
raise RuntimeError('Invalid Qt API %r, valid values are: %r or %r' %
7067
(QT_API, QT_API_PYQT, QT_API_PYSIDE))
68+
69+
def _getSaveFileName(self, msg, start, filters, selectedFilter):
70+
return _get_save(self, msg, start, filters, selectedFilter)[0]
71+

lib/matplotlib/backends/qt4_editor/formlayout.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
QtGui.QTabWidget, QtGui.QApplication, QtGui.QStackedWidget, QtGui.QDateEdit,
6363
QtGui.QDateTimeEdit, QtGui.QFont, QtGui.QFontComboBox, QtGui.QFontDatabase,
6464
QtGui.QGridLayout, QtGui.QFormLayout, QtGui.QDoubleValidator)
65-
65+
6666
(Qt, SIGNAL, SLOT, QObject, QSize,pyqtSignature, pyqtProperty) =\
67-
(QtCore.Qt, QtCore.SIGNAL, QtCore.SLOT, QtCore.QObject, QtCore.QSize,
68-
QtCore.pyqtSignature, QtCore.pyqtProperty)
67+
(QtCore.Qt, QtCore.SIGNAL, QtCore.SLOT, QtCore.QObject, QtCore.QSize,
68+
QtCore.Slot, QtCore.Property)
6969

7070
import datetime
7171

@@ -74,22 +74,22 @@ class ColorButton(QPushButton):
7474
Color choosing push button
7575
"""
7676
__pyqtSignals__ = ("colorChanged(QColor)",)
77-
77+
7878
def __init__(self, parent=None):
7979
QPushButton.__init__(self, parent)
8080
self.setFixedSize(20, 20)
8181
self.setIconSize(QSize(12, 12))
8282
self.connect(self, SIGNAL("clicked()"), self.choose_color)
8383
self._color = QColor()
84-
84+
8585
def choose_color(self):
8686
color = QColorDialog.getColor(self._color,self.parentWidget(),'')
8787
if color.isValid():
8888
self.set_color(color)
89-
89+
9090
def get_color(self):
9191
return self._color
92-
92+
9393
@pyqtSignature("QColor")
9494
def set_color(self, color):
9595
if color != self._color:
@@ -98,7 +98,7 @@ def set_color(self, color):
9898
pixmap = QPixmap(self.iconSize())
9999
pixmap.fill(color)
100100
self.setIcon(QIcon(pixmap))
101-
101+
102102
color = pyqtProperty("QColor", get_color, set_color)
103103

104104

@@ -146,11 +146,11 @@ def update_color(self, text):
146146

147147
def update_text(self, color):
148148
self.lineedit.setText(color.name())
149-
149+
150150
def text(self):
151151
return self.lineedit.text()
152-
153-
152+
153+
154154
def font_is_installed(font):
155155
"""Check if font is installed"""
156156
return [fam for fam in QFontDatabase().families() if unicode(fam)==font]
@@ -184,12 +184,12 @@ def __init__(self, value, parent=None):
184184
QGridLayout.__init__(self)
185185
font = tuple_to_qfont(value)
186186
assert font is not None
187-
187+
188188
# Font family
189189
self.family = QFontComboBox(parent)
190190
self.family.setCurrentFont(font)
191191
self.addWidget(self.family, 0, 0, 1, -1)
192-
192+
193193
# Font size
194194
self.size = QComboBox(parent)
195195
self.size.setEditable(True)
@@ -201,17 +201,17 @@ def __init__(self, value, parent=None):
201201
self.size.addItems([str(s) for s in sizelist])
202202
self.size.setCurrentIndex(sizelist.index(size))
203203
self.addWidget(self.size, 1, 0)
204-
204+
205205
# Italic or not
206206
self.italic = QCheckBox(self.tr("Italic"), parent)
207207
self.italic.setChecked(font.italic())
208208
self.addWidget(self.italic, 1, 1)
209-
209+
210210
# Bold or not
211211
self.bold = QCheckBox(self.tr("Bold"), parent)
212212
self.bold.setChecked(font.bold())
213213
self.addWidget(self.bold, 1, 2)
214-
214+
215215
def get_font(self):
216216
font = self.family.currentFont()
217217
font.setItalic(self.italic.isChecked())
@@ -223,7 +223,7 @@ def get_font(self):
223223
def is_edit_valid(edit):
224224
text = edit.text()
225225
state = edit.validator().validate(text, 0)[0]
226-
226+
227227
return state == QDoubleValidator.Acceptable
228228

229229
class FormWidget(QWidget):
@@ -242,7 +242,7 @@ def __init__(self, data, comment="", parent=None):
242242
print "*"*80
243243
print "COMMENT:", comment
244244
print "*"*80
245-
245+
246246
def get_dialog(self):
247247
"""Return FormDialog instance"""
248248
dialog = self.parent()
@@ -315,7 +315,7 @@ def setup(self):
315315
field = QLineEdit(repr(value), self)
316316
self.formlayout.addRow(label, field)
317317
self.widgets.append(field)
318-
318+
319319
def get(self):
320320
valuelist = []
321321
for index, (label, value) in enumerate(self.data):
@@ -356,26 +356,26 @@ def __init__(self, datalist, comment="", parent=None):
356356
self.setLayout(layout)
357357
self.combobox = QComboBox()
358358
layout.addWidget(self.combobox)
359-
359+
360360
self.stackwidget = QStackedWidget(self)
361361
layout.addWidget(self.stackwidget)
362362
self.connect(self.combobox, SIGNAL("currentIndexChanged(int)"),
363363
self.stackwidget, SLOT("setCurrentIndex(int)"))
364-
364+
365365
self.widgetlist = []
366366
for data, title, comment in datalist:
367367
self.combobox.addItem(title)
368368
widget = FormWidget(data, comment=comment, parent=self)
369369
self.stackwidget.addWidget(widget)
370370
self.widgetlist.append(widget)
371-
371+
372372
def setup(self):
373373
for widget in self.widgetlist:
374374
widget.setup()
375375

376376
def get(self):
377377
return [ widget.get() for widget in self.widgetlist]
378-
378+
379379

380380
class FormTabWidget(QWidget):
381381
def __init__(self, datalist, comment="", parent=None):
@@ -393,11 +393,11 @@ def __init__(self, datalist, comment="", parent=None):
393393
index = self.tabwidget.addTab(widget, title)
394394
self.tabwidget.setTabToolTip(index, comment)
395395
self.widgetlist.append(widget)
396-
396+
397397
def setup(self):
398398
for widget in self.widgetlist:
399399
widget.setup()
400-
400+
401401
def get(self):
402402
return [ widget.get() for widget in self.widgetlist]
403403

@@ -409,7 +409,7 @@ def __init__(self, data, title="", comment="",
409409
QDialog.__init__(self, parent)
410410

411411
self.apply_callback = apply
412-
412+
413413
# Form
414414
if isinstance(data[0][0], (list, tuple)):
415415
self.formwidget = FormTabWidget(data, comment=comment,
@@ -418,11 +418,11 @@ def __init__(self, data, title="", comment="",
418418
self.formwidget = FormComboWidget(data, comment=comment,
419419
parent=self)
420420
else:
421-
self.formwidget = FormWidget(data, comment=comment,
421+
self.formwidget = FormWidget(data, comment=comment,
422422
parent=self)
423423
layout = QVBoxLayout()
424424
layout.addWidget(self.formwidget)
425-
425+
426426
self.float_fields = []
427427
self.formwidget.setup()
428428

@@ -439,15 +439,15 @@ def __init__(self, data, title="", comment="",
439439
layout.addWidget(bbox)
440440

441441
self.setLayout(layout)
442-
442+
443443
self.setWindowTitle(title)
444444
if not isinstance(icon, QIcon):
445445
icon = QWidget().style().standardIcon(QStyle.SP_MessageBoxQuestion)
446446
self.setWindowIcon(icon)
447-
447+
448448
def register_float_field(self, field):
449449
self.float_fields.append(field)
450-
450+
451451
def update_buttons(self):
452452
valid = True
453453
for field in self.float_fields:
@@ -457,18 +457,18 @@ def update_buttons(self):
457457
btn = self.bbox.button(btn_type)
458458
if btn is not None:
459459
btn.setEnabled(valid)
460-
460+
461461
def accept(self):
462462
self.data = self.formwidget.get()
463463
QDialog.accept(self)
464-
464+
465465
def reject(self):
466466
self.data = None
467467
QDialog.reject(self)
468-
468+
469469
def apply(self):
470470
self.apply_callback(self.formwidget.get())
471-
471+
472472
def get(self):
473473
"""Return form result"""
474474
return self.data
@@ -478,22 +478,22 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
478478
"""
479479
Create form dialog and return result
480480
(if Cancel button is pressed, return None)
481-
481+
482482
data: datalist, datagroup
483483
title: string
484484
comment: string
485485
icon: QIcon instance
486486
parent: parent QWidget
487487
apply: apply callback (function)
488-
488+
489489
datalist: list/tuple of (field_name, field_value)
490490
datagroup: list/tuple of (datalist *or* datagroup, title, comment)
491-
491+
492492
-> one field for each member of a datalist
493493
-> one tab for each member of a top-level datagroup
494494
-> one page (of a multipage widget, each page can be selected with a combo
495495
box) for each member of a datagroup inside a datagroup
496-
496+
497497
Supported types for field_value:
498498
- int, float, str, unicode, bool
499499
- colors: in Qt-compatible text form, i.e. in hex format or name (red,...)
@@ -502,12 +502,12 @@ def fedit(data, title="", comment="", icon=None, parent=None, apply=None):
502502
* the first element will be the selected index (or value)
503503
* the other elements can be couples (key, value) or only values
504504
"""
505-
505+
506506
# Create a QApplication instance if no instance currently exists
507507
# (e.g. if the module is used directly from the interpreter)
508508
if QApplication.startingUp():
509509
_app = QApplication([])
510-
510+
511511
dialog = FormDialog(data, title, comment, icon, parent, apply)
512512
if dialog.exec_():
513513
return dialog.get()
@@ -531,25 +531,25 @@ def create_datalist_example():
531531
('date', datetime.date(2010, 10, 10)),
532532
('datetime', datetime.datetime(2010, 10, 10)),
533533
]
534-
534+
535535
def create_datagroup_example():
536536
datalist = create_datalist_example()
537537
return ((datalist, "Category 1", "Category 1 comment"),
538538
(datalist, "Category 2", "Category 2 comment"),
539539
(datalist, "Category 3", "Category 3 comment"))
540-
540+
541541
#--------- datalist example
542542
datalist = create_datalist_example()
543543
def apply_test(data):
544544
print "data:", data
545545
print "result:", fedit(datalist, title="Example",
546546
comment="This is just an <b>example</b>.",
547547
apply=apply_test)
548-
548+
549549
#--------- datagroup example
550550
datagroup = create_datagroup_example()
551551
print "result:", fedit(datagroup, "Global title")
552-
552+
553553
#--------- datagroup inside a datagroup example
554554
datalist = create_datalist_example()
555555
datagroup = create_datagroup_example()

0 commit comments

Comments
 (0)