def _AddSomeDefaults(self, defaults_callable, add_callable): defaults = defaults_callable() selected = False choice_tuples = [(default.GetName(), default, selected) for default in defaults] import ClientGUIDialogs with ClientGUIDialogs.DialogCheckFromList( self, 'select the defaults to add', choice_tuples) as dlg: if dlg.ShowModal() == wx.ID_OK: defaults_to_add = dlg.GetChecked() for default in defaults_to_add: add_callable(default)
def ImportFromHTA( parent, hta_path, tag_service_key, hashes ): hta = HydrusTagArchive.HydrusTagArchive( hta_path ) potential_namespaces = list( hta.GetNamespaces() ) potential_namespaces.sort() hash_type = hta.GetHashType() # this tests if the hta can produce a hashtype del hta service = HG.client_controller.services_manager.GetService( tag_service_key ) service_type = service.GetServiceType() can_delete = True if service_type == HC.TAG_REPOSITORY: if service.HasPermission( HC.CONTENT_TYPE_MAPPINGS, HC.PERMISSION_ACTION_OVERRULE ): can_delete = False if can_delete: text = 'Would you like to add or delete the archive\'s tags?' with ClientGUIDialogs.DialogYesNo( parent, text, title = 'Add or delete?', yes_label = 'add', no_label = 'delete' ) as dlg_add: result = dlg_add.ShowModal() if result == wx.ID_YES: adding = True elif result == wx.ID_NO: adding = False else: return else: text = 'You cannot quickly delete tags from this service, so I will assume you want to add tags.' wx.MessageBox( text ) adding = True text = 'Choose which namespaces to ' if adding: text += 'add.' else: text += 'delete.' list_of_tuples = [ ( HydrusData.ConvertUglyNamespaceToPrettyString( namespace ), namespace, False ) for namespace in potential_namespaces ] with ClientGUIDialogs.DialogCheckFromList( parent, text, list_of_tuples ) as dlg_namespaces: if dlg_namespaces.ShowModal() == wx.ID_OK: namespaces = dlg_namespaces.GetChecked() if hash_type == HydrusTagArchive.HASH_TYPE_SHA256: text = 'This tag archive can be fully merged into your database, but this may be more than you want.' text += os.linesep * 2 text += 'Would you like to import the tags only for files you actually have, or do you want absolutely everything?' with ClientGUIDialogs.DialogYesNo( parent, text, title = 'How much do you want?', yes_label = 'just for my local files', no_label = 'everything' ) as dlg_add: result = dlg_add.ShowModal() if result == wx.ID_YES: file_service_key = CC.LOCAL_FILE_SERVICE_KEY elif result == wx.ID_NO: file_service_key = CC.COMBINED_FILE_SERVICE_KEY else: return else: file_service_key = CC.LOCAL_FILE_SERVICE_KEY text = 'Are you absolutely sure you want to ' if adding: text += 'add' else: text += 'delete' text += ' the namespaces:' text += os.linesep * 2 text += os.linesep.join( HydrusData.ConvertUglyNamespacesToPrettyStrings( namespaces ) ) text += os.linesep * 2 file_service = HG.client_controller.services_manager.GetService( file_service_key ) text += 'For ' if hashes is None: text += 'all' else: text += HydrusData.ToHumanInt( len( hashes ) ) text += ' files in \'' + file_service.GetName() + '\'' if adding: text += ' to ' else: text += ' from ' text += '\'' + service.GetName() + '\'?' with ClientGUIDialogs.DialogYesNo( parent, text ) as dlg_final: if dlg_final.ShowModal() == wx.ID_YES: HG.client_controller.pub( 'sync_to_tag_archive', hta_path, tag_service_key, file_service_key, adding, namespaces, hashes )