def __init__(self): QtGui.QWidget.__init__(self) self.setWindowTitle("Button Window") self.setGeometry(300, 200, 200, 200) vbox = QtGui.QVBoxLayout(self) vbox.setContentsMargins(QtCore.QMargins(5,5,5,5)) vbox.setSpacing(10) self.checkbox = QtGui.QCheckBox("CheckButton", self) self.checkbox.setObjectName("check") vbox.addWidget(self.checkbox) buttongroup = QtGui.QButtonGroup() self.radiobutton1 = QtGui.QRadioButton("RadioButton1", self) self.radiobutton1.setObjectName("radio1") buttongroup.addButton(self.radiobutton1) vbox.addWidget(self.radiobutton1) self.radiobutton2 = QtGui.QRadioButton("RadioButton2", self) self.radiobutton2.setObjectName("radio2") buttongroup.addButton(self.radiobutton2) vbox.addWidget(self.radiobutton2) self.button = QtGui.QPushButton("OK", self) self.button.setObjectName("button") vbox.addWidget(self.button) self.button.clicked.connect(self.clicked) self.combo = QtGui.QComboBox(self) self.combo.setObjectName("combo") self.combo.addItem("Apple") self.combo.addItem("Banana") self.combo.addItem("Grapes") vbox.addWidget(self.combo) self.combo.activated[str].connect(self.activated) self.resize(350, 200)
def _build_layout(horizontal): if (horizontal): layout = QtWidgets.QHBoxLayout() else: layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) return layout
def createEditWidget(self, parent): """ Creates a new Widget that contains both a LineEdit and a button. The button displays the selected colour via the button's background colour (using a stylesheet), the LineEdit shows the hexadecimal value as string. Both are editable. When clicking the button a ColorDialog pops up. Upon accepting a colour, the colour will be set. The LineEdit works analogoues: Changing its text will parse the new text and if the text can be successfully used as a CEGUI Colour then this new Colour will be set. :param parent: QWidget :return: """ self.editWidget = QtGui.QWidget(parent) self.editWidget.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.editWidget.setContentsMargins(QtCore.QMargins(0, 0, 0, 0)) hBoxLayout = QtGui.QHBoxLayout(self.editWidget) hBoxLayout.setContentsMargins(QtCore.QMargins(0, 0, 0, 0)) hBoxLayout.setSpacing(0) self.colourEditbox = QtGui.QLineEdit() self.colourEditbox.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) options = self.property.getEditorOption("string/", {}) # setup options self.colourEditbox.setMaxLength( int(options.get("maxLength", self.colourEditbox.maxLength()))) self.colourEditbox.setPlaceholderText( options.get("placeholderText", self.colourEditbox.placeholderText())) self.colourEditbox.setInputMask( options.get("inputMask", self.colourEditbox.inputMask())) self.colourEditbox.setValidator( options.get("validator", self.colourEditbox.validator())) hBoxLayout.addWidget(self.colourEditbox, 0) self.colourButton = QtGui.QPushButton() self.colourButton.setMinimumSize(QtCore.QSize(23, 23)) self.colourButton.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.MinimumExpanding) hBoxLayout.addWidget(self.colourButton, 1) self.colourDialogParent = parent self.colourButton.released.connect(self.colourButtonReleased) self.colourEditbox.textEdited.connect(self.lineEditTextEdited) self.colourEditbox.editingFinished.connect( self.lineEditEditingFinished) return self.editWidget
def __init__(self, tool, *args, **kwargs): super(ToolSettingsWidget, self).__init__(*args, **kwargs) # layout self.vLayout = QtGui.QVBoxLayout() self.vLayout.setContentsMargins(QtCore.QMargins(15, 15, 15, 20)) self.setLayout(self.vLayout) if tool.settings: QPALETTE_INPUTITEM = PyQt.QtGui.QPalette() QPALETTE_INPUTITEM.setColor(PyQt.QtGui.QPalette.Text, PyQt.QtGui.QColor( 255, 255, 255, )) for settingObject in tool.settings: # horizontal layout hLayout = QtGui.QHBoxLayout() hLayout.setContentsMargins(QtCore.QMargins(0, 0, 0, 0)) hLayout.setSpacing(0) self.vLayout.addLayout(hLayout) # add Label settingLabel = QtGui.QLabel('%s:' % settingObject.settingName) settingLabel.setFixedWidth(settingLabel.sizeHint().width()) settingLabel.setPalette(QPALETTE_INPUTITEM) hLayout.addWidget(settingLabel) hLayout.addSpacing(10) # setting widget self.settingWidget = self._getSettingInputWidget(settingObject) self.settingWidget.setPalette(QPALETTE_INPUTITEM) hLayout.addWidget(self.settingWidget) hLayout.addStretch() self.vLayout.addSpacing(10)
def __init__(self, parent, cor, tituloGrafico, unidade, host, porta, Ymin=None, Ymax=None, hostDisplay=None, portaDisplay=None, atualizaDisplay=None): super(Pagina, self).__init__(parent) self.cor = cor self.grafico = Grafico(self, cor, tituloGrafico, unidade, Ymin, Ymax) self.display = Display(self, cor) botaoesquerda = QtGui.QPushButton('<', self) botaoesquerda.setStyleSheet('color: {0}'.format(cor)) botaoesquerda.setGeometry(QtCore.QRect(240, 0, 40, 25)) botaoesquerda.clicked.connect(self.graficoAnterior) botaodireita = QtGui.QPushButton('>', self) botaodireita.setStyleSheet('color: {0}'.format(cor)) botaodireita.setGeometry(QtCore.QRect(425, 0, 40, 25)) botaodireita.clicked.connect(self.proximoGrafico) layout = QtGui.QHBoxLayout(self) layout.addWidget(self.grafico) layout.addWidget(self.display) layout.setContentsMargins(QtCore.QMargins(0, 0, 0, 0)) self.threadGrafico = ThreadGrafico(self.grafico, host, porta, display=self.display, atualizaDisplay=atualizaDisplay) self.threadGrafico.sinal.connect(self.grafico.myplot) if hostDisplay != None and portaDisplay != None: self.threadDisplay = ThreadDisplay(self.display, hostDisplay, portaDisplay) else: self.threadDisplay = None
def showWindows(self): mainLayoutTabs = QtGui.QHBoxLayout() mainTabs = QtGui.QTabWidget() self.margins = QtCore.QMargins(5, 0, 5, 0) tab1 = self.constructTab1() tab2 = self.constructTab2() mainTabs.addTab(tab1, "BAKE") mainTabs.addTab(tab2, "CREATE") mainLayoutTabs.addWidget(mainTabs) self.setLayout(mainLayoutTabs) flags = QtCore.Qt.WindowFlags() flags |= QtCore.Qt.WindowStaysOnTopHint self.setWindowTitle("Hoongman TD Test") self.setWindowFlags(flags) self.resize(450, 500) self.show()
def __init__(self, documentedObject, *args, **kwargs): super(DocStringWidget, self).__init__(*args, **kwargs) # layout self.vLayout = QtGui.QVBoxLayout() self.vLayout.setContentsMargins(QtCore.QMargins(15, 15, 15, 20)) self.setLayout(self.vLayout) self.label = QtGui.QLabel() indent = ' ' #docStringHeader = '%s:\n< %s.%s >\n\n%s' % (tool.label, tool._function.__module__, tool._function.__name__, indent) docString = str(documentedObject.__doc__).replace( '\n', '\n%s' % indent) self.label.setText(docString) self.vLayout.addWidget(self.label)
def set(self, v=NOTSET, firstTime=False): # Validate value if v == NOTSET and self.required: raise self.configurationError('require %s to be set' % self.name) if getattr(self, 'type', None) is not callable and not isinstance(v, Factory): numArgs = getNumArgs(v) if numArgs is not None: self.recalculable = True if firstTime: self.value = getattr(self, 'default', NOTSET) return numArgs = getNumArgs(v) args = (self.field.form, self.field, self) v = v(*(args[:numArgs])) else: self.recalculable = False else: self.recalculable = False # Validate the value type (if a type was specified) if hasattr(self, 'type'): # special shortcuts for certain Qt types if self.type is QtCore.QSize and type(v) is tuple: v = QtCore.QSize(*v) elif self.type is QtCore.QMargins and type(v) is tuple: v = QtCore.QMargins(*v) elif self.type is QtGui.QIcon and type(v) in (str, unicode): v = QtGui.QIcon(v) # check base type if self.type in (unicode, str): if type(v) not in (unicode, str): self.configurationError('must be a string/unicode value') elif self.type is callable: if not callable(v): self.configurationError('must be a callable object') elif not isinstance(v, self.type): self.configurationError('must be of type %r' % self.type) # check sub-type for lists/tuples if self.type in (tuple, list) and hasattr(self, 'subType'): if type(self.subType) in (tuple, list): if len(self.subType) != len(v): self.configurationError('must be of type %r' % self.subType) for i in range(len(self.subType)): if not isinstance(v[i], self.subType[i]): self.configurationError('must be of type %r' % self.subType) else: for index, i in enumerate(v): if not isinstance(i, self.subType): self.configurationError( 'item at index %d should be of type %r' % (index, self.subType)) if hasattr(self, 'options'): if v not in self.options: self.configurationError('must be one of %r' % self.options) # Store the value self.value = v
def _create_widgets(self): vl = _build_layout(False) self._main_layout.addLayout(vl) self._frame_before = QtWidgets.QSpinBox(parent=self) self._frame_before.setSingleStep(1) self._frame_before.setMinimum(0) vl.addWidget( LineWidget("Frame before:", self._frame_before, parent=self)) self._frame_after = QtWidgets.QSpinBox(parent=self) self._frame_after.setSingleStep(1) self._frame_after.setMinimum(0) vl.addWidget(LineWidget("Frame after:", self._frame_after, parent=self)) vl.addWidget(self._get_selection_group_box()) vl.addWidget(self._get_pivots_group_box()) self._main_layout.addWidget(create_separator(True)) gl = QtWidgets.QGridLayout() gl.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) self._main_layout.addLayout(gl) self._show_key_frames = QtWidgets.QPushButton() self._show_key_frames.setCheckable(True) self._show_key_frames.setFixedWidth(120) self._show_key_frames.setText("Show keyframes") gl.addWidget(self._show_key_frames, 0, 0) self._show_tangents = QtWidgets.QPushButton() self._show_tangents.setCheckable(True) self._show_tangents.setFixedWidth(120) self._show_tangents.setText("Show tangents") gl.addWidget(self._show_tangents, 1, 0) self._show_key_number = QtWidgets.QPushButton() self._show_key_number.setCheckable(True) self._show_key_number.setFixedWidth(120) self._show_key_number.setText("Show key numbers") gl.addWidget(self._show_key_number, 2, 0) self._show_rotation = QtWidgets.QPushButton() self._show_rotation.setCheckable(True) self._show_rotation.setFixedWidth(120) self._show_rotation.setText("Show rotation keys") gl.addWidget(self._show_rotation, 3, 0) self._show_path = QtWidgets.QPushButton() self._show_path.setCheckable(True) self._show_path.setFixedWidth(120) self._show_path.setText("Show path") gl.addWidget(self._show_path, 0, 1) self._alternating_color = QtWidgets.QPushButton() self._alternating_color.setCheckable(True) self._alternating_color.setFixedWidth(120) self._alternating_color.setText("Alternate path color") gl.addWidget(self._alternating_color, 1, 1) self._show_frame_number = QtWidgets.QPushButton() self._show_frame_number.setCheckable(True) self._show_frame_number.setFixedWidth(120) self._show_frame_number.setText("Show frame numbers") gl.addWidget(self._show_frame_number, 2, 1)
Slider(name='f6',label='Field 6 [f6]:',default=4,minimum=0,maximum=100,tickInterval=10,singleStep=5,tickPosition=QtGui.QSlider.TicksBelow,orientation=Qt.Horizontal), GroupBox(name='g1',title='Group 1',groupData=True,contents=[ LineEdit(name='f7',label='Field g1.1 [f7]:',default='default_value'), LineEdit(name='f8',label='Field g1.2 (int) [f8]:',default=2,type=int), GroupBox(name='g2',title='Group 1',groupData=True,checkable=True,checked=False,contents=[ LineEdit(name='f9',label='Field g1.g2.1 [f9]:',default='default_value'), LineEdit(name='f10',label='Field g1.g2.2 (int) [f10]:',default=2,type=int), ]), ]), File(name='f11',label='File [f11]:',caption='my caption'),#,mode=FileMode.ExistingDirectory), Dial(name='d1',label='Dial [d1]:',default=4,minimum=0,maximum=100,fixedSize=(50,50),singleStep=1,notchesVisible=True), DateTimeEdit(name='dte1',label='DateTimeEdit [dte1]:'), ]), Tab(name='tab2',label='Tab 2',contents=[ TableView(name='t1',tableActions=TableAction.All,formPosition=FormPosition.Top, editForm=Form(name='tableEdit',contentsMargins=QtCore.QMargins(0,11,0,11),contents=[ LineEdit(name='label',label='Label:',type=unicode), LineEdit(name='percentage',label='Percentage:',type=int), ]), columns=[ Column(name='label',resizeMode=QtGui.QHeaderView.Stretch,label='Label'), Column(name='percentage',label='Percentage'), ], ), TableView(name='t2',tableActions=TableAction.All, columns=[ Column(name='label',label='Label',resizeMode=QtGui.QHeaderView.Stretch,editable=True,editor=LineEdit(name='labelEditor')), Column(name='percentage',label='Percentage',editable=True,editor= SpinBox(name='percentageEditor',default=4,minimum=0,maximum=100,singleStep=2,prefix='v=',suffix='%') ), Column(name='combo',label='Combo',editable=True,editor=
def __init__(self, columns=2, colors=( (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 1, 1), (0, 0, 1), (1, 0, 1), ), buttonHeight=25, buttonWidth=25, function=None, **kwargs): """ Kwargs: columns - int -default=2 -number of columns colors - list/tuple of list/tuples - colors to display buttonHeight - int - height of the buttons buttonWidth - int - width of the buttons function - function - the function to call on button press. The color value (0.0-1.0) will be passed as the first arg """ super(ColorSelectorWidget, self).__init__(*args, **kwargs) #columns = kwargs.pop('columns', 2) #colors = kwargs.pop('colors', ((1,0,0), (1,1,0), (0,1,0), (0,1,1), (0,0,1), (1,0,1), )) #buttonHeight = kwargs.pop('buttonHeight', 25) #buttonWidth = kwargs.pop('buttonWidth', 25) #function = kwargs.pop('function', self.function) if function == None: self.function self.setStyleSheet(self.STYLE_SHEET) # layout self.vLayout = QtGui.QVBoxLayout() self.vLayout.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) self.vLayout.setSpacing(0) self.setLayout(self.vLayout) i = 0 last = columns hLayout = None for color in colors: if i == last: i = 0 if i == 0: hLayout = QtGui.QHBoxLayout() self.vLayout.addLayout(hLayout) i += 1 button = QtGui.QPushButton() button.setFixedSize(buttonWidth, buttonHeight) hLayout.addWidget(button) button.setStyleSheet("background-color: rgb(%s,%s,%s)" % ( str(int(color[0] * 255)), str(int(color[1] * 255)), str(int(color[2] * 255)), )) def functionWrapper(function=function, color=color): function(color) button.pressed.connect(functionWrapper)