def createEditor(self, parent, option, index): """ Creates the combobox inside a parent. :param parent: The container of the combobox :type parent: QWidget :param option: QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widget. :type option: Object :param index: The index where the combobox will be added. :type index: QModelIndex :return: The combobox :rtype: QComboBox """ if index.column() == 0: str_combo = QComboBox(parent) str_combo.insertItem(0, " ") for id, type in self.str_type_set_data().iteritems(): str_combo.addItem(type, id) if self.str_type_id is not None: str_combo.setCurrentIndex(self.str_type_id) return str_combo elif index.column() == 1: spinbox = QDoubleSpinBox(parent) spinbox.setObjectName(unicode(index.row())) spinbox.setMinimum(0.00) spinbox.setSuffix('%') spinbox.setMaximum(100.00) return spinbox
def createEditor(self, parent, option, index): """ Creates the combobox inside a parent. :param parent: The container of the combobox :type parent: QWidget :param option: QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widget. :type option: Object :param index: The index where the combobox will be added. :type index: QModelIndex :return: The combobox :rtype: QComboBox """ if index.column() == 0: str_combo = QComboBox(parent) str_combo.setObjectName(unicode(index.row())) return str_combo elif index.column() == 1: spinbox = QDoubleSpinBox(parent) spinbox.setObjectName(unicode(index.row())) spinbox.setMinimum(0.00) spinbox.setSuffix('%') spinbox.setMaximum(100.00) return spinbox
def _create_widget(cls, c, parent): dsb = QDoubleSpinBox(parent) dsb.setObjectName(u'{0}_{1}'.format(cls._TYPE_PREFIX, c.name)) #Set ranges dsb.setMinimum(float(c.minimum)) dsb.setMaximum(float(c.maximum)) return dsb
def _create_widget(cls, c, parent, host=None): dsb = QDoubleSpinBox(parent) dsb.setObjectName(u'{0}_{1}'.format(cls._TYPE_PREFIX, c.name)) # Set decimal places dsb.setDecimals(c.scale) # Set ranges dsb.setMinimum(float(c.minimum)) dsb.setMaximum(float(c.maximum)) return dsb
def create_double_spinbox(self, parent, index): """ Creates double spinbox. :param parent: The parent widget. :type parent: QWidget :param index: The index. :type index: QModelIndex :return: The double spinbox :rtype: QDoubleSpinBox """ spinbox = QDoubleSpinBox(parent) spinbox.setObjectName(unicode(index.row())) return spinbox
def create_double_spinbox(self, parent, index): """ Creates double spinbox. :param parent: The parent widget. :type parent: QWidget :param index: The index. :type index: QModelIndex :return: The double spinbox :rtype: QDoubleSpinBox """ spinbox = QDoubleSpinBox(parent) spinbox.setObjectName(unicode(index.row())) return spinbox
def spinBoxFromHabName(self,habname): """ If the spin box exists, return it. If not make it and return it. """ #print "looking for habname: %s" % habname sbname = slugify( unicode(habname) ) + u"SpinBox" htw = self.habitatTableWidget try: sb = htw.findChild(QDoubleSpinBox,sbname) assert( sb!=None ) return sb except AssertionError: #print "making SB: %s" % sbname newsb = QDoubleSpinBox(self.habitatTableWidget) newsb.setMaximum(1.0) newsb.setSingleStep(0.1) newsb.setObjectName(_fromUtf8(sbname)) return newsb
def spinBoxFromHabName(self, habname): """ If the spin box exists, return it. If not make it and return it. """ #print "looking for habname: %s" % habname sbname = slugify(unicode(habname)) + u"SpinBox" htw = self.habitatTableWidget try: sb = htw.findChild(QDoubleSpinBox, sbname) assert (sb != None) return sb except AssertionError: #print "making SB: %s" % sbname newsb = QDoubleSpinBox(self.habitatTableWidget) newsb.setMaximum(1.0) newsb.setSingleStep(0.1) newsb.setObjectName(_fromUtf8(sbname)) return newsb
class MainWindow(QWidget): # set up signals resetClicked = pyqtSignal() inputChanged = pyqtSignal() input_one = None def __init__(self, parent=None): super(MainWindow, self).__init__(parent) # -------------------------------------------------------- # main window self.setObjectName("Multiply") self.resize(400, 300) # label self.label = QLabel(self) self.label.setGeometry(QRect(20, 10, 250, 50)) self.label.setText("Multiply two numbers!") # self.label.show() # input frame self.input_frame = QFrame(self) self.input_frame.setGeometry(QRect(20, 60, 350, 130)) self.input_frame.setFrameShape(QFrame.StyledPanel) self.input_frame.setFrameShadow(QFrame.Raised) # set the layout of the frame self.verticalLayout = QVBoxLayout(self.input_frame) self.verticalLayout.setObjectName("verticalLayout") # first input self.input_one = QDoubleSpinBox(self.input_frame) self.input_one.setObjectName("input_one") self.input_one.setDecimals(4) self.input_one.setSingleStep(0.01) self.verticalLayout.addWidget(self.input_one) # second input self.input_two = QDoubleSpinBox(self.input_frame) self.input_two.setObjectName("input_two") self.input_two.setDecimals(4) self.input_two.setSingleStep(0.01) self.verticalLayout.addWidget(self.input_two) # LCD result self.result_lcd = QLCDNumber(self) self.result_lcd.setObjectName("result_lcd") self.result_lcd.setGeometry(QRect(20, 200, 350, 80)) self.result_lcd.setDigitCount(10) self.result_lcd.setSmallDecimalPoint(True) # Reset Button self.reset_button = QPushButton(self) self.reset_button.setGeometry(QRect(270, 10, 100, 30)) self.reset_button.setObjectName("reset_button") self.reset_button.setText("Reset") # -------------------------------------------------------- # connect slots self.reset_button.clicked.connect(self.onResetClick) self.input_one.valueChanged.connect(self.onInputChanged) self.input_two.valueChanged.connect(self.onInputChanged) # define slots def onResetClick(self): self.resetClicked.emit() def onInputChanged(self): self.inputChanged.emit() def setResult(self, value): self.result_lcd.display(value)
class QgsAnnotationWidget(QWidget): def __init__(self, parent, item): QWidget.__init__(self, parent) self.gridLayout_2 = QGridLayout(self) self.gridLayout_2.setObjectName(("gridLayout_2")) self.mMapPositionFixedCheckBox = QCheckBox(self) self.mMapPositionFixedCheckBox.setObjectName( ("mMapPositionFixedCheckBox")) self.gridLayout_2.addWidget(self.mMapPositionFixedCheckBox, 0, 0, 1, 1) self.gridLayout = QGridLayout() self.gridLayout.setObjectName(("gridLayout")) self.mFrameColorButton = QgsColorButton(self) self.mFrameColorButton.setText(("")) self.mFrameColorButton.setObjectName(("mFrameColorButton")) self.gridLayout.addWidget(self.mFrameColorButton, 3, 1, 1, 1) self.mFrameColorButton.colorChanged.connect( self.on_mFrameColorButton_colorChanged) self.mBackgroundColorLabel = QLabel(self) self.mBackgroundColorLabel.setObjectName(("mBackgroundColorLabel")) self.gridLayout.addWidget(self.mBackgroundColorLabel, 2, 0, 1, 1) self.mMapMarkerLabel = QLabel(self) self.mMapMarkerLabel.setObjectName(("mMapMarkerLabel")) self.gridLayout.addWidget(self.mMapMarkerLabel, 0, 0, 1, 1) self.mBackgroundColorButton = QgsColorButton(self) self.mBackgroundColorButton.setText(("")) self.mBackgroundColorButton.setObjectName(("mBackgroundColorButton")) self.gridLayout.addWidget(self.mBackgroundColorButton, 2, 1, 1, 1) self.mBackgroundColorButton.colorChanged.connect( self.on_mBackgroundColorButton_colorChanged) self.mMapMarkerButton = QPushButton(self) self.mMapMarkerButton.setText(("")) self.mMapMarkerButton.setObjectName(("mMapMarkerButton")) self.gridLayout.addWidget(self.mMapMarkerButton, 0, 1, 1, 1) self.mMapMarkerButton.clicked.connect(self.on_mMapMarkerButton_clicked) self.mFrameWidthLabel = QLabel(self) self.mFrameWidthLabel.setObjectName(("mFrameWidthLabel")) self.gridLayout.addWidget(self.mFrameWidthLabel, 1, 0, 1, 1) self.mFrameWidthSpinBox = QDoubleSpinBox(self) self.mFrameWidthSpinBox.setObjectName(("mFrameWidthSpinBox")) self.gridLayout.addWidget(self.mFrameWidthSpinBox, 1, 1, 1, 1) self.mFrameColorLabel = QLabel(self) self.mFrameColorLabel.setObjectName(("mFrameColorLabel")) self.gridLayout.addWidget(self.mFrameColorLabel, 3, 0, 1, 1) self.gridLayout_2.addLayout(self.gridLayout, 1, 0, 1, 1) self.mMapMarkerLabel.setBuddy(self.mMapMarkerButton) self.mFrameWidthLabel.setBuddy(self.mFrameWidthSpinBox) self.setWindowTitle("QgsAnnotationWidgetBase") self.mMapPositionFixedCheckBox.setText("Fixed map position") self.mBackgroundColorLabel.setText("Background color") self.mMapMarkerLabel.setText("Map marker") self.mFrameWidthLabel.setText("Frame width") self.mFrameColorLabel.setText("Frame color") self.setLayout(self.gridLayout_2) self.mItem = item if (self.mItem != None): self.blockAllSignals(True) if (self.mItem.mapPositionFixed()): self.mMapPositionFixedCheckBox.setCheckState(Qt.Checked) else: self.mMapPositionFixedCheckBox.setCheckState(Qt.Unchecked) self.mFrameWidthSpinBox.setValue(self.mItem.frameBorderWidth()) self.mFrameColorButton.setColor(self.mItem.frameColor()) self.mFrameColorButton.setColorDialogTitle("Select frame color") self.mFrameColorButton.setColorDialogOptions( QColorDialog.ShowAlphaChannel) self.mBackgroundColorButton.setColor( self.mItem.frameBackgroundColor()) self.mBackgroundColorButton.setColorDialogTitle( "Select background color") self.mBackgroundColorButton.setColorDialogOptions( QColorDialog.ShowAlphaChannel) self.symbol = self.mItem.markerSymbol() if (self.symbol != None): self.mMarkerSymbol = self.symbol.clone() self.updateCenterIcon() self.blockAllSignals(False) def apply(self): if (self.mItem != None): self.mItem.setMapPositionFixed( self.mMapPositionFixedCheckBox.checkState() == Qt.Checked) self.mItem.setFrameBorderWidth(self.mFrameWidthSpinBox.value()) self.mItem.setFrameColor(self.mFrameColorButton.color()) self.mItem.setFrameBackgroundColor( self.mBackgroundColorButton.color()) self.mItem.setMarkerSymbol(self.mMarkerSymbol) self.mMarkerSymbol = None #//item takes ownership self.mItem.update() def blockAllSignals(self, block): self.mMapPositionFixedCheckBox.blockSignals(block) self.mMapMarkerButton.blockSignals(block) self.mFrameWidthSpinBox.blockSignals(block) self.mFrameColorButton.blockSignals(block) def on_mMapMarkerButton_clicked(self): if (self.mMarkerSymbol == None): return markerSymbol = self.mMarkerSymbol.clone() dlg = QgsSymbolV2SelectorDialog(markerSymbol, QgsStyleV2.defaultStyle(), None, self) if (dlg.exec_() != QDialog.Rejected): self.mMarkerSymbol = markerSymbol self.updateCenterIcon() def on_mFrameColorButton_colorChanged(self, color): if (self.mItem == None): return self.mItem.setFrameColor(color) def updateCenterIcon(self): if (self.mMarkerSymbol == None): return icon = QgsSymbolLayerV2Utils.symbolPreviewIcon( self.mMarkerSymbol, self.mMapMarkerButton.iconSize()) self.mMapMarkerButton.setIcon(icon) def on_mBackgroundColorButton_colorChanged(self, color): if (self.mItem == None): return self.mItem.setFrameBackgroundColor(color)
class GUI(QWidget): def __init__(self, parent=None): global f f = open(filename, "a") f.write("Widget init.\n") f.close() QWidget.__init__(self, parent, Qt.WindowStaysOnTopHint) self.__setup_gui__(self) self._flag = False self._change = False f = open(filename, "a") f.write("End of widget init.\n") f.close() def closeEvent(self, event): reply = QMessageBox.question(self, "Confirm", "Are you sure You want to quit?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore() def __setup_gui__(self, Dialog): global f f = open(filename, "a") f.write("Setup of gui.\n") f.close() Dialog.setObjectName("Dialog") Dialog.resize(270, 145) self.setWindowTitle("Map Layer") screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) self.Render = QPushButton("Render", Dialog) self.Render.setGeometry(QRect(85, 90, 100, 25)) self.Render.setObjectName("Render") self.comboBox = QComboBox(Dialog) self.comboBox.setGeometry(QRect(100, 34, 115, 18)) self.comboBox.setEditable(False) self.comboBox.setMaxVisibleItems(11) self.comboBox.setInsertPolicy(QComboBox.InsertAtBottom) self.comboBox.setObjectName("comboBox") self.comboBox.addItems([ "Google Roadmap", "Google Terrain", "Google Satellite", "Google Hybrid", "Yahoo Roadmap", "Yahoo Satellite", "Yahoo Hybrid", "Bing Roadmap", "Bing Satellite", "Bing Hybrid", "Open Street Maps" ]) self.comboBox.setCurrentIndex(10) self.label1 = QLabel("Source:", Dialog) self.label1.setGeometry(QRect(55, 35, 35, 16)) self.label1.setObjectName("label1") self.slider = QSlider(Dialog) self.slider.setOrientation(Qt.Horizontal) self.slider.setMinimum(1) self.slider.setMaximum(12) self.slider.setValue(4) self.slider.setGeometry(QRect(110, 61, 114, 16)) self.label2 = QLabel("Quality: " + str(self.slider.value()), Dialog) self.label2.setGeometry(QRect(47, 61, 54, 16)) self.label2.setObjectName("label2") self.doubleSpinBox = QDoubleSpinBox(Dialog) self.doubleSpinBox.setGeometry(QRect(160, 5, 40, 20)) self.doubleSpinBox.setDecimals(0) self.doubleSpinBox.setObjectName("doubleSpinBox") self.doubleSpinBox.setMinimum(10.0) self.doubleSpinBox.setValue(20.0) self.doubleSpinBox.setEnabled(False) self.checkBox = QCheckBox("Auto refresh", Dialog) self.checkBox.setGeometry(QRect(50, 6, 100, 20)) self.checkBox.setLayoutDirection(Qt.RightToLeft) self.checkBox.setObjectName("checkBox") self.progressBar = QProgressBar(Dialog) self.progressBar.setGeometry(QRect(5, 130, 260, 10)) self.progressBar.setProperty("value", 0) self.progressBar.setTextVisible(False) self.progressBar.setObjectName("progressBar") self.progressBar.setVisible(False) QObject.connect(self.Render, SIGNAL("clicked()"), Dialog.__repaint__) QMetaObject.connectSlotsByName(Dialog) QObject.connect(self.slider, SIGNAL("valueChanged(int)"), self.__update_slider_label__) QObject.connect(self.comboBox, SIGNAL("activated(int)"), self.__combobox_changed__) self.timerRepaint = QTimer() QObject.connect(self.checkBox, SIGNAL("clicked()"), self.__activate_timer__) QObject.connect(self.timerRepaint, SIGNAL("timeout()"), self.__on_timer__) f = open(filename, "a") f.write("End of setup of gui.\n") f.close() def __combobox_changed__(self): self._change = True def __activate_timer__(self): self.doubleSpinBox.setEnabled(self.checkBox.isChecked()) if self.checkBox.isChecked(): self.timerRepaint.start(self.doubleSpinBox.value() * 1000) self.Render.setEnabled(False) if _progress == 0: self.__repaint__() else: self.timerRepaint.stop() self.Render.setEnabled(True) def __get_net_size__(self): global f f = open(filename, "a") f.write("Geting net size...\n") f.close() if not os.path.exists(Paths["Screenshot"]): Visum.Graphic.Screenshot(Paths["Screenshot"]) size = Image.open(Paths["Screenshot"]).size f = open(filename, "a") f.write("Read net size:" + str(size) + ".\n") f.close() return size def __on_timer__(self): global _paramGlobal self._flag = False Visum.Graphic.MaximizeNetWindow() param = _paramGlobal _paramGlobal = Visum.Graphic.GetWindow() shift = abs((param[0] - _paramGlobal[0]) / (param[2] - param[0])) zoom = abs((param[2] - param[0]) / (_paramGlobal[2] - _paramGlobal[0]) - 1) print _windowSizeGlobal if _windowSizeGlobal[2:4] != Visum.Graphic.GetMainWindowPos()[2:4]: self.__get_net_size__() self._flag = True elif shift > 0.4 or zoom > 0.2: self._flag = True if self._flag or self._change and _progress == 0: self.__repaint__() self._change = False def __update_slider_label__(self, value): self.label2.setText("Quality: " + str(value)) self._change = True def __update_progress_bar__(self): if _progress != 0: self.progressBar.setVisible(True) self.progressBar.setValue(_progress) else: self.progressBar.setVisible(False) def __rebuild_paths__(self): global Paths Paths["Images"] = [] list = os.listdir(Paths["ScriptFolder"]) imageList = [] for i in range(len(list)): if list[i][-3:] == "png": imageList.append(list[i]) for i in range(len(imageList)): try: Visum.Graphic.Backgrounds.ItemByKey(imageList[i]) Paths["Images"].append(Paths["ScriptFolder"] + "\\" + imageList[i]) except: pass def __repaint__(self): global _progress, f if len(Visum.Graphic.Backgrounds.GetAll) != len(Paths["Images"]): self.__rebuild_paths__() if _progress == 0: f = open(filename, "a") f.write("Doing repaint...\n") f.close() QWebSettings.clearMemoryCaches() timer = QTimer() timer.start(100) QObject.connect(timer, SIGNAL("timeout()"), self.__update_progress_bar__) Main(self.comboBox.currentIndex(), Visum.Graphic.GetWindow(), self.slider.value() / 4.0, self.__get_net_size__()) Visum.Graphic.Draw() self.__update_progress_bar__() _progress = 0 QTimer().singleShot(1500, self.__update_progress_bar__) f = open(filename, "a") f.write("End of doing repaint.\n") f.close()
class AnalogConfigLayout(QFormLayout): rangeChanged = pyqtSignal() def __init__(self, showSampleRateSb=False, settings=None, parent=None): super(AnalogConfigLayout, self).__init__(parent) self.deviceCombo = QComboBox() self.deviceCombo.setObjectName('deviceCombo') self.addRow('&Device', self.deviceCombo) self.channelCombo = QComboBox() self.channelCombo.setObjectName('channelCombo') self.addRow('&Channel', self.channelCombo) self.rangeCombo = QComboBox() self.rangeCombo.setObjectName('rangeCombo') self.addRow('&Range', self.rangeCombo) if showSampleRateSb: self.sampleRateSb = QDoubleSpinBox() self.sampleRateSb.setSuffix(' kHz') self.sampleRateSb.setMinimum(0.001) self.sampleRateSb.setDecimals(3) self.sampleRateSb.setValue(1) self.sampleRateSb.setObjectName('sampleRateSb') self.addRow('&Sample rate', self.sampleRateSb) else: self.sampleRateSb = None self._ranges = [] self.deviceCombo.currentIndexChanged.connect(self.deviceChanged) self.populateDevices() self.rangeCombo.currentIndexChanged.connect(self.rangeChanged) self.deviceCombo.setContextMenuPolicy(Qt.CustomContextMenu) self.deviceCombo.customContextMenuRequested.connect(self.contextMenu) def contextMenu(self, point): globalPos = self.deviceCombo.mapToGlobal(point) menu = QMenu() refreshAction = QAction("&Refresh", menu) menu.addAction(refreshAction) selected = menu.exec_(globalPos) if selected == refreshAction: self.populateDevices() def populateDevices(self): self.deviceCombo.clear() system = daq.System() devices = system.findDevices() for dev in devices: self.deviceCombo.addItem(dev) def deviceChanged(self): self.channelCombo.clear() for channel in self.channels(): self.channelCombo.addItem(channel) self.rangeCombo.clear() self._ranges = self.ranges() for r in self._ranges: self.rangeCombo.addItem('%+.2f -> %+.2f V' % (r.min, r.max)) if self.sampleRateSb is not None: fmax = self.maxSampleRate() self.sampleRateSb.setMaximum(1E-3 * fmax) def maxSampleRate(self): raise NotImplementedError def device(self): t = self.deviceCombo.currentText() if len(t): return str(t) else: return None def channel(self): return str(self.channelCombo.currentText()) def voltageRange(self): i = self.rangeCombo.currentIndex() return None if i < 0 else self._ranges[i] def restoreSettings(self, s=None): if s is None: s = QSettings() try: device = s.value('device', '', type=str) i = self.deviceCombo.findText(device) self.deviceCombo.setCurrentIndex(i) except: pass channel = s.value('channel', '', type=str) i = self.channelCombo.findText(channel) self.channelCombo.setCurrentIndex(i) voltageRange = s.value('range', '', type=str) i = self.rangeCombo.findText(voltageRange) self.rangeCombo.setCurrentIndex(i) def saveSettings(self, s=None): if s is None: s = QSettings() s.setValue('device', self.device()) s.setValue('channel', self.channel()) s.setValue('range', self.rangeCombo.currentText())