Skip to content

Commit

Permalink
Check for Qt version instead of python version where appropriate
Browse files Browse the repository at this point in the history
Previously there was an implicit assumption that Python2 comes with Qt4,
while Python 3 comes with Qt5. This is not necessarily true.
Now we explicitly check the Qt version when we need different code for
different Qt versions
  • Loading branch information
andreabrambilla authored and Andrea Brambilla committed Oct 18, 2019
1 parent cc351d0 commit 872e625
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
7 changes: 3 additions & 4 deletions ert_gui/main_window.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import functools
import os
import pkg_resources
import sys
import webbrowser
import yaml

from ErtQt.Qt import QSettings, Qt, QMainWindow, qApp, QWidget, QVBoxLayout, QDockWidget, QAction, QToolButton
from ErtQt import QT5

from ert_gui.about_dialog import AboutDialog

Expand Down Expand Up @@ -105,14 +105,13 @@ def closeEvent(self, event):


def __fetchSettings(self):
py3 = sys.version_info[0] == 3
settings = QSettings("Equinor", "Ert-Gui")
geo = settings.value("geometry")
if geo:
self.restoreGeometry(geo if py3 else geo.toByteArray())
self.restoreGeometry(geo if QT5 else geo.toByteArray())
wnd = settings.value("windowState")
if wnd:
self.restoreState (wnd if py3 else wnd.toByteArray())
self.restoreState (wnd if QT5 else wnd.toByteArray())


def setWidget(self, widget):
Expand Down
8 changes: 3 additions & 5 deletions ert_gui/tools/plot/style_chooser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import sys

try:
from PyQt4.QtGui import QWidget, QHBoxLayout, QComboBox, QDoubleSpinBox, QLabel, QHBoxLayout
except ImportError:
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QComboBox, QDoubleSpinBox, QLabel, QHBoxLayout
from ErtQt.Qt import QWidget, QHBoxLayout, QComboBox, QDoubleSpinBox, QLabel, QHBoxLayout

from ert_gui.plottery import PlotStyle

Expand Down Expand Up @@ -136,7 +133,8 @@ def _updateStyle(self):
thickness = float(self.thickness_spinner.value())
size = float(self.size_spinner.value())

if sys.version_info[0] == 2:
from ErtQt import QT4
if QT4:
self._style.line_style = str(line_style.toString())
self._style.marker = str(marker_style.toString())
else:
Expand Down
20 changes: 11 additions & 9 deletions ert_gui/tools/plot/widgets/clearable_line_edit.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import sys

try:
from PyQt4.QtCore import QString, QSize, Qt
from PyQt4.QtGui import QPushButton, QColor, QLineEdit, QStyle
except ImportError:
from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QPushButton, QLineEdit, QStyle
from PyQt5.QtGui import QColor

from ErtQt.Qt import (
QColor,
QLineEdit,
QPushButton,
QSize,
QStyle,
Qt,
)

from ert_gui.ertwidgets import resourceIcon

Expand Down Expand Up @@ -100,7 +100,9 @@ def setText(self, string):

def text(self):
if self._placeholder_active:
if sys.version_info[0] == 2:
from ErtQt import QT4
if QT4:
from ErtQt.Qt import QString
return QString("")
else:
return ""
Expand Down

0 comments on commit 872e625

Please sign in to comment.