Пример #1
0
 def set_user_options(self):
     options = self.coredata.user_options
     keys = list(options.keys())
     keys.sort()
     self.opt_keys = keys
     self.opt_widgets = []
     for key in keys:
         opt = options[key]
         if isinstance(opt, optinterpreter.UserStringOption):
             w = PyQt5.QtWidgets.QLineEdit(opt.value)
             w.textChanged.connect(self.user_option_changed)
         elif isinstance(opt, optinterpreter.UserBooleanOption):
             w = QCheckBox('')
             w.setChecked(opt.value)
             w.stateChanged.connect(self.user_option_changed)
         elif isinstance(opt, optinterpreter.UserComboOption):
             w = QComboBox()
             for i in opt.choices:
                 w.addItem(i)
             w.setCurrentText(opt.value)
             w.currentTextChanged.connect(self.user_option_changed)
         else:
             raise RuntimeError("Unknown option type")
         self.opt_widgets.append(w)
         self.form.addRow(opt.description, w)
Пример #2
0
def get_widget_from_value(value, optional=None):
    if isinstance(value, bool):
        rv = QCheckBox()
        rv.setChecked(value)
        return rv
    if isinstance(value, tuple):
        rv = QComboBox()
        for i in value:
            rv.addItem(i)
        if isinstance(optional, int) and 0 <= optional < len(value):
            rv.setCurrentIndex(optional)
        if callable(optional):
            rv.currentIndexChanged.connect(optional)
        return rv
    if isinstance(value, str):
        return QLineEdit(value)
    if isinstance(value, Value):
        return LineEdit(None, value)
Пример #3
0
    def _initWidget(self, **kwargs):
        if issubtype(self.objType, bool):
            widget = QCheckBox(self)
        elif issubtype(self.objType, str):
            widget = LineEdit(self)
            if kwargs.get("completions"):
                completer = QCompleter(kwargs["completions"], self)
                widget.setCompleter(completer)
        elif issubtype(self.objType, int):
            widget = LineEdit(self)
            widget.setValidator(QIntValidator())
        elif issubtype(self.objType, float):
            widget = LineEdit(self)
            widget.setValidator(QDoubleValidator())
        elif issubtype(self.objType, (Enum, Type)):
            if issubtype(self.objType, Enum):
                # add enum types to types
                types = [member for member in self.objType]
            else:  # Type
                union = self.objType.__args__[0]
                if type(union) == TypeVar:
                    # add Type inheritors to types
                    baseType = union.__bound__
                    types = inheritors(baseType)
                else:
                    # add Union Type attrs to types
                    types = union.__args__

            if len(types) <= 6:
                widget = QComboBox(self)
            else:
                widget = CompleterComboBox(self)

            for typ in types:
                widget.addItem(getTypeName(typ), typ)
            widget.model().sort(0, Qt.AscendingOrder)

            if widget.count():
                widget.setCurrentIndex(0)

        return widget
Пример #4
0
 def __create_qt_widget(self, layout, widget, nullable_widget):
     if isinstance(widget, UflDialogCheckWidget):
         qt_widget = QCheckBox(widget.label)
         self.__qt_widgets[widget.id] = qt_widget
         qt_widget.stateChanged.connect(partial(self.__state_changed, widget))
         self.__add_qt_widget(layout, None, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogChildWidget):
         qt_widget = QPushButton(_("Edit..."))
         self.__qt_widgets[widget.id] = qt_widget
         qt_widget.clicked.connect(partial(self.__show_dialog, widget))
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogColorWidget):
         qt_widget = ColorSelectionWidget()
         qt_widget.color_changed.connect(partial(self.__value_changed, widget))
         self.__qt_widgets[widget.id] = qt_widget
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogComboWidget):
         qt_widget = QComboBox()
         qt_widget.setEditable(True)
         for item in widget.possibilities:
             qt_widget.addItem(item)
         self.__qt_widgets[widget.id] = qt_widget
         qt_widget.editTextChanged.connect(partial(self.__value_changed, widget))
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogFontWidget):
         qt_widget = FontSelectionWidget()
         qt_widget.font_changed.connect(partial(self.__value_changed, widget))
         self.__qt_widgets[widget.id] = qt_widget
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogIntegerWidget):
         qt_widget = SelectAllSpinBox()
         self.__qt_widgets[widget.id] = qt_widget
         qt_widget.valueChanged[int].connect(partial(self.__value_changed, widget))
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogDecimalWidget):
         qt_widget = SelectAllDoubleSpinBox()
         self.__qt_widgets[widget.id] = qt_widget
         qt_widget.valueChanged[float].connect(partial(self.__value_changed, widget))
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogMultiSelectWidget):
         qt_widget = MultiSelectComboBox()
         self.__qt_widgets[widget.id] = qt_widget
         for checked, item in widget.possibilities:
             qt_widget.add_check_item(checked, item)
         qt_widget.check_changed.connect(partial(self.__multi_changed, widget))
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogSelectWidget):
         qt_widget = QComboBox()
         self.__qt_widgets[widget.id] = qt_widget
         for item in widget.possibilities:
             qt_widget.addItem(item)
         qt_widget.currentIndexChanged[int].connect(partial(self.__index_changed, widget))
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogTextWidget):
         qt_widget = SelectAllLineEdit()
         self.__qt_widgets[widget.id] = qt_widget
         qt_widget.textChanged.connect(partial(self.__value_changed, widget))
         self.__add_qt_widget(layout, widget.label, qt_widget, False, nullable_widget)
     elif isinstance(widget, UflDialogTextAreaWidget):
         qt_widget = SmallTextEdit()
         policy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
         policy.setVerticalStretch(1)
         qt_widget.setSizePolicy(policy)
         qt_widget.setTabChangesFocus(True)
         self.__qt_widgets[widget.id] = qt_widget
         qt_widget.textChanged.connect(partial(self.__text_changed, widget, qt_widget))
         self.__add_qt_widget(layout, widget.label, qt_widget, True, nullable_widget)
     elif isinstance(widget, UflDialogNullableWidget):
         self.__create_qt_widget(layout, widget.inner_widget, widget)
     else:
         raise Exception()
