gui: cleanup code in modulewidget
- line length - spacing style - copyright header Change-Id: Ib402baf271868e82010e9acdfad4087164d91714 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30647 Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de> Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Georg Brandl <g.brandl@fz-juelich.de>
This commit is contained in:
parent
c3bfc0a930
commit
efad0e2079
@ -1,3 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# *****************************************************************************
|
||||||
|
# Copyright (c) 2015-2023 by the authors, see LICENSE
|
||||||
|
#
|
||||||
|
# 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 the Free Software
|
||||||
|
# Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
# details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
# Module authors:
|
||||||
|
# Alexander Zaft <a.zaft@fz-juelich.de>
|
||||||
|
#
|
||||||
|
# *****************************************************************************
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
@ -45,7 +68,8 @@ class Console(QWidget):
|
|||||||
einfo = e.args[0] if len(e.args) == 1 else json.dumps(e.args)
|
einfo = e.args[0] if len(e.args) == 1 else json.dumps(e.args)
|
||||||
self._addLogEntry('%s: %s' % (e.name, einfo), error=True)
|
self._addLogEntry('%s: %s' % (e.name, einfo), error=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._addLogEntry('error when sending %r: %r' % (msg, e), error=True)
|
self._addLogEntry('error when sending %r: %r' % (msg, e),
|
||||||
|
error=True)
|
||||||
|
|
||||||
self.msgLineEdit.selectAll()
|
self.msgLineEdit.selectAll()
|
||||||
|
|
||||||
@ -64,11 +88,11 @@ class Console(QWidget):
|
|||||||
def _addLogEntry(self, msg, raw=False, error=False):
|
def _addLogEntry(self, msg, raw=False, error=False):
|
||||||
if not raw:
|
if not raw:
|
||||||
if error:
|
if error:
|
||||||
msg = '<div style="color:#FF0000"><b><pre>%s</pre></b></div>' % toHtmlEscaped(
|
msg = ('<div style="color:#FF0000"><b><pre>%s</pre></b></div>'
|
||||||
str(msg)).replace('\n', '<br />')
|
% toHtmlEscaped(str(msg)).replace('\n', '<br />'))
|
||||||
else:
|
else:
|
||||||
msg = '<pre>%s</pre>' % toHtmlEscaped(
|
msg = ('<pre>%s</pre>'
|
||||||
str(msg)).replace('\n', '<br />')
|
% toHtmlEscaped(str(msg)).replace('\n', '<br />'))
|
||||||
|
|
||||||
content = ''
|
content = ''
|
||||||
if self.logTextBrowser.toPlainText():
|
if self.logTextBrowser.toPlainText():
|
||||||
@ -85,6 +109,7 @@ class Console(QWidget):
|
|||||||
result = self.logTextBrowser.width() / fontMetrics.width('m')
|
result = self.logTextBrowser.width() / fontMetrics.width('m')
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class NodeWidget(QWidget):
|
class NodeWidget(QWidget):
|
||||||
noPlots = pyqtSignal(bool)
|
noPlots = pyqtSignal(bool)
|
||||||
|
|
||||||
@ -104,12 +129,13 @@ class NodeWidget(QWidget):
|
|||||||
self.top_splitter.setStretchFactor(1, 10)
|
self.top_splitter.setStretchFactor(1, 10)
|
||||||
self.top_splitter.setSizes([180, 500])
|
self.top_splitter.setSizes([180, 500])
|
||||||
|
|
||||||
self.middle_splitter.setCollapsible(self.middle_splitter.indexOf(self.view), False)
|
self.middle_splitter.setCollapsible(
|
||||||
|
self.middle_splitter.indexOf(self.view), False)
|
||||||
self.middle_splitter.setStretchFactor(0, 20)
|
self.middle_splitter.setStretchFactor(0, 20)
|
||||||
self.middle_splitter.setStretchFactor(1, 1)
|
self.middle_splitter.setStretchFactor(1, 1)
|
||||||
|
|
||||||
self.infobox_splitter.setStretchFactor(0,3)
|
self.infobox_splitter.setStretchFactor(0, 3)
|
||||||
self.infobox_splitter.setStretchFactor(1,2)
|
self.infobox_splitter.setStretchFactor(1, 2)
|
||||||
|
|
||||||
self.consoleWidget.setTitle('Console')
|
self.consoleWidget.setTitle('Console')
|
||||||
cmd = Console(node, self.consoleWidget)
|
cmd = Console(node, self.consoleWidget)
|
||||||
@ -133,7 +159,6 @@ class NodeWidget(QWidget):
|
|||||||
|
|
||||||
self._initNodeInfo()
|
self._initNodeInfo()
|
||||||
|
|
||||||
|
|
||||||
def _initNodeInfo(self):
|
def _initNodeInfo(self):
|
||||||
self.tree = ModuleOverview(self._node)
|
self.tree = ModuleOverview(self._node)
|
||||||
infolayout = QVBoxLayout()
|
infolayout = QVBoxLayout()
|
||||||
@ -145,7 +170,7 @@ class NodeWidget(QWidget):
|
|||||||
self.tree.customContextMenuRequested.connect(self._treeContextMenu)
|
self.tree.customContextMenuRequested.connect(self._treeContextMenu)
|
||||||
|
|
||||||
self.descriptionEdit.setPlainText(
|
self.descriptionEdit.setPlainText(
|
||||||
self._node.properties.get('description','no description available'))
|
self._node.properties.get('description', 'no description available'))
|
||||||
self.hostLabel.setText(self._node.conn.uri)
|
self.hostLabel.setText(self._node.conn.uri)
|
||||||
self.protocolLabel.setText(
|
self.protocolLabel.setText(
|
||||||
# insert some invisible spaces to get better wrapping
|
# insert some invisible spaces to get better wrapping
|
||||||
@ -154,7 +179,7 @@ class NodeWidget(QWidget):
|
|||||||
def _set_node_state(self, nodename, online, state):
|
def _set_node_state(self, nodename, online, state):
|
||||||
p = self.palette()
|
p = self.palette()
|
||||||
if online:
|
if online:
|
||||||
p.setColor(self.backgroundRole(),Colors.palette.window().color())
|
p.setColor(self.backgroundRole(), Colors.palette.window().color())
|
||||||
self.tree.setToReconnected()
|
self.tree.setToReconnected()
|
||||||
else:
|
else:
|
||||||
p.setColor(self.backgroundRole(), Colors.colors['orange'])
|
p.setColor(self.backgroundRole(), Colors.colors['orange'])
|
||||||
@ -162,7 +187,6 @@ class NodeWidget(QWidget):
|
|||||||
self.tree.setToDisconnected()
|
self.tree.setToDisconnected()
|
||||||
self.setPalette(p)
|
self.setPalette(p)
|
||||||
|
|
||||||
|
|
||||||
def _rebuildAdvanced(self, advanced):
|
def _rebuildAdvanced(self, advanced):
|
||||||
self.detailed = advanced
|
self.detailed = advanced
|
||||||
self.tree._rebuildAdvanced(advanced)
|
self.tree._rebuildAdvanced(advanced)
|
||||||
@ -174,7 +198,7 @@ class NodeWidget(QWidget):
|
|||||||
|
|
||||||
def changeViewContent(self, module, param):
|
def changeViewContent(self, module, param):
|
||||||
if module == '' and param == '':
|
if module == '' and param == '':
|
||||||
return # for now, don't do anything when resetting selection
|
return # for now, don't do anything when resetting selection
|
||||||
if param == '':
|
if param == '':
|
||||||
self.view.ensureWidgetVisible(self._modules[module])
|
self.view.ensureWidgetVisible(self._modules[module])
|
||||||
else:
|
else:
|
||||||
@ -195,8 +219,8 @@ class NodeWidget(QWidget):
|
|||||||
if not self._activePlots:
|
if not self._activePlots:
|
||||||
menu_plot_ext.setEnabled(False)
|
menu_plot_ext.setEnabled(False)
|
||||||
else:
|
else:
|
||||||
for (m,p),plot in self._activePlots.items():
|
for (m, p), plot in self._activePlots.items():
|
||||||
opt_ext = menu_plot_ext.addAction("%s:%s" % (m,p))
|
opt_ext = menu_plot_ext.addAction("%s:%s" % (m, p))
|
||||||
opt_ext.triggered.connect(
|
opt_ext.triggered.connect(
|
||||||
lambda plot=plot: self._requestPlot(item, plot))
|
lambda plot=plot: self._requestPlot(item, plot))
|
||||||
|
|
||||||
@ -204,7 +228,7 @@ class NodeWidget(QWidget):
|
|||||||
opt_clear = menu.addAction('Clear Selection')
|
opt_clear = menu.addAction('Clear Selection')
|
||||||
opt_plot.triggered.connect(lambda: self._requestPlot(item))
|
opt_plot.triggered.connect(lambda: self._requestPlot(item))
|
||||||
opt_clear.triggered.connect(self.tree.clearTreeSelection)
|
opt_clear.triggered.connect(self.tree.clearTreeSelection)
|
||||||
#menu.exec(self.mapToGlobal(pos))
|
# menu.exec(self.mapToGlobal(pos))
|
||||||
menu.exec(QCursor.pos())
|
menu.exec(QCursor.pos())
|
||||||
|
|
||||||
def _requestPlot(self, item, plot=None):
|
def _requestPlot(self, item, plot=None):
|
||||||
@ -213,9 +237,9 @@ class NodeWidget(QWidget):
|
|||||||
self.plotParam(module, param, plot)
|
self.plotParam(module, param, plot)
|
||||||
|
|
||||||
def _plotPopUp(self, module, param):
|
def _plotPopUp(self, module, param):
|
||||||
plots = {'%s -> %s' % (m,p): (m,p) for (m,p) in self._activePlots}
|
plots = {'%s -> %s' % mp: mp for mp in self._activePlots}
|
||||||
dialog = QInputDialog()
|
dialog = QInputDialog()
|
||||||
#dialog.setInputMode()
|
# dialog.setInputMode()
|
||||||
dialog.setOption(
|
dialog.setOption(
|
||||||
QInputDialog.InputDialogOption.UseListViewForComboBoxItems)
|
QInputDialog.InputDialogOption.UseListViewForComboBoxItems)
|
||||||
dialog.setComboBoxItems(plots.keys())
|
dialog.setComboBoxItems(plots.keys())
|
||||||
@ -227,7 +251,6 @@ class NodeWidget(QWidget):
|
|||||||
item = dialog.textValue()
|
item = dialog.textValue()
|
||||||
self.plotParam(module, param, self._activePlots[plots[item]])
|
self.plotParam(module, param, self._activePlots[plots[item]])
|
||||||
|
|
||||||
|
|
||||||
def plotParam(self, module, param, plot=None):
|
def plotParam(self, module, param, plot=None):
|
||||||
# - liveness?
|
# - liveness?
|
||||||
# - better plot window management?
|
# - better plot window management?
|
||||||
@ -237,7 +260,8 @@ class NodeWidget(QWidget):
|
|||||||
return
|
return
|
||||||
if plot:
|
if plot:
|
||||||
plot.addCurve(self._node, module, param)
|
plot.addCurve(self._node, module, param)
|
||||||
plot.setCurveColor(module, param, Colors.colors[len(plot.curves) % 6])
|
plot.setCurveColor(module, param,
|
||||||
|
Colors.colors[len(plot.curves) % 6])
|
||||||
else:
|
else:
|
||||||
plot = getPlotWidget(self)
|
plot = getPlotWidget(self)
|
||||||
plot.addCurve(self._node, module, param)
|
plot.addCurve(self._node, module, param)
|
||||||
@ -254,5 +278,5 @@ class NodeWidget(QWidget):
|
|||||||
plot.update(module, param, cache[param])
|
plot.update(module, param, cache[param])
|
||||||
|
|
||||||
def _removePlot(self, module, param):
|
def _removePlot(self, module, param):
|
||||||
self._activePlots.pop((module,param))
|
self._activePlots.pop((module, param))
|
||||||
self.noPlots.emit(len(self._activePlots) == 0)
|
self.noPlots.emit(len(self._activePlots) == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user