Esempio n. 1
0
    def setup_page(self):
        # Variables
        newcb = self.create_checkbox

        # Widgets
        general_widget = QWidget()
        check_show_all = newcb(_("Show all files"), 'show_all')
        check_show_hidden_files = newcb(_("Show hidden files"), 'show_hidden')
        check_single_click = newcb(_("Single click to open files"),
                                   'single_click_to_open')
        edit_filename_filters = self.create_textedit(
            _("Show files with these extensions:"),
            'name_filters',
            tip=("Enter values separated by commas"),
            content_type=list,
        )
        edit_filename_filters.setEnabled(not check_show_all.isChecked())

        associations_widget = QWidget()
        self.edit_file_associations = self.create_textedit(
            '',
            'file_associations',
            content_type=dict,
        )
        file_associations = FileAssociationsWidget()

        # Widget setup
        file_associations.load_values(self.get_option('file_associations'))
        # The actual config data is stored on this text edit set to invisible
        self.edit_file_associations.setVisible(False)

        # Layout
        layout = QVBoxLayout()
        layout.addWidget(check_show_all)
        layout.addWidget(check_show_hidden_files)
        layout.addWidget(check_single_click)
        layout.addWidget(edit_filename_filters)
        general_widget.setLayout(layout)

        layout_file = QVBoxLayout()
        layout_file.addWidget(file_associations)
        layout_file.addWidget(self.edit_file_associations)
        associations_widget.setLayout(layout_file)

        tabs = QTabWidget()
        tabs.addTab(self.create_tab(general_widget), _("General"))
        tabs.addTab(self.create_tab(associations_widget),
                    _("File associations"))

        tab_layout = QVBoxLayout()
        tab_layout.addWidget(tabs)

        self.setLayout(tab_layout)

        # Signals
        file_associations.sig_data_changed.connect(self.update_associations)
        check_show_all.toggled.connect(
            lambda show_all: edit_filename_filters.setEnabled(not show_all))
Esempio n. 2
0
def file_assoc_widget(qtbot, tmp_path):
    widget = FileAssociationsWidget()
    qtbot.addWidget(widget)
    if os.name == 'nt':
        ext = '.exe'
        path_obj = tmp_path / ('app 2' + ext)
        path_obj.write_bytes(b'Binary file contents')
        fpath = str(path_obj)
    elif sys.platform == 'darwin':
        ext = '.app'
        path_obj = tmp_path / ('app 2' + ext)
        path_obj.mkdir()
        fpath = str(path_obj)
    else:
        ext = '.desktop'
        path_obj = tmp_path / ('app 2' + ext)
        path_obj.write_text(u'Text file contents')
        fpath = str(path_obj)

    data = {
        '*.csv':
            [
                ('App name 1', '/path/to/app 1' + ext),
                ('App name 2', fpath),
            ],
        '*.txt':
            [
                ('App name 2', fpath),
                ('App name 3', '/path/to/app 3' + ext),
            ],
    }
    widget.load_values(data)
    widget.show()
    widget.test_data = data
    return qtbot, widget
Esempio n. 3
0
    def setup_page(self):
        # Variables
        newcb = self.create_checkbox

        # Widgets
        general_widget = QWidget()

        # General options group
        basic_group = QGroupBox(_("General options"))
        check_show_hidden_files = newcb(_("Show hidden files"), 'show_hidden')
        check_single_click = newcb(_("Single click to open files"),
                                   'single_click_to_open')
        basic_layout = QVBoxLayout()
        basic_layout.addWidget(check_show_hidden_files)
        basic_layout.addWidget(check_single_click)
        basic_group.setLayout(basic_layout)

        # Filter options group
        filter_group = QGroupBox(_("Filter settings"))
        description_label = QLabel(
            _('Filter files by name, extension, or more using '
              '<a href="https://en.wikipedia.org/wiki/Glob_(programming)">glob '
              'patterns.</a> Please enter the glob patterns of the files you '
              'want to show, separated by commas.'))
        description_label.setOpenExternalLinks(True)
        description_label.setWordWrap(True)
        self.edit_filename_filters = self.create_textedit(
            '',
            'name_filters',
            tip=("Enter values separated by commas"),
            content_type=list,
        )

        self.edit_filename_filters.setEnabled(True)

        reset_btn = QPushButton(_("Reset to default values"))
        reset_btn.clicked.connect(self.reset_to_default)
        filter_layout = QVBoxLayout()
        filter_layout.addWidget(description_label)
        filter_layout.addWidget(self.edit_filename_filters)
        filter_layout.addWidget(reset_btn)
        filter_group.setLayout(filter_layout)

        associations_widget = QWidget()
        self.edit_file_associations = self.create_textedit(
            '',
            'file_associations',
            content_type=dict,
        )
        file_associations = FileAssociationsWidget()

        # Widget setup
        file_associations.load_values(self.get_option('file_associations'))
        # The actual config data is stored on this text edit set to invisible
        self.edit_file_associations.setVisible(False)

        layout = QVBoxLayout()
        layout.addWidget(basic_group)
        layout.addWidget(filter_group)
        general_widget.setLayout(layout)

        layout_file = QVBoxLayout()
        layout_file.addWidget(file_associations)
        layout_file.addWidget(self.edit_file_associations)
        associations_widget.setLayout(layout_file)

        self.tabs = QTabWidget()
        self.tabs.addTab(self.create_tab(general_widget), _("General"))
        self.tabs.addTab(self.create_tab(associations_widget),
                         _("File associations"))

        tab_layout = QVBoxLayout()
        tab_layout.addWidget(self.tabs)

        self.setLayout(tab_layout)

        # Signals
        file_associations.sig_data_changed.connect(self.update_associations)