Пример #5
0
    def initUI(self):
        lbl_red = QLabel('Red')
        lbl_green = QLabel('Green')
        lbl_green.setStyleSheet("color: green;"
                                "background-color: #7FFFD4")
        lbl_red.setStyleSheet("color: red;"
                              "border-style: solid;"
                              "border-width: 2px;"
                              "border-color: #FA8072;"
                              "border-radius: 3px")

        '''
        lbl_blue = QLabel('Blue')
        lbl_blue.setStyleSheet("color: blue;"
                              "background-color: #87CEFA;"
                              "border-style: dashed;"
                              "border-width: 3px;"
                              "border-color: #1E90FF")

        vbox = QVBoxLayout()
        vbox.addWidget(lbl_red)
        vbox.addWidget(lbl_green)
        vbox.addWidget(lbl_blue)

        self.setLayout(vbox)

        btn = QPushButton('Quit 버튼', self)
        btn.setToolTip('팁이다아ㅏ아ㅏ')
        btn.move(500, 500)
        btn.resize(btn.sizeHint())
        btn.clicked.connect(QCoreApplication.instance().quit)

        label1 = QLabel('Label1', self)
        label1.move(20, 20)
        label2 = QLabel('Label2', self)
        label2.move(20, 60)

        btn1 = QPushButton('Button1', self)
        btn1.move(80, 13)
        btn2 = QPushButton('Button2', self)
        btn2.move(80, 53)
        '''
        '''
        박스 레이아웃
        okButton = QPushButton('OK')
        okButton.clicked.connect(QCoreApplication.instance().quit)

        cancelButton = QPushButton('Cancel')

        hbox = QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(okButton)
        hbox.addWidget(cancelButton)
        hbox.addStretch(1)

        vbox = QVBoxLayout()
        vbox.addStretch(2)
        vbox.addWidget(lbl_red)
        vbox.addStretch(1)
        vbox.addLayout(hbox)
        vbox.addWidget(lbl_green)
        vbox.addStretch(1)

        self.setLayout(vbox)
        '''
        #QCheckBox
        cb = QCheckBox('Show title', self)
        cb.move(20, 20)
        cb.toggle()
        cb.stateChanged.connect(self.changeTitle)

        grid = QGridLayout()
        self.setLayout(grid)

        grid.addWidget(cb, 0, 0)
        grid.addWidget(QLabel('Author:'), 1, 0)
        grid.addWidget(QLabel('Review:'), 2, 0)

        grid.addWidget(QLineEdit(), 0, 1)
        grid.addWidget(QLineEdit(), 1, 1)
        grid.addWidget(QTextEdit(), 2, 1)

        self.lbl = QLabel('Option1', self)
        cb = QComboBox(self)
        cb.addItem('Option1')
        cb.addItem('Option2')
        cb.addItem('Option3')
        cb.addItem('Option4')
        cb.move(50, 50)

        cb.activated[str].connect(self.onActivated)

        self.setWindowIcon(QIcon('Hanabi.PNG'))
        #self.setWindowTitle('나는 제목')
        self.setGeometry(300, 300, 800, 800)
        self.show()