diff --git a/qtwidgets/__init__.py b/qtwidgets/__init__.py index c1b9ac3..b25b994 100644 --- a/qtwidgets/__init__.py +++ b/qtwidgets/__init__.py @@ -11,3 +11,9 @@ # # ##################################################################### +try: + from labscript_utils import check_version +except ImportError: + raise ImportError('Require labscript_utils > 2.1.0') + +check_version('qtutils', '2.0.0', '3.0.0') diff --git a/qtwidgets/analogoutput.py b/qtwidgets/analogoutput.py index 00e01fc..f084012 100644 --- a/qtwidgets/analogoutput.py +++ b/qtwidgets/analogoutput.py @@ -13,12 +13,9 @@ import sys -if 'PySide' in sys.modules.copy(): - from PySide.QtCore import * - from PySide.QtGui import * -else: - from PyQt4.QtCore import * - from PyQt4.QtGui import * +from qtutils.qt.QtCore import * +from qtutils.qt.QtGui import * +from qtutils.qt.QtWidgets import * class NoStealFocusDoubleSpinBox(QDoubleSpinBox): @@ -274,4 +271,4 @@ def unlock(self,notify_ao=True): sys.exit(qapplication.exec_()) - \ No newline at end of file + \ No newline at end of file diff --git a/qtwidgets/ddsoutput.py b/qtwidgets/ddsoutput.py index 9e5edff..8962887 100644 --- a/qtwidgets/ddsoutput.py +++ b/qtwidgets/ddsoutput.py @@ -13,13 +13,10 @@ import sys -if 'PySide' in sys.modules.copy(): - from PySide.QtCore import * - from PySide.QtGui import * -else: - from PyQt4.QtCore import * - from PyQt4.QtGui import * - +from qtutils.qt.QtCore import * +from qtutils.qt.QtGui import * +from qtutils.qt.QtWidgets import * + from labscript_utils.qtwidgets.analogoutput import AnalogOutput from labscript_utils.qtwidgets.digitaloutput import DigitalOutput @@ -134,4 +131,4 @@ def show_sub_widget(self,subchnl): sys.exit(qapplication.exec_()) - \ No newline at end of file + \ No newline at end of file diff --git a/qtwidgets/digitaloutput.py b/qtwidgets/digitaloutput.py index 0b173f1..7ce353d 100644 --- a/qtwidgets/digitaloutput.py +++ b/qtwidgets/digitaloutput.py @@ -13,12 +13,10 @@ import sys -if 'PySide' in sys.modules.copy(): - from PySide.QtCore import * - from PySide.QtGui import * -else: - from PyQt4.QtCore import * - from PyQt4.QtGui import * +from qtutils.qt.QtCore import * +from qtutils.qt.QtGui import * +from qtutils.qt import QT_ENV, PYQT5 +from qtutils.qt.QtWidgets import * class DigitalOutput(QPushButton): @@ -56,7 +54,7 @@ def eventFilter(self, obj, event): # pass scrollwheel events of disabled buttons through to the parent # code adapted from: http://www.qtforum.org/article/28540/disabled-widgets-and-wheel-events.html - elif obj and not obj.isEnabled() and event.type() == QEvent.Wheel: + elif obj and not obj.isEnabled() and event.type() == QEvent.Wheel and QT_ENV != PYQT5: newEvent = QWheelEvent(obj.mapToParent(event.pos()), event.globalPos(), event.delta(), event.buttons(), event.modifiers(), event.orientation()) diff --git a/qtwidgets/dragdroptab.py b/qtwidgets/dragdroptab.py index cd78b72..2108133 100644 --- a/qtwidgets/dragdroptab.py +++ b/qtwidgets/dragdroptab.py @@ -12,13 +12,9 @@ ##################################################################### import sys -if 'PySide' in sys.modules.copy(): - from PySide.QtCore import * - from PySide.QtGui import * -else: - from PyQt4.QtCore import * - from PyQt4.QtGui import * - +from qtutils.qt.QtCore import * +from qtutils.qt.QtGui import * +from qtutils.qt.QtWidgets import * from qtutils import * debug = False @@ -393,8 +389,8 @@ def __init__(self, id, container_layout,i): container_layout.addWidget(self.tab_widget) self.tab_widget.addTab(QLabel("foo %d"%i), 'foo') self.tab_widget.addTab(QLabel("bar %d"%i), 'bar') - self.tab_widget.tabBar().setTabTextColor(0,"red") - self.tab_widget.tabBar().setTabTextColor(1,"green") + self.tab_widget.tabBar().setTabTextColor(0, QColor(255, 0, 0)) + self.tab_widget.tabBar().setTabTextColor(1, QColor(0, 255, 0)) class RunViewer(object): diff --git a/qtwidgets/elide_label.py b/qtwidgets/elide_label.py index d89c7b1..fbb3e9c 100644 --- a/qtwidgets/elide_label.py +++ b/qtwidgets/elide_label.py @@ -1,10 +1,8 @@ import sys -if 'PySide' in sys.modules: - from PySide.QtCore import * - from PySide.QtGui import * -else: - from PyQt4.QtCore import * - from PyQt4.QtGui import * + +from qtutils.qt.QtCore import * +from qtutils.qt.QtGui import * +from qtutils.qt.QtWidgets import * from qtutils import * diff --git a/qtwidgets/fingertab.py b/qtwidgets/fingertab.py index 133e888..2a9bb32 100644 --- a/qtwidgets/fingertab.py +++ b/qtwidgets/fingertab.py @@ -6,38 +6,36 @@ # [@LegoStormtoopr](http://www.twitter.com/legostormtroopr) to say thanks! import sys -if 'PySide' in sys.modules.copy(): - from PySide import QtCore - from PySide import QtGui -else: - from PyQt4 import QtCore - from PyQt4 import QtGui - -class FingerTabBarWidget(QtGui.QTabBar): +from qtutils.qt import QtCore, QtGui, QtWidgets + + +class FingerTabBarWidget(QtWidgets.QTabBar): def __init__(self, parent=None, *args, **kwargs): - self.tabSize = QtCore.QSize(kwargs.pop('width',100), kwargs.pop('height',25)) - QtGui.QTabBar.__init__(self, parent, *args, **kwargs) - + self.tabSize = QtCore.QSize(kwargs.pop('width', 100), kwargs.pop('height', 25)) + QtWidgets.QTabBar.__init__(self, parent, *args, **kwargs) + def paintEvent(self, event): - painter = QtGui.QStylePainter(self) - option = QtGui.QStyleOptionTab() - + painter = QtWidgets.QStylePainter(self) + option = QtWidgets.QStyleOptionTab() + for index in range(self.count()): self.initStyleOption(option, index) tabRect = self.tabRect(index) tabRect.moveLeft(10) - painter.drawControl(QtGui.QStyle.CE_TabBarTabShape, option) - painter.drawText(tabRect, QtCore.Qt.AlignVCenter |\ - QtCore.Qt.TextDontClip, \ - self.tabText(index)); + painter.drawControl(QtWidgets.QStyle.CE_TabBarTabShape, option) + painter.drawText(tabRect, QtCore.Qt.AlignVCenter | + QtCore.Qt.TextDontClip, + self.tabText(index)) painter.end() - def tabSizeHint(self,index): + + def tabSizeHint(self, index): return self.tabSize - + # Shamelessly stolen from this thread: # http://www.riverbankcomputing.com/pipermail/pyqt/2005-December/011724.html -class FingerTabWidget(QtGui.QTabWidget): +class FingerTabWidget(QtWidgets.QTabWidget): """A QTabWidget equivalent which uses our FingerTabBarWidget""" + def __init__(self, parent, *args): - QtGui.QTabWidget.__init__(self, parent, *args) - self.setTabBar(FingerTabBarWidget(self)) \ No newline at end of file + QtWidgets.QTabWidget.__init__(self, parent, *args) + self.setTabBar(FingerTabBarWidget(self)) diff --git a/qtwidgets/headerview_with_widgets.py b/qtwidgets/headerview_with_widgets.py index b7d46e5..d4077b2 100644 --- a/qtwidgets/headerview_with_widgets.py +++ b/qtwidgets/headerview_with_widgets.py @@ -1,8 +1,8 @@ from __future__ import division -from PyQt4 import QtCore, QtGui +from qtutils.qt import QtCore, QtGui, QtWidgets -class HorizontalHeaderViewWithWidgets(QtGui.QHeaderView): +class HorizontalHeaderViewWithWidgets(QtWidgets.QHeaderView): """A QHeaderView that supports inserting arbitrary widgets into sections. Use setWidget(logical_index, widget) @@ -32,7 +32,7 @@ def __init__(self, model, parent=None): self.widgets = {} self.indents = {} self.model = model - QtGui.QHeaderView.__init__(self, QtCore.Qt.Horizontal, parent) + QtWidgets.QHeaderView.__init__(self, QtCore.Qt.Horizontal, parent) self.setDefaultAlignment(QtCore.Qt.AlignLeft) self.sectionMoved.connect(self.update_widget_positions) self.sectionResized.connect(self.update_widget_positions) @@ -40,7 +40,7 @@ def __init__(self, model, parent=None): self.sectionCountChanged.connect(self.update_widget_positions) self.model.columnsInserted.connect(self.on_columnsInserted) self.model.columnsRemoved.connect(self.on_columnsRemoved) - self.setMovable(True) + self.setSectionsMovable(True) self.vertical_padding = 0 self.position_update_required = False self.custom_style = '' @@ -51,19 +51,19 @@ def setStyleSheet(self, custom_style): self.update_indents() def showSection(self, *args, **kwargs): - result = QtGui.QHeaderView.showSection(self, *args, **kwargs) + result = QtWidgets.QHeaderView.showSection(self, *args, **kwargs) self.update_indents() self.update_widget_positions() return result def hideSection(self, *args, **kwargs): - result = QtGui.QHeaderView.hideSection(self, *args, **kwargs) + result = QtWidgets.QHeaderView.hideSection(self, *args, **kwargs) self.update_indents() self.update_widget_positions() return result def setSectionHidden(self, *args, **kwargs): - result = QtGui.QHeaderView.setSectionHidden(self, *args, **kwargs) + result = QtWidgets.QHeaderView.setSectionHidden(self, *args, **kwargs) self.update_indents() self.update_widget_positions() return result @@ -71,7 +71,7 @@ def setSectionHidden(self, *args, **kwargs): def viewportEvent(self, event): if event.type() == QtCore.QEvent.Paint: self.update_widget_positions() - return QtGui.QHeaderView.viewportEvent(self, event) + return QtWidgets.QHeaderView.viewportEvent(self, event) def setWidget(self, logical_index, widget=None): header_item = self.model.horizontalHeaderItem(logical_index) @@ -106,7 +106,7 @@ def setWidget(self, logical_index, widget=None): self.update_widget_positions() def showEvent(self, event): - QtGui.QHeaderView.showEvent(self, event) + QtWidgets.QHeaderView.showEvent(self, event) self.update_indents() self.update_widget_positions() @@ -131,10 +131,10 @@ def update_indents(self): height = fontmetrics.height() required_padding = (max_widget_height + 2 - height) // 2 required_padding = max(required_padding, 3) - QtGui.QHeaderView.setStyleSheet(self, self.stylesheet % (required_padding, required_padding, self.custom_style)) + QtWidgets.QHeaderView.setStyleSheet(self, self.stylesheet % (required_padding, required_padding, self.custom_style)) def sectionSizeFromContents(self, logical_index): - base_size = QtGui.QHeaderView.sectionSizeFromContents(self, logical_index) + base_size = QtWidgets.QHeaderView.sectionSizeFromContents(self, logical_index) width, height = base_size.width(), base_size.height() if logical_index in self.widgets: widget_size = self.widgets[logical_index].size() diff --git a/qtwidgets/imageoutput.py b/qtwidgets/imageoutput.py index 8ed63af..dc0cc5a 100644 --- a/qtwidgets/imageoutput.py +++ b/qtwidgets/imageoutput.py @@ -15,14 +15,10 @@ import sys import os -if 'PySide' in sys.modules.copy(): - from PySide.QtCore import * - from PySide.QtGui import * -else: - from PyQt4.QtCore import * - from PyQt4.QtGui import * - from PyQt4.QtCore import pyqtSignal as Signal -import qtutils.icons +from qtutils.qt.QtCore import * +from qtutils.qt.QtGui import * +from qtutils.qt.QtWidgets import * +from qtutils.qt.QtCore import pyqtSignal as Signal class BrowseButton(QPushButton): def __init__(self, image_output, *args, **kwargs): @@ -43,7 +39,8 @@ def browse(self): supported_images += ")" image_file = QFileDialog.getOpenFileName(self, 'Select image file to load', self.last_opened_folder, supported_images) - + if type(image_file) is tuple: + image_file, _ = image_file if image_file == None or image_file == "": return image_file = os.path.abspath(image_file) diff --git a/qtwidgets/toolpalette.py b/qtwidgets/toolpalette.py index bb337e4..e6f2ced 100644 --- a/qtwidgets/toolpalette.py +++ b/qtwidgets/toolpalette.py @@ -13,14 +13,9 @@ import sys -if 'PySide' in sys.modules.copy(): - from PySide.QtCore import * - from PySide.QtGui import * -else: - from PyQt4.QtCore import * - from PyQt4.QtGui import * - -import qtutils.icons +from qtutils.qt.QtCore import * +from qtutils.qt.QtGui import * +from qtutils.qt.QtWidgets import * EXPAND_ICON = ':/qtutils/fugue/toggle-small-expand' CONTRACT_ICON = ':/qtutils/fugue/toggle-small' diff --git a/settings.py b/settings.py index 67eb231..d84ad32 100644 --- a/settings.py +++ b/settings.py @@ -10,17 +10,16 @@ # for the full license. # # # ##################################################################### +try: + from labscript_utils import check_version +except ImportError: + raise ImportError('Require labscript_utils > 2.1.0') -import os -import sys -if 'PySide' in sys.modules.copy(): - import PySide # This is done so that we can eval() constants from the PySide module (eg column ASC/DESC sort order) - from PySide.QtCore import * - from PySide.QtGui import * -else: - import PyQt4 - from PyQt4.QtCore import * - from PyQt4.QtGui import * +check_version('qtutils', '2.0.0', '3.0.0') + +from qtutils.qt.QtCore import * +from qtutils.qt.QtGui import * +from qtutils.qt.QtWidgets import * import h5_lock, h5py from labscript_utils.qtwidgets.fingertab import FingerTabWidget