示例#1
0
        def init_ui(self):
            layout = QVBoxLayout(self)
            self.combo_box = QComboBox()
            self.combo_box.currentIndexChanged.connect(self.change_value)
            layout.addWidget(self.combo_box)

            return layout
示例#2
0
        def init_ui(self):
            layout = QVBoxLayout(self)
            self.check_box = QCheckBox()
            self.check_box.toggled.connect(self.change_value)
            layout.addWidget(self.check_box)

            return layout
示例#3
0
    def setup_ui(self):
        master_layout = QHBoxLayout()
        self.tree = QTreeWidget()
        self.tree.setHeaderLabels(['item', '# of episodes', 'location'])

        master_layout.addWidget(self.tree)

        button_set = QVBoxLayout()
        save_btn = QToolButton()
        save_btn.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        save_action = QAction('save')
        save_btn.setDefaultAction(save_action)
        save_menu = QMenu(parent=self)
        save_as_action = save_menu.addAction('save as')

        def save_project(proj: CerialProject, path: Path):
            with path.open('w') as w:
                proj.dump(w)
            proj.path = path

        def save_as(*a):
            filename, _ = QFileDialog.getSaveFileName(
                self,
                'save as',
                filter='cerial project (*.cerl);; all files (*.*)')
            if not filename:
                return
            path = Path(filename)
            save_project(self.project, path)

        save_as_action.triggered.connect(save_as)

        @save_action.triggered.connect
        def save(*a):
            if self.project.path is None:
                save_as(*a)
            else:
                save_project(self.project, self.project.path)

        save_btn.setMenu(save_menu)
        save_btn.setPopupMode(QToolButton.MenuButtonPopup)

        add_btn = QPushButton('add episodes')
        add_btn.clicked.connect(self.show_add_dialog)
        play_btn = QPushButton('play...')
        stats_btn = QPushButton('statistics')

        button_set.addWidget(save_btn)
        button_set.addWidget(add_btn)
        button_set.addWidget(play_btn)
        button_set.addWidget(stats_btn)

        master_layout.addLayout(button_set)

        self.setLayout(master_layout)

        self.add_dialog = FidgetQuestion(AddEpisodes('add episodes'),
                                         cancel_value=None)
示例#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
示例#5
0
    def setup_provided(self, pre_layout: QVBoxLayout, post_layout=..., exclude=()):
        """
        a context manager that will add the pre_provided widgets before the block and the post_provided after it.
        :param pre_layout: a layout to add the pre_provided to
        :param post_layout: a layout to add teh post_provided to, default is to use pre_layout
        :param exclude: which provided widgets to exclude
        """
        for p in self.provided_pre(exclude=exclude):
            pre_layout.addWidget(p)
        yield
        if post_layout is ...:
            post_layout = pre_layout
        for p in self.provided_post(exclude=exclude):
            post_layout.addWidget(p)

        self._update_indicator()
示例#6
0
    def init_ui(self, frame_style=None, layout_cls=None):
        super().init_ui()

        master_layout = QVBoxLayout(self)

        frame = QFrame()
        if frame_style is not None:
            frame.setFrameStyle(frame_style)

        layout_cls = first_valid(layout_cls=layout_cls,
                                 LAYOUT_CLS=self.LAYOUT_CLS,
                                 _self=self)

        layout = layout_cls()

        with self.setup_provided(master_layout, layout):
            self.selector = self.selector_cls('select option')
            self.stacked = QStackedWidget()

            self.inners = {}
            for name, inner_template in self.inner_templates.items():
                inner: Fidget[T] = inner_template()
                if self.inners.setdefault(name, inner) is not inner:
                    raise TypeError(f'duplicate inner name: {name}')

                for p in chain(inner.provided_pre(), inner.provided_post()):
                    p.hide()

                self.stacked.addWidget(inner)
                self.selector.add_option(name)

                inner.on_change.connect(self.change_value)

            self.selector.on_change.connect(self._selector_changed)
            layout.addWidget(self.selector)
            layout.addWidget(self.stacked)

        if not self.inners:
            raise ValueError('at least one inner fidget must be provided')
        self.setFocusProxy(next(iter(self.inners.values())))

        frame.setLayout(layout)
        master_layout.addWidget(frame)

        return master_layout
