improve Py2/3 compat
Change-Id: I1dfdcb88a492401851d5157c734cd708496bf004 Reviewed-on: https://forge.frm2.tum.de/review/17734 Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de> Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
This commit is contained in:
@ -24,10 +24,17 @@
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
try:
|
||||
# py2
|
||||
unicode(u'')
|
||||
except NameError:
|
||||
# py3
|
||||
unicode = str # pylint: disable=redefined-builtin
|
||||
|
||||
from secop.gui.util import loadUi
|
||||
from secop.gui.params import ParameterView
|
||||
|
||||
from secop.datatypes import * # pylint: disable=unused-wildcard-import,wildcard-import
|
||||
#from secop.datatypes import ...
|
||||
|
||||
from secop.gui.qt import QDialog, QLabel, QCheckBox, QWidget, QMessageBox, \
|
||||
QPushButton, QSizePolicy
|
||||
@ -93,7 +100,7 @@ class ParameterGroup(QWidget):
|
||||
self._row = 0
|
||||
self._widgets = []
|
||||
|
||||
self.paramGroupBox.setTitle('Group: ' + str(groupname))
|
||||
self.paramGroupBox.setTitle('Group: ' + unicode(groupname))
|
||||
self.paramGroupBox.toggled.connect(self.on_toggle_clicked)
|
||||
self.paramGroupBox.setChecked(False)
|
||||
|
||||
@ -275,7 +282,7 @@ class ModuleCtrl(QWidget):
|
||||
label.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
|
||||
|
||||
# make 'display' label
|
||||
view = QLabel(str(props[prop]))
|
||||
view = QLabel(unicode(props[prop]))
|
||||
view.setFont(self.font())
|
||||
view.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
||||
view.setWordWrap(True)
|
||||
@ -351,9 +358,9 @@ class ModuleCtrl(QWidget):
|
||||
try:
|
||||
self._node.setParameter(module, parameter, target)
|
||||
except Exception as e:
|
||||
QMessageBox.warning(self.parent(), 'Operation failed', str(e))
|
||||
QMessageBox.warning(self.parent(), 'Operation failed', unicode(e))
|
||||
|
||||
def _updateValue(self, module, parameter, value):
|
||||
if module != self._module:
|
||||
return
|
||||
self._paramWidgets[parameter][1].updateValue(str(value[0]))
|
||||
self._paramWidgets[parameter][1].updateValue(unicode(value[0]))
|
||||
|
@ -21,6 +21,14 @@
|
||||
#
|
||||
# *****************************************************************************
|
||||
|
||||
from __future__ import print_function, division
|
||||
|
||||
try:
|
||||
# py2
|
||||
unicode(u'')
|
||||
except NameError:
|
||||
unicode = str # pylint: disable=redefined-builtin
|
||||
|
||||
import pprint
|
||||
import json
|
||||
from time import sleep
|
||||
@ -121,9 +129,9 @@ class NodeCtrl(QWidget):
|
||||
|
||||
def _getLogWidth(self):
|
||||
fontMetrics = QFontMetrics(QFont('Monospace'))
|
||||
# calculate max avail characters by using an a (which is possible
|
||||
# calculate max avail characters by using an m (which is possible
|
||||
# due to monospace)
|
||||
result = self.logTextBrowser.width() / fontMetrics.width('a')
|
||||
result = self.logTextBrowser.width() / fontMetrics.width('m')
|
||||
return result
|
||||
|
||||
def _init_modules_tab(self):
|
||||
@ -277,6 +285,7 @@ class DrivableWidget(ReadableWidget):
|
||||
if self._is_enum:
|
||||
# EnumType: disable Linedit
|
||||
self.targetLineEdit.setHidden(True)
|
||||
self.cmdPushButton.setHidden(True)
|
||||
else:
|
||||
# normal types: disable Combobox
|
||||
self.targetComboBox.setHidden(True)
|
||||
|
@ -21,11 +21,17 @@
|
||||
#
|
||||
# *****************************************************************************
|
||||
|
||||
try:
|
||||
# py2
|
||||
unicode(u'')
|
||||
except NameError:
|
||||
unicode = str # pylint: disable=redefined-builtin
|
||||
|
||||
from secop.gui.qt import QWidget, QLabel, QPushButton as QButton, QLineEdit, \
|
||||
QMessageBox, QCheckBox, QSizePolicy, Qt, pyqtSignal, pyqtSlot
|
||||
|
||||
from secop.gui.util import loadUi
|
||||
from secop.datatypes import * # pylint: disable=wildcard-import
|
||||
from secop.datatypes import EnumType
|
||||
|
||||
|
||||
class ParameterWidget(QWidget):
|
||||
@ -107,9 +113,8 @@ class EnumParameterWidget(GenericParameterWidget):
|
||||
|
||||
@pyqtSlot()
|
||||
def on_setPushButton_clicked(self):
|
||||
enumval, enumname = self._map[self.setComboBox.currentIndex()]
|
||||
_enumval, enumname = self._map[self.setComboBox.currentIndex()]
|
||||
self.setRequested.emit(self._module, self._paramcmd, enumname)
|
||||
self.setRequested.emit(self._module, self._paramcmd, str(enumval))
|
||||
|
||||
def updateValue(self, valuestr):
|
||||
try:
|
||||
|
@ -21,10 +21,16 @@
|
||||
#
|
||||
# *****************************************************************************
|
||||
|
||||
try:
|
||||
# py2
|
||||
unicode(u'')
|
||||
except NameError:
|
||||
# py3
|
||||
unicode = str # pylint: disable=redefined-builtin
|
||||
|
||||
from secop.gui.qt import QWidget, QLabel, QSizePolicy
|
||||
|
||||
from secop.gui.util import loadUi
|
||||
#from secop.datatypes import get_datatype
|
||||
|
||||
|
||||
class ParameterView(QWidget):
|
||||
|
@ -1,3 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# *****************************************************************************
|
||||
#
|
||||
# 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:
|
||||
# Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
|
||||
#
|
||||
# *****************************************************************************
|
||||
"""Import needed stuff from PyQt4/PyQt5"""
|
||||
|
||||
# pylint: disable=unused-import
|
||||
from __future__ import print_function
|
||||
|
||||
|
@ -23,7 +23,8 @@
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from secop.datatypes import * # pylint: disable=unused-wildcard-import,wildcard-import
|
||||
from secop.datatypes import FloatRange, IntRange, StringType, BLOBType, \
|
||||
EnumType, BoolType, TupleOf, StructOf, ArrayOf
|
||||
|
||||
from secop.gui.qt import QDialog, QLabel, QLineEdit,\
|
||||
QGroupBox, QSpinBox, QDoubleSpinBox, QComboBox, QCheckBox, \
|
||||
@ -112,8 +113,8 @@ class FloatWidget(QDoubleSpinBox):
|
||||
self.datatype = datatype
|
||||
if readonly:
|
||||
self.setEnabled(False)
|
||||
self.setMaximum(datatype.max)
|
||||
self.setMinimum(datatype.min)
|
||||
self.setMaximum(datatype.max or 1e6) # XXX!
|
||||
self.setMinimum(datatype.min or 0) # XXX!
|
||||
self.setDecimals(12)
|
||||
|
||||
def get_value(self):
|
||||
@ -141,7 +142,7 @@ class TupleWidget(QFrame):
|
||||
self.update()
|
||||
|
||||
def get_value(self):
|
||||
return [v.validate(w.get_value()) for w,v in zip(self.subwidgets, self.datatypes)]
|
||||
return [v.validate(w.get_value()) for w, v in zip(self.subwidgets, self.datatypes)]
|
||||
|
||||
def set_value(self, value):
|
||||
for w, _ in zip(self.subwidgets, value):
|
||||
@ -225,7 +226,7 @@ class msg(QDialog):
|
||||
row = 0
|
||||
|
||||
self.gridLayout.addWidget(QLabel('struct'), row, 0)
|
||||
dt = StructOf(i=IntRange(0,10), f=FloatRange(), b=BoolType())
|
||||
dt = StructOf(i=IntRange(0, 10), f=FloatRange(), b=BoolType())
|
||||
w = StructWidget(dt)
|
||||
self.gridLayout.addWidget(w, row, 1)
|
||||
row+=1
|
||||
|
Reference in New Issue
Block a user