From 6b772d18b85221f45559473b508df2e0ac760e54 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 17 May 2018 15:53:40 +0200 Subject: [PATCH] Fixes to qt5 port of viewer app --- .../ifcopenshell/geom/app.py | 19 ++++++++-------- .../ifcopenshell/geom/code_editor_pane.py | 22 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/geom/app.py b/src/ifcopenshell-python/ifcopenshell/geom/app.py index 7a8d2c8771..9fcd3191a0 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/app.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/app.py @@ -49,13 +49,11 @@ from .main import settings, iterator from .occ_utils import display_shape from .. import open as open_ifc_file -from .. import get_supertype - -# Depending on Python version and what not there may or may not be a QString -try: -except ImportError: - QString = str +from .. import version as ifcopenshell_version +if ifcopenshell_version < "0.6": + # not yet ported + from .. import get_supertype class configuration(object): def __init__(self): @@ -158,7 +156,7 @@ class application(QtWidgets.QApplication): elif action in displaymode: self.instanceDisplayModeChanged.emit(inst, displaymode.index(action)) - def clicked(self, index): + def clicked_(self, index): inst = index.data(QtCore.Qt.UserRole) if hasattr(inst, 'toPyObject'): inst = inst @@ -215,7 +213,7 @@ class application(QtWidgets.QApplication): itm.setData(0, QtCore.Qt.UserRole, product) self.children[parent].append(product) self.product_to_item = dict(zip(items.keys(), map(self.indexFromItem, items.values()))) - self.clicked[QModelIndex].connect(self.clicked) + self.clicked.connect(self.clicked_) self.expandAll() class type_treeview(abstract_treeview): @@ -239,7 +237,8 @@ class application(QtWidgets.QApplication): itm.setData(0, QtCore.Qt.UserRole, t2) self.children[s2].append(t2) - add(t) + if ifcopenshell_version < "0.6": + add(t) for p in products: t = QString(p.is_a()) @@ -248,7 +247,7 @@ class application(QtWidgets.QApplication): self.children[t].append(p) self.product_to_item = dict(zip(items.keys(), map(self.indexFromItem, items.values()))) - self.clicked[QModelIndex].connect(self.clicked) + self.clicked.connect(self.clicked) self.expandAll() class property_table(QtWidgets.QWidget): diff --git a/src/ifcopenshell-python/ifcopenshell/geom/code_editor_pane.py b/src/ifcopenshell-python/ifcopenshell/geom/code_editor_pane.py index e4306cd1a7..760f36b76f 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/code_editor_pane.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/code_editor_pane.py @@ -7,10 +7,10 @@ import sys import logging from code import InteractiveConsole -from PyQt4 import QtCore, QtGui +from PyQt5 import QtCore, QtGui, QtWidgets try: - from PyQt4 import QtWidgets + from PyQt5 import QtWidgets except BaseException: QtWidgets = QtGui @@ -48,7 +48,7 @@ class StdoutRedirector(object): self.widget.moveCursor(QtGui.QTextCursor.End) -class code_edit(QtGui.QWidget): +class code_edit(QtWidgets.QWidget): class Console(InteractiveConsole): def __init__(*args): InteractiveConsole.__init__(*args) @@ -73,18 +73,15 @@ class code_edit(QtGui.QWidget): self.c = self.Console({'model': self.model, 'viewer': self.viewer, 'selection': product}) def __init__(self, viewer, snippets=None): - self.model = None self.viewer = viewer - QtGui.QWidget.__init__(self) - self.layout = QtGui.QVBoxLayout(self) + QtWidgets.QWidget.__init__(self) + self.layout = QtWidgets.QVBoxLayout(self) self.setLayout(self.layout) self.c = None - - self.tools = QtGui.QHBoxLayout(self) + self.tools = QtWidgets.QHBoxLayout(self) self.layout.addLayout(self.tools) - - self.runbutton = QtGui.QPushButton("Run") + self.runbutton = QtWidgets.QPushButton("Run") width = self.runbutton.fontMetrics().boundingRect("Run").width() + 20 self.runbutton.setMaximumWidth(width) self.tools.addWidget(self.runbutton) @@ -129,11 +126,10 @@ class code_edit(QtGui.QWidget): for snip_name in self.snippets.keys(): self.list.addItem(snip_name) self.tools.addWidget(self.list) - QtCore.QObject.connect(self.list, QtCore.SIGNAL("currentIndexChanged(int)"), self.replace_snippet) + self.list.currentIndexChanged[int].connect(self.replace_snippet) self.layout.addWidget(self.editor) - - self.output = QtGui.QTextEdit() + self.output = QtWidgets.QTextEdit() self.output.setReadOnly(True) self.output.setStyleSheet('font-size: 10pt; font-family: Consolas, Courier; background-color: #444;') self.layout.addWidget(self.output)