示例#7
0
class FidgetTabs(FidgetMapping):
    def __init__(self,
                 title,
                 inner_templates: Iterable[NamedTemplate] = None,
                 **kwargs):
        super().__init__(title, inner_templates, **kwargs)
        self.tabbed: QTabWidget = None
        self.summary_layout = None

        self.init_ui()

    INNER_TEMPLATES: Iterable[NamedTemplate] = None

    def init_ui(self):
        super().init_ui()

        layout = QVBoxLayout()

        self.tabbed = QTabWidget()
        self.summary_layout = QVBoxLayout()

        for name, inner in self.make_inners().items():
            inner.on_change.connect(self.change_value)
            self.tabbed.addTab(inner, name)

        with self.setup_provided(self.summary_layout):
            pass
        if self.summary_layout.count():
            summary = QWidget()
            summary.setLayout(self.summary_layout)
            self.tabbed.addTab(summary, 'summary')
        else:
            self.summary_layout = None

        layout.addWidget(self.tabbed)
        self.setLayout(layout)

        return layout

    def indication_changed(self, value):
        if self.summary_layout:
            icon = ok_icon if value.is_ok() else error_icon
            self.tabbed.setTabIcon(len(self.inners), icon())

    def keyPressEvent(self, event):
        def mutate_focus(change):
            curr_index = self.tabbed.currentIndex()
            curr_index += change
            self.tabbed.setCurrentIndex(curr_index)

        if event.key() == Qt.Key_Right:
            mutate_focus(1)
        if event.key() == Qt.Key_Left:
            mutate_focus(-1)
        else:
            super().keyPressEvent(event)
示例#8
0
    class RadioSelector(Selector):
        """
        a selector using radio buttons
        """
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)

            self.group_box: QGroupBox = None
            self.layout: QVBoxLayout = None
            self.radio_buttons: List[QRadioButton] = None

            self.init_ui()

        def init_ui(self):
            layout = QVBoxLayout(self)
            self.group_box = QGroupBox()
            self.layout = QVBoxLayout(self.group_box)
            self.radio_buttons = []

            layout.addWidget(self.group_box)

            return layout

        def parse(self):
            for i, rb in enumerate(self.radio_buttons):
                if rb.isChecked():
                    return i
            raise ParseError('no radio buttons')

        def add_option(self, name):
            rb = QRadioButton()
            rb.setText(name)
            self.layout.addWidget(rb)
            if not self.radio_buttons:
                rb.setChecked(True)
            self.radio_buttons.append(rb)
            rb.toggled.connect(self.change_value)
            super().add_option(name)

        def fill(self, index):
            if isinstance(index, int):
                self.radio_buttons[index].setChecked(True)
            super().fill(index)
示例#9
0
    def init_ui(self):
        super().init_ui()

        layout = QVBoxLayout()

        self.tabbed = QTabWidget()
        self.summary_layout = QVBoxLayout()

        for name, inner in self.make_inners().items():
            inner.on_change.connect(self.change_value)
            self.tabbed.addTab(inner, name)

        with self.setup_provided(self.summary_layout):
            pass
        if self.summary_layout.count():
            summary = QWidget()
            summary.setLayout(self.summary_layout)
            self.tabbed.addTab(summary, 'summary')
        else:
            self.summary_layout = None

        layout.addWidget(self.tabbed)
        self.setLayout(layout)

        return layout
示例#10
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)
示例#11
0
        def init_ui(self):
            layout = QVBoxLayout(self)
            self.group_box = QGroupBox()
            self.layout = QVBoxLayout(self.group_box)
            self.radio_buttons = []

            layout.addWidget(self.group_box)

            return layout
