def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt5.Qt import (QDialog, QDialogButtonBox, QVBoxLayout, QLabel, Qt, QLineEdit, QCheckBox) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) v = QVBoxLayout(config_dialog) def size_dialog(): config_dialog.resize(config_dialog.sizeHint()) button_box.accepted.connect(config_dialog.accept) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle(_('Customize') + ' ' + self.name) from calibre.customize.ui import (plugin_customization, customize_plugin) help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) help_text.setTextInteractionFlags( Qt.TextInteractionFlag.LinksAccessibleByMouse | Qt.TextInteractionFlag.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) bf = QCheckBox(_('Add linked files in breadth first order')) bf.setToolTip( _('Normally, when following links in HTML files' ' calibre does it depth first, i.e. if file A links to B and ' ' C, but B links to D, the files are added in the order A, B, D, C. ' ' With this option, they will instead be added as A, B, C, D')) sc = plugin_customization(self) if not sc: sc = '' sc = sc.strip() enc = sc.partition('|')[0] bfs = sc.partition('|')[-1] bf.setChecked(bfs == 'bf') sc = QLineEdit(enc, config_dialog) v.addWidget(sc) v.addWidget(bf) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.DialogCode.Accepted: sc = unicode_type(sc.text()).strip() if bf.isChecked(): sc += '|bf' customize_plugin(self, sc) return config_dialog.result()
def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt5.Qt import (QDialog, QDialogButtonBox, QVBoxLayout, QLabel, Qt, QLineEdit, QCheckBox) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) v = QVBoxLayout(config_dialog) def size_dialog(): config_dialog.resize(config_dialog.sizeHint()) button_box.accepted.connect(config_dialog.accept) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle(_('Customize') + ' ' + self.name) from calibre.customize.ui import (plugin_customization, customize_plugin) help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) bf = QCheckBox(_('Add linked files in breadth first order')) bf.setToolTip(_('Normally, when following links in HTML files' ' calibre does it depth first, i.e. if file A links to B and ' ' C, but B links to D, the files are added in the order A, B, D, C. ' ' With this option, they will instead be added as A, B, C, D')) sc = plugin_customization(self) if not sc: sc = '' sc = sc.strip() enc = sc.partition('|')[0] bfs = sc.partition('|')[-1] bf.setChecked(bfs == 'bf') sc = QLineEdit(enc, config_dialog) v.addWidget(sc) v.addWidget(bf) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: sc = unicode(sc.text()).strip() if bf.isChecked(): sc += '|bf' customize_plugin(self, sc) return config_dialog.result()
def createWordDialog(self, word=Word('')): dialog = QDialog(self) layout = QGridLayout(self) dialog.setLayout(layout) shortEdit = QLineEdit(word.short) longEdit = QLineEdit(word.long) explainEdit = QLineEdit(word.explain) okButton = QPushButton('OK') okButton.clicked.connect(dialog.accept) cancelButton = QPushButton('Cancel') cancelButton.clicked.connect(dialog.reject) layout.addWidget(QLabel('Short'), 0, 0) layout.addWidget(shortEdit, 0, 1) layout.addWidget(QLabel('Long'), 1, 0) layout.addWidget(longEdit, 1, 1) layout.addWidget(QLabel('Translate'), 2, 0) layout.addWidget(explainEdit, 2, 1) layout.addWidget(okButton, 3, 0) layout.addWidget(cancelButton, 3, 1) dialog.exec() if (dialog.result() == QDialog.Accepted): word = Word( '%s,%s,%s' % (shortEdit.text(), longEdit.text(), explainEdit.text())) self.dictionary.append(word) self.dictionary.save() self.updateTable(self.dictionary.words)
def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt5.Qt import QDialog, QDialogButtonBox, QVBoxLayout from calibre.gui2 import gprefs prefname = 'plugin config dialog:' + self.type + ':' + self.name geom = gprefs.get(prefname, None) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) layout = QVBoxLayout(config_dialog) def size_dialog(): '''Sets size of dialog''' if geom is None: config_dialog.resize(config_dialog.sizeHint()) else: config_dialog.restoreGeometry(geom) button_box.accepted.connect( lambda: self.validate(config_dialog, config_widget)) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle('Customize ' + self.name) config_widget = self.config_widget() layout.addWidget(config_widget) layout.addWidget(button_box) size_dialog() config_dialog.exec_() geom = bytearray(config_dialog.saveGeometry()) gprefs[prefname] = geom return config_dialog.result()
def _onMenuBarItemSelectComPort(self): ''' Selection of COM port. Starts model on valid port selection. ''' #Stop model self._model.stop() #We are no more connected self.setStatusIndicator(Status.TARGET_OFFLINE) #Create dialog for COM port selection qDialog = QDialog() settingWindow = Ui_AppSettings() settingWindow.setupUi(qDialog) #Get COM ports with connected devices ports = sorted([port.device for port in list_ports.comports()]) #Populate comboBox with found COM ports settingWindow.comboBoxComPorts.clear() settingWindow.comboBoxComPorts.addItems(ports) #Show dialog qDialog.exec_() #Evaluate user selection if QDialog.Accepted == qDialog.result(): # User has accepted by pressing OK button #Get selected COM-Port selectedIdx = settingWindow.comboBoxComPorts.currentIndex() comPort = ports[selectedIdx] self._model.start(comPort) else: # User has rejected by pressing CANCEL button pass
def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt5.Qt import QDialog, QDialogButtonBox, QVBoxLayout from calibre.gui2 import gprefs prefname = 'plugin config dialog:' + self.type + ':' + self.name geom = gprefs.get(prefname, None) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) layout = QVBoxLayout(config_dialog) def size_dialog(): '''Sets size of dialog''' if geom is None: config_dialog.resize(config_dialog.sizeHint()) else: config_dialog.restoreGeometry(geom) button_box.accepted.connect(lambda: self.validate(config_dialog, config_widget)) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle('Customize ' + self.name) config_widget = self.config_widget() layout.addWidget(config_widget) layout.addWidget(button_box) size_dialog() config_dialog.exec_() geom = bytearray(config_dialog.saveGeometry()) gprefs[prefname] = geom return config_dialog.result()
def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt5.Qt import QDialog, QDialogButtonBox, QVBoxLayout, \ QLabel, Qt, QLineEdit from calibre.gui2 import gprefs prefname = 'plugin config dialog:'+self.type + ':' + self.name geom = gprefs.get(prefname, None) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) v = QVBoxLayout(config_dialog) def size_dialog(): if geom is None: config_dialog.resize(config_dialog.sizeHint()) else: config_dialog.restoreGeometry(geom) button_box.accepted.connect(config_dialog.accept) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle(_('Customize') + ' ' + self.name) try: config_widget = self.config_widget() except NotImplementedError: config_widget = None if isinstance(config_widget, tuple): from calibre.gui2 import warning_dialog warning_dialog(parent, _('Cannot configure'), config_widget[0], det_msg=config_widget[1], show=True) return False if config_widget is not None: v.addWidget(config_widget) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: if hasattr(config_widget, 'validate'): if config_widget.validate(): self.save_settings(config_widget) else: self.save_settings(config_widget) else: from calibre.customize.ui import plugin_customization, \ customize_plugin help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) sc = plugin_customization(self) if not sc: sc = '' sc = sc.strip() sc = QLineEdit(sc, config_dialog) v.addWidget(sc) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: sc = unicode(sc.text()).strip() customize_plugin(self, sc) geom = bytearray(config_dialog.saveGeometry()) gprefs[prefname] = geom return config_dialog.result()
def do_user_config(self, parent=None): ''' This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied. ''' from PyQt5.Qt import QDialog, QDialogButtonBox, QVBoxLayout, \ QLabel, Qt, QLineEdit from calibre.gui2 import gprefs prefname = 'plugin config dialog:' + self.type + ':' + self.name geom = gprefs.get(prefname, None) config_dialog = QDialog(parent) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) v = QVBoxLayout(config_dialog) def size_dialog(): if geom is None: config_dialog.resize(config_dialog.sizeHint()) else: from PyQt5.Qt import QApplication QApplication.instance().safe_restore_geometry( config_dialog, geom) button_box.accepted.connect(config_dialog.accept) button_box.rejected.connect(config_dialog.reject) config_dialog.setWindowTitle(_('Customize') + ' ' + self.name) try: config_widget = self.config_widget() except NotImplementedError: config_widget = None if isinstance(config_widget, tuple): from calibre.gui2 import warning_dialog warning_dialog(parent, _('Cannot configure'), config_widget[0], det_msg=config_widget[1], show=True) return False if config_widget is not None: v.addWidget(config_widget) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: if hasattr(config_widget, 'validate'): if config_widget.validate(): self.save_settings(config_widget) else: self.save_settings(config_widget) else: from calibre.customize.ui import plugin_customization, \ customize_plugin help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) sc = plugin_customization(self) if not sc: sc = '' sc = sc.strip() sc = QLineEdit(sc, config_dialog) v.addWidget(sc) v.addWidget(button_box) size_dialog() config_dialog.exec_() if config_dialog.result() == QDialog.Accepted: sc = unicode_type(sc.text()).strip() customize_plugin(self, sc) geom = bytearray(config_dialog.saveGeometry()) gprefs[prefname] = geom return config_dialog.result()
class Controller(QtWidgets.QMainWindow): ''' Responsible for updating of UI/View. Control and updates of model with new data. ''' def __init__(self, model): ''' initialization of class ''' super().__init__() self.value = str() # Current Model we use self._model = model # Application's UI main window self._ui = Ui_MainWindow() # Setup main window self._ui.setupUi(self) #setup numpad self.qDialog = QDialog() self.numpadWindow = Ui_Numpad() self.numpadWindow.setupUi(self.qDialog) self.numpadWindow.numberToSet.setAlignment(QtCore.Qt.AlignRight) self.numpadWindow.numberToSet.setMaxLength(6) self.numpadWindow.numberToSet.setReadOnly(True) self.qLineValidator = QtGui.QIntValidator self.numpadButtons = [ self.numpadWindow.button0, self.numpadWindow.button1, self.numpadWindow.button2, self.numpadWindow.button3, self.numpadWindow.button4, self.numpadWindow.button5, self.numpadWindow.button6, self.numpadWindow.button7, self.numpadWindow.button8, self.numpadWindow.button9 ] for idx, item in enumerate(self.numpadButtons): #print(type(item)) #print(idx) item.setText(str(idx)) item.clicked.connect(lambda: self._buttonpres()) self.numpadWindow.buttonBackspace.clicked.connect(self._dellast) self.numpadWindow.buttonSub.clicked.connect(self._negateValue) # Set UI input objects to default state/value self._setUiInputsToDefault() # Connect UI elements/objects signals and slots self._connectSignalSlots() # Add menu bar items self._addMenubarItems() # Setup Plots self._bvddPlot = self._ui.graphicsViewBVDD.plot([], [], pen=(0, 0, 255)) self._ui.graphicsViewBVDD.setLabel('left', 'BVDD', units='V') self._ui.graphicsViewBVDD.setLabel('bottom', 'Time', units='s') self._ui.graphicsViewBVDD.showGrid(x=True, y=True) self._ui.graphicsViewBVDD.setYRange( DefinedValues.BVDD_Y_MIN_RANGE.value, DefinedValues.BVDD_Y_MAX_RANGE.value, 0, True) self._temperaturePlot = self._ui.graphicsViewTemperature.plot([], [], pen=(0, 255, 0)) self._ui.graphicsViewTemperature.setLabel('left', 'Tj', units='°C') self._ui.graphicsViewTemperature.setLabel('bottom', 'Time', units='s') self._ui.graphicsViewTemperature.showGrid(x=True, y=True) self._ui.graphicsViewTemperature.setYRange( DefinedValues.TJ_Y_MIN_RANGE.value, DefinedValues.TJ_Y_MAX_RANGE.value, 0, True) self._rotorSpeedPlot = self._ui.graphicsViewRotorSpeed.plot([], [], pen=(255, 0, 0)) self._ui.graphicsViewRotorSpeed.setLabel('left', 'Rotor Speed', units='PPS') self._ui.graphicsViewRotorSpeed.setLabel('bottom', 'Time', units='s') self._ui.graphicsViewRotorSpeed.showGrid(x=True, y=True) self._ui.graphicsViewRotorSpeed.setYRange( DefinedValues.RS_Y_MIN_RANGE.value, DefinedValues.RS_Y_MAX_RANGE.value, 0, True) self.__rawCurrentSpeed = 0 self.__currentSpeed = 0 self._picIndex = 0 # first image to be replaced self._picTimer = QTimer() self._picTimer.timeout.connect(self.updatePic) self._picTimer.start(DefinedValues.PIC_SWAP_TIME.value) def updatePic(self): ''' cyclical switch of banner pic ''' self._picIndex += 1 # next image if (self._picIndex > 5): # last image reached ? self._picIndex = 0 if (self._picIndex == 0): self._ui.ImageButton.setStyleSheet( "border-image: url(:/Image/resources/NT_BannerSW31.png);") elif (self._picIndex == 1): self._ui.ImageButton.setStyleSheet( "border-image: url(:/Image/resources/NT_BannerSW32.png);") elif (self._picIndex == 2): self._ui.ImageButton.setStyleSheet( "border-image: url(:/Image/resources/NT_BannerSW33.png);") elif (self._picIndex == 3): self._ui.ImageButton.setStyleSheet( "border-image: url(:/Image/resources/NT_BannerSW34.png);") elif (self._picIndex == 4): self._ui.ImageButton.setStyleSheet( "border-image: url(:/Image/resources/NT_BannerSW35.png);") elif (self._picIndex == 5): self._ui.ImageButton.setStyleSheet( "border-image: url(:/Image/resources/NT_BannerSW36.png);") else: self._picIndex = 0 #default never reached def updateCurrentPosition(self, position): ''' Set current position displayed in 'Current Status' LCD element. ''' self._ui.currentPositionLCD.display(position) def setStatusIndicator(self, statusIndicator): ''' Set status indicator elements. ''' if Status.OVER_CURRENT == statusIndicator: self._ui.labelOverCurrentLED.setPixmap( QtGui.QPixmap(":/led/resources/red-led-on.png")) elif Status.NO_OVER_CURRENT == statusIndicator: self._ui.labelOverCurrentLED.setPixmap( QtGui.QPixmap(":/led/resources/red-led-off.png")) elif Status.OVER_TEMPERATURE == statusIndicator: self._ui.labelOverTemperatureLED.setPixmap( QtGui.QPixmap(":/led/resources/red-led-on.png")) elif Status.NO_OVER_TEMPERATURE == statusIndicator: self._ui.labelOverTemperatureLED.setPixmap( QtGui.QPixmap(":/led/resources/red-led-off.png")) elif Status.ERROR == statusIndicator: self._ui.labelErrorLED.setPixmap( QtGui.QPixmap(":/led/resources/red-led-on.png")) elif Status.NO_ERROR == statusIndicator: self._ui.labelErrorLED.setPixmap( QtGui.QPixmap(":/led/resources/red-led-off.png")) elif Status.TARGET_ONLINE == statusIndicator: self._ui.labelTargetOnlineLED.setPixmap( QtGui.QPixmap(":/led/resources/green-led-on.png")) elif Status.TARGET_OFFLINE == statusIndicator: self._ui.labelTargetOnlineLED.setPixmap( QtGui.QPixmap(":/led/resources/green-led-off.png")) else: #Nothing to do here pass def updateBvddPlot(self, plotData): ''' Updates BVDD plot with plotData. ''' self._bvddPlot.setData(plotData.x, plotData.y) def updateTemeperatuePlot(self, plotData): ''' Updates Temperature plot with plotData. ''' self._temperaturePlot.setData(plotData.x, plotData.y) def updateRotorSpeedPlot(self, plotData): ''' Updates Rotor Speed plot with plotData. ''' self._rotorSpeedPlot.setData(plotData.x, plotData.y) def updateCurrentSpeed(self, speed): ''' get current speed value ''' self.__rawCurrentSpeed = speed def getCurrentSpeedRPM(self): ''' returns the current speed''' self.__currentSpeedRPM = (self.__rawCurrentSpeed * DefinedValues.RPM_FACTOR.value) return self.__currentSpeedRPM def buttonLearnMore(self): ''' open micronas webaddress ''' webbrowser.open(DefinedValues.LEARN_MORE_WEB_ADDRESS.value) def showErrorDialog(self, errorMsg): ''' Shows a modal error message dialog. errorMsg: Message (string) displayed in dialog. ''' msg = QtWidgets.QErrorMessage() msg.setWindowTitle("ERROR MESSAGE") msg.setWindowModality(QtCore.Qt.ApplicationModal) msg.showMessage(errorMsg) msg.exec_() def _addMenubarItems(self): ''' create sub items in menu bar and connect with actions ''' action = QtWidgets.QAction("Connect", self) action.triggered.connect(self._onMenuBarItemSelectComPort) self._ui.menuSettings.addAction(action) action = QtWidgets.QAction("License", self) action.triggered.connect(self._onLicense) self._ui.menuClose.addAction(action) action = QtWidgets.QAction("Exit", self) action.triggered.connect(self._closeApp) self._ui.menuClose.addAction(action) def _connectSignalSlots(self): ''' Connect UI's signals and slots connections. ''' # Connect push buttons self._ui.pushButtonEnableMotorCtrl.clicked.connect( self._onPushButtonEnableMotorCtrl) self._ui.pushButtonResetInputs.clicked.connect( self._onPushButtonResetInputs) # Connect Direction radio buttons self._ui.radioButtonDirectionStop.clicked.connect( self._onRadioButtonDirection) self._ui.radioButtonDirectionClockWise.clicked.connect( self._onRadioButtonDirection) self._ui.radioButtonDirectionAntiClockwise.clicked.connect( self._onRadioButtonDirection) # Connect Control radio buttons self._ui.radioButtonPositionCtrl.clicked.connect( self._onRadioButtonControlSelection) self._ui.radioButtonSpeedCtrl.clicked.connect( self._onRadioButtonControlSelection) # Connect speed slider control self._ui.speedSlider.valueChanged.connect(self._updateSpeedGroupBox) # Connect speed spinBox self._ui.speedspinBox.editingFinished.connect(self._updateSpeedSpinBox) self._ui.speedChangeButton.clicked.connect(self._ChangeSpeed) # Connect position slider control self._ui.positionSlider.valueChanged.connect( self._updatePositionGroupBox) # Connect position spinBox self._ui.positionspinBox.editingFinished.connect( self._updatePositionSpinBox) self._ui.posChangeButton.clicked.connect(self._ChangePos) # Connect pushButton_learnMore self._ui.ImageButton.clicked.connect(self.buttonLearnMore) def _onPushButtonEnableMotorCtrl(self): ''' action for Button to Enable/Disable Motor control''' if self._ui.pushButtonEnableMotorCtrl.isChecked(): self._ui.pushButtonEnableMotorCtrl.setText("Disable Motor Control") self._model.ctrlFrame.motorEnabled = True #we want only a change of speed and position if the motor is enabled if self._ui.radioButtonPositionCtrl.isChecked(): self._ui.groupBoxAcceleration.setEnabled(True) self._ui.groupBoxPosition.setEnabled(True) self._ui.groupBoxSpeed.setEnabled(True) self._model.ctrlFrame.opMode = rpc.OpMode.POSITION_CTRL else: self._ui.groupBoxAcceleration.setEnabled(True) self._ui.groupBoxPosition.setEnabled(False) self._ui.groupBoxDirection.setEnabled(True) self._ui.groupBoxSpeed.setEnabled(True) self._model.ctrlFrame.opMode = rpc.OpMode.SPEED_CTRL else: self._ui.pushButtonEnableMotorCtrl.setText("Enable Motor Control") self._model.ctrlFrame.motorEnabled = False #motor disable -> no changes on speed and position self._ui.groupBoxPosition.setEnabled(False) self._ui.groupBoxSpeed.setEnabled(False) self._ui.groupBoxDirection.setEnabled(False) self._ui.groupBoxAcceleration.setEnabled(False) if self._ui.radioButtonPositionCtrl.isChecked(): self._model.ctrlFrame.opMode = rpc.OpMode.POSITION_CTRL #pass elif self._ui.radioButtonSpeedCtrl.isChecked(): self._model.ctrlFrame.opMode = rpc.OpMode.SPEED_CTRL #pass def _onPushButtonResetInputs(self): ''' Reset inputs to default values ''' self._setUiInputsToDefault() def _onRadioButtonControlSelection(self): ''' action to activate speed or position control''' if self._ui.pushButtonEnableMotorCtrl.isChecked(): if self._ui.radioButtonPositionCtrl.isChecked( ) and self.getCurrentSpeedRPM() < 1: self._ui.groupBoxDirection.setEnabled(False) self._ui.groupBoxPosition.setEnabled(True) self._ui.groupBoxSpeed.setEnabled(True) self._model.ctrlFrame.opMode = rpc.OpMode.POSITION_CTRL elif self._ui.radioButtonSpeedCtrl.isChecked( ) and self.getCurrentSpeedRPM() < 1: self._ui.groupBoxDirection.setEnabled(True) self._ui.groupBoxPosition.setEnabled(False) self._ui.groupBoxSpeed.setEnabled(True) self._model.ctrlFrame.opMode = rpc.OpMode.SPEED_CTRL elif self._ui.radioButtonPositionCtrl.isChecked( ) and self.getCurrentSpeedRPM() > 1: self._ui.radioButtonPositionCtrl.setChecked(False) self._ui.radioButtonSpeedCtrl.setChecked(True) elif self._ui.radioButtonSpeedCtrl.isChecked( ) and self.getCurrentSpeedRPM() > 1: self._ui.radioButtonSpeedCtrl.setChecked(False) self._ui.radioButtonPositionCtrl.setChecked(True) def _onRadioButtonDirection(self): ''' Update model with selected direction. ''' if self._ui.radioButtonDirectionStop.isChecked(): self._model.ctrlFrame.direction = rpc.Direction.STOP elif self._ui.radioButtonDirectionClockWise.isChecked(): self._model.ctrlFrame.direction = rpc.Direction.CLOCKWISE elif self._ui.radioButtonDirectionAntiClockwise.isChecked(): self._model.ctrlFrame.direction = rpc.Direction.ANTI_CLOCKWISE else: #Nothing to do here pass def _updateSpeedGroupBox(self): ''' Updates Speed Group Box elements. ''' speed = self._ui.speedSlider.value() #self._ui.speedLCD.display(speed) self._model.ctrlFrame.speed = int(speed / DefinedValues.RPM_FACTOR.value) # Sync between slider and Spinbox self._syncSpeedSpinBoxAndSpeedSlider(speed) def _updateSpeedSpinBox(self): ''' update speed in speed display''' speed = self._ui.speedspinBox.value() #self._ui.speedLCD.display(speed) self._model.ctrlFrame.speed = int(speed / DefinedValues.RPM_FACTOR.value) # Sync between slider and Spinbox self._syncSpeedSpinBoxAndSpeedSlider(speed) def _syncSpeedSpinBoxAndSpeedSlider(self, speed): ''' Update and Sync of the GUI-Values ''' self._ui.speedSlider.setValue(speed) self._ui.speedspinBox.setValue(speed) def _updatePositionGroupBox(self): ''' Updates Position Group Box elements. ''' position = self._ui.positionSlider.value() #self._ui.positionLCD.display(position) self._model.ctrlFrame.newPosition = position # Sync between slider and Spinbox self._syncPositionSpinBoxAndPositionSlider(position) def _updatePositionSpinBox(self): '''update position in position display''' position = self._ui.positionspinBox.value() #self._ui.positionLCD.display(position) self._model.ctrlFrame.newPosition = position # Sync between slider and Spinbox self._syncPositionSpinBoxAndPositionSlider(position) def _syncPositionSpinBoxAndPositionSlider(self, position): ''' Update and Sync of the GUI-Values ''' self._ui.positionSlider.setValue(position) self._ui.positionspinBox.setValue(position) def _setUiInputsToDefault(self): ''' Set UI elements to default values. ''' self._ui.pushButtonEnableMotorCtrl.setChecked( model.DefaultValues.MOTOR_ENABLED) self._onPushButtonEnableMotorCtrl() self._ui.speedSlider.setValue(model.DefaultValues.SPEED) self._ui.positionSlider.setValue(model.DefaultValues.INIT_CURRENT_POS) #self._ui.radioButtonAcceleration1.setChecked(model.DefaultValues.ACCELERATION) self._ui.radioButtonDirectionStop.setChecked( model.DefaultValues.DIRECTION) self._onRadioButtonControlSelection() def _onLicense(self): ''' open message box and show license information ''' # create message box msg = QtWidgets.QMessageBox() # icon information (I) msg.setIcon(QtWidgets.QMessageBox.Information) # text format RichText to interprete links in html style msg.setTextFormat(QtCore.Qt.RichText) # Text string with license text msg.setText(LicenseText) # title of window msg.setWindowTitle("License Information") # show message box msg.exec_() def _onMenuBarItemSelectComPort(self): ''' Selection of COM port. Starts model on valid port selection. ''' #Stop model self._model.stop() #We are no more connected self.setStatusIndicator(Status.TARGET_OFFLINE) #Create dialog for COM port selection qDialog = QDialog() settingWindow = Ui_AppSettings() settingWindow.setupUi(qDialog) #Get COM ports with connected devices ports = sorted([port.device for port in list_ports.comports()]) #Populate comboBox with found COM ports settingWindow.comboBoxComPorts.clear() settingWindow.comboBoxComPorts.addItems(ports) #Show dialog qDialog.exec_() #Evaluate user selection if QDialog.Accepted == qDialog.result(): # User has accepted by pressing OK button #Get selected COM-Port selectedIdx = settingWindow.comboBoxComPorts.currentIndex() comPort = ports[selectedIdx] self._model.start(comPort) else: # User has rejected by pressing CANCEL button pass def _buttonpres(self): ''' action asoziated with Button 1 on the numpad ''' #print(type(self.sender())) buttonpressed = self.sender() #print(type(buttonpressed)) #print(self.sender().text()) self.value = self.numpadWindow.numberToSet.text() self.value = self.value + buttonpressed.text() self.numpadWindow.numberToSet.setText(self.value) def _dellast(self): ''' usebackspace from qLineEdit to remove last number ''' self.numpadWindow.numberToSet.backspace() def _negateValue(self): '''negate value for numpad window ''' currentstring = self.numpadWindow.numberToSet.text() if currentstring: number = int(currentstring) else: number = 0 number = number * (-1) self.numpadWindow.numberToSet.setText(str(number)) def _ChangeSpeed(self): ''' Change speed via Numpad. ''' self.numpadWindow.numberToSet.setValidator(self.qLineValidator( 0, 4992)) # needs to be the same range as set in UI of qt designer #Show dialog self.qDialog.exec_() #Evaluate user selection if QDialog.Accepted == self.qDialog.result(): # User has accepted by pressing OK button #Get selected COM-Port if (self.numpadWindow.numberToSet.text()): speed = int(self.numpadWindow.numberToSet.text()) self._syncSpeedSpinBoxAndSpeedSlider(speed) self.value = str() self.numpadWindow.numberToSet.setText(self.value) else: self._syncSpeedSpinBoxAndSpeedSlider(0) self.value = str() self.numpadWindow.numberToSet.setText(self.value) else: # User has rejected by pressing CANCEL button self.value = str() self.numpadWindow.numberToSet.setText(self.value) pass def _ChangePos(self): ''' Change Position via Numpad ''' self.numpadWindow.numberToSet.setValidator( self.qLineValidator(-16000, 16000) ) # needs to be the same range as set in UI of qt designer #Show dialog self.qDialog.exec_() #Evaluate user selection if QDialog.Accepted == self.qDialog.result(): # User has accepted by pressing OK button #Get selected COM-Port if (self.numpadWindow.numberToSet.text()): pos = int(self.numpadWindow.numberToSet.text() ) #need to protect against no return value self._syncPositionSpinBoxAndPositionSlider(pos) self.value = str() self.numpadWindow.numberToSet.setText(self.value) else: self._syncPositionSpinBoxAndPositionSlider(0) self.value = str() self.numpadWindow.numberToSet.setText(self.value) else: # User has rejected by pressing CANCEL button self.value = str() self.numpadWindow.numberToSet.setText(self.value) pass def _closeApp(self): ''' Close and exit application. ''' sys.exit()