Skip to content

Commit

Permalink
Merged in PhyNerd/Qt5 (Pull request labscript-suite#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjbillington committed Aug 15, 2017
2 parents 5b93953 + b12e69c commit d94c041
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 98 deletions.
6 changes: 6 additions & 0 deletions qtwidgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
11 changes: 4 additions & 7 deletions qtwidgets/analogoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -274,4 +271,4 @@ def unlock(self,notify_ao=True):


sys.exit(qapplication.exec_())


13 changes: 5 additions & 8 deletions qtwidgets/ddsoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -134,4 +131,4 @@ def show_sub_widget(self,subchnl):


sys.exit(qapplication.exec_())


12 changes: 5 additions & 7 deletions qtwidgets/digitaloutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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())
Expand Down
14 changes: 5 additions & 9 deletions qtwidgets/dragdroptab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 4 additions & 6 deletions qtwidgets/elide_label.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down
44 changes: 21 additions & 23 deletions qtwidgets/fingertab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
QtWidgets.QTabWidget.__init__(self, parent, *args)
self.setTabBar(FingerTabBarWidget(self))
22 changes: 11 additions & 11 deletions qtwidgets/headerview_with_widgets.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -32,15 +32,15 @@ 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)
self.geometriesChanged.connect(self.update_widget_positions)
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 = ''
Expand All @@ -51,27 +51,27 @@ 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

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)
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand Down
15 changes: 6 additions & 9 deletions qtwidgets/imageoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions qtwidgets/toolpalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
19 changes: 9 additions & 10 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d94c041

Please sign in to comment.