Пример #1
0
    def ui(self):
        super(AutoRenameWidget, self).ui()

        top_layout = layouts.HorizontalLayout(spacing=2, margins=(0, 0, 0, 0))
        self._unique_id_cbx = checkbox.BaseCheckBox('Unique Id')
        self._last_joint_end_cbx = checkbox.BaseCheckBox('Make Last Joint End')
        top_layout.addStretch()
        top_layout.addWidget(self._unique_id_cbx)
        top_layout.addWidget(self._last_joint_end_cbx)
        self.main_layout.addLayout(top_layout)

        main_splitter = QSplitter(Qt.Horizontal)
        main_splitter.setSizePolicy(QSizePolicy.Preferred,
                                    QSizePolicy.Expanding)
        self.main_layout.addWidget(main_splitter)

        auto_widget = QWidget()
        auto_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0))
        auto_widget.setLayout(auto_layout)
        main_splitter.addWidget(auto_widget)

        self._rules_list = QTreeWidget(self)
        self._rules_list.setHeaderHidden(True)
        self._rules_list.setSortingEnabled(True)
        self._rules_list.setRootIsDecorated(False)
        self._rules_list.setSelectionMode(QAbstractItemView.SingleSelection)
        self._rules_list.sortByColumn(0, Qt.AscendingOrder)
        self._rules_list.setUniformRowHeights(True)
        self._rules_list.setAlternatingRowColors(True)

        auto_layout.addWidget(self._rules_list)

        auto_w = QWidget()
        self.auto_l = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0))
        auto_w.setLayout(self.auto_l)
        auto_w.setMinimumWidth(200)
        main_splitter.addWidget(auto_w)

        self.main_auto_layout = QFormLayout()
        self.auto_l.addLayout(self.main_auto_layout)

        self._rename_btn = buttons.BaseButton('Rename')
        self._rename_btn.setIcon(resources.icon('rename'))
        self.main_layout.addLayout(dividers.DividerLayout())
        self.main_layout.addWidget(self._rename_btn)
Пример #2
0
class PreferencesWidget(base.BaseWidget, object):

    closed = Signal(bool, dict)

    def __init__(self, settings=None, parent=None):
        self._settings = settings
        super(PreferencesWidget, self).__init__(parent=parent)

        self._indexes = dict()
        self._category_buttons = dict()
        self._settings = settings

        self._try_create_defaults()

    def ui(self):
        super(PreferencesWidget, self).ui()

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self._splitter = QSplitter()
        self._splitter.setOrientation(Qt.Horizontal)
        self._splitter.setSizePolicy(QSizePolicy.Preferred,
                                     QSizePolicy.Expanding)
        self._scroll_area = QScrollArea()
        self._scroll_area.setWidgetResizable(True)
        self._scroll_area.setSizePolicy(QSizePolicy.Expanding,
                                        QSizePolicy.Expanding)
        # self._scroll_area.setMinimumWidth(200)
        self._scroll_area_widget_contents = QWidget()
        # self._scroll_area_widget_contents.setGeometry(QRect(0, 0, 480, 595))
        self._scroll_area_layout = layouts.VerticalLayout(spacing=2,
                                                          margins=(1, 1, 1, 1))
        self._scroll_area_layout.setAlignment(Qt.AlignTop)
        self._scroll_area_widget_contents.setLayout(self._scroll_area_layout)
        self._categories_layout = layouts.VerticalLayout()
        self._stack = stack.SlidingStackedWidget()
        self._stack.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self._stack.set_vertical_mode()
        self._buttons_layout = layouts.HorizontalLayout(spacing=1,
                                                        margins=(0, 0, 0, 0))
        self._save_prefs_close_btn = buttons.BaseButton(
            'Save and Close', icon=resources.icon('save'), parent=self)
        self._close_btn = buttons.BaseButton('Close',
                                             icon=resources.icon('cancel'),
                                             parent=self)

        self._buttons_layout.addStretch()
        self._buttons_layout.addWidget(self._save_prefs_close_btn)
        self._buttons_layout.addWidget(self._close_btn)
        self._scroll_area_layout.addLayout(self._categories_layout)
        self._scroll_area.setWidget(self._scroll_area_widget_contents)
        self._splitter.addWidget(self._scroll_area)
        self._splitter.addWidget(self._stack)
        self._splitter.setSizes([150, 450])

        self.main_layout.addWidget(self._splitter)
        self.main_layout.addWidget(dividers.Divider(parent=self))
        self.main_layout.addLayout(self._buttons_layout)

    def setup_signals(self):
        self._save_prefs_close_btn.clicked.connect(
            self._on_save_and_close_prefs)
        self._close_btn.clicked.connect(self._on_close)

    def showEvent(self, event):
        settings = self.settings()
        if not settings:
            return

        groups = settings.childGroups()
        for name, index_widget in self._indexes.items():
            index, widget = index_widget
            settings.beginGroup(name)
            if name not in groups:
                widget.init_defaults(settings)
            widget.show_widget(settings)
            settings.endGroup()

    def settings(self):
        return self._settings

    def set_settings(self, settings):
        if not settings:
            return
        self._settings = settings
        self._try_create_defaults()

    def add_category(self, name, widget):
        category_button = CategoryButton(text=name, parent=self)
        self._categories_layout.insertWidget(
            self._categories_layout.count() - 2, category_button)
        widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        index = self._stack.addWidget(widget)
        self._indexes[name] = (index, widget)
        self._category_buttons[index] = category_button
        category_button.clicked.connect(lambda checked=False, idx=index: self.
                                        _on_switch_category_content(idx))
        widget.init_defaults(settings=self.settings())
        self.closed.connect(widget._on_reset)

    def select_by_name(self, name):
        if name not in self._indexes:
            return
        index = self._indexes[name][0]
        self._stack.setCurrentIndex(index)
        self._category_buttons[index].setChecked(True)

    def _try_create_defaults(self):
        settings = self.settings()
        if not settings:
            return

        groups = settings.childGroups()
        for name, index_widget in self._indexes.items():
            index, widget = index_widget
            init_defaults = False
            if name not in groups:
                init_defaults = True
            settings.beginGroup(name)
            if init_defaults:
                widget.init_defaults(settings)
            settings.endGroup()
        settings.sync()

    def _on_switch_category_content(self, index):
        self._stack.slide_in_index(index)
        self._category_buttons[index].toggle()

    def _on_save_prefs(self):
        settings = self.settings()
        if not settings:
            return

        stored_data = dict()

        for name, index_widget in self._indexes.items():
            index, widget = index_widget
            settings.beginGroup(name)
            data = widget.serialize(settings)
            if data:
                stored_data[name] = data
            settings.endGroup()
        settings.sync()

        return stored_data

    def _on_save_and_close_prefs(self):
        stored_data = self._on_save_prefs()
        self.closed.emit(True, stored_data)

    def _on_close(self):
        self.closed.emit(False, None)
