Commit 97fea3b9 authored by Michael Büsch's avatar Michael Büsch

gui: Add support for PySide2 and remove support for Qt4

This removes support for PySide1 and PyQt4.
Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent facc3cfa
......@@ -974,10 +974,7 @@ class FupDrawWidget(QWidget):
def wheelEvent(self, ev):
if ev.modifiers() & Qt.ControlModifier:
# Ctrl + Scroll-wheel: Zoom
if isQt4:
numDegrees = ev.delta() / 8
else:
numDegrees = ev.angleDelta().y() / 8
numDegrees = ev.angleDelta().y() / 8
numSteps = numDegrees / 15
self.__wheelSteps += numSteps
......@@ -998,8 +995,8 @@ class FupDrawWidget(QWidget):
self.removeElems()
event.accept()
return
elif isQt5 and (event.matches(QKeySequence.Cancel) or\
event.matches(QKeySequence.Deselect)):
elif (event.matches(QKeySequence.Cancel) or
event.matches(QKeySequence.Deselect)):
self.__grid.deselectAllElems()
self.__selectionChanged()
self.repaint()
......@@ -1121,8 +1118,7 @@ class FupDrawWidget(QWidget):
if not mime.hasFormat("application/x-awlsim-xml-fup-elem"):
return ignore()
mimeData = mime.data("application/x-awlsim-xml-fup-elem")
if isQt4:
mimeData = mimeData.data() # QByteArray to bytes/str
mimeData = mimeData.data() # QByteArray to bytes/str
mimeData = bytearray(mimeData)
if not mimeData:
return ignore()
......
......@@ -35,10 +35,7 @@ class AwlInterfaceView(QTableView):
def __init__(self, parent=None):
QTableView.__init__(self, parent)
if isQt4:
self.verticalHeader().setMovable(True)
else:
self.verticalHeader().setSectionsMovable(True)
self.verticalHeader().setSectionsMovable(True)
self.verticalHeader().setDefaultSectionSize(20)
self.verticalHeader().sectionMoved.connect(self.__rowMoved)
......
......@@ -242,10 +242,7 @@ class LibTableView(QTableView):
model = LibTableModel()
self.setModel(model)
if isQt4:
self.verticalHeader().setMovable(True)
else:
self.verticalHeader().setSectionsMovable(True)
self.verticalHeader().setSectionsMovable(True)
self.verticalHeader().sectionMoved.connect(self.__rowMoved)
self.pressed.connect(self.__handleMousePress)
......
......@@ -263,11 +263,7 @@ class MainWidget(QWidget):
return True
def load(self):
if isPyQt and isQt4:
getOpenFileName = QFileDialog.getOpenFileNameAndFilter
else:
getOpenFileName = QFileDialog.getOpenFileName
fn, fil = getOpenFileName(self,
fn, fil = QFileDialog.getOpenFileName(self,
"Open project", "",
"Awlsim project or AWL/STL source (*.awlpro *.awl);;"
"Awlsim project (*.awlpro);;"
......@@ -295,11 +291,7 @@ class MainWidget(QWidget):
def save(self, newFile=False):
if newFile or not self.filename:
if isPyQt and isQt4:
getSaveFileName = QFileDialog.getSaveFileNameAndFilter
else:
getSaveFileName = QFileDialog.getSaveFileName
fn, fil = getSaveFileName(self,
fn, fil = QFileDialog.getSaveFileName(self,
"Awlsim project save as", "",
"Awlsim project (*.awlpro)",
"*.awlpro")
......
......@@ -2,7 +2,7 @@
#
# AWL simulator - QT bindings wrapper
#
# Copyright 2015-2017 Michael Buesch <m@bues.ch>
# Copyright 2015-2018 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -31,7 +31,11 @@ import os
def __frameworkError(msg):
printError("awlsim-gui ERROR: " + msg)
input("Press enter to exit.")
try:
if osIsWindows:
input("Press enter to exit.")
except (KeyboardInterrupt, Exception) as e:
pass
sys.exit(1)
def __testQStringAPI(scope, silent=False):
......@@ -42,33 +46,26 @@ def __testQStringAPI(scope, silent=False):
return False
__frameworkError("Deprecated QString API detected.\n"
"Awlsim does not support PyQt QString v1 API.\n"
"---> Please use PySide or a newer PyQt with v2 APIs. <---")
"---> Please use PySide2 or a newer PyQt5. <---")
return True
def __autodetectGuiFramework():
urls = {
"pyside" : "http://www.pyside.org/",
"pyqt4" : "http://www.riverbankcomputing.com/software/pyqt/download",
"pyqt5" : "http://www.riverbankcomputing.com/software/pyqt/download5",
"pyqt" : "http://www.riverbankcomputing.com/software/pyqt/download5",
}
with contextlib.suppress(ImportError):
import PyQt5.QtCore as __pyQtCore
if __testQStringAPI(dir(__pyQtCore), True):
return "pyqt5"
with contextlib.suppress(ImportError):
import PySide.QtCore as __pySideCore
return "pyside4"
with contextlib.suppress(ImportError):
import PyQt4.QtCore as __pyQtCore
if __testQStringAPI(dir(__pyQtCore), True):
return "pyqt4"
import PySide2.QtCore as __pySideCore
return "pyside2"
__frameworkError("Neither PySide nor PyQt found.\n"
"PLEASE INSTALL PySide (%s)\n"
" or PyQt4 with v2 APIs (%s)\n"
" or PyQt5 with v2 APIs (%s)" %\
"PLEASE INSTALL PySide2 (%s)\n"
" or PyQt5 (%s)" %\
(urls["pyside"],
urls["pyqt4"],
urls["pyqt5"]))
urls["pyqt"]))
# The Qt bindings can be set via AWLSIM_GUI environment variable.
__guiFramework = AwlSimEnv.getGuiFramework()
......@@ -77,24 +74,18 @@ __guiFramework = AwlSimEnv.getGuiFramework()
if __guiFramework == "auto":
__guiFramework = __autodetectGuiFramework()
if __guiFramework == "pyside":
__guiFramework = "pyside4"
__guiFramework = "pyside2"
if __guiFramework == "pyqt":
__guiFramework = "pyqt5"
# Load the Qt modules
if __guiFramework == "pyside4":
try:
from PySide.QtCore import *
from PySide.QtGui import *
except ImportError as e:
__frameworkError("Failed to import PySide modules:\n" + str(e))
elif __guiFramework == "pyqt4":
if __guiFramework == "pyside2":
try:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
except ImportError as e:
__frameworkError("Failed to import PyQt4 modules:\n" + str(e))
__testQStringAPI(globals())
__frameworkError("Failed to import PySide2 modules:\n" + str(e))
elif __guiFramework == "pyqt5":
try:
from PyQt5.QtCore import *
......@@ -104,26 +95,16 @@ elif __guiFramework == "pyqt5":
__frameworkError("Failed to import PyQt5 modules:\n" + str(e))
__testQStringAPI(globals())
else:
__frameworkError("Unknown GUI framework '%s' requested. "
"Please fix AWLSIM_GUI environment variable." %\
__frameworkError("Unknown GUI framework '%s' requested.\n"
"Please fix the AWLSIM_GUI environment variable." %\
__guiFramework)
def getGuiFrameworkName():
return __guiFramework
# Helpers for distinction between Qt4 and Qt5 API.
isQt4 = (__guiFramework == "pyside4" or\
__guiFramework == "pyqt4")
isQt5 = (__guiFramework == "pyqt5")
# Helpers for distinction between PySide and PyQt API.
isPySide = __guiFramework.startswith("pyside")
isPyQt = __guiFramework.startswith("pyqt")
if isQt4:
# Compatibility
QGuiApplication = QApplication
if isPyQt:
# Compatibility
Signal = pyqtSignal
......@@ -240,10 +240,7 @@ class SourceCodeEdit(QPlainTextEdit):
def wheelEvent(self, ev):
if ev.modifiers() & Qt.ControlModifier:
# Ctrl + Scroll-wheel: Font resizing
if isQt4:
numDegrees = ev.delta() / 8
else:
numDegrees = ev.angleDelta().y() / 8
numDegrees = ev.angleDelta().y() / 8
numSteps = numDegrees / 15
self.__wheelSteps += numSteps
if self.__wheelSteps >= 1.0:
......
......@@ -198,10 +198,7 @@ class SymTabView(QTableView):
def __init__(self, parent=None):
QTableView.__init__(self, parent)
if isQt4:
self.verticalHeader().setMovable(True)
else:
self.verticalHeader().setSectionsMovable(True)
self.verticalHeader().setSectionsMovable(True)
self.verticalHeader().sectionMoved.connect(self.__rowMoved)
self.pressed.connect(self.__handleMousePress)
......
......@@ -14,5 +14,7 @@ exec apt install \
python3-dev \
python3-nose \
python3-pyqt5 \
python3-pyside \
python3-pyside2.qtcore \
python3-pyside2.qtgui \
python3-pyside2.qtwidgets \
python3-serial
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment