Exemplo n.º 1
0
    def __init__(self,
                 title: str,
                 body: str,
                 locale_keys: dict,
                 components: List[ViewComponent] = None,
                 confirmation_label: str = None,
                 deny_label: str = None):
        super(ConfirmationDialog, self).__init__()
        self.setWindowTitle(title)
        self.setStyleSheet('QLabel { margin-right: 25px; }')
        self.bt_yes = self.addButton(
            locale_keys['popup.button.yes'] if not confirmation_label else
            confirmation_label.capitalize(), QMessageBox.YesRole)
        self.bt_yes.setStyleSheet(css.OK_BUTTON)

        self.addButton(
            locale_keys['popup.button.no']
            if not deny_label else deny_label.capitalize(), QMessageBox.NoRole)

        if body:
            if not components:
                self.setIcon(QMessageBox.Question)

            self.layout().addWidget(QLabel(body), 0, 1)

        if components:
            comps_container = QWidget(parent=self)
            comps_container.setLayout(QVBoxLayout())

            for idx, comp in enumerate(components):
                if isinstance(comp, SingleSelectComponent):
                    inst = new_single_select(comp)
                elif isinstance(comp, MultipleSelectComponent):
                    inst = MultipleSelectQt(comp, None)
                else:
                    raise Exception("Cannot render instances of " +
                                    comp.__class__.__name__)

                comps_container.layout().addWidget(inst)

            self.layout().addWidget(comps_container, 1, 1)

        self.exec_()
Exemplo n.º 2
0
    def __init__(self,
                 window: QWidget,
                 manager: GenericSoftwareManager,
                 i18n: dict,
                 config: Configuration,
                 show_panel_after_restart: bool = False):
        super(GemSelectorPanel, self).__init__()
        self.window = window
        self.manager = manager
        self.config = config
        self.setLayout(QGridLayout())
        self.setWindowIcon(QIcon(resource.get_path('img/logo.svg')))
        self.setWindowTitle(i18n['gem_selector.title'])
        self.resize(400, 400)
        self.show_panel_after_restart = show_panel_after_restart

        self.label_question = QLabel(i18n['gem_selector.question'])
        self.label_question.setStyleSheet('QLabel { font-weight: bold}')
        self.layout().addWidget(self.label_question, 0, 1, Qt.AlignHCenter)

        self.bt_proceed = QPushButton(i18n['change'].capitalize())
        self.bt_proceed.setStyleSheet(css.OK_BUTTON)
        self.bt_proceed.clicked.connect(self.save)

        self.bt_exit = QPushButton(i18n['exit'].capitalize())
        self.bt_exit.clicked.connect(self.exit)

        self.gem_map = {}
        gem_options = []
        default = set()

        for m in manager.managers:
            if m.can_work():
                modname = m.__module__.split('.')[-2]
                op = InputOption(
                    label=i18n.get('gem.{}.label'.format(modname),
                                   modname.capitalize()),
                    tooltip=i18n.get('gem.{}.info'.format(modname)),
                    value=modname,
                    icon_path='{r}/gems/{n}/resources/img/{n}.png'.format(
                        r=ROOT_DIR, n=modname))

                gem_options.append(op)
                self.gem_map[modname] = m

                if m.is_enabled() and m in manager.working_managers:
                    default.add(op)

        if self.config.enabled_gems:
            default_ops = {
                o
                for o in gem_options if o.value in self.config.enabled_gems
            }
        else:
            default_ops = default

        self.bt_proceed.setEnabled(bool(default_ops))

        self.gem_select_model = MultipleSelectComponent(
            label='',
            options=gem_options,
            default_options=default_ops,
            max_per_line=3)

        self.gem_select = MultipleSelectQt(self.gem_select_model,
                                           self.check_state)
        self.layout().addWidget(self.gem_select, 1, 1)

        self.layout().addWidget(new_spacer(), 2, 1)

        self.layout().addWidget(self.bt_proceed, 3, 1, Qt.AlignRight)
        self.layout().addWidget(self.bt_exit, 3, 1, Qt.AlignLeft)

        self.adjustSize()
        self.setFixedSize(self.size())
        qt_utils.centralize(self)