Ejemplo n.º 1
0
    def init_ui(self) -> Optional[QBoxLayout]:
        """
        initialise the internal widgets of the Fidget
        :inheritors: If you intend your class to be subclassed, don't add any widgets to self.
        """
        self.setWindowTitle(self.title)

        if self.make_indicator:
            self.indicator_label = QLabel('')
            self.indicator_label.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
            self.indicator_label.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
            self.indicator_label.linkActivated.connect(self._detail_button_clicked)

        if self.make_auto:
            self.auto_button = QPushButton('auto')
            self.auto_button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
            self.auto_button.clicked.connect(self._auto_btn_click)

        if self.make_plaintext:
            self.plaintext_button = QPushButton('text')
            self.plaintext_button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
            self.plaintext_button.clicked.connect(self._plaintext_btn_click)

            self._plaintext_widget = PlaintextEditWidget(parent=self)

        if self.make_title:
            self.title_label = QLabel(self.title)
            self.title_label.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
            if self.help:
                self.title_label.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
                self.title_label.linkActivated.connect(self._help_clicked)
Ejemplo n.º 2
0
 def inner_layout(self):
     ret = QHBoxLayout()
     ret.addWidget(link_to('eval("',
                           "https://docs.python.org/3/library/functions.html#eval"))
     ret.addWidget(self.edit)
     ret.addWidget(QLabel('", {"value":value})'))
     return ret
Ejemplo n.º 3
0
    def inner_layout(self):
        ret = QHBoxLayout()

        self.combo_box = QFontComboBox()
        self.combo_box.setCurrentIndex(-1)
        self.combo_box.currentTextChanged.connect(self._update_preview)
        ret.addWidget(self.combo_box)

        self.size_edit = QSpinBox()
        self.size_edit.setValue(8)
        self.size_edit.setRange(6, 50)
        self.size_edit.valueChanged[int].connect(self._update_preview)
        ret.addWidget(self.size_edit)

        self.preview_label = QLabel('preview\n1234567')
        ret.addWidget(self.preview_label)

        self.default_btn = QPushButton('default')

        @self.default_btn.clicked.connect
        def fill_default(a):
            self.fill(QFontDatabase.systemFont(QFontDatabase.GeneralFont))

        ret.addWidget(self.default_btn)

        self.monospace_btn = QPushButton('monospace')

        @self.monospace_btn.clicked.connect
        def fill_mono(a):
            self.fill(QFontDatabase.systemFont(QFontDatabase.FixedFont))

        ret.addWidget(self.monospace_btn)

        return ret
Ejemplo n.º 4
0
 def inner_layout(self):
     ret = QVBoxLayout()
     ret.addWidget(link_to('exec("def main(value):',
                           "https://docs.python.org/3/library/functions.html#exec"))
     ret.addWidget(self.edit)
     ret.addWidget(QLabel('")\nreturn main(value)'))
     return ret
Ejemplo n.º 5
0
    def init_ui(self):
        super().init_ui()

        layout = QHBoxLayout(self)

        with self.setup_provided(layout):
            self.label = QLabel(self.options[0][0][0])
            layout.addWidget(self.label)

        self.setFocusProxy(self.label)
        return layout
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        b = 0
        num_dialog = FidgetQuestion(FidgetInt('b', make_plaintext=True),
                                    parent=self,
                                    cancel_value=None)

        layout = QVBoxLayout()

        line_edit = FidgetInt('a')
        layout.addWidget(line_edit)

        label = QLabel('0')
        layout.addWidget(label)

        browse_btn = QPushButton('...')
        layout.addWidget(browse_btn)

        @browse_btn.clicked.connect
        def _(click_event):
            nonlocal b

            value = num_dialog.exec()
            if value.is_ok() and value.value is not None:
                b = value.value
                label.setText(str(b))

        show_btn = QPushButton('show')
        layout.addWidget(show_btn)

        @show_btn.clicked.connect
        def _(ce):
            a = line_edit.value()
            if not a.is_ok():
                print(a)
                return
            print(a.value * b)

        self.setLayout(layout)
Ejemplo n.º 7
0
    def init_ui(self, layout_cls=None, scrollable=None):
        super().init_ui()
        layout_cls = first_valid(layout_cls=layout_cls,
                                 LAYOUT_CLS=self.LAYOUT_CLS,
                                 _self=self)

        owner = self
        scrollable = first_valid(scrollable=scrollable,
                                 SCROLLABLE=self.SCROLLABLE,
                                 _self=self)

        owner_layout = QVBoxLayout()
        owner.setLayout(owner_layout)

        if scrollable:
            owner = QScrollArea(owner)
            owner.setWidgetResizable(True)
            owner_layout.addWidget(owner)

        master = QWidget()
        master_layout = layout_cls(master)

        if scrollable:
            owner.setWidget(master)
        else:
            owner_layout.addWidget(master)

        self.inners = []
        self.col_labels = []
        self.row_btns = []

        title_in_grid = not self.row_bounds.is_const

        self.col_offset = int(not self.row_bounds.is_const)

        if title_in_grid:
            exclude = (self.title_label, )
        else:
            exclude = ()

        with self.setup_provided(
                master_layout,
                exclude=exclude), self.suppress_update(call_on_exit=False):
            self.grid_layout = QGridLayout()

            field_names = []
            for i, column_template in enumerate(self.inner_templates):
                title = column_template.title or '_' + str(i)
                label = QLabel(title)
                field_names.append(title)
                self.col_labels.append(label)
                self.grid_layout.addWidget(label, 0, i + self.col_offset)

            self.column_count = len(self.inner_templates)

            for i in range(self.row_bounds.initial):
                self.add_row(i)

            master_layout.addLayout(self.grid_layout)

        self.value_type = namedtuple(to_identifier(self.title),
                                     (to_identifier(i.title)
                                      for i in self.inners),
                                     rename=True)

        if title_in_grid and self.title_label:
            self.grid_layout.addWidget(self.title_label, 0, 0)

        # self.setLayout(master_layout)
        self.apply_matrix()

        return master_layout
Ejemplo n.º 8
0
def link_to(text: str, url: str):
    ret = QLabel(f'''<a href='{url}'>{text}</a>''')
    ret.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
    ret.setOpenExternalLinks(True)
    return ret