Пример #1
0
    def finilizeSubiTLanguageSelectionGuiWidgets(self):
        from SubProviders import getAvaliableLanguages
        from Settings.Config import SubiTConfig

        languages_order = SubiTConfig.Singleton().getList\
            ('Providers', 'languages_order')
        all_languages = getAvaliableLanguages()
        not_selected_languages = filter\
            (lambda l: l not in languages_order, all_languages)

        def _add_languages(languages, check_state):
            for language in languages:
                lang_item = QtGui.QListWidgetItem(language)
                lang_item.setCheckState(check_state)
                self.subitLanguageDialog.languageOrderListWidget.addItem\
                    (lang_item)

        _add_languages(languages_order, QtCore.Qt.CheckState.Checked)
        _add_languages(not_selected_languages, QtCore.Qt.CheckState.Unchecked)

        def _on_item_clicked(item):
            languages_items = \
                self.subitLanguageDialog.languageOrderListWidget.findItems\
                    ('.*', QtCore.Qt.MatchFlag.MatchRegExp)
            languages_checked = Utils.myfilter\
                (lambda i: i.checkState() == QtCore.Qt.CheckState.Checked,
                 languages_items)
            self.subitLanguageDialog.okPushButton.setEnabled\
                (len(languages_checked) > 0)

        self.subitLanguageDialog.languageOrderListWidget.itemClicked.connect\
            (_on_item_clicked)

        # Connect the click event on up and down buttons
        self.subitLanguageDialog.languageDownToolButton.clicked.connect\
            (lambda: (self._onDownToolButtonClicked
                          (self.subitLanguageDialog.languageOrderListWidget)))
        self.subitLanguageDialog.languageUpToolButton.clicked.connect\
            (lambda: (self._onUpToolButtonClicked
                          (self.subitLanguageDialog.languageOrderListWidget)))
        self.subitLanguageDialog.okPushButton.clicked.connect\
            (self._onLanguageSelectionOkClicked)

        from Utils import exit
        self.subitLanguageDialog.cancelPushButton.clicked.connect(exit)