Пример #3
0
    def ui(self):
        super(NameIt, self).ui()

        tools_toolbar = toolbar.ToolBar('Main ToolBar', parent=self)
        tools_toolbar.setMovable(False)
        # tools_toolbar.setAllowedAreas(Qt.TopToolBarArea | Qt.BottomToolBarArea)
        self.main_layout.addWidget(tools_toolbar)

        refresh_btn = buttons.BaseToolButton(parent=tools_toolbar)
        refresh_btn.setIcon(resources.icon('refresh'))
        refresh_btn.clicked.connect(self._on_refresh)
        self._refresh_btn = tools_toolbar.addWidget(refresh_btn)
        self._refresh_btn.setEnabled(False)

        save_btn = buttons.BaseToolButton(parent=tools_toolbar)
        save_btn.setIcon(resources.icon('save'))
        save_btn.clicked.connect(self._on_save)
        self._save_btn = tools_toolbar.addWidget(save_btn)
        self._save_btn.setEnabled(False)

        if self._is_renamer_tool_available():
            renamer_btn = buttons.BaseToolButton(parent=tools_toolbar)
            renamer_btn.setIcon(resources.icon('rename'))
            renamer_btn.clicked.connect(self._on_open_renamer_tool)
            tools_toolbar.addWidget(renamer_btn)

        self._name_file_line = directory.SelectFile(label_text='Naming File',
                                                    parent=tools_toolbar)
        tools_toolbar.addWidget(self._name_file_line)

        base_layout = layouts.HorizontalLayout(spacing=0, margins=(0, 0, 0, 0))
        self.main_layout.addLayout(base_layout)

        panels_splitter = QSplitter(parent=self)
        panels_splitter.setSizePolicy(QSizePolicy.Expanding,
                                      QSizePolicy.Expanding)
        base_layout.addWidget(panels_splitter)

        left_panel_widget = QWidget()
        left_panel_layout = layouts.VerticalLayout(margins=(5, 0, 5, 0))
        left_panel_widget.setLayout(left_panel_layout)
        panels_splitter.addWidget(left_panel_widget)

        # Tab Widget
        rules_tab = QWidget()
        tokens_tab = QWidget()
        templates_tab = QWidget()
        templates_tokens_tab = QWidget()

        self.tabs = tabs.BaseTabWidget()
        self.tabs.addTab(rules_tab, 'Rules')
        self.tabs.addTab(tokens_tab, 'Tokens')
        self.tabs.addTab(templates_tab, 'Templates')
        self.tabs.addTab(templates_tokens_tab, 'Templates Tokens')
        left_panel_layout.addWidget(self.tabs)

        # Rules Tab
        rules_main_layout = layouts.VerticalLayout(spacing=0,
                                                   margins=(5, 5, 5, 5))
        self.rules_list = QListWidget()
        rules_main_layout.addWidget(self.rules_list)
        left_panel_buttons_layout_rules = layouts.HorizontalLayout(margins=(5,
                                                                            5,
                                                                            5,
                                                                            0))
        rules_main_layout.addLayout(left_panel_buttons_layout_rules)
        self.add_rule_btn = buttons.BaseButton(parent=self)
        self.remove_rule_btn = buttons.BaseButton(parent=self)
        self.add_rule_btn.setIcon(resources.icon('plus'))
        self.remove_rule_btn.setIcon(resources.icon('minus'))
        left_panel_buttons_layout_rules.addStretch()
        left_panel_buttons_layout_rules.addWidget(self.add_rule_btn)
        left_panel_buttons_layout_rules.addWidget(self.remove_rule_btn)
        rules_tab.setLayout(rules_main_layout)

        # Tokens Tab
        tokens_main_layout = layouts.VerticalLayout(margins=(5, 5, 5, 5))
        tokens_main_layout.setSpacing(0)
        self.tokens_list = QListWidget()
        tokens_main_layout.addWidget(self.tokens_list)
        left_panel_buttons_layout_tokens = layouts.HorizontalLayout(
            margins=(5, 5, 5, 0))
        tokens_main_layout.addLayout(left_panel_buttons_layout_tokens)
        self.add_token_btn = buttons.BaseButton(parent=self)
        self.remove_token_btn = buttons.BaseButton(parent=self)
        self.add_token_btn.setIcon(resources.icon('plus'))
        self.remove_token_btn.setIcon(resources.icon('minus'))
        left_panel_buttons_layout_tokens.addStretch()
        left_panel_buttons_layout_tokens.addWidget(self.add_token_btn)
        left_panel_buttons_layout_tokens.addWidget(self.remove_token_btn)
        tokens_tab.setLayout(tokens_main_layout)

        # Templates Tab
        templates_main_layout = layouts.VerticalLayout(spacing=0,
                                                       margins=(5, 5, 5, 5))
        self.templates_list = QListWidget()
        templates_main_layout.addWidget(self.templates_list)
        left_panel_buttons_layout_templates = layouts.HorizontalLayout(
            margins=(5, 5, 5, 0))
        templates_main_layout.addLayout(left_panel_buttons_layout_templates)
        self.add_template_btn = buttons.BaseButton(parent=self)
        self.remove_template_btn = buttons.BaseButton(parent=self)
        self.add_template_btn.setIcon(resources.icon('plus'))
        self.remove_template_btn.setIcon(resources.icon('minus'))
        left_panel_buttons_layout_templates.addStretch()
        left_panel_buttons_layout_templates.addWidget(self.add_template_btn)
        left_panel_buttons_layout_templates.addWidget(self.remove_template_btn)
        templates_tab.setLayout(templates_main_layout)

        # Template Tokens Tab
        templates_tokens_main_layout = layouts.VerticalLayout(spacing=0,
                                                              margins=(5, 5, 5,
                                                                       5))
        self.template_tokens_list = QListWidget()
        templates_tokens_main_layout.addWidget(self.template_tokens_list)
        left_panel_buttons_layout_templates_tokens = layouts.HorizontalLayout(
            margins=(5, 5, 5, 0))
        left_panel_buttons_layout_templates_tokens.setContentsMargins(
            5, 5, 5, 0)
        templates_tokens_main_layout.addLayout(
            left_panel_buttons_layout_templates_tokens)
        self.add_template_token_btn = buttons.BaseButton(parent=self)
        self.remove_template_token_btn = buttons.BaseButton(parent=self)
        self.add_template_token_btn.setIcon(resources.icon('plus'))
        self.remove_template_token_btn.setIcon(resources.icon('minus'))
        left_panel_buttons_layout_templates_tokens.addStretch()
        left_panel_buttons_layout_templates_tokens.addWidget(
            self.add_template_token_btn)
        left_panel_buttons_layout_templates_tokens.addWidget(
            self.remove_template_token_btn)
        templates_tokens_tab.setLayout(templates_tokens_main_layout)

        # === PROPERTIES === #
        main_group = QGroupBox('Properties')
        panels_splitter.addWidget(main_group)

        self.group_layout = layouts.VerticalLayout(spacing=0,
                                                   margins=(5, 5, 5, 5))
        main_group.setLayout(self.group_layout)

        # Rules Panel
        self.rules_widget = QWidget(self)
        rules_layout = layouts.GridLayout()
        self.rules_widget.setLayout(rules_layout)
        expression_lbl = label.BaseLabel('Expression', parent=self)
        self.expression_line = lineedit.BaseLineEdit(parent=self)
        self.expression_btn = buttons.BaseButton('   <', parent=self)
        self.expression_btn.setEnabled(False)
        self.expression_btn.setStyleSheet(
            "QPushButton::menu-indicator{image:url(none.jpg);}")
        self.expression_menu = QMenu(self)
        self.expression_btn.setMenu(self.expression_menu)
        iterator_lbl = label.BaseLabel('Iterator', parent=self)
        self.iterator_cbx = combobox.BaseComboBox(parent=self)
        for it_format in [
                '@', '@^', '#', '##', '###', '####', '#####', 'None'
        ]:
            self.iterator_cbx.addItem(it_format)
        description_rule_lbl = label.BaseLabel('Description', parent=self)
        self.description_rule_text = QTextEdit(parent=self)
        self.group_layout.addWidget(self.rules_widget)

        rules_layout.addWidget(expression_lbl, 0, 0, Qt.AlignRight)
        rules_layout.addWidget(self.expression_line, 0, 1)
        rules_layout.addWidget(self.expression_btn, 0, 2)
        rules_layout.addWidget(iterator_lbl, 1, 0, Qt.AlignRight | Qt.AlignTop)
        rules_layout.addWidget(self.iterator_cbx, 1, 1, 1, 2)
        rules_layout.addWidget(description_rule_lbl, 2, 0,
                               Qt.AlignRight | Qt.AlignTop)
        rules_layout.addWidget(self.description_rule_text, 2, 1, 1, 2)

        # Tokens Panel
        self.tokens_widget = QWidget(parent=self)
        tokens_layout = layouts.GridLayout()
        self.tokens_widget.setLayout(tokens_layout)
        values_lbl = label.BaseLabel('Values')
        data = {'key': list(), 'value': list()}
        self.values_table = TokensTable(data, 0, 2)
        self.values_table.setSizePolicy(QSizePolicy.Expanding,
                                        QSizePolicy.Expanding)
        values_buttons_layout = layouts.HorizontalLayout(margins=(5, 5, 5, 0))
        self.add_key_value_btn = buttons.BaseButton(parent=self)
        self.remove_key_value_btn = buttons.BaseButton(parent=self)
        self.add_key_value_btn.setIcon(resources.icon('plus'))
        self.remove_key_value_btn.setIcon(resources.icon('minus'))
        values_buttons_layout.addWidget(self.add_key_value_btn)
        values_buttons_layout.addWidget(self.remove_key_value_btn)
        values_buttons_layout.addStretch()
        default_lbl = label.BaseLabel('Default', parent=self)
        self.default_cbx = combobox.BaseComboBox(parent=self)
        description_tokens_lbl = label.BaseLabel('Description', parent=self)
        self.description_token_text = QTextEdit(parent=self)
        self.group_layout.addWidget(self.tokens_widget)
        self.tokens_widget.hide()
        tokens_layout.addWidget(values_lbl, 0, 0, Qt.AlignRight | Qt.AlignTop)
        tokens_layout.addWidget(self.values_table, 0, 1, 2, 1)
        tokens_layout.addLayout(values_buttons_layout, 0, 2)
        tokens_layout.addWidget(default_lbl, 4, 0, Qt.AlignRight)
        tokens_layout.addWidget(self.default_cbx, 4, 1, 1, 2)
        tokens_layout.addWidget(description_tokens_lbl, 5, 0,
                                Qt.AlignRight | Qt.AlignTop)
        tokens_layout.addWidget(self.description_token_text, 5, 1, 1, 2)

        # Templates Panel
        self.templates_widget = QWidget(parent=self)
        templates_layout = layouts.VerticalLayout()
        self.templates_widget.setLayout(templates_layout)
        pattern_layout = layouts.HorizontalLayout(spacing=5,
                                                  margins=(5, 5, 5, 5))
        pattern_lbl = label.BaseLabel('Pattern: ', parent=self)
        self.pattern_line = lineedit.BaseLineEdit(parent=self)
        pattern_layout.addWidget(pattern_lbl)
        pattern_layout.addWidget(self.pattern_line)
        templates_layout.addLayout(pattern_layout)
        templates_layout.addLayout(dividers.DividerLayout())
        self.template_tokens_layout = layouts.GridLayout()
        self.template_tokens_layout.setAlignment(Qt.AlignTop)
        template_tokens_frame = QFrame(parent=self)
        template_tokens_frame.setFrameShape(QFrame.StyledPanel)
        template_tokens_frame.setFrameShadow(QFrame.Sunken)
        template_tokens_frame.setLayout(self.template_tokens_layout)
        templates_layout.addWidget(template_tokens_frame)
        self.group_layout.addWidget(self.templates_widget)
        self.templates_widget.hide()

        # Templates Tokens Panel
        self.templates_tokens_widget = QWidget(parent=self)
        templates_tokens_layout = layouts.VerticalLayout()
        self.templates_tokens_widget.setLayout(templates_tokens_layout)
        description_templates_token_layout = layouts.HorizontalLayout(
            spacing=5, margins=(5, 5, 5, 5))
        description_tokens_layout = layouts.VerticalLayout()
        description_templates_token_lbl = label.BaseLabel('Description: ',
                                                          parent=self)
        description_tokens_layout.addWidget(description_templates_token_lbl)
        description_tokens_layout.addStretch()
        self.description_templates_token_text = QTextEdit(parent=self)
        description_templates_token_layout.addLayout(description_tokens_layout)
        description_templates_token_layout.addWidget(
            self.description_templates_token_text)
        templates_tokens_layout.addLayout(description_templates_token_layout)
        self.group_layout.addWidget(self.templates_tokens_widget)
        self.templates_tokens_widget.hide()

        # Initialize database
        self._init_db()

        # First update of the UI
        self.update_expression_menu()
        self.update_tokens_properties_state()
        self.update_rules_properties_state()
        self.update_templates_properties_state()