示例#12
0
    def init_ui(self):
        master_layout = QVBoxLayout()

        inner_layout = self.inner_layout()
        master_layout.addLayout(inner_layout)

        btn_layout = QHBoxLayout()
        btn_layout.addWidget(self.cancel_btn)
        btn_layout.addWidget(self.ok_btn)
        master_layout.addLayout(btn_layout)

        self.setLayout(master_layout)

        self.setWindowTitle(self.TITLE)
示例#13
0
 def inner_layout(self):
     ret = QVBoxLayout()
     ret.addWidget(self.edit)
     ret.addWidget(link_to('python formatted string specifications',
                           r'https://docs.python.org/3/library/string.html#format-string-syntax'))
     return ret
示例#14
0
 def inner_layout(self):
     ret = QVBoxLayout()
     ret.addWidget(self.edit)
     ret.addWidget(link_to('python format mini-language specifications',
                           r'https://docs.python.org/3/library/string.html#format-specification-mini-language'))
     return ret
示例#15
0
文件: table.py 项目: talos-gis/Fidget
    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
示例#16
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_btns = []
        self.row_btns = []

        title_in_grid = not (self.row_bounds.is_const
                             or self.column_bounds.is_const)

        self.row_offset = int(not self.column_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()

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

            for i in range(self.column_bounds.initial):
                self.add_col(i)

            master_layout.addLayout(self.grid_layout)

        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
示例#17
0
    def init_ui(self) -> Optional[QBoxLayout]:
        super().init_ui()
        self.setWindowModality(Qt.WindowModal)

        master_layout = QVBoxLayout(self)

        self.print_widget = QGroupBox('current value:')
        print_master_layout = QVBoxLayout(self.print_widget)

        print_layout = QHBoxLayout()
        print_master_layout.addLayout(print_layout)

        self.print_edit = QPlainTextEdit()
        self.print_edit.setReadOnly(True)
        print_layout.addWidget(self.print_edit)

        print_extras_layout = QGridLayout()

        self.print_combo = QComboBox()
        file_button = QPushButton('to file...')
        file_button.clicked.connect(self.save_file)
        print_extras_layout.addWidget(file_button, 0, 0)
        print_extras_layout.addWidget(self.print_combo, 1, 0)

        print_layout.addLayout(print_extras_layout)

        master_layout.addWidget(self.print_widget)

        self.clone_button = QPushButton('🡇')
        self.clone_button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.clone_button.clicked.connect(self._clone_btn_clicked)
        master_layout.addWidget(self.clone_button)

        self.parse_widget = QGroupBox('set value:')
        parse_master_layout = QVBoxLayout(self.parse_widget)

        parse_layout = QHBoxLayout()
        parse_master_layout.addLayout(parse_layout)

        self.parse_edit = self._ShiftEnterIgnoringPlainTextEdit()
        self.parse_edit.textChanged.connect(self.change_value)
        self.print_combo.activated.connect(self.update_print)
        parse_layout.addWidget(self.parse_edit)

        parse_extras_layout = QGridLayout()

        self.parse_combo = QComboBox()
        self.parse_combo.activated.connect(self.change_value)
        parse_extras_layout.addWidget(self.parse_combo, 0, 0)

        if self.indicator_label:
            parse_extras_layout.addWidget(self.indicator_label, 0, 1)

        file_button = QPushButton('from file...')
        file_button.clicked.connect(self.load_file)
        parse_extras_layout.addWidget(file_button, 1, 0, 1, 2)

        self.apply_button = QPushButton('apply')
        self.apply_button.clicked.connect(self.apply_parse)
        parse_extras_layout.addWidget(self.apply_button, 2, 0)

        self.ok_button = QPushButton('OK')
        self.ok_button.clicked.connect(self.commit_parse)
        parse_extras_layout.addWidget(self.ok_button, 2, 1)

        parse_layout.addLayout(parse_extras_layout)

        master_layout.addWidget(self.parse_widget)

        self.font_button = QPushButton('font...')
        self.font_button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.font_button.clicked.connect(self._choose_font)
        master_layout.addWidget(self.font_button)

        self.on_change.connect(self._on_value_change)

        return master_layout