Skip to content

Commit

Permalink
Correct QtGui/QtWidgets namespace for GUI components
Browse files Browse the repository at this point in the history
This is related to the Pyside->PySide2 transition but previously
we were relying on pyqtgraph monkey-patching the PySide libraries
to avoid the need to update. Now this is gone in pyqtgraph 0.12
we need to actually fix it here
  • Loading branch information
mcraig-ibme committed Sep 9, 2021
1 parent 17cf960 commit aacbf05
Show file tree
Hide file tree
Showing 33 changed files with 585 additions and 585 deletions.
32 changes: 16 additions & 16 deletions examples/example-plugin/ExampleWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ def __init__(self, **kwargs):
group="Examples", **kwargs)

def init_ui(self):
layout = QtGui.QVBoxLayout()
layout = QtWidgets.QVBoxLayout()
self.setLayout(layout)

hbox = QtGui.QHBoxLayout()
hbox.addWidget(QtGui.QLabel('<font size="5">Example Plugin Widget</font>'))
hbox = QtWidgets.QHBoxLayout()
hbox.addWidget(QtWidgets.QLabel('<font size="5">Example Plugin Widget</font>'))
hbox.addStretch(1)
hbox.addWidget(BatchButton(self))
hbox.addWidget(HelpButton(self, "example_plugin"))
layout.addLayout(hbox)

desc = QtGui.QLabel(DESC)
desc = QtWidgets.QLabel(DESC)
desc.setWordWrap(True)
layout.addWidget(desc)
layout.addWidget(QtGui.QLabel(""))
layout.addWidget(QtWidgets.QLabel(""))

def activate(self):
self.ivm.sig_all_data.connect(self.data_changed)
Expand All @@ -64,37 +64,37 @@ def __init__(self, **kwargs):
super(ExampleWidget, self).__init__(name="Threshold", desc="Threshold data", icon="quantiphyse", **kwargs)

def init_ui(self):
main_vbox = QtGui.QVBoxLayout()
main_vbox = QtWidgets.QVBoxLayout()

hbox = QtGui.QHBoxLayout()
hbox.addWidget(QtGui.QLabel('<font size="5">Threshold volume</font>'))
hbox = QtWidgets.QHBoxLayout()
hbox.addWidget(QtWidgets.QLabel('<font size="5">Threshold volume</font>'))
hbox.addStretch(1)
hbox.addWidget(HelpButton(self))
main_vbox.addLayout(hbox)

explanation = QtGui.QLabel('This is a basic example of a \n'
explanation = QtWidgets.QLabel('This is a basic example of a \n'
'widget for development purposes. \n'
'A DCE-MRI image and ROI are \n'
'loaded normally and clicking run \n'
'creates a data set which only shows values \n'
'in the ROI above a defined threshold.')
main_vbox.addWidget(explanation)

hbox = QtGui.QHBoxLayout()
self.b1 = QtGui.QPushButton('Process', self)
hbox = QtWidgets.QHBoxLayout()
self.b1 = QtWidgets.QPushButton('Process', self)
self.b1.clicked.connect(self.run_threshold)
hbox.addWidget(self.b1)
hbox.addStretch(1)

hbox.addWidget(QtGui.QLabel('ROI threshold value:'))
self.val_t1 = QtGui.QLineEdit('1', self)
hbox.addWidget(QtWidgets.QLabel('ROI threshold value:'))
self.val_t1 = QtWidgets.QLineEdit('1', self)
hbox.addWidget(self.val_t1)
main_vbox.addLayout(hbox)

hbox = QtGui.QHBoxLayout()
hbox = QtWidgets.QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(QtGui.QLabel('Slice to threshold:'))
self.val_s1 = QtGui.QLineEdit('0', self)
hbox.addWidget(QtWidgets.QLabel('Slice to threshold:'))
self.val_s1 = QtWidgets.QLineEdit('0', self)
hbox.addWidget(self.val_s1)
main_vbox.addLayout(hbox)

Expand Down
62 changes: 31 additions & 31 deletions quantiphyse/gui/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def error_dialog(msg, title="Warning", detail=None, subtitle="Details:"):
detail_str = detail_str.replace(os.linesep, "<br>")
text += "<br><br><b>%s</b><br><br>%s" % (subtitle, detail_str)

QtGui.QMessageBox.warning(MAINWIN, title, text, QtGui.QMessageBox.Close)
QtWidgets.QMessageBox.warning(MAINWIN, title, text, QtWidgets.QMessageBox.Close)

class MultiTextViewerDialog(QtGui.QDialog):
class MultiTextViewerDialog(QtWidgets.QDialog):
"""
Text viewer dialog with multiple pages presented as tabs
Expand All @@ -58,9 +58,9 @@ class MultiTextViewerDialog(QtGui.QDialog):
def __init__(self, parent, title="Log", pages=()):
super(MultiTextViewerDialog, self).__init__(parent)
self.setWindowTitle(title)
vbox = QtGui.QVBoxLayout()
vbox = QtWidgets.QVBoxLayout()

self.tabs = QtGui.QTabWidget()
self.tabs = QtWidgets.QTabWidget()
self._browsers = {}
for heading, content in pages:
browser = self._text_browser(content)
Expand All @@ -69,12 +69,12 @@ def __init__(self, parent, title="Log", pages=()):

vbox.addWidget(self.tabs)

hbox = QtGui.QHBoxLayout()
self.copy_btn = QtGui.QPushButton("Copy")
hbox = QtWidgets.QHBoxLayout()
self.copy_btn = QtWidgets.QPushButton("Copy")
self.copy_btn.clicked.connect(self._copy)
hbox.addWidget(self.copy_btn)
hbox.addStretch(1)
self.button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
self.button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok)
self.button_box.accepted.connect(self.close)
hbox.addWidget(self.button_box)
vbox.addLayout(hbox)
Expand All @@ -100,13 +100,13 @@ def setText(self, heading, content):
scrollbar.setValue(original_pos)

def _text_browser(self, content):
browser = QtGui.QTextBrowser()
browser = QtWidgets.QTextBrowser()
browser.setFontFamily("Courier")
browser.setText(content)
return browser

def _copy(self):
clipboard = QtGui.QApplication.clipboard()
clipboard = QtWidgets.QApplication.clipboard()
clipboard.setText(self.tabs.currentWidget().toPlainText())

class TextViewerDialog(MultiTextViewerDialog):
Expand All @@ -126,63 +126,63 @@ def text(self):
def text(self, newtext):
self.setText("", newtext)

class MatrixViewerDialog(QtGui.QDialog):
class MatrixViewerDialog(QtWidgets.QDialog):
"""
Dialog box enabling a read-only viewing of a number matrix
"""

def __init__(self, parent, vals, title="Data", text=""):
super(MatrixViewerDialog, self).__init__(parent)
self.setWindowTitle(title)
vbox = QtGui.QVBoxLayout()
vbox = QtWidgets.QVBoxLayout()

self.table = QtGui.QTableWidget(len(vals), len(vals[0]))
self.table = QtWidgets.QTableWidget(len(vals), len(vals[0]))
vbox.addWidget(self.table)
for row, rvals in enumerate(vals):
for col, val in enumerate(rvals):
self.table.setItem(row, col, QtGui.QTableWidgetItem(str(val)))
self.table.setItem(row, col, QtWidgets.QTableWidgetItem(str(val)))

self.text = QtGui.QLabel(text)
self.text = QtWidgets.QLabel(text)
vbox.addWidget(self.text)

self.button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
self.button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.reject)
vbox.addWidget(self.button_box)

self.setLayout(vbox)
self.resize(500, 500)

class GridEditDialog(QtGui.QDialog):
class GridEditDialog(QtWidgets.QDialog):
"""
Dialog box enabling a numerical matrix to be edited
"""

def __init__(self, parent, vals, col_headers=None, row_headers=None, title="Data", text="", expandable=(True, True)):
super(GridEditDialog, self).__init__(parent)
self.setWindowTitle(title)
vbox = QtGui.QVBoxLayout()
vbox = QtWidgets.QVBoxLayout()

from .widgets import NumberGrid # prevent circular import dependency
self.table = NumberGrid(vals, col_headers=col_headers, row_headers=row_headers, expandable=expandable)
self.table.sig_changed.connect(self._validate)
vbox.addWidget(self.table)

self.text = QtGui.QLabel(text)
self.text = QtWidgets.QLabel(text)
vbox.addWidget(self.text)

self.button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
self.button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.reject)
self.button_box.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
self.button_box.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
vbox.addWidget(self.button_box)

self.setLayout(vbox)

def _validate(self):
self.button_box.button(QtGui.QDialogButtonBox.Ok).setEnabled(self.table.valid())
self.button_box.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(self.table.valid())

class ChooseFromListDialog(QtGui.QDialog):
class ChooseFromListDialog(QtWidgets.QDialog):
"""
Dialog box enabling one item to be chosen from a list
"""
Expand All @@ -193,50 +193,50 @@ def __init__(self, parent, values, return_values=None, title="Choose"):
self.sel_data = None

self.setWindowTitle(title)
vbox = QtGui.QVBoxLayout()
vbox = QtWidgets.QVBoxLayout()

if return_values is None:
return_values = values
self._list = QtGui.QListWidget(self)
self._list = QtWidgets.QListWidget(self)
for value, data in zip(values, return_values):
item = QtGui.QListWidgetItem(value)
item = QtWidgets.QListWidgetItem(value)
item.setData(QtCore.Qt.UserRole, data)
self._list.addItem(item)

vbox.addWidget(self._list)
self._list.itemClicked.connect(self._item_clicked)
self._list.itemDoubleClicked.connect(self._item_double_clicked)

self.button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
self.button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.reject)
self.button_box.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
self.button_box.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
vbox.addWidget(self.button_box)

self.setLayout(vbox)

def _item_clicked(self, item):
self.sel_text = item.text()
self.sel_data = item.data(QtCore.Qt.UserRole)
self.button_box.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
self.button_box.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(True)

def _item_double_clicked(self, item):
self._item_clicked(item)
self.accept()

class PlotDialog1d(QtGui.QDialog):
class PlotDialog1d(QtWidgets.QDialog):
"""
Dialog that shows a 1D plot
"""

def __init__(self, parent, arr, title="Plot"):
QtGui.QDialog.__init__(self, parent)
QtWidgets.QDialog.__init__(self, parent)

if arr.ndim != 1:
raise ValueError("Only for 1D plotting")

self.setWindowTitle(title)
vbox = QtGui.QVBoxLayout()
vbox = QtWidgets.QVBoxLayout()
self.setLayout(vbox)

from quantiphyse.gui.plot import Plot
Expand Down

0 comments on commit aacbf05

Please sign in to comment.