示例#1
0
def handleAssociationAction(associate):
    from Settings.Associators import getAssociator

    associator = getAssociator()
    if not associator:
        print "Association is not avaliable."
        return
    if associate:
        associator.SetAssociation()
    else:
        associator.RemoveAssociation()
    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()
示例#3
0
    def _onOkPushButtonClicked(self):
        """ Will save the config """
        from Settings import DEFAULT_DIRECTORY_DEFAULT_VAL
        from Settings.Config import SubiTConfig
        from Settings.Associators import getAssociator

        #============================================
        # Global Tab
        #============================================
        close_on_finish = self.subitSettingsDialog.closeOnFinishCheckBox\
            .isChecked()
        default_directory = self.subitSettingsDialog.defaultDirectoryLineEdit\
            .text() or DEFAULT_DIRECTORY_DEFAULT_VAL
        always_use_default_directory = self.subitSettingsDialog\
            .alwaysUseDefaultDirCheckBox.isChecked()

        remember_last_window_size = self.subitSettingsDialog\
            .rememberLastWindowSizeCheckBox.isChecked()
        remember_last_window_position = self.subitSettingsDialog\
            .rememberLastWindowPositionCheckBox.isChecked()

        check_updates = self.subitSettingsDialog.checkForUpdatesCheckBox\
            .isChecked()
        auto_update = self.subitSettingsDialog.autoUpdateCheckBox.isChecked()

        #============================================
        # Providers Tab
        #============================================
        # Thats how we can get the the items inside a QListWidget in QT..., we
        # look for items with the wild card, so we get all the items.
        languages_items = self.subitSettingsDialog.advancedLanguageListWidget\
            .findItems('.*', QtCore.Qt.MatchFlag.MatchRegExp)
        # We take only the checked once, and return their text() value
        languages_order = Utils.myfilter\
            (lambda i: i.checkState() == QtCore.Qt.CheckState.Checked, 
             languages_items,
             lambda i: i.text())

        # Again, QT sucks...
        providers_items = self.subitSettingsDialog.advancedProvidersListWidget\
            .findItems('.*', QtCore.Qt.MatchFlag.MatchRegExp)
        # We take only the checked once, and return their text() value
        providers_order = Utils.myfilter\
            (lambda i: i.checkState() == QtCore.Qt.CheckState.Checked, 
             providers_items, 
             lambda i: i.text())

        do_properties_based_ranks = self.subitSettingsDialog\
            .rankUsingPropertiesCheckBox.isChecked()
        do_in_depth_search = \
            self.subitSettingsDialog.inDepthSearchCheckBox.isChecked()

        #============================================
        # Association Tab
        #============================================
        if getAssociator():
            associate_extensions = self.subitSettingsDialog\
                .associateExtensionsCheckBox.isChecked()
            # Again, QT...
            extensions_items = self.subitSettingsDialog.extensionsListWidget\
                .findItems('.*', QtCore.Qt.MatchFlag.MatchRegExp)
            extensions_keys = list(map(lambda i: i.text(), extensions_items))


            from Interaction import InteractionTypes
            from Utils import myfilter
            interaction_desc = self.subitSettingsDialog\
                .interactionTypeSelectionComboBox.currentText()
            # Take the interaction_type of the selected item in the combobox
            interaction_type = myfilter\
                (lambda i: i[1] == interaction_desc, 
                 InteractionTypes.InteractionTypeDescriptions.items(), 
                 lambda i: i[0], 
                 True)

        
        # Now we finally save the settings
        SubiTConfig.Singleton().setValue\
            ('Global', 'close_on_finish', close_on_finish)
        SubiTConfig.Singleton().setValue\
            ('Global', 'default_directory', default_directory)
        SubiTConfig.Singleton().setValue\
            ('Global', 'always_use_default_directory', always_use_default_directory)

        SubiTConfig.Singleton().setValue\
            ('Gui', 'remember_last_window_size', remember_last_window_size)
        SubiTConfig.Singleton().setValue\
            ('Gui', 'remember_last_window_position', remember_last_window_position)

        SubiTConfig.Singleton().setValue\
            ('Updates', 'check_updates', check_updates)
        SubiTConfig.Singleton().setValue\
            ('Updates', 'auto_update', auto_update)

        SubiTConfig.Singleton().setList\
            ('Providers', 'languages_order', languages_order)
        SubiTConfig.Singleton().setList\
            ('Providers', 'providers_order', providers_order)
        SubiTConfig.Singleton().setValue\
            ('Flow', 'do_properties_based_rank', do_properties_based_ranks)
        SubiTConfig.Singleton().setValue\
            ('Flow', 'in_depth_search', do_in_depth_search)

        if getAssociator():
            SubiTConfig.Singleton().setValue\
                ('Association', 'associate_extensions', associate_extensions)
            SubiTConfig.Singleton().setList\
                ('Association', 'extensions_keys', extensions_keys)
            SubiTConfig.Singleton().setValue\
                ('Association', 'interaction_type', interaction_type)

            if associate_extensions:
                getAssociator().SetAssociation()
            else:
                getAssociator().RemoveAssociation()
        
        # Restart subit, with the user input if there was any, otherwise, we
        # restart we the original sys.argv values
        movie_name_query = self.subitMainWindow.movieNameLineEdit.displayText()
        if movie_name_query:
            Utils.restart(movie_name_query)
        else:
            Utils.restart()