GUI fixes
- do not show command result dialog when result is None - apply fmtstr, if available + fix io import in secop.core + change old style <basecls>.__init__(self, ...) calls to super().__init__(...) Change-Id: I599d5d8e8ff430ea9454a0858d703290e87454fc Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/26397 Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de> Reviewed-by: Jens Krueger <jens.krueger@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
parent
bc6a99e11b
commit
f3978385b4
@ -36,4 +36,4 @@ from secop.params import Command, Parameter
|
||||
from secop.poller import AUTO, DYNAMIC, REGULAR, SLOW
|
||||
from secop.properties import Property
|
||||
from secop.proxy import Proxy, SecNode, proxy_class
|
||||
from secop.stringio import HasIodev, StringIO
|
||||
from secop.io import HasIodev, StringIO, BytesIO
|
||||
|
@ -1080,7 +1080,7 @@ UInt64 = IntRange(0, (1 << 64) - 1)
|
||||
# Goodie: Convenience Datatypes for Programming
|
||||
class LimitsType(TupleOf):
|
||||
def __init__(self, members):
|
||||
TupleOf.__init__(self, members, members)
|
||||
super().__init__(members, members)
|
||||
|
||||
def __call__(self, value):
|
||||
limits = TupleOf.__call__(self, value)
|
||||
@ -1092,7 +1092,7 @@ class LimitsType(TupleOf):
|
||||
class StatusType(TupleOf):
|
||||
# shorten initialisation and allow access to status enumMembers from status values
|
||||
def __init__(self, enum):
|
||||
TupleOf.__init__(self, EnumType(enum), StringType())
|
||||
super().__init__(EnumType(enum), StringType())
|
||||
self._enum = enum
|
||||
|
||||
def __getattr__(self, key):
|
||||
|
@ -25,7 +25,7 @@
|
||||
class SECoPError(RuntimeError):
|
||||
|
||||
def __init__(self, *args, **kwds):
|
||||
RuntimeError.__init__(self)
|
||||
super().__init__()
|
||||
self.args = args
|
||||
for k, v in list(kwds.items()):
|
||||
setattr(self, k, v)
|
||||
|
@ -39,7 +39,7 @@ COMMENT = 'comment'
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
def __init__(self, file_path=None, parent=None):
|
||||
QMainWindow.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
loadUi(self, 'mainwindow.ui')
|
||||
self.tabWidget.currentChanged.connect(self.tab_relevant_btns_disable)
|
||||
if file_path is None:
|
||||
|
@ -26,7 +26,7 @@ from secop.gui.qt import QHBoxLayout, QSizePolicy, QSpacerItem, Qt, QWidget
|
||||
|
||||
class NodeDisplay(QWidget):
|
||||
def __init__(self, file_path=None, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
loadUi(self, 'node_display.ui')
|
||||
self.saved = bool(file_path)
|
||||
self.created = self.tree_widget.set_file(file_path)
|
||||
|
@ -44,7 +44,7 @@ class TreeWidgetItem(QTreeWidgetItem):
|
||||
the datatype passed onto ValueWidget should be on of secop.datatypes"""
|
||||
# TODO: like stated in docstring the datatype for parameters and
|
||||
# properties must be found out through their object
|
||||
QTreeWidgetItem.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
self.kind = kind
|
||||
self.name = name
|
||||
self.class_object = class_object
|
||||
@ -129,7 +129,7 @@ class ValueWidget(QWidget):
|
||||
|
||||
def __init__(self, name='', value='', datatype=None, kind='', parent=None):
|
||||
# TODO: implement: change module/interface class
|
||||
QWidget.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
self.datatype = datatype
|
||||
self.layout = QVBoxLayout()
|
||||
self.name_label = QLabel(name)
|
||||
@ -205,7 +205,7 @@ class ValueWidget(QWidget):
|
||||
|
||||
class ChangeNameDialog(QDialog):
|
||||
def __init__(self, current_name='', invalid_names=None, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
loadUi(self, 'change_name_dialog.ui')
|
||||
self.invalid_names = invalid_names
|
||||
self.name.setText(current_name)
|
||||
|
@ -31,7 +31,7 @@ from secop.gui.cfg_editor.utils import get_all_items, \
|
||||
get_props, loadUi, set_name_edit_style, setActionIcon
|
||||
from secop.gui.qt import QComboBox, QDialog, QDialogButtonBox, QLabel, \
|
||||
QLineEdit, QMenu, QPoint, QSize, QStandardItem, QStandardItemModel, \
|
||||
Qt, QTabBar, QTextEdit, QTreeView, QTreeWidget, QWidget, pyqtSignal
|
||||
Qt, QTabBar, QTextEdit, QTreeView, QTreeWidget, pyqtSignal
|
||||
|
||||
NODE = 'node'
|
||||
MODULE = 'module'
|
||||
@ -47,7 +47,7 @@ class TreeWidget(QTreeWidget):
|
||||
add_canceled = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QTreeWidget.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
self.file_path = None
|
||||
self.setIconSize(QSize(24, 24))
|
||||
self.setSelectionMode(QTreeWidget.SingleSelection)
|
||||
@ -335,7 +335,7 @@ class AddDialog(QDialog):
|
||||
"""Notes:
|
||||
self.get_value: is mapped to the specific method for getting
|
||||
the value from self.value"""
|
||||
QWidget.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
loadUi(self, 'add_dialog.ui')
|
||||
self.setWindowTitle('add %s' % kind)
|
||||
self.kind = kind
|
||||
@ -402,7 +402,7 @@ class AddDialog(QDialog):
|
||||
|
||||
class TabBar(QTabBar):
|
||||
def __init__(self, parent=None):
|
||||
QTabBar.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.context_pos = QPoint(0, 0)
|
||||
self.menu = QMenu()
|
||||
@ -436,7 +436,7 @@ class TabBar(QTabBar):
|
||||
|
||||
class TreeComboBox(QComboBox):
|
||||
def __init__(self, value_dict, parent=None):
|
||||
QComboBox.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
self.tree_view = QTreeView()
|
||||
self.tree_view.setHeaderHidden(True)
|
||||
self.tree_view.expanded.connect(self.resize_length)
|
||||
|
@ -44,7 +44,7 @@ class QSECNode(QObject):
|
||||
logEntry = pyqtSignal(str)
|
||||
|
||||
def __init__(self, uri, parent=None):
|
||||
QObject.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
self.conn = conn = secop.client.SecopClient(uri)
|
||||
conn.validate_data = True
|
||||
self.log = conn.log
|
||||
@ -83,10 +83,7 @@ class QSECNode(QObject):
|
||||
return self.conn.getParameter(module, parameter, True)
|
||||
|
||||
def execCommand(self, module, command, argument):
|
||||
try:
|
||||
return self.conn.execCommand(module, command, argument)
|
||||
except Exception as e:
|
||||
return 'ERROR: %r' % e, {}
|
||||
return self.conn.execCommand(module, command, argument)
|
||||
|
||||
def queryCache(self, module):
|
||||
return {k: Value(*self.conn.cache[(module, k)])
|
||||
@ -115,7 +112,7 @@ class QSECNode(QObject):
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self, hosts, parent=None):
|
||||
super(MainWindow, self).__init__(parent)
|
||||
super().__init__(parent)
|
||||
|
||||
loadUi(self, 'mainwindow.ui')
|
||||
|
||||
|
@ -160,7 +160,7 @@ class MiniPlotFitCurve(MiniPlotCurve):
|
||||
return float('-inf')
|
||||
|
||||
def __init__(self, formula, params):
|
||||
super(MiniPlotFitCurve, self).__init__()
|
||||
super().__init__()
|
||||
self.formula = formula
|
||||
self.params = params
|
||||
|
||||
@ -193,7 +193,7 @@ class MiniPlot(QWidget):
|
||||
autoticky = True
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
super().__init__(parent)
|
||||
self.xmin = self.xmax = None
|
||||
self.ymin = self.ymax = None
|
||||
self.curves = []
|
||||
|
@ -32,7 +32,7 @@ from secop.gui.valuewidgets import get_widget
|
||||
|
||||
class CommandDialog(QDialog):
|
||||
def __init__(self, cmdname, argument, parent=None):
|
||||
super(CommandDialog, self).__init__(parent)
|
||||
super().__init__(parent)
|
||||
loadUi(self, 'cmddialog.ui')
|
||||
|
||||
self.setWindowTitle('Arguments for %s' % cmdname)
|
||||
@ -58,7 +58,7 @@ class CommandDialog(QDialog):
|
||||
return True, self.widgets[0].get_value()
|
||||
|
||||
def exec_(self):
|
||||
if super(CommandDialog, self).exec_():
|
||||
if super().exec_():
|
||||
return self.get_value()
|
||||
return None
|
||||
|
||||
@ -71,16 +71,17 @@ def showCommandResultDialog(command, args, result, extras=''):
|
||||
m.exec_()
|
||||
|
||||
|
||||
def showErrorDialog(error):
|
||||
def showErrorDialog(command, args, error):
|
||||
m = QMessageBox()
|
||||
m.setText('Error %r' % error)
|
||||
args = '' if args is None else repr(args)
|
||||
m.setText('calling: %s(%s)\nraised %r' % (command, args, error))
|
||||
m.exec_()
|
||||
|
||||
|
||||
class ParameterGroup(QWidget):
|
||||
|
||||
def __init__(self, groupname, parent=None):
|
||||
super(ParameterGroup, self).__init__(parent)
|
||||
super().__init__(parent)
|
||||
loadUi(self, 'paramgroup.ui')
|
||||
|
||||
self._groupname = groupname
|
||||
@ -112,7 +113,7 @@ class ParameterGroup(QWidget):
|
||||
class CommandButton(QPushButton):
|
||||
|
||||
def __init__(self, cmdname, cmdinfo, cb, parent=None):
|
||||
super(CommandButton, self).__init__(parent)
|
||||
super().__init__(parent)
|
||||
|
||||
self._cmdname = cmdname
|
||||
self._argintype = cmdinfo['datatype'].argument # single datatype
|
||||
@ -140,7 +141,7 @@ class CommandButton(QPushButton):
|
||||
class ModuleCtrl(QWidget):
|
||||
|
||||
def __init__(self, node, module, parent=None):
|
||||
super(ModuleCtrl, self).__init__(parent)
|
||||
super().__init__(parent)
|
||||
loadUi(self, 'modulectrl.ui')
|
||||
self._node = node
|
||||
self._module = module
|
||||
@ -161,11 +162,11 @@ class ModuleCtrl(QWidget):
|
||||
try:
|
||||
result, qualifiers = self._node.execCommand(
|
||||
self._module, command, args)
|
||||
except TypeError:
|
||||
result = None
|
||||
qualifiers = {}
|
||||
# XXX: flag missing data report as error
|
||||
showCommandResultDialog(command, args, result, qualifiers)
|
||||
except Exception as e:
|
||||
showErrorDialog(command, args, e)
|
||||
return
|
||||
if result is not None:
|
||||
showCommandResultDialog(command, args, result, qualifiers)
|
||||
|
||||
def _initModuleWidgets(self):
|
||||
initValues = self._node.queryCache(self._module)
|
||||
|
@ -39,7 +39,7 @@ class ParameterWidget(QWidget):
|
||||
initvalue=None,
|
||||
readonly=True,
|
||||
parent=None):
|
||||
super(ParameterWidget, self).__init__(parent)
|
||||
super().__init__(parent)
|
||||
self._module = module
|
||||
self._paramcmd = paramcmd
|
||||
self._datatype = datatype
|
||||
@ -76,7 +76,12 @@ class GenericParameterWidget(ParameterWidget):
|
||||
self.setLineEdit.text())
|
||||
|
||||
def updateValue(self, value):
|
||||
self.currentLineEdit.setText(str(value))
|
||||
fmtstr = getattr(self._datatype, 'fmtstr', '%s')
|
||||
if value.readerror:
|
||||
value = str(value)
|
||||
else:
|
||||
value = fmtstr % (value.value,)
|
||||
self.currentLineEdit.setText(value)
|
||||
|
||||
|
||||
class EnumParameterWidget(GenericParameterWidget):
|
||||
|
Loading…
x
Reference in New Issue
Block a user