Пример #2
0
    def finilizeSubiTSettingsGuiWidgets(self):
        #============================================
        # Global Tab
        #============================================
        from Settings.Config import SubiTConfig
        from Settings.Updaters import getUpdater
        
        version = SubiTConfig.Singleton().getStr\
            ('Global', 'version', 'Failed getting the vesion')
        close_on_finish = SubiTConfig.Singleton().getBoolean\
            ('Global', 'close_on_finish', False)
        default_directory = SubiTConfig.Singleton().getStr\
            ('Global', 'default_directory', Utils.GetProgramDir())
        always_use_default_directory = SubiTConfig.Singleton().getBoolean\
            ('Global', 'always_use_default_directory', False)

        remember_last_window_size = SubiTConfig.Singleton().getBoolean\
            ('Gui', 'remember_last_window_size', True)
        remember_last_window_position = SubiTConfig.Singleton().getBoolean\
            ('Gui', 'remember_last_window_position', False)

        check_updates = SubiTConfig.Singleton().getBoolean\
            ('Updates', 'check_updates', True)
        auto_update = SubiTConfig.Singleton().getBoolean\
            ('Updates', 'auto_update', False)

        self.subitSettingsDialog.closeOnFinishCheckBox\
            .setChecked(close_on_finish)
        self.subitSettingsDialog.defaultDirectoryLineEdit\
            .setText(default_directory)
        self.subitSettingsDialog.alwaysUseDefaultDirCheckBox\
            .setChecked(always_use_default_directory)

        self.subitSettingsDialog.rememberLastWindowSizeCheckBox.setChecked\
            (remember_last_window_size)
        self.subitSettingsDialog.rememberLastWindowPositionCheckBox.setChecked\
            (remember_last_window_position)

        self.subitSettingsDialog.checkForUpdatesCheckBox\
            .setChecked(check_updates)
        self.subitSettingsDialog.autoUpdateCheckBox\
            .setEnabled(check_updates)
        self.subitSettingsDialog.autoUpdateCheckBox\
            .setChecked(auto_update)

        self.subitSettingsDialog.okPushButton.clicked.connect\
            (self._onOkPushButtonClicked)
        self.subitSettingsDialog.defaultDirectoryBrowseButton.clicked.connect\
            (self._onDefaultDirectoryBrowseButtonClicked)
        self.subitSettingsDialog.checkForUpdatesButton.clicked.connect\
            (self._onCheckForUpdateFiredInSettings)

        #============================================
        # Providers Tab
        #============================================
        from SubProviders import getAvaliableLanguages
        from SubProviders import getAvaliableSubProviders
        from SubProviders import getSubProviderByName
        from SubProviders import buildSubProviderName
        from SubProviders import getSubProviderPngByName

        languages_order = SubiTConfig.Singleton().getList\
            ('Providers', 'languages_order')
        all_languages = getAvaliableLanguages()
        not_selected_languages = filter\
            (lambda l: l not in languages_order, all_languages)

        def _add_languages(languages, check_state):
            for language in languages:
                lang_item = QtGui.QListWidgetItem(language)
                lang_item.setCheckState(check_state)
                self.subitSettingsDialog.advancedLanguageListWidget\
                    .addItem(lang_item)

        _add_languages(languages_order, QtCore.Qt.CheckState.Checked)
        _add_languages(not_selected_languages, QtCore.Qt.CheckState.Unchecked)

        # Connect the click event on up and down buttons
        self.subitSettingsDialog.languageDownToolButton.clicked.connect\
            (lambda: (self._onDownToolButtonClicked
                      (self.subitSettingsDialog.advancedLanguageListWidget)))
        self.subitSettingsDialog.languageUpToolButton.clicked.connect\
            (lambda: (self._onUpToolButtonClicked
                      (self.subitSettingsDialog.advancedLanguageListWidget)))
        

        providers_order = SubiTConfig.Singleton().getList\
            ('Providers', 'providers_order')
        all_providers = getAvaliableSubProviders()
        not_selected_providers = filter\
            (lambda p: p not in providers_order, all_providers)

        def _add_providers(providers, check_stage):
            for provider_name in providers:
                provider_png = getSubProviderPngByName(provider_name)
                provider_item = self._list_widget_item_with_provider_icon\
                    (provider_png, provider_name, provider_name)
                provider_item.setCheckState(check_stage)
                self.subitSettingsDialog.advancedProvidersListWidget\
                    .addItem(provider_item)

        _add_providers(providers_order, QtCore.Qt.CheckState.Checked)
        _add_providers(not_selected_providers, QtCore.Qt.CheckState.Unchecked)

        # Connect the click event on up and down buttons
        self.subitSettingsDialog.providerUpTooButton.clicked.connect\
            (lambda: (self._onUpToolButtonClicked
                      (self.subitSettingsDialog.advancedProvidersListWidget)))
        self.subitSettingsDialog.providerDownToolButton.clicked.connect\
            (lambda: (self._onDownToolButtonClicked
                      (self.subitSettingsDialog.advancedProvidersListWidget)))


        def _select_all_providers(select):
            # If the checkbox is checked, we want to disable the widget because
            # we are going to select all the providers.
            self.subitSettingsDialog.advancedProvidersListWidget.setEnabled(not select)
            self.subitSettingsDialog.providerUpTooButton.setEnabled(not select)
            self.subitSettingsDialog.providerDownToolButton.setEnabled(not select)

            if select:
                providers_items = self.subitSettingsDialog.\
                    advancedProvidersListWidget.findItems\
                    ('.*', QtCore.Qt.MatchFlag.MatchRegExp)
                for item in providers_items:
                    # Check
                    item.setCheckState(QtCore.Qt.CheckState.Checked)


        self.subitSettingsDialog.useAllProvidersCheckBox.toggled.connect(_select_all_providers)

        do_properties_based_ranks = SubiTConfig.Singleton().getBoolean\
            ('Flow', 'do_properties_based_rank', True)
        self.subitSettingsDialog.rankUsingPropertiesCheckBox.setChecked\
            (do_properties_based_ranks)
        do_in_depth_search = SubiTConfig.Singleton().getBoolean\
            ('Flow', 'in_depth_search', False)
        self.subitSettingsDialog.inDepthSearchCheckBox.setChecked\
            (do_in_depth_search)

        #============================================
        # Association Tab
        #============================================
        from Settings.Associators import getAssociator
        if getAssociator():
            associate_extensions = SubiTConfig.Singleton().getBoolean\
                ('Association', 'associate_extensions', True)
            extensions_keys = SubiTConfig.Singleton().getList\
                ('Association', 'extensions_keys')

            self.subitSettingsDialog.associateExtensionsCheckBox.setChecked\
                (associate_extensions)
            self.subitSettingsDialog.extensionsListWidget.addItems\
                (extensions_keys)

            self.subitSettingsDialog.extensionsDeleteToolButton.clicked.connect\
                (self._onExtensionsDeleteToolButtonClicked)
            self.subitSettingsDialog.extensionsAddToolButton.clicked.connect\
                (self._onExtensionsAddToolButtonClicked)

            from Interaction import getDefaultInteractorByConfig
            from Interaction import InteractionTypes
            
            interaction_type = getDefaultInteractorByConfig()
            self.subitSettingsDialog.interactionTypeSelectionComboBox.addItem\
                (InteractionTypes.InteractionTypeDescriptions[interaction_type])

            for type in InteractionTypes.InteractionTypeDescriptions.iteritems():
                if type[0] != interaction_type:
                    self.subitSettingsDialog\
                        .interactionTypeSelectionComboBox.addItem(type[1])

        else:
            # We disable the whole tab
            self.subitSettingsDialog.fileExtensionsGroupBpx.setEnabled(False)

        self._onCheckForUpdateFiredInSettings()