def __init__(self, *args, **kwargs): abstractCustomMinMaxLineEdit.__init__(self, *args, **kwargs) self._setType(self.FLOAT) validator = QDoubleValidator() validator.setNotation(QDoubleValidator.StandardNotation) self.setValidator(validator)
def createDialog (self): """ Create qt dialog """ self.TIMEOUT_ACTION = Settings.instance().readValue( key = 'TestGenerator/timeout-framework-action' ) self.timeoutLine = QLineEdit() self.timeoutLine.setText(str(self.TIMEOUT_ACTION)) validatorTimeout = QDoubleValidator(self) validatorTimeout.setNotation(QDoubleValidator.StandardNotation) self.timeoutLine.setValidator(validatorTimeout) self.timeoutLine.installEventFilter(self) optionLayout = QHBoxLayout() optionLayout.addWidget(QLabel( self.tr("Max time to run action (in seconds):") ) ) optionLayout.addWidget(self.timeoutLine) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setStyleSheet( """QDialogButtonBox { dialogbuttonbox-buttons-have-icons: 1; dialog-ok-icon: url(:/ok.png); dialog-cancel-icon: url(:/ko.png); }""") self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) mainLayout = QVBoxLayout() mainLayout.addLayout(optionLayout) mainLayout.addWidget(self.buttonBox) self.setLayout(mainLayout) self.setWindowTitle(self.tr("Framework Options"))
def double_validator(widget, min=0, max=999999, decimals=3, notation=QDoubleValidator().StandardNotation): validator = QDoubleValidator(min, max, decimals) validator.setNotation(notation) widget.setValidator(validator)
def __init__(self, value, decimals=1): super(QTrapProperty, self).__init__() self.setAlignment(Qt.AlignRight) self.setMaximumWidth(50) self.setMaxLength(7) self.fmt = '%' + '.%df' % decimals v = QDoubleValidator(decimals=decimals) v.setNotation(QDoubleValidator.StandardNotation) self.setValidator(v) self.value = value self.returnPressed.connect(self.updateValue)
def get_point(self, virtual_layer_name): validator = QDoubleValidator(0.00, 999.00, 3) validator.setNotation(QDoubleValidator().StandardNotation) self.dlg_create_circle.radius.setValidator(validator) self.dlg_create_circle.btn_accept.pressed.connect(self.get_radius) self.dlg_create_circle.btn_cancel.pressed.connect(self.cancel) self.dlg_create_circle.radius.setFocus() self.active_layer = self.iface.mapCanvas().currentLayer() self.virtual_layer_polygon = self.controller.get_layer_by_layername(virtual_layer_name, True) # Open dialog self.open_dialog(self.dlg_create_circle, maximize_button=False)
def init_create_circle_form(self, point): # Create the dialog and signals self.dlg_create_circle = Cad_add_circle() self.load_settings(self.dlg_create_circle) self.cancel_circle = False validator = QDoubleValidator(0.00, 999.00, 3) validator.setNotation(QDoubleValidator().StandardNotation) self.dlg_create_circle.radius.setValidator(validator) self.dlg_create_circle.btn_accept.clicked.connect( partial(self.get_radius, point)) self.dlg_create_circle.btn_cancel.clicked.connect(self.cancel) self.dlg_create_circle.radius.setFocus() self.dlg_create_circle.exec_()
def createDialog(self): """ Create qt dialog """ self.TIMEOUT_ANDROID_ACTION = Settings.instance().readValue( key='TestGenerator/timeout-android-action') self.timeoutAndroidLine = QLineEdit() self.timeoutAndroidLine.setText(str(self.TIMEOUT_ANDROID_ACTION)) validatorAndroid = QDoubleValidator(self) validatorAndroid.setNotation(QDoubleValidator.StandardNotation) self.timeoutAndroidLine.setValidator(validatorAndroid) self.timeoutAndroidLine.installEventFilter(self) self.agentNameLineAndroid = QLineEdit("AGENT_ANDROID") self.agentsAndroidList = QComboBox() self.agentsAndroidList.setMinimumWidth(300) optionAndroidLayout = QGridLayout() optionAndroidLayout.addWidget( QLabel(self.tr("Max time to run action:")), 1, 0) optionAndroidLayout.addWidget(self.timeoutAndroidLine, 1, 1) optionAndroidLayout.addWidget(QLabel(self.tr("Agent Key Name:")), 3, 0) optionAndroidLayout.addWidget(self.agentNameLineAndroid, 3, 1) optionAndroidLayout.addWidget(QLabel(self.tr("Agent:")), 4, 0) optionAndroidLayout.addWidget(self.agentsAndroidList, 4, 1) self.buttonBox = QDialogButtonBox(self) self.buttonBox.setStyleSheet("""QDialogButtonBox { dialogbuttonbox-buttons-have-icons: 1; dialog-ok-icon: url(:/ok.png); dialog-cancel-icon: url(:/ko.png); }""") self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) mainLayout = QVBoxLayout() mainLayout.addLayout(optionAndroidLayout) mainLayout.addWidget(self.buttonBox) self.setLayout(mainLayout) self.setWindowTitle(self.tr("Android Options"))
def get_point(self, virtual_layer_name): validator = QDoubleValidator(-99999.99, 99999.999, 3) validator.setNotation(QDoubleValidator().StandardNotation) self.dlg_create_point.dist_x.setValidator(validator) validator = QDoubleValidator(-99999.99, 99999.999, 3) validator.setNotation(QDoubleValidator().StandardNotation) self.dlg_create_point.dist_y.setValidator(validator) self.dlg_create_point.btn_accept.pressed.connect(self.get_values) self.dlg_create_point.btn_cancel.pressed.connect(self.cancel) self.dlg_create_point.dist_x.setFocus() self.active_layer = self.iface.mapCanvas().currentLayer() self.virtual_layer_point = self.controller.get_layer_by_layername( virtual_layer_name, True) # Open dialog self.open_dialog(self.dlg_create_point, maximize_button=False)
def init_create_point_form(self, point_1=None, point_2=None): # Create the dialog and signals self.dlg_create_point = Cad_add_point() self.load_settings(self.dlg_create_point) validator = QDoubleValidator(-99999.99, 99999.999, 3) validator.setNotation(QDoubleValidator().StandardNotation) self.dlg_create_point.dist_x.setValidator(validator) validator = QDoubleValidator(-99999.99, 99999.999, 3) validator.setNotation(QDoubleValidator().StandardNotation) self.dlg_create_point.dist_y.setValidator(validator) self.dlg_create_point.dist_x.setFocus() self.dlg_create_point.btn_accept.clicked.connect( partial(self.get_values, point_1, point_2)) self.dlg_create_point.btn_cancel.clicked.connect(self.cancel) rb_left = self.controller.plugin_settings_value( self.dlg_create_point.rb_left.objectName()) if rb_left == 'true': self.dlg_create_point.rb_left.setChecked(True) else: self.dlg_create_point.rb_right.setChecked(True) self.open_dialog(self.dlg_create_point, maximize_button=False)
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) self.setupUi(self) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.confParam = { 'rowsF': 50.0, 'colsF': 100.0, 'focusF': 35.0, 'numCamerasF': 6, 'distPowerF': 0.5, 'pheromPowerF': 0.5, 'evaporationF': 0.2, 'numAntsF': 5, 'numCrazyF': 5.0, 'minThresholdF': 2.0 } onlyFloat = QDoubleValidator() onlyFloat.setNotation(QDoubleValidator.StandardNotation) onlyInt = QIntValidator() # Default initialization of variables self.rows.setText('50') self.rows.setValidator(onlyFloat) self.rows.textEdited.connect(self.getRows) self.cols.setText('100') self.cols.setValidator(onlyFloat) self.cols.textEdited.connect(self.getCols) self.focus.setText('35') self.focus.setValidator(onlyFloat) self.focus.textEdited.connect(self.getFocus) self.numCameras.setText('6') self.numCameras.setValidator(onlyInt) self.numCameras.textEdited.connect(self.getCameras) self.distPower.setText('0.5') self.distPower.setValidator(onlyFloat) self.distPower.textEdited.connect(self.getDistPower) self.pheromPower.setText('0.5') self.pheromPower.setValidator(onlyFloat) self.pheromPower.textEdited.connect(self.getPheromPower) self.evaporation.setText('0.2') self.evaporation.setValidator(onlyFloat) self.evaporation.textEdited.connect(self.getEvaporation) self.numAnts.setText('5') self.numAnts.setValidator(onlyInt) self.numAnts.textEdited.connect(self.getAnts) self.numCrazy.setText('5') self.numCrazy.setValidator(onlyFloat) self.numCrazy.textEdited.connect(self.getCrazy) self.minThreshold.setText('2.0') self.minThreshold.setValidator(onlyFloat) self.minThreshold.textEdited.connect(self.getThreshold) # Initial labels self.state.setText('Estado: Configuration') self.state.setStyleSheet('QLabel#state {color: gray}') self.setGeometry(0, 0, 2000, 1000) self.process.setText('') self.listProcess.setText('') self.result.setText('') # It connects the button to start the application self.start.clicked.connect(self.button_clicked) # Window is showed self.show()
class RunDialog(QDialog): """ Run parameters dialog implementation """ # See utils.run for runParameters def __init__(self, path, runParameters, termType, profilerParams, debuggerParams, action="", parent=None): QDialog.__init__(self, parent) # Used as a return value self.termType = termType self.profilerParams = copy.deepcopy(profilerParams) self.debuggerParams = copy.deepcopy(debuggerParams) self.__action = action.lower() # Avoid pylint complains self.__argsEdit = None self.__scriptWDRButton = None self.__dirRButton = None self.__dirEdit = None self.__dirSelectButton = None self.__inheritParentRButton = None self.__inheritParentPlusRButton = None self.__inhPlusEnvTable = None self.__addInhButton = None self.__delInhButton = None self.__editInhButton = None self.__specificRButton = None self.__specEnvTable = None self.__addSpecButton = None self.__delSpecButton = None self.__editSpecButton = None self.__runButton = None self.__nodeLimitEdit = None self.__edgeLimitEdit = None self.__createLayout(action) self.setWindowTitle(action + " parameters for " + path) # Restore the values self.runParams = copy.deepcopy(runParameters) self.__argsEdit.setText(self.runParams.arguments) # Working dir if self.runParams.useScriptLocation: self.__scriptWDRButton.setChecked(True) self.__dirEdit.setEnabled(False) self.__dirSelectButton.setEnabled(False) else: self.__dirRButton.setChecked(True) self.__dirEdit.setEnabled(True) self.__dirSelectButton.setEnabled(True) self.__dirEdit.setText(self.runParams.specificDir) # Environment self.__populateTable(self.__inhPlusEnvTable, self.runParams.additionToParentEnv) self.__populateTable(self.__specEnvTable, self.runParams.specificEnv) if self.runParams.envType == RunParameters.InheritParentEnv: self.__inheritParentRButton.setChecked(True) self.__setEnabledInheritedPlusEnv(False) self.__setEnabledSpecificEnv(False) elif self.runParams.envType == RunParameters.InheritParentEnvPlus: self.__inheritParentPlusRButton.setChecked(True) self.__setEnabledSpecificEnv(False) else: self.__specificRButton.setChecked(True) self.__setEnabledInheritedPlusEnv(False) # Terminal if self.termType == TERM_REDIRECT: self.__redirectRButton.setChecked(True) elif self.termType == TERM_AUTO: self.__autoRButton.setChecked(True) elif self.termType == TERM_KONSOLE: self.__konsoleRButton.setChecked(True) elif self.termType == TERM_GNOME: self.__gnomeRButton.setChecked(True) else: self.__xtermRButton.setChecked(True) # Close checkbox self.__closeCheckBox.setChecked(self.runParams.closeTerminal) if self.termType == TERM_REDIRECT: self.__closeCheckBox.setEnabled(False) # Profile limits if so if self.__action == "profile": if self.profilerParams.nodeLimit < 0.0 or \ self.profilerParams.nodeLimit > 100.0: self.profilerParams.nodeLimit = 1.0 self.__nodeLimitEdit.setText(str(self.profilerParams.nodeLimit)) if self.profilerParams.edgeLimit < 0.0 or \ self.profilerParams.edgeLimit > 100.0: self.profilerParams.edgeLimit = 1.0 self.__edgeLimitEdit.setText(str(self.profilerParams.edgeLimit)) elif self.__action == "debug": self.__reportExceptionCheckBox.setChecked( self.debuggerParams.reportExceptions) self.__traceInterpreterCheckBox.setChecked( self.debuggerParams.traceInterpreter) self.__stopAtFirstCheckBox.setChecked( self.debuggerParams.stopAtFirstLine) self.__autoforkCheckBox.setChecked(self.debuggerParams.autofork) self.__debugChildCheckBox.setChecked( self.debuggerParams.followChild) self.__debugChildCheckBox.setEnabled(self.debuggerParams.autofork) self.__setRunButtonProps() return @staticmethod def __populateTable(table, dictionary): " Populates the given table " for key, value in dictionary.iteritems(): item = QTreeWidgetItem([key, value]) table.addTopLevelItem(item) if dictionary: table.setCurrentItem(table.topLevelItem(0)) return def __setEnabledInheritedPlusEnv(self, value): " Disables/enables 'inherited and add' section controls " self.__inhPlusEnvTable.setEnabled(value) self.__addInhButton.setEnabled(value) self.__delInhButton.setEnabled(value) self.__editInhButton.setEnabled(value) return def __setEnabledSpecificEnv(self, value): " Disables/enables 'specific env' section controls " self.__specEnvTable.setEnabled(value) self.__addSpecButton.setEnabled(value) self.__delSpecButton.setEnabled(value) self.__editSpecButton.setEnabled(value) return def __createLayout(self, action): """ Creates the dialog layout """ self.resize(650, 300) self.setSizeGripEnabled(True) # Top level layout layout = QVBoxLayout(self) # Cmd line arguments argsLabel = QLabel("Command line arguments") self.__argsEdit = QLineEdit() self.__argsEdit.textChanged.connect(self.__argsChanged) argsLayout = QHBoxLayout() argsLayout.addWidget(argsLabel) argsLayout.addWidget(self.__argsEdit) layout.addLayout(argsLayout) # Working directory workDirGroupbox = QGroupBox(self) workDirGroupbox.setTitle("Working directory") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( \ workDirGroupbox.sizePolicy().hasHeightForWidth() ) workDirGroupbox.setSizePolicy(sizePolicy) gridLayoutWD = QGridLayout(workDirGroupbox) self.__scriptWDRButton = QRadioButton(workDirGroupbox) self.__scriptWDRButton.setText("&Use script location") gridLayoutWD.addWidget(self.__scriptWDRButton, 0, 0) self.__scriptWDRButton.clicked.connect(self.__scriptWDirClicked) self.__dirRButton = QRadioButton(workDirGroupbox) self.__dirRButton.setText("Select &directory") gridLayoutWD.addWidget(self.__dirRButton, 1, 0) self.__dirRButton.clicked.connect(self.__dirClicked) self.__dirEdit = QLineEdit(workDirGroupbox) gridLayoutWD.addWidget(self.__dirEdit, 1, 1) self.__dirEdit.textChanged.connect(self.__workingDirChanged) self.__dirSelectButton = QPushButton(workDirGroupbox) self.__dirSelectButton.setText("...") gridLayoutWD.addWidget(self.__dirSelectButton, 1, 2) self.__dirSelectButton.clicked.connect(self.__selectDirClicked) layout.addWidget(workDirGroupbox) # Environment envGroupbox = QGroupBox(self) envGroupbox.setTitle("Environment") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( \ envGroupbox.sizePolicy().hasHeightForWidth() ) envGroupbox.setSizePolicy(sizePolicy) layoutEnv = QVBoxLayout(envGroupbox) self.__inheritParentRButton = QRadioButton(envGroupbox) self.__inheritParentRButton.setText("Inherit &parent") self.__inheritParentRButton.clicked.connect(self.__inhClicked) layoutEnv.addWidget(self.__inheritParentRButton) self.__inheritParentPlusRButton = QRadioButton(envGroupbox) self.__inheritParentPlusRButton.setText( "Inherit parent and add/&modify") self.__inheritParentPlusRButton.clicked.connect(self.__inhPlusClicked) layoutEnv.addWidget(self.__inheritParentPlusRButton) hInhPlusLayout = QHBoxLayout() self.__inhPlusEnvTable = QTreeWidget() self.__inhPlusEnvTable.itemActivated.connect( self.__inhPlusItemActivated) self.__tuneTable(self.__inhPlusEnvTable) hInhPlusLayout.addWidget(self.__inhPlusEnvTable) vInhPlusLayout = QVBoxLayout() self.__addInhButton = QPushButton() self.__addInhButton.clicked.connect(self.__addInhClicked) self.__addInhButton.setText('Add') vInhPlusLayout.addWidget(self.__addInhButton) self.__delInhButton = QPushButton() self.__delInhButton.clicked.connect(self.__delInhClicked) self.__delInhButton.setText('Delete') vInhPlusLayout.addWidget(self.__delInhButton) self.__editInhButton = QPushButton() self.__editInhButton.clicked.connect(self.__editInhClicked) self.__editInhButton.setText("Edit") vInhPlusLayout.addWidget(self.__editInhButton) hInhPlusLayout.addLayout(vInhPlusLayout) layoutEnv.addLayout(hInhPlusLayout) self.__specificRButton = QRadioButton(envGroupbox) self.__specificRButton.setText("&Specific") self.__specificRButton.clicked.connect(self.__specClicked) layoutEnv.addWidget(self.__specificRButton) hSpecLayout = QHBoxLayout() self.__specEnvTable = QTreeWidget() self.__specEnvTable.itemActivated.connect(self.__specItemActivated) self.__tuneTable(self.__specEnvTable) hSpecLayout.addWidget(self.__specEnvTable) vSpecLayout = QVBoxLayout() self.__addSpecButton = QPushButton() self.__addSpecButton.clicked.connect(self.__addSpecClicked) self.__addSpecButton.setText('Add') vSpecLayout.addWidget(self.__addSpecButton) self.__delSpecButton = QPushButton() self.__delSpecButton.clicked.connect(self.__delSpecClicked) self.__delSpecButton.setText('Delete') vSpecLayout.addWidget(self.__delSpecButton) self.__editSpecButton = QPushButton() self.__editSpecButton.clicked.connect(self.__editSpecClicked) self.__editSpecButton.setText("Edit") vSpecLayout.addWidget(self.__editSpecButton) hSpecLayout.addLayout(vSpecLayout) layoutEnv.addLayout(hSpecLayout) layout.addWidget(envGroupbox) # Terminal and profile limits if self.__action in ["profile", "debug"]: layout.addWidget(self.__getIDEWideGroupbox()) else: termGroupbox = self.__getTermGroupbox() termGroupbox.setTitle("Terminal to run in (IDE wide setting)") layout.addWidget(termGroupbox) # Close checkbox self.__closeCheckBox = QCheckBox("&Close terminal upon " "successful completion") self.__closeCheckBox.stateChanged.connect(self.__onCloseChanged) layout.addWidget(self.__closeCheckBox) # Buttons at the bottom buttonBox = QDialogButtonBox(self) buttonBox.setOrientation(Qt.Horizontal) buttonBox.setStandardButtons(QDialogButtonBox.Cancel) self.__runButton = buttonBox.addButton(action, QDialogButtonBox.AcceptRole) self.__runButton.setDefault(True) self.__runButton.clicked.connect(self.onAccept) layout.addWidget(buttonBox) buttonBox.rejected.connect(self.close) return def __getTermGroupbox(self): " Creates the term groupbox " termGroupbox = QGroupBox(self) sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( termGroupbox.sizePolicy().hasHeightForWidth()) termGroupbox.setSizePolicy(sizePolicy) layoutTerm = QVBoxLayout(termGroupbox) self.__redirectRButton = QRadioButton(termGroupbox) self.__redirectRButton.setText("&Redirect to IDE") self.__redirectRButton.toggled.connect(self.__redirectedChanged) layoutTerm.addWidget(self.__redirectRButton) self.__autoRButton = QRadioButton(termGroupbox) self.__autoRButton.setText("Aut&o detection") layoutTerm.addWidget(self.__autoRButton) self.__konsoleRButton = QRadioButton(termGroupbox) self.__konsoleRButton.setText("Default &KDE konsole") layoutTerm.addWidget(self.__konsoleRButton) self.__gnomeRButton = QRadioButton(termGroupbox) self.__gnomeRButton.setText("gnome-&terminal") layoutTerm.addWidget(self.__gnomeRButton) self.__xtermRButton = QRadioButton(termGroupbox) self.__xtermRButton.setText("&xterm") layoutTerm.addWidget(self.__xtermRButton) return termGroupbox def __redirectedChanged(self, checked): " Triggered when the redirected radio button changes its state " self.__closeCheckBox.setEnabled(not checked) return def __getIDEWideGroupbox(self): " Creates the IDE wide groupbox " ideGroupbox = QGroupBox(self) ideGroupbox.setTitle("IDE Wide Settings") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( ideGroupbox.sizePolicy().hasHeightForWidth()) ideGroupbox.setSizePolicy(sizePolicy) layoutIDE = QHBoxLayout(ideGroupbox) termGroupbox = self.__getTermGroupbox() termGroupbox.setTitle("Terminal to run in") layoutIDE.addWidget(termGroupbox) if self.__action == "profile": # Profile version of the dialog limitsGroupbox = self.__getProfileLimitsGroupbox() layoutIDE.addWidget(limitsGroupbox) else: # Debug version of the dialog dbgGroupbox = self.__getDebugGroupbox() layoutIDE.addWidget(dbgGroupbox) return ideGroupbox def __getProfileLimitsGroupbox(self): " Creates the profile limits groupbox " limitsGroupbox = QGroupBox(self) limitsGroupbox.setTitle("Profiler diagram limits") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( limitsGroupbox.sizePolicy().hasHeightForWidth()) limitsGroupbox.setSizePolicy(sizePolicy) layoutLimits = QGridLayout(limitsGroupbox) self.__nodeLimitEdit = QLineEdit() self.__nodeLimitEdit.textEdited.connect(self.__setRunButtonProps) self.__nodeLimitValidator = QDoubleValidator(0.0, 100.0, 2, self) self.__nodeLimitValidator.setNotation( QDoubleValidator.StandardNotation) self.__nodeLimitEdit.setValidator(self.__nodeLimitValidator) nodeLimitLabel = QLabel("Hide nodes below") self.__edgeLimitEdit = QLineEdit() self.__edgeLimitEdit.textEdited.connect(self.__setRunButtonProps) self.__edgeLimitValidator = QDoubleValidator(0.0, 100.0, 2, self) self.__edgeLimitValidator.setNotation( QDoubleValidator.StandardNotation) self.__edgeLimitEdit.setValidator(self.__edgeLimitValidator) edgeLimitLabel = QLabel("Hide edges below") layoutLimits.addWidget(nodeLimitLabel, 0, 0) layoutLimits.addWidget(self.__nodeLimitEdit, 0, 1) layoutLimits.addWidget(QLabel("%"), 0, 2) layoutLimits.addWidget(edgeLimitLabel, 1, 0) layoutLimits.addWidget(self.__edgeLimitEdit, 1, 1) layoutLimits.addWidget(QLabel("%"), 1, 2) return limitsGroupbox def __getDebugGroupbox(self): " Creates the debug settings groupbox " dbgGroupbox = QGroupBox(self) dbgGroupbox.setTitle("Debugger") sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( dbgGroupbox.sizePolicy().hasHeightForWidth()) dbgGroupbox.setSizePolicy(sizePolicy) dbgLayout = QVBoxLayout(dbgGroupbox) self.__reportExceptionCheckBox = QCheckBox("Report &exceptions") self.__reportExceptionCheckBox.stateChanged.connect( self.__onReportExceptionChanged) self.__traceInterpreterCheckBox = QCheckBox("T&race interpreter libs") self.__traceInterpreterCheckBox.stateChanged.connect( self.__onTraceInterpreterChanged) self.__stopAtFirstCheckBox = QCheckBox("Stop at first &line") self.__stopAtFirstCheckBox.stateChanged.connect( self.__onStopAtFirstChanged) self.__autoforkCheckBox = QCheckBox("&Fork without asking") self.__autoforkCheckBox.stateChanged.connect(self.__onAutoforkChanged) self.__debugChildCheckBox = QCheckBox("Debu&g child process") self.__debugChildCheckBox.stateChanged.connect(self.__onDebugChild) dbgLayout.addWidget(self.__reportExceptionCheckBox) dbgLayout.addWidget(self.__traceInterpreterCheckBox) dbgLayout.addWidget(self.__stopAtFirstCheckBox) dbgLayout.addWidget(self.__autoforkCheckBox) dbgLayout.addWidget(self.__debugChildCheckBox) return dbgGroupbox @staticmethod def __tuneTable(table): " Sets the common settings for a table " table.setAlternatingRowColors(True) table.setRootIsDecorated(False) table.setItemsExpandable(False) table.setUniformRowHeights(True) table.setSelectionMode(QAbstractItemView.SingleSelection) table.setSelectionBehavior(QAbstractItemView.SelectRows) table.setItemDelegate(NoOutlineHeightDelegate(4)) table.setHeaderLabels(["Variable", "Value"]) header = table.header() header.setSortIndicator(0, Qt.AscendingOrder) header.setSortIndicatorShown(True) header.setClickable(True) table.setSortingEnabled(True) return def __scriptWDirClicked(self): " The script working dir button is clicked " self.__dirEdit.setEnabled(False) self.__dirSelectButton.setEnabled(False) self.runParams.useScriptLocation = True self.__setRunButtonProps() return def __dirClicked(self): " The script specific working dir button is clicked " self.__dirEdit.setEnabled(True) self.__dirSelectButton.setEnabled(True) self.runParams.useScriptLocation = False self.__setRunButtonProps() return def __argsChanged(self, value): " Triggered when cmd line args are changed " value = str(value).strip() self.runParams.arguments = value self.__setRunButtonProps() return def __workingDirChanged(self, value): " Triggered when a working dir value is changed " value = str(value) self.runParams.specificDir = value self.__setRunButtonProps() return def __onCloseChanged(self, state): " Triggered when the close terminal check box changed " self.runParams.closeTerminal = state != 0 return def __onReportExceptionChanged(self, state): " Triggered when exception report check box changed " self.debuggerParams.reportExceptions = state != 0 return def __onTraceInterpreterChanged(self, state): " Triggered when trace interpreter changed " self.debuggerParams.traceInterpreter = state != 0 return def __onStopAtFirstChanged(self, state): " Triggered when stop at first changed " self.debuggerParams.stopAtFirstLine = state != 0 return def __onAutoforkChanged(self, state): " Triggered when autofork changed " self.debuggerParams.autofork = state != 0 self.__debugChildCheckBox.setEnabled(self.debuggerParams.autofork) return def __onDebugChild(self, state): " Triggered when debug child changed " self.debuggerParams.followChild = state != 0 return def __argumentsOK(self): " Returns True if the arguments are OK " try: parseCommandLineArguments(self.runParams.arguments) return True except: return False def __dirOK(self): " Returns True if the working dir is OK " if self.__scriptWDRButton.isChecked(): return True return os.path.isdir(self.__dirEdit.text()) def __setRunButtonProps(self, newText=None): " Enable/disable run button and set its tooltip " if not self.__argumentsOK(): self.__runButton.setEnabled(False) self.__runButton.setToolTip("No closing quotation in arguments") return if not self.__dirOK(): self.__runButton.setEnabled(False) self.__runButton.setToolTip("The given working " "dir is not found") return if self.__nodeLimitEdit is not None: txt = self.__nodeLimitEdit.text().strip() try: value = float(txt) if value < 0.0 or value > 100.0: raise Exception("Out of range") except: self.__runButton.setEnabled(False) self.__runButton.setToolTip("The given node limit " "is out of range") return if self.__edgeLimitEdit is not None: txt = self.__edgeLimitEdit.text().strip() try: value = float(txt) if value < 0.0 or value > 100.0: raise Exception("Out of range") except: self.__runButton.setEnabled(False) self.__runButton.setToolTip("The given edge limit " "is out of range") return self.__runButton.setEnabled(True) self.__runButton.setToolTip("Save parameters and " + self.__action + " script") return def __selectDirClicked(self): " Selects the script working dir " dirName = QFileDialog.getExistingDirectory( self, "Select the script working directory", self.__dirEdit.text(), QFileDialog.Options(QFileDialog.ShowDirsOnly)) if dirName: self.__dirEdit.setText(os.path.normpath(dirName)) return def __inhClicked(self): " Inerit parent env radio button clicked " self.__setEnabledInheritedPlusEnv(False) self.__setEnabledSpecificEnv(False) self.runParams.envType = RunParameters.InheritParentEnv return def __inhPlusClicked(self): " Inherit parent and add radio button clicked " self.__setEnabledInheritedPlusEnv(True) self.__setEnabledSpecificEnv(False) self.runParams.envType = RunParameters.InheritParentEnvPlus if self.__inhPlusEnvTable.selectedIndexes(): self.__delInhButton.setEnabled(True) self.__editInhButton.setEnabled(True) else: self.__delInhButton.setEnabled(False) self.__editInhButton.setEnabled(False) return def __specClicked(self): " Specific env radio button clicked " self.__setEnabledInheritedPlusEnv(False) self.__setEnabledSpecificEnv(True) self.runParams.envType = RunParameters.SpecificEnvironment if self.__specEnvTable.selectedIndexes(): self.__delSpecButton.setEnabled(True) self.__editSpecButton.setEnabled(True) else: self.__delSpecButton.setEnabled(False) self.__editSpecButton.setEnabled(False) return @staticmethod def __delAndInsert(table, name, value): " Deletes an item by name if so; insert new; highlight it " for index in xrange(table.topLevelItemCount()): item = table.topLevelItem(index) if str(item.text(0)) == name: table.takeTopLevelItem(index) break item = QTreeWidgetItem([name, value]) table.addTopLevelItem(item) table.setCurrentItem(item) return item def __addInhClicked(self): " Add env var button clicked " dlg = EnvVarDialog() if dlg.exec_() == QDialog.Accepted: name = str(dlg.name) value = str(dlg.value) self.__delAndInsert(self.__inhPlusEnvTable, name, value) self.runParams.additionToParentEnv[name] = value self.__delInhButton.setEnabled(True) self.__editInhButton.setEnabled(True) return def __addSpecClicked(self): " Add env var button clicked " dlg = EnvVarDialog() if dlg.exec_() == QDialog.Accepted: name = str(dlg.name) value = str(dlg.value) self.__delAndInsert(self.__specEnvTable, name, value) self.runParams.specificEnv[name] = value self.__delSpecButton.setEnabled(True) self.__editSpecButton.setEnabled(True) return def __delInhClicked(self): " Delete the highlighted variable " if self.__inhPlusEnvTable.topLevelItemCount() == 0: return name = self.__inhPlusEnvTable.currentItem().text(0) for index in xrange(self.__inhPlusEnvTable.topLevelItemCount()): item = self.__inhPlusEnvTable.topLevelItem(index) if name == item.text(0): self.__inhPlusEnvTable.takeTopLevelItem(index) break del self.runParams.additionToParentEnv[str(name)] if self.__inhPlusEnvTable.topLevelItemCount() == 0: self.__delInhButton.setEnabled(False) self.__editInhButton.setEnabled(False) else: self.__inhPlusEnvTable.setCurrentItem( \ self.__inhPlusEnvTable.topLevelItem( 0 ) ) return def __delSpecClicked(self): " Delete the highlighted variable " if self.__specEnvTable.topLevelItemCount() == 0: return name = self.__specEnvTable.currentItem().text(0) for index in xrange(self.__specEnvTable.topLevelItemCount()): item = self.__specEnvTable.topLevelItem(index) if name == item.text(0): self.__specEnvTable.takeTopLevelItem(index) break del self.runParams.specificEnv[str(name)] if self.__specEnvTable.topLevelItemCount() == 0: self.__delSpecButton.setEnabled(False) self.__editSpecButton.setEnabled(False) else: self.__specEnvTable.setCurrentItem( \ self.__specEnvTable.topLevelItem( 0 ) ) return def __editInhClicked(self): " Edits the highlighted variable " if self.__inhPlusEnvTable.topLevelItemCount() == 0: return item = self.__inhPlusEnvTable.currentItem() dlg = EnvVarDialog(str(item.text(0)), str(item.text(1)), self) if dlg.exec_() == QDialog.Accepted: name = str(dlg.name) value = str(dlg.value) self.__delAndInsert(self.__inhPlusEnvTable, name, value) self.runParams.additionToParentEnv[name] = value return def __inhPlusItemActivated(self, item, column): " Triggered when a table item is activated " self.__editInhClicked() return def __editSpecClicked(self): " Edits the highlighted variable " if self.__specEnvTable.topLevelItemCount() == 0: return item = self.__specEnvTable.currentItem() dlg = EnvVarDialog(str(item.text(0)), str(item.text(1)), self) if dlg.exec_() == QDialog.Accepted: name = str(dlg.name) value = str(dlg.value) self.__delAndInsert(self.__specEnvTable, name, value) self.runParams.specificEnv[name] = value return def __specItemActivated(self, item, column): " Triggered when a table item is activated " self.__editSpecClicked() return def onAccept(self): " Saves the selected terminal and profiling values " if self.__redirectRButton.isChecked(): self.termType = TERM_REDIRECT elif self.__autoRButton.isChecked(): self.termType = TERM_AUTO elif self.__konsoleRButton.isChecked(): self.termType = TERM_KONSOLE elif self.__gnomeRButton.isChecked(): self.termType = TERM_GNOME else: self.termType = TERM_XTERM if self.__action == "profile": self.profilerParams.nodeLimit = float(self.__nodeLimitEdit.text()) self.profilerParams.edgeLimit = float(self.__edgeLimitEdit.text()) self.accept() return
def double_validator(self, widget): validator = QDoubleValidator(-9999999, 99, 2) validator.setNotation(QDoubleValidator().StandardNotation) widget.setValidator(validator)
class RunDialog( QDialog ): """ Run parameters dialog implementation """ # See utils.run for runParameters def __init__( self, path, runParameters, termType, profilerParams, debuggerParams, action = "", parent = None ): QDialog.__init__( self, parent ) # Used as a return value self.termType = termType self.profilerParams = copy.deepcopy( profilerParams ) self.debuggerParams = copy.deepcopy( debuggerParams ) self.__action = action.lower() # Avoid pylint complains self.__argsEdit = None self.__scriptWDRButton = None self.__dirRButton = None self.__dirEdit = None self.__dirSelectButton = None self.__inheritParentRButton = None self.__inheritParentPlusRButton = None self.__inhPlusEnvTable = None self.__addInhButton = None self.__delInhButton = None self.__editInhButton = None self.__specificRButton = None self.__specEnvTable = None self.__addSpecButton = None self.__delSpecButton = None self.__editSpecButton = None self.__runButton = None self.__nodeLimitEdit = None self.__edgeLimitEdit = None self.__createLayout( action ) self.setWindowTitle( action + " parameters for " + path ) # Restore the values self.runParams = copy.deepcopy( runParameters ) self.__argsEdit.setText( self.runParams.arguments ) # Working dir if self.runParams.useScriptLocation: self.__scriptWDRButton.setChecked( True ) self.__dirEdit.setEnabled( False ) self.__dirSelectButton.setEnabled( False ) else: self.__dirRButton.setChecked( True ) self.__dirEdit.setEnabled( True ) self.__dirSelectButton.setEnabled( True ) self.__dirEdit.setText( self.runParams.specificDir ) # Environment self.__populateTable( self.__inhPlusEnvTable, self.runParams.additionToParentEnv ) self.__populateTable( self.__specEnvTable, self.runParams.specificEnv ) if self.runParams.envType == RunParameters.InheritParentEnv: self.__inheritParentRButton.setChecked( True ) self.__setEnabledInheritedPlusEnv( False ) self.__setEnabledSpecificEnv( False ) elif self.runParams.envType == RunParameters.InheritParentEnvPlus: self.__inheritParentPlusRButton.setChecked( True ) self.__setEnabledSpecificEnv( False ) else: self.__specificRButton.setChecked( True ) self.__setEnabledInheritedPlusEnv( False ) # Terminal if self.termType == TERM_REDIRECT: self.__redirectRButton.setChecked( True ) elif self.termType == TERM_AUTO: self.__autoRButton.setChecked( True ) elif self.termType == TERM_KONSOLE: self.__konsoleRButton.setChecked( True ) elif self.termType == TERM_GNOME: self.__gnomeRButton.setChecked( True ) else: self.__xtermRButton.setChecked( True ) # Close checkbox self.__closeCheckBox.setChecked( self.runParams.closeTerminal ) if self.termType == TERM_REDIRECT: self.__closeCheckBox.setEnabled( False ) # Profile limits if so if self.__action == "profile": if self.profilerParams.nodeLimit < 0.0 or \ self.profilerParams.nodeLimit > 100.0: self.profilerParams.nodeLimit = 1.0 self.__nodeLimitEdit.setText( str( self.profilerParams.nodeLimit ) ) if self.profilerParams.edgeLimit < 0.0 or \ self.profilerParams.edgeLimit > 100.0: self.profilerParams.edgeLimit = 1.0 self.__edgeLimitEdit.setText( str( self.profilerParams.edgeLimit ) ) elif self.__action == "debug": self.__reportExceptionCheckBox.setChecked( self.debuggerParams.reportExceptions ) self.__traceInterpreterCheckBox.setChecked( self.debuggerParams.traceInterpreter ) self.__stopAtFirstCheckBox.setChecked( self.debuggerParams.stopAtFirstLine ) self.__autoforkCheckBox.setChecked( self.debuggerParams.autofork ) self.__debugChildCheckBox.setChecked( self.debuggerParams.followChild ) self.__debugChildCheckBox.setEnabled( self.debuggerParams.autofork ) self.__setRunButtonProps() return @staticmethod def __populateTable( table, dictionary ): " Populates the given table " for key, value in dictionary.iteritems(): item = QTreeWidgetItem( [ key, value ] ) table.addTopLevelItem( item ) if dictionary: table.setCurrentItem( table.topLevelItem( 0 ) ) return def __setEnabledInheritedPlusEnv( self, value ): " Disables/enables 'inherited and add' section controls " self.__inhPlusEnvTable.setEnabled( value ) self.__addInhButton.setEnabled( value ) self.__delInhButton.setEnabled( value ) self.__editInhButton.setEnabled( value ) return def __setEnabledSpecificEnv( self, value ): " Disables/enables 'specific env' section controls " self.__specEnvTable.setEnabled( value ) self.__addSpecButton.setEnabled( value ) self.__delSpecButton.setEnabled( value ) self.__editSpecButton.setEnabled( value ) return def __createLayout( self, action ): """ Creates the dialog layout """ self.resize( 650, 300 ) self.setSizeGripEnabled( True ) # Top level layout layout = QVBoxLayout( self ) # Cmd line arguments argsLabel = QLabel( "Command line arguments" ) self.__argsEdit = QLineEdit() self.__argsEdit.textChanged.connect( self.__argsChanged ) argsLayout = QHBoxLayout() argsLayout.addWidget( argsLabel ) argsLayout.addWidget( self.__argsEdit ) layout.addLayout( argsLayout ) # Working directory workDirGroupbox = QGroupBox( self ) workDirGroupbox.setTitle( "Working directory" ) sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred ) sizePolicy.setHorizontalStretch( 0 ) sizePolicy.setVerticalStretch( 0 ) sizePolicy.setHeightForWidth( \ workDirGroupbox.sizePolicy().hasHeightForWidth() ) workDirGroupbox.setSizePolicy( sizePolicy ) gridLayoutWD = QGridLayout( workDirGroupbox ) self.__scriptWDRButton = QRadioButton( workDirGroupbox ) self.__scriptWDRButton.setText( "&Use script location" ) gridLayoutWD.addWidget( self.__scriptWDRButton, 0, 0 ) self.__scriptWDRButton.clicked.connect( self.__scriptWDirClicked ) self.__dirRButton = QRadioButton( workDirGroupbox ) self.__dirRButton.setText( "Select &directory" ) gridLayoutWD.addWidget( self.__dirRButton, 1, 0 ) self.__dirRButton.clicked.connect( self.__dirClicked ) self.__dirEdit = QLineEdit( workDirGroupbox ) gridLayoutWD.addWidget( self.__dirEdit, 1, 1 ) self.__dirEdit.textChanged.connect( self.__workingDirChanged ) self.__dirSelectButton = QPushButton( workDirGroupbox ) self.__dirSelectButton.setText( "..." ) gridLayoutWD.addWidget( self.__dirSelectButton, 1, 2 ) self.__dirSelectButton.clicked.connect( self.__selectDirClicked ) layout.addWidget( workDirGroupbox ) # Environment envGroupbox = QGroupBox( self ) envGroupbox.setTitle( "Environment" ) sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred ) sizePolicy.setHorizontalStretch( 0 ) sizePolicy.setVerticalStretch( 0 ) sizePolicy.setHeightForWidth( \ envGroupbox.sizePolicy().hasHeightForWidth() ) envGroupbox.setSizePolicy( sizePolicy ) layoutEnv = QVBoxLayout( envGroupbox ) self.__inheritParentRButton = QRadioButton( envGroupbox ) self.__inheritParentRButton.setText( "Inherit &parent" ) self.__inheritParentRButton.clicked.connect( self.__inhClicked ) layoutEnv.addWidget( self.__inheritParentRButton ) self.__inheritParentPlusRButton = QRadioButton( envGroupbox ) self.__inheritParentPlusRButton.setText( "Inherit parent and add/&modify" ) self.__inheritParentPlusRButton.clicked.connect( self.__inhPlusClicked ) layoutEnv.addWidget( self.__inheritParentPlusRButton ) hInhPlusLayout = QHBoxLayout() self.__inhPlusEnvTable = QTreeWidget() self.__inhPlusEnvTable.itemActivated.connect( self.__inhPlusItemActivated ) self.__tuneTable( self.__inhPlusEnvTable ) hInhPlusLayout.addWidget( self.__inhPlusEnvTable ) vInhPlusLayout = QVBoxLayout() self.__addInhButton = QPushButton() self.__addInhButton.clicked.connect( self.__addInhClicked ) self.__addInhButton.setText( 'Add' ) vInhPlusLayout.addWidget( self.__addInhButton ) self.__delInhButton = QPushButton() self.__delInhButton.clicked.connect( self.__delInhClicked ) self.__delInhButton.setText( 'Delete' ) vInhPlusLayout.addWidget( self.__delInhButton ) self.__editInhButton = QPushButton() self.__editInhButton.clicked.connect( self.__editInhClicked ) self.__editInhButton.setText( "Edit" ) vInhPlusLayout.addWidget( self.__editInhButton ) hInhPlusLayout.addLayout( vInhPlusLayout ) layoutEnv.addLayout( hInhPlusLayout ) self.__specificRButton = QRadioButton( envGroupbox ) self.__specificRButton.setText( "&Specific" ) self.__specificRButton.clicked.connect( self.__specClicked ) layoutEnv.addWidget( self.__specificRButton ) hSpecLayout = QHBoxLayout() self.__specEnvTable = QTreeWidget() self.__specEnvTable.itemActivated.connect( self.__specItemActivated ) self.__tuneTable( self.__specEnvTable ) hSpecLayout.addWidget( self.__specEnvTable ) vSpecLayout = QVBoxLayout() self.__addSpecButton = QPushButton() self.__addSpecButton.clicked.connect( self.__addSpecClicked ) self.__addSpecButton.setText( 'Add' ) vSpecLayout.addWidget( self.__addSpecButton ) self.__delSpecButton = QPushButton() self.__delSpecButton.clicked.connect( self.__delSpecClicked ) self.__delSpecButton.setText( 'Delete' ) vSpecLayout.addWidget( self.__delSpecButton ) self.__editSpecButton = QPushButton() self.__editSpecButton.clicked.connect( self.__editSpecClicked ) self.__editSpecButton.setText( "Edit" ) vSpecLayout.addWidget( self.__editSpecButton ) hSpecLayout.addLayout( vSpecLayout ) layoutEnv.addLayout( hSpecLayout ) layout.addWidget( envGroupbox ) # Terminal and profile limits if self.__action in [ "profile", "debug" ]: layout.addWidget( self.__getIDEWideGroupbox() ) else: termGroupbox = self.__getTermGroupbox() termGroupbox.setTitle( "Terminal to run in (IDE wide setting)" ) layout.addWidget( termGroupbox ) # Close checkbox self.__closeCheckBox = QCheckBox( "&Close terminal upon " "successful completion" ) self.__closeCheckBox.stateChanged.connect( self.__onCloseChanged ) layout.addWidget( self.__closeCheckBox ) # Buttons at the bottom buttonBox = QDialogButtonBox( self ) buttonBox.setOrientation( Qt.Horizontal ) buttonBox.setStandardButtons( QDialogButtonBox.Cancel ) self.__runButton = buttonBox.addButton( action, QDialogButtonBox.AcceptRole ) self.__runButton.setDefault( True ) self.__runButton.clicked.connect( self.onAccept ) layout.addWidget( buttonBox ) buttonBox.rejected.connect( self.close ) return def __getTermGroupbox( self ): " Creates the term groupbox " termGroupbox = QGroupBox( self ) sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred ) sizePolicy.setHorizontalStretch( 0 ) sizePolicy.setVerticalStretch( 0 ) sizePolicy.setHeightForWidth( termGroupbox.sizePolicy().hasHeightForWidth() ) termGroupbox.setSizePolicy( sizePolicy ) layoutTerm = QVBoxLayout( termGroupbox ) self.__redirectRButton = QRadioButton( termGroupbox ) self.__redirectRButton.setText( "&Redirect to IDE" ) self.__redirectRButton.toggled.connect( self.__redirectedChanged ) layoutTerm.addWidget( self.__redirectRButton ) self.__autoRButton = QRadioButton( termGroupbox ) self.__autoRButton.setText( "Aut&o detection" ) layoutTerm.addWidget( self.__autoRButton ) self.__konsoleRButton = QRadioButton( termGroupbox ) self.__konsoleRButton.setText( "Default &KDE konsole" ) layoutTerm.addWidget( self.__konsoleRButton ) self.__gnomeRButton = QRadioButton( termGroupbox ) self.__gnomeRButton.setText( "gnome-&terminal" ) layoutTerm.addWidget( self.__gnomeRButton ) self.__xtermRButton = QRadioButton( termGroupbox ) self.__xtermRButton.setText( "&xterm" ) layoutTerm.addWidget( self.__xtermRButton ) return termGroupbox def __redirectedChanged( self, checked ): " Triggered when the redirected radio button changes its state " self.__closeCheckBox.setEnabled( not checked ) return def __getIDEWideGroupbox( self ): " Creates the IDE wide groupbox " ideGroupbox = QGroupBox( self ) ideGroupbox.setTitle( "IDE Wide Settings" ) sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred ) sizePolicy.setHorizontalStretch( 0 ) sizePolicy.setVerticalStretch( 0 ) sizePolicy.setHeightForWidth( ideGroupbox.sizePolicy().hasHeightForWidth() ) ideGroupbox.setSizePolicy( sizePolicy ) layoutIDE = QHBoxLayout( ideGroupbox ) termGroupbox = self.__getTermGroupbox() termGroupbox.setTitle( "Terminal to run in" ) layoutIDE.addWidget( termGroupbox ) if self.__action == "profile": # Profile version of the dialog limitsGroupbox = self.__getProfileLimitsGroupbox() layoutIDE.addWidget( limitsGroupbox ) else: # Debug version of the dialog dbgGroupbox = self.__getDebugGroupbox() layoutIDE.addWidget( dbgGroupbox ) return ideGroupbox def __getProfileLimitsGroupbox( self ): " Creates the profile limits groupbox " limitsGroupbox = QGroupBox( self ) limitsGroupbox.setTitle( "Profiler diagram limits" ) sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred ) sizePolicy.setHorizontalStretch( 0 ) sizePolicy.setVerticalStretch( 0 ) sizePolicy.setHeightForWidth( limitsGroupbox.sizePolicy().hasHeightForWidth() ) limitsGroupbox.setSizePolicy( sizePolicy ) layoutLimits = QGridLayout( limitsGroupbox ) self.__nodeLimitEdit = QLineEdit() self.__nodeLimitEdit.textEdited.connect( self.__setRunButtonProps ) self.__nodeLimitValidator = QDoubleValidator( 0.0, 100.0, 2, self ) self.__nodeLimitValidator.setNotation( QDoubleValidator.StandardNotation ) self.__nodeLimitEdit.setValidator( self.__nodeLimitValidator ) nodeLimitLabel = QLabel( "Hide nodes below" ) self.__edgeLimitEdit = QLineEdit() self.__edgeLimitEdit.textEdited.connect( self.__setRunButtonProps ) self.__edgeLimitValidator = QDoubleValidator( 0.0, 100.0, 2, self ) self.__edgeLimitValidator.setNotation( QDoubleValidator.StandardNotation ) self.__edgeLimitEdit.setValidator( self.__edgeLimitValidator ) edgeLimitLabel = QLabel( "Hide edges below" ) layoutLimits.addWidget( nodeLimitLabel, 0, 0 ) layoutLimits.addWidget( self.__nodeLimitEdit, 0, 1 ) layoutLimits.addWidget( QLabel( "%" ), 0, 2 ) layoutLimits.addWidget( edgeLimitLabel, 1, 0 ) layoutLimits.addWidget( self.__edgeLimitEdit, 1, 1 ) layoutLimits.addWidget( QLabel( "%" ), 1, 2 ) return limitsGroupbox def __getDebugGroupbox( self ): " Creates the debug settings groupbox " dbgGroupbox = QGroupBox( self ) dbgGroupbox.setTitle( "Debugger" ) sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Preferred ) sizePolicy.setHorizontalStretch( 0 ) sizePolicy.setVerticalStretch( 0 ) sizePolicy.setHeightForWidth( dbgGroupbox.sizePolicy().hasHeightForWidth() ) dbgGroupbox.setSizePolicy( sizePolicy ) dbgLayout = QVBoxLayout( dbgGroupbox ) self.__reportExceptionCheckBox = QCheckBox( "Report &exceptions" ) self.__reportExceptionCheckBox.stateChanged.connect( self.__onReportExceptionChanged ) self.__traceInterpreterCheckBox = QCheckBox( "T&race interpreter libs" ) self.__traceInterpreterCheckBox.stateChanged.connect( self.__onTraceInterpreterChanged ) self.__stopAtFirstCheckBox = QCheckBox( "Stop at first &line" ) self.__stopAtFirstCheckBox.stateChanged.connect( self.__onStopAtFirstChanged ) self.__autoforkCheckBox = QCheckBox( "&Fork without asking" ) self.__autoforkCheckBox.stateChanged.connect(self.__onAutoforkChanged ) self.__debugChildCheckBox = QCheckBox( "Debu&g child process" ) self.__debugChildCheckBox.stateChanged.connect( self.__onDebugChild ) dbgLayout.addWidget( self.__reportExceptionCheckBox ) dbgLayout.addWidget( self.__traceInterpreterCheckBox ) dbgLayout.addWidget( self.__stopAtFirstCheckBox ) dbgLayout.addWidget( self.__autoforkCheckBox ) dbgLayout.addWidget( self.__debugChildCheckBox ) return dbgGroupbox @staticmethod def __tuneTable( table ): " Sets the common settings for a table " table.setAlternatingRowColors( True ) table.setRootIsDecorated( False ) table.setItemsExpandable( False ) table.setUniformRowHeights( True ) table.setSelectionMode( QAbstractItemView.SingleSelection ) table.setSelectionBehavior( QAbstractItemView.SelectRows ) table.setItemDelegate( NoOutlineHeightDelegate( 4 ) ) table.setHeaderLabels( [ "Variable", "Value" ] ) header = table.header() header.setSortIndicator( 0, Qt.AscendingOrder ) header.setSortIndicatorShown( True ) header.setClickable( True ) table.setSortingEnabled( True ) return def __scriptWDirClicked( self ): " The script working dir button is clicked " self.__dirEdit.setEnabled( False ) self.__dirSelectButton.setEnabled( False ) self.runParams.useScriptLocation = True self.__setRunButtonProps() return def __dirClicked( self ): " The script specific working dir button is clicked " self.__dirEdit.setEnabled( True ) self.__dirSelectButton.setEnabled( True ) self.runParams.useScriptLocation = False self.__setRunButtonProps() return def __argsChanged( self, value ): " Triggered when cmd line args are changed " value = str( value ).strip() self.runParams.arguments = value self.__setRunButtonProps() return def __workingDirChanged( self, value ): " Triggered when a working dir value is changed " value = str( value ) self.runParams.specificDir = value self.__setRunButtonProps() return def __onCloseChanged( self, state ): " Triggered when the close terminal check box changed " self.runParams.closeTerminal = state != 0 return def __onReportExceptionChanged( self, state ): " Triggered when exception report check box changed " self.debuggerParams.reportExceptions = state != 0 return def __onTraceInterpreterChanged( self, state ): " Triggered when trace interpreter changed " self.debuggerParams.traceInterpreter = state != 0 return def __onStopAtFirstChanged( self, state ): " Triggered when stop at first changed " self.debuggerParams.stopAtFirstLine = state != 0 return def __onAutoforkChanged( self, state ): " Triggered when autofork changed " self.debuggerParams.autofork = state != 0 self.__debugChildCheckBox.setEnabled( self.debuggerParams.autofork ) return def __onDebugChild( self, state ): " Triggered when debug child changed " self.debuggerParams.followChild = state != 0 return def __argumentsOK( self ): " Returns True if the arguments are OK " try: parseCommandLineArguments( self.runParams.arguments ) return True except: return False def __dirOK( self ): " Returns True if the working dir is OK " if self.__scriptWDRButton.isChecked(): return True return os.path.isdir( self.__dirEdit.text() ) def __setRunButtonProps( self, newText = None ): " Enable/disable run button and set its tooltip " if not self.__argumentsOK(): self.__runButton.setEnabled( False ) self.__runButton.setToolTip( "No closing quotation in arguments" ) return if not self.__dirOK(): self.__runButton.setEnabled( False ) self.__runButton.setToolTip( "The given working " "dir is not found" ) return if self.__nodeLimitEdit is not None: txt = self.__nodeLimitEdit.text().strip() try: value = float( txt ) if value < 0.0 or value > 100.0: raise Exception( "Out of range" ) except: self.__runButton.setEnabled( False ) self.__runButton.setToolTip( "The given node limit " "is out of range" ) return if self.__edgeLimitEdit is not None: txt = self.__edgeLimitEdit.text().strip() try: value = float( txt ) if value < 0.0 or value > 100.0: raise Exception( "Out of range" ) except: self.__runButton.setEnabled( False ) self.__runButton.setToolTip( "The given edge limit " "is out of range" ) return self.__runButton.setEnabled( True ) self.__runButton.setToolTip( "Save parameters and " + self.__action + " script" ) return def __selectDirClicked( self ): " Selects the script working dir " dirName = QFileDialog.getExistingDirectory( self, "Select the script working directory", self.__dirEdit.text(), QFileDialog.Options( QFileDialog.ShowDirsOnly ) ) if dirName: self.__dirEdit.setText( os.path.normpath( dirName ) ) return def __inhClicked( self ): " Inerit parent env radio button clicked " self.__setEnabledInheritedPlusEnv( False ) self.__setEnabledSpecificEnv( False ) self.runParams.envType = RunParameters.InheritParentEnv return def __inhPlusClicked( self ): " Inherit parent and add radio button clicked " self.__setEnabledInheritedPlusEnv( True ) self.__setEnabledSpecificEnv( False ) self.runParams.envType = RunParameters.InheritParentEnvPlus if self.__inhPlusEnvTable.selectedIndexes(): self.__delInhButton.setEnabled( True ) self.__editInhButton.setEnabled( True ) else: self.__delInhButton.setEnabled( False ) self.__editInhButton.setEnabled( False ) return def __specClicked( self ): " Specific env radio button clicked " self.__setEnabledInheritedPlusEnv( False ) self.__setEnabledSpecificEnv( True ) self.runParams.envType = RunParameters.SpecificEnvironment if self.__specEnvTable.selectedIndexes(): self.__delSpecButton.setEnabled( True ) self.__editSpecButton.setEnabled( True ) else: self.__delSpecButton.setEnabled( False ) self.__editSpecButton.setEnabled( False ) return @staticmethod def __delAndInsert( table, name, value ): " Deletes an item by name if so; insert new; highlight it " for index in xrange( table.topLevelItemCount() ): item = table.topLevelItem( index ) if str( item.text( 0 ) ) == name: table.takeTopLevelItem( index ) break item = QTreeWidgetItem( [ name, value ] ) table.addTopLevelItem( item ) table.setCurrentItem( item ) return item def __addInhClicked( self ): " Add env var button clicked " dlg = EnvVarDialog() if dlg.exec_() == QDialog.Accepted: name = str( dlg.name ) value = str( dlg.value ) self.__delAndInsert( self.__inhPlusEnvTable, name, value ) self.runParams.additionToParentEnv[ name ] = value self.__delInhButton.setEnabled( True ) self.__editInhButton.setEnabled( True ) return def __addSpecClicked( self ): " Add env var button clicked " dlg = EnvVarDialog() if dlg.exec_() == QDialog.Accepted: name = str( dlg.name ) value = str( dlg.value ) self.__delAndInsert( self.__specEnvTable, name, value ) self.runParams.specificEnv[ name ] = value self.__delSpecButton.setEnabled( True ) self.__editSpecButton.setEnabled( True ) return def __delInhClicked( self ): " Delete the highlighted variable " if self.__inhPlusEnvTable.topLevelItemCount() == 0: return name = self.__inhPlusEnvTable.currentItem().text( 0 ) for index in xrange( self.__inhPlusEnvTable.topLevelItemCount() ): item = self.__inhPlusEnvTable.topLevelItem( index ) if name == item.text( 0 ): self.__inhPlusEnvTable.takeTopLevelItem( index ) break del self.runParams.additionToParentEnv[ str( name ) ] if self.__inhPlusEnvTable.topLevelItemCount() == 0: self.__delInhButton.setEnabled( False ) self.__editInhButton.setEnabled( False ) else: self.__inhPlusEnvTable.setCurrentItem( \ self.__inhPlusEnvTable.topLevelItem( 0 ) ) return def __delSpecClicked( self ): " Delete the highlighted variable " if self.__specEnvTable.topLevelItemCount() == 0: return name = self.__specEnvTable.currentItem().text( 0 ) for index in xrange( self.__specEnvTable.topLevelItemCount() ): item = self.__specEnvTable.topLevelItem( index ) if name == item.text( 0 ): self.__specEnvTable.takeTopLevelItem( index ) break del self.runParams.specificEnv[ str( name ) ] if self.__specEnvTable.topLevelItemCount() == 0: self.__delSpecButton.setEnabled( False ) self.__editSpecButton.setEnabled( False ) else: self.__specEnvTable.setCurrentItem( \ self.__specEnvTable.topLevelItem( 0 ) ) return def __editInhClicked( self ): " Edits the highlighted variable " if self.__inhPlusEnvTable.topLevelItemCount() == 0: return item = self.__inhPlusEnvTable.currentItem() dlg = EnvVarDialog( str( item.text( 0 ) ), str( item.text( 1 ) ), self ) if dlg.exec_() == QDialog.Accepted: name = str( dlg.name ) value = str( dlg.value ) self.__delAndInsert( self.__inhPlusEnvTable, name, value ) self.runParams.additionToParentEnv[ name ] = value return def __inhPlusItemActivated( self, item, column ): " Triggered when a table item is activated " self.__editInhClicked() return def __editSpecClicked( self ): " Edits the highlighted variable " if self.__specEnvTable.topLevelItemCount() == 0: return item = self.__specEnvTable.currentItem() dlg = EnvVarDialog( str( item.text( 0 ) ), str( item.text( 1 ) ), self ) if dlg.exec_() == QDialog.Accepted: name = str( dlg.name ) value = str( dlg.value ) self.__delAndInsert( self.__specEnvTable, name, value ) self.runParams.specificEnv[ name ] = value return def __specItemActivated( self, item, column ): " Triggered when a table item is activated " self.__editSpecClicked() return def onAccept( self ): " Saves the selected terminal and profiling values " if self.__redirectRButton.isChecked(): self.termType = TERM_REDIRECT elif self.__autoRButton.isChecked(): self.termType = TERM_AUTO elif self.__konsoleRButton.isChecked(): self.termType = TERM_KONSOLE elif self.__gnomeRButton.isChecked(): self.termType = TERM_GNOME else: self.termType = TERM_XTERM if self.__action == "profile": self.profilerParams.nodeLimit = float( self.__nodeLimitEdit.text() ) self.profilerParams.edgeLimit = float( self.__edgeLimitEdit.text() ) self.accept() return
def __init__(self, # .. _numMavs: # # The number of MAVs in the simulation. numMavs, # See _flyTimeSec. flyTimeSec, # See _chargeTimeSec. chargeTimeSec): # First, let the QDialog initialize itself. super(MavDialog, self).__init__() # Create a ChargingStation to manage the MAVs. self._chargingStation = ChargingStation(self, numMavs, flyTimeSec, chargeTimeSec) # `Load <http://pyqt.sourceforge.net/Docs/PyQt4/designer.html#PyQt4.uic.loadUi>`_ # in our UI. The secord parameter lods the resulting UI directly into # this class. uic.loadUi(join(dirname(__file__), 'mav_gui.ui'), self) # Only allow numbers between 0 and 99 for the line edits. flyTimeValidator = QDoubleValidator(0.0, 9.9, 1, self) flyTimeValidator.setNotation(QDoubleValidator.StandardNotation) self.leFlyTime.setValidator(flyTimeValidator) chargeTimeValidator = QDoubleValidator(0.0, 9.9, 1, self) chargeTimeValidator.setNotation(QDoubleValidator.StandardNotation) self.leChargeTime.setValidator(chargeTimeValidator) # Example: create a separate thread self._thread = QThread(self) #self._thread.start() # Create a worker. self._worker = DummyWorker(self) # Timer examples # ^^^^^^^^^^^^^^ # A single-shot timer. It can't be canceled. QTimer.singleShot(1500, self._onTimeout) # Another single-shot timer. Because it has a name, it can be canceled. self._timer = QTimer(self) self._timer.timeout.connect(self._onTimeout) self._timer.setSingleShot(True) self._timer.start(3000) # Add in status info GUI for numMavs MAVs. hl = QHBoxLayout() self.wMavStatus.setLayout(hl) assert numMavs > 0 self.numMavs = numMavs self.mavStatus = [] self.electrodeStatus = [] self._chargeTimeSec = [chargeTimeSec]*self.numMavs self._flyTimeSec = [flyTimeSec]*self.numMavs for index in range(self.numMavs): e = UncheckableRadioButton(self) self.electrodeStatus.append(e) hl.addWidget(e) # Add in a group box. smw = SingleMavWidget() mavName = 'MAV {}'.format(index + 1) smw.gb = QGroupBox(mavName, self.wMavStatus) vl = QVBoxLayout() smw.gb.setLayout(vl) smw.rbFlying = UncheckableRadioButton('Flying', smw.gb) smw.rbWaiting = UncheckableRadioButton('Waiting', smw.gb) smw.rbCharging = UncheckableRadioButton('Charging', smw.gb) vl.addWidget(smw.rbFlying) vl.addWidget(smw.rbWaiting) vl.addWidget(smw.rbCharging) self.mavStatus.append(smw) hl.addWidget(smw.gb) # Update the combo box. self.cbSelectedMav.insertItem(index, mavName) # Update GUI with parameters. self.on_cbSelectedMav_currentIndexChanged(0) self.updateMavState.connect(self._on_updateMavState)