def test_SERIALISABLE_TYPE_APPLICATION_COMMAND(self): def test(obj, dupe_obj): self.assertEqual(obj.GetCommandType(), dupe_obj.GetCommandType()) self.assertEqual(obj.GetData(), dupe_obj.GetData()) acs = [] acs.append( (ClientData.ApplicationCommand(CC.APPLICATION_COMMAND_TYPE_SIMPLE, 'archive_file'), 'archive_file')) acs.append((ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (HydrusData.GenerateKey(), HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test')), 'flip on/off mappings "test" for unknown service!')) acs.append((ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test')), 'flip on/off mappings "test" for my tags')) acs.append((ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (HydrusData.GenerateKey(), HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_SET, 0.4)), 'set ratings "0.4" for unknown service!')) for (ac, s) in acs: self._dump_and_load_and_test(ac, test) self.assertEqual(ac.ToString(), s)
def _ConvertGallerySeedToListCtrlTuples(self, gallery_seed): try: gallery_seed_index = self._gallery_seed_log.GetGallerySeedIndex( gallery_seed) except: gallery_seed_index = '--' url = gallery_seed.url status = gallery_seed.status added = gallery_seed.created modified = gallery_seed.modified note = gallery_seed.note pretty_gallery_seed_index = HydrusData.ToHumanInt(gallery_seed_index) pretty_url = url pretty_status = CC.status_string_lookup[status] pretty_added = ClientData.TimestampToPrettyTimeDelta(added) pretty_modified = ClientData.TimestampToPrettyTimeDelta(modified) pretty_note = note.split(os.linesep)[0] display_tuple = (pretty_gallery_seed_index, pretty_url, pretty_status, pretty_added, pretty_modified, pretty_note) sort_tuple = (gallery_seed_index, url, status, added, modified, note) return (display_tuple, sort_tuple)
def GetUndoRedoStrings(self): with self._lock: (undo_string, redo_string) = (None, None) if self._current_index > 0: undo_index = self._current_index - 1 (action, args, kwargs) = self._commands[undo_index] if action == 'content_updates': (service_keys_to_content_updates, ) = args undo_string = 'undo ' + ClientData.ConvertServiceKeysToContentUpdatesToPrettyString( service_keys_to_content_updates) if len(self._commands) > 0 and self._current_index < len( self._commands): redo_index = self._current_index (action, args, kwargs) = self._commands[redo_index] if action == 'content_updates': (service_keys_to_content_updates, ) = args redo_string = 'redo ' + ClientData.ConvertServiceKeysToContentUpdatesToPrettyString( service_keys_to_content_updates) return (undo_string, redo_string)
def test_SERIALISABLE_TYPE_SHORTCUT_SET( self ): def test( obj, dupe_obj ): for ( shortcut, command ) in obj: self.assertEqual( dupe_obj.GetCommand( shortcut ).GetData(), command.GetData() ) default_shortcuts = ClientDefaults.GetDefaultShortcuts() for shortcuts in default_shortcuts: self._dump_and_load_and_test( shortcuts, test ) command_1 = ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_SIMPLE, 'archive_file' ) command_2 = ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, ( HydrusData.GenerateKey(), HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test' ) ) command_3 = ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, ( CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test' ) ) k_shortcut_1 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_KEYBOARD_SPECIAL, ClientGUIShortcuts.SHORTCUT_KEY_SPECIAL_SPACE, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [] ) k_shortcut_2 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_KEYBOARD_CHARACTER, ord( 'a' ), ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_CTRL ] ) k_shortcut_3 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_KEYBOARD_CHARACTER, ord( 'A' ), ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_CTRL ] ) k_shortcut_4 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_KEYBOARD_SPECIAL, ClientGUIShortcuts.SHORTCUT_KEY_SPECIAL_HOME, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_ALT, ClientGUIShortcuts.SHORTCUT_MODIFIER_CTRL ] ) m_shortcut_1 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_MOUSE, ClientGUIShortcuts.SHORTCUT_MOUSE_LEFT, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [] ) m_shortcut_2 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_MOUSE, ClientGUIShortcuts.SHORTCUT_MOUSE_MIDDLE, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_CTRL ] ) m_shortcut_3 = ClientGUIShortcuts.Shortcut( ClientGUIShortcuts.SHORTCUT_TYPE_MOUSE, ClientGUIShortcuts.SHORTCUT_MOUSE_SCROLL_DOWN, ClientGUIShortcuts.SHORTCUT_PRESS_TYPE_PRESS, [ ClientGUIShortcuts.SHORTCUT_MODIFIER_ALT, ClientGUIShortcuts.SHORTCUT_MODIFIER_SHIFT ] ) shortcut_set = ClientGUIShortcuts.ShortcutSet( 'test' ) shortcut_set.SetCommand( k_shortcut_1, command_1 ) shortcut_set.SetCommand( k_shortcut_2, command_2 ) shortcut_set.SetCommand( k_shortcut_3, command_2 ) shortcut_set.SetCommand( k_shortcut_4, command_3 ) shortcut_set.SetCommand( m_shortcut_1, command_1 ) shortcut_set.SetCommand( m_shortcut_2, command_2 ) shortcut_set.SetCommand( m_shortcut_3, command_3 ) self._dump_and_load_and_test( shortcut_set, test ) self.assertEqual( shortcut_set.GetCommand( k_shortcut_1 ).GetData(), command_1.GetData() ) shortcut_set.SetCommand( k_shortcut_1, command_3 ) self.assertEqual( shortcut_set.GetCommand( k_shortcut_1 ).GetData(), command_3.GetData() )
def _GetRatingsLike(self): selection = self._ratings_like_service_keys.currentIndex() if selection != -1: service_key = QP.GetClientData(self._ratings_like_service_keys, selection) action = self._flip_or_set_action.GetValue() if self._ratings_like_like.isChecked(): value = 1.0 elif self._ratings_like_dislike.isChecked(): value = 0.0 else: value = None return ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (service_key, HC.CONTENT_TYPE_RATINGS, action, value)) else: raise HydrusExceptions.VetoException( 'Please select a rating service!')
def GetNextCheckStatusString(self): if self._check_now: return 'checking on dialog ok' elif self._checker_status == ClientImporting.CHECKER_STATUS_DEAD: return 'dead, so not checking' else: if HydrusData.TimeHasPassed(self._next_check_time): s = 'imminent' else: s = ClientData.TimestampToPrettyTimeDelta( self._next_check_time) if self._paused: s = 'paused, but would be ' + s return s
def GetStatus( self ): with self._lock: file_status = self._file_status if self._checking_status == ClientImporting.CHECKER_STATUS_404: watcher_status = 'URL 404' elif self._checking_status == ClientImporting.CHECKER_STATUS_DEAD: watcher_status = 'URL DEAD' elif not HydrusData.TimeHasPassed( self._no_work_until ): no_work_text = self._no_work_until_reason + ' - ' + 'next check ' + ClientData.TimestampToPrettyTimeDelta( self._next_check_time ) file_status = no_work_text watcher_status = no_work_text else: watcher_status = self._watcher_status return ( file_status, self._files_paused, self._file_velocity_status, self._next_check_time, watcher_status, self._subject, self._checking_status, self._check_now, self._checking_paused )
def __init__(self, shortcut_type=None, shortcut_key=None, shortcut_press_type=None, modifiers=None): if shortcut_type is None: shortcut_type = SHORTCUT_TYPE_KEYBOARD_SPECIAL if shortcut_key is None: shortcut_key = SHORTCUT_KEY_SPECIAL_F7 if shortcut_press_type is None: shortcut_press_type = SHORTCUT_PRESS_TYPE_PRESS if modifiers is None: modifiers = [] if shortcut_type == SHORTCUT_TYPE_KEYBOARD_CHARACTER and ClientData.OrdIsAlphaUpper( shortcut_key): shortcut_key += 32 # convert A to a modifiers.sort() HydrusSerialisable.SerialisableBase.__init__(self) self.shortcut_type = shortcut_type self.shortcut_key = shortcut_key self.shortcut_press_type = shortcut_press_type self.modifiers = modifiers
def _ConvertFileSeedToListCtrlTuples(self, file_seed): try: file_seed_index = self._file_seed_cache.GetFileSeedIndex(file_seed) pretty_file_seed_index = HydrusData.ToHumanInt(file_seed_index) except: file_seed_index = '--' pretty_file_seed_index = '--' file_seed_data = file_seed.file_seed_data status = file_seed.status added = file_seed.created modified = file_seed.modified source_time = file_seed.source_time note = file_seed.note pretty_file_seed_data = str(file_seed_data) pretty_status = CC.status_string_lookup[status] pretty_added = ClientData.TimestampToPrettyTimeDelta(added) pretty_modified = ClientData.TimestampToPrettyTimeDelta(modified) if source_time is None: pretty_source_time = 'unknown' else: pretty_source_time = ClientData.TimestampToPrettyTimeDelta( source_time) sort_source_time = ClientGUIListCtrl.SafeNoneInt(source_time) pretty_note = note.split(os.linesep)[0] display_tuple = (pretty_file_seed_index, pretty_file_seed_data, pretty_status, pretty_added, pretty_modified, pretty_source_time, pretty_note) sort_tuple = (file_seed_index, file_seed_data, status, added, modified, sort_source_time, note) return (display_tuple, sort_tuple)
def GetServiceKeysToContentUpdates( self, status: int, media_result: ClientMediaResult.MediaResult, filterable_tags: typing.Iterable[str], external_filterable_tags=None, external_additional_service_keys_to_tags=None): if external_filterable_tags is None: external_filterable_tags = set() if external_additional_service_keys_to_tags is None: external_additional_service_keys_to_tags = ClientTags.ServiceKeysToTags( ) filterable_tags = HydrusTags.CleanTags(filterable_tags) service_keys_to_tags = ClientTags.ServiceKeysToTags() for service_key in HG.client_controller.services_manager.GetServiceKeys( HC.REAL_TAG_SERVICES): service_additional_tags = set() if service_key in external_additional_service_keys_to_tags: service_additional_tags.update( external_additional_service_keys_to_tags[service_key]) if service_key in self._service_keys_to_service_tag_import_options: service_tag_import_options = self._service_keys_to_service_tag_import_options[ service_key] service_filterable_tags = set(filterable_tags) service_filterable_tags.update(external_filterable_tags) service_tags = service_tag_import_options.GetTags( service_key, status, media_result, service_filterable_tags, service_additional_tags) else: service_tags = service_additional_tags if len(service_tags) > 0: service_keys_to_tags[service_key] = service_tags hash = media_result.GetHash() service_keys_to_content_updates = ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( {hash}, service_keys_to_tags) return service_keys_to_content_updates
def _GetSimple(self): action = self._simple_actions.currentText() if action == '': raise HydrusExceptions.VetoException('Please select an action!') else: return ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_SIMPLE, action)
def AddShortcut(self): shortcut = ClientGUIShortcuts.Shortcut() command = ClientData.ApplicationCommand() name = self._name.text() with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit shortcut command') as dlg: panel = EditShortcutAndCommandPanel(dlg, shortcut, command, name) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: (shortcut, command) = panel.GetValue() data = (shortcut, command) self._shortcuts.AddDatas((data, ))
def _GetRatingsNumericalIncDec(self): selection = self._ratings_numerical_incdec_service_keys.currentIndex() if selection != -1: service_key = QP.GetClientData( self._ratings_numerical_incdec_service_keys, selection) action = self._ratings_numerical_incdec.GetValue() value = 1 return ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (service_key, HC.CONTENT_TYPE_RATINGS, action, value)) else: raise HydrusExceptions.VetoException( 'Please select a rating service!')
def _GetRatingsNumerical(self): selection = self._ratings_numerical_service_keys.currentIndex() if selection != -1: service_key = QP.GetClientData( self._ratings_numerical_service_keys, selection) action = self._flip_or_set_action.GetValue() if self._ratings_numerical_remove.isChecked(): value = None else: value = self._ratings_numerical_slider.GetValue() num_stars = self._current_ratings_numerical_service.GetNumStars( ) allow_zero = self._current_ratings_numerical_service.AllowZero( ) if allow_zero: value = value / num_stars else: value = (value - 1) / (num_stars - 1) return ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (service_key, HC.CONTENT_TYPE_RATINGS, action, value)) else: raise HydrusExceptions.VetoException( 'Please select a rating service!')
def GetSimpleStatus( self ): with self._lock: if self._checking_status == ClientImporting.CHECKER_STATUS_404: return '404' elif self._checking_status == ClientImporting.CHECKER_STATUS_DEAD: return 'DEAD' elif not HydrusData.TimeHasPassed( self._no_work_until ): return self._no_work_until_reason + ' - ' + 'next check ' + ClientData.TimestampToPrettyTimeDelta( self._next_check_time ) elif self._watcher_status != '' or self._file_status != '': return 'working' else: return ''
def _GetTag(self): selection = self._tag_service_keys.currentIndex() if selection != -1: service_key = QP.GetClientData(self._tag_service_keys, selection) action = self._flip_or_set_action.GetValue() value = self._tag_value.text() if value == '': raise HydrusExceptions.VetoException('Please enter a tag!') return ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (service_key, HC.CONTENT_TYPE_MAPPINGS, action, value)) else: raise HydrusExceptions.VetoException( 'Please select a tag service!')
def ToString(self): components = [] if SHORTCUT_MODIFIER_CTRL in self.modifiers: components.append('ctrl') if SHORTCUT_MODIFIER_ALT in self.modifiers: components.append('alt') if SHORTCUT_MODIFIER_SHIFT in self.modifiers: components.append('shift') if SHORTCUT_MODIFIER_GROUP_SWITCH in self.modifiers: components.append('Mode_switch') if self.shortcut_press_type != SHORTCUT_PRESS_TYPE_PRESS: action_name = '{} '.format( shortcut_press_type_str_lookup[self.shortcut_press_type]) else: action_name = '' if self.shortcut_type == SHORTCUT_TYPE_MOUSE and self.shortcut_key in shortcut_mouse_string_lookup: action_name += shortcut_mouse_string_lookup[self.shortcut_key] elif self.shortcut_type == SHORTCUT_TYPE_KEYBOARD_SPECIAL and self.shortcut_key in special_key_shortcut_str_lookup: action_name += special_key_shortcut_str_lookup[self.shortcut_key] elif self.shortcut_type == SHORTCUT_TYPE_KEYBOARD_CHARACTER: try: if ClientData.OrdIsAlphaUpper(self.shortcut_key): action_name += chr(self.shortcut_key + 32) # + 32 for converting ascii A -> a else: action_name += chr(self.shortcut_key) except: action_name += 'unknown key: {}'.format(repr( self.shortcut_key)) else: action_name += 'unknown key: {}'.format(repr(self.shortcut_key)) components.append(action_name) s = '+'.join(components) if SHORTCUT_MODIFIER_KEYPAD in self.modifiers: s += ' (on numpad)' return s
def _ImportFiles(self, job_key): did_work = False time_to_save = HydrusData.GetNow() + 600 num_files_imported = 0 presentation_hashes = [] presentation_hashes_fast = set() i = 0 num_total = len(self._file_seed_cache) num_total_unknown = self._file_seed_cache.GetFileSeedCount( CC.STATUS_UNKNOWN) num_total_done = num_total - num_total_unknown while True: file_seed = self._file_seed_cache.GetNextFileSeed( CC.STATUS_UNKNOWN) p1 = HC.options['pause_import_folders_sync'] or self._paused p2 = HydrusThreading.IsThreadShuttingDown() p3 = job_key.IsCancelled() if file_seed is None or p1 or p2 or p3: break did_work = True if HydrusData.TimeHasPassed(time_to_save): HG.client_controller.WriteSynchronous('serialisable', self) time_to_save = HydrusData.GetNow() + 600 gauge_num_done = num_total_done + num_files_imported + 1 job_key.SetVariable( 'popup_text_1', 'importing file ' + HydrusData.ConvertValueRangeToPrettyString( gauge_num_done, num_total)) job_key.SetVariable('popup_gauge_1', (gauge_num_done, num_total)) path = file_seed.file_seed_data file_seed.ImportPath(self._file_seed_cache, self._file_import_options, limited_mimes=self._mimes) if file_seed.status in CC.SUCCESSFUL_IMPORT_STATES: if file_seed.HasHash(): hash = file_seed.GetHash() if self._tag_import_options.HasAdditionalTags(): media_result = HG.client_controller.Read( 'media_result', hash) downloaded_tags = [] service_keys_to_content_updates = self._tag_import_options.GetServiceKeysToContentUpdates( file_seed.status, media_result, downloaded_tags) # additional tags if len(service_keys_to_content_updates) > 0: HG.client_controller.WriteSynchronous( 'content_updates', service_keys_to_content_updates) service_keys_to_tags = ClientTags.ServiceKeysToTags() for (tag_service_key, filename_tagging_options) in list( self._tag_service_keys_to_filename_tagging_options. items()): if not HG.client_controller.services_manager.ServiceExists( tag_service_key): continue try: tags = filename_tagging_options.GetTags( tag_service_key, path) if len(tags) > 0: service_keys_to_tags[tag_service_key] = tags except Exception as e: HydrusData.ShowText( 'Trying to parse filename tags in the import folder "' + self._name + '" threw an error!') HydrusData.ShowException(e) if len(service_keys_to_tags) > 0: service_keys_to_content_updates = ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( {hash}, service_keys_to_tags) HG.client_controller.WriteSynchronous( 'content_updates', service_keys_to_content_updates) num_files_imported += 1 if hash not in presentation_hashes_fast: if file_seed.ShouldPresent(self._file_import_options): presentation_hashes.append(hash) presentation_hashes_fast.add(hash) elif file_seed.status == CC.STATUS_ERROR: HydrusData.Print( 'A file failed to import from import folder ' + self._name + ':' + path) i += 1 if i % 10 == 0: self._ActionPaths() if num_files_imported > 0: HydrusData.Print('Import folder ' + self._name + ' imported ' + HydrusData.ToHumanInt(num_files_imported) + ' files.') if len(presentation_hashes) > 0: ClientImporting.PublishPresentationHashes( self._name, presentation_hashes, self._publish_files_to_popup_button, self._publish_files_to_page) self._ActionPaths() return did_work
def test_dict_to_content_updates(self): hash = HydrusData.GenerateKey() hashes = {hash} local_key = CC.DEFAULT_LOCAL_TAG_SERVICE_KEY remote_key = HG.test_controller.example_tag_repo_service_key service_keys_to_tags = ClientTags.ServiceKeysToTags({local_key: {'a'}}) content_updates = { local_key: [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('a', hashes)) ] } self.assertEqual( ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( {hash}, service_keys_to_tags), content_updates) service_keys_to_tags = ClientTags.ServiceKeysToTags( {remote_key: {'c'}}) content_updates = { remote_key: [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ('c', hashes)) ] } self.assertEqual( ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( {hash}, service_keys_to_tags), content_updates) service_keys_to_tags = ClientTags.ServiceKeysToTags({ local_key: ['a', 'character:b'], remote_key: ['c', 'series:d'] }) content_updates = {} content_updates[local_key] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('a', hashes)), HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('character:b', hashes)) ] content_updates[remote_key] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ('c', hashes)), HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ('series:d', hashes)) ] self.assertEqual( HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, 'c'), HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, 'c')) self.assertEqual( ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( {hash}, service_keys_to_tags), content_updates)
def GetCounts( self, tag_display_type, tag_service_id, file_service_id, tag_ids, include_current, include_pending, zero_count_ok = False, job_key = None, tag_ids_table_name = None ): if len( tag_ids ) == 0: return {} if tag_service_id == self.modules_services.combined_tag_service_id and file_service_id == self.modules_services.combined_file_service_id: ids_to_count = {} return ids_to_count if tag_service_id == self.modules_services.combined_tag_service_id: search_tag_service_ids = self.modules_services.GetServiceIds( HC.REAL_TAG_SERVICES ) else: search_tag_service_ids = [ tag_service_id ] cache_results = [] if len( tag_ids ) > 1: if tag_ids_table_name is None: with self._MakeTemporaryIntegerTable( tag_ids, 'tag_id' ) as temp_tag_id_table_name: for search_tag_service_id in search_tag_service_ids: if job_key is not None and job_key.IsCancelled(): return {} cache_results.extend( self.GetCountsForTags( tag_display_type, file_service_id, search_tag_service_id, temp_tag_id_table_name ) ) else: for search_tag_service_id in search_tag_service_ids: if job_key is not None and job_key.IsCancelled(): return {} cache_results.extend( self.GetCountsForTags( tag_display_type, file_service_id, search_tag_service_id, tag_ids_table_name ) ) else: ( tag_id, ) = tag_ids for search_tag_service_id in search_tag_service_ids: cache_results.extend( self.GetCountsForTag( tag_display_type, file_service_id, search_tag_service_id, tag_id ) ) # ids_to_count = {} for ( tag_id, current_count, pending_count ) in cache_results: if not include_current: current_count = 0 if not include_pending: pending_count = 0 if current_count == 0 and pending_count == 0 and not zero_count_ok: continue if tag_id in ids_to_count: ( current_min, current_max, pending_min, pending_max ) = ids_to_count[ tag_id ] ( current_min, current_max ) = ClientData.MergeCounts( current_min, current_max, current_count, None ) ( pending_min, pending_max ) = ClientData.MergeCounts( pending_min, pending_max, pending_count, None ) else: ( current_min, current_max, pending_min, pending_max ) = ( current_count, None, pending_count, None ) ids_to_count[ tag_id ] = ( current_min, current_max, pending_min, pending_max ) if zero_count_ok: for tag_id in tag_ids: if tag_id not in ids_to_count: ids_to_count[ tag_id ] = ( 0, None, 0, None ) return ids_to_count
def _UpdateSerialisableInfo(self, version, old_serialisable_info): if version == 1: (serialisable_mouse_actions, serialisable_keyboard_actions) = old_serialisable_info shortcuts_to_commands = {} # this never stored mouse actions, so skip services_manager = HG.client_controller.services_manager for (modifier, key, (serialisable_service_key, data)) in serialisable_keyboard_actions: # no longer updating modifier, as that was wx legacy modifiers = [] shortcut = Shortcut(SHORTCUT_TYPE_KEYBOARD_CHARACTER, key, SHORTCUT_PRESS_TYPE_PRESS, modifiers) if serialisable_service_key is None: command = ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_SIMPLE, data) else: service_key = bytes.fromhex(serialisable_service_key) if not services_manager.ServiceExists(service_key): continue action = HC.CONTENT_UPDATE_FLIP value = data service = services_manager.GetService(service_key) service_type = service.GetServiceType() if service_type in HC.REAL_TAG_SERVICES: content_type = HC.CONTENT_TYPE_MAPPINGS elif service_type in HC.RATINGS_SERVICES: content_type = HC.CONTENT_TYPE_RATINGS else: continue command = ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (service_key, content_type, action, value)) shortcuts_to_commands[shortcut] = command new_serialisable_info = ( (shortcut.GetSerialisableTuple(), command.GetSerialisableTuple()) for (shortcut, command) in list(shortcuts_to_commands.items())) return (2, new_serialisable_info)
def GetCounts(self, tag_display_type, tag_service_id, file_service_id, tag_ids, include_current, include_pending, domain_is_cross_referenced=True, zero_count_ok=False, job_key=None, tag_ids_table_name=None): if len(tag_ids) == 0: return {} if tag_service_id == self.modules_services.combined_tag_service_id and file_service_id == self.modules_services.combined_file_service_id: ids_to_count = {} return ids_to_count if tag_service_id == self.modules_services.combined_tag_service_id: search_tag_service_ids = self.modules_services.GetServiceIds( HC.REAL_TAG_SERVICES) else: search_tag_service_ids = [tag_service_id] cache_results = [] if len(tag_ids) > 1: if tag_ids_table_name is None: with self._MakeTemporaryIntegerTable( tag_ids, 'tag_id') as temp_tag_id_table_name: for search_tag_service_id in search_tag_service_ids: if job_key is not None and job_key.IsCancelled(): return {} cache_results.extend( self.GetCountsForTags(tag_display_type, file_service_id, search_tag_service_id, temp_tag_id_table_name)) else: for search_tag_service_id in search_tag_service_ids: if job_key is not None and job_key.IsCancelled(): return {} cache_results.extend( self.GetCountsForTags(tag_display_type, file_service_id, search_tag_service_id, tag_ids_table_name)) else: (tag_id, ) = tag_ids for search_tag_service_id in search_tag_service_ids: cache_results.extend( self.GetCountsForTag(tag_display_type, file_service_id, search_tag_service_id, tag_id)) # ids_to_count = {} for (tag_id, current_count, pending_count) in cache_results: if not include_current: current_count = 0 if not include_pending: pending_count = 0 if current_count == 0 and pending_count == 0 and not zero_count_ok: continue current_max = current_count pending_max = pending_count if domain_is_cross_referenced: # file counts are perfectly accurate current_min = current_count pending_min = pending_count else: # for instance this is a search for 'my files' deleted files, but we are searching on 'all deleted files' domain current_min = 0 pending_min = 0 if tag_id in ids_to_count: (existing_current_min, existing_current_max, existing_pending_min, existing_pending_max) = ids_to_count[tag_id] (current_min, current_max) = ClientData.MergeCounts( existing_current_min, existing_current_max, current_min, current_max) (pending_min, pending_max) = ClientData.MergeCounts( existing_pending_min, existing_pending_max, pending_min, pending_max) ids_to_count[tag_id] = (current_min, current_max, pending_min, pending_max) if zero_count_ok: for tag_id in tag_ids: if tag_id not in ids_to_count: ids_to_count[tag_id] = (0, 0, 0, 0) return ids_to_count
def _UpdateSerialisableInfo(self, version, old_serialisable_info): if version == 1: # these are dicts that convert fixed wx enums to new stuff wx_to_qt_flat_conversion = { 32: SHORTCUT_KEY_SPECIAL_SPACE, 8: SHORTCUT_KEY_SPECIAL_BACKSPACE, 9: SHORTCUT_KEY_SPECIAL_TAB, 13: SHORTCUT_KEY_SPECIAL_RETURN, 310: SHORTCUT_KEY_SPECIAL_PAUSE, 27: SHORTCUT_KEY_SPECIAL_ESCAPE, 322: SHORTCUT_KEY_SPECIAL_INSERT, 127: SHORTCUT_KEY_SPECIAL_DELETE, 315: SHORTCUT_KEY_SPECIAL_UP, 317: SHORTCUT_KEY_SPECIAL_DOWN, 314: SHORTCUT_KEY_SPECIAL_LEFT, 316: SHORTCUT_KEY_SPECIAL_RIGHT, 313: SHORTCUT_KEY_SPECIAL_HOME, 312: SHORTCUT_KEY_SPECIAL_END, 367: SHORTCUT_KEY_SPECIAL_PAGE_DOWN, 366: SHORTCUT_KEY_SPECIAL_PAGE_UP, 340: SHORTCUT_KEY_SPECIAL_F1, 341: SHORTCUT_KEY_SPECIAL_F2, 342: SHORTCUT_KEY_SPECIAL_F3, 343: SHORTCUT_KEY_SPECIAL_F4, 344: SHORTCUT_KEY_SPECIAL_F5, 345: SHORTCUT_KEY_SPECIAL_F6, 346: SHORTCUT_KEY_SPECIAL_F7, 347: SHORTCUT_KEY_SPECIAL_F8, 348: SHORTCUT_KEY_SPECIAL_F9, 349: SHORTCUT_KEY_SPECIAL_F10, 350: SHORTCUT_KEY_SPECIAL_F11, 351: SHORTCUT_KEY_SPECIAL_F12 } # regular keys, but numpad, that are tracked in wx by combined unique enum wx_to_qt_numpad_ascii_conversion = { 324: ord('0'), 325: ord('1'), 326: ord('2'), 327: ord('3'), 328: ord('4'), 329: ord('5'), 330: ord('6'), 331: ord('7'), 332: ord('8'), 333: ord('9'), 388: ord('+'), 392: ord('/'), 390: ord('-'), 387: ord('*'), 391: ord('.') } wx_to_qt_numpad_conversion = { 377: SHORTCUT_KEY_SPECIAL_UP, 379: SHORTCUT_KEY_SPECIAL_DOWN, 376: SHORTCUT_KEY_SPECIAL_LEFT, 378: SHORTCUT_KEY_SPECIAL_RIGHT, 375: SHORTCUT_KEY_SPECIAL_HOME, 382: SHORTCUT_KEY_SPECIAL_END, 381: SHORTCUT_KEY_SPECIAL_PAGE_DOWN, 380: SHORTCUT_KEY_SPECIAL_PAGE_UP, 385: SHORTCUT_KEY_SPECIAL_DELETE, 370: SHORTCUT_KEY_SPECIAL_ENTER } (shortcut_type, shortcut_key, modifiers) = old_serialisable_info if shortcut_type == SHORTCUT_TYPE_KEYBOARD_CHARACTER: if shortcut_key in wx_to_qt_flat_conversion: shortcut_type = SHORTCUT_TYPE_KEYBOARD_SPECIAL shortcut_key = wx_to_qt_flat_conversion[shortcut_key] elif shortcut_key in wx_to_qt_numpad_ascii_conversion: shortcut_key = wx_to_qt_numpad_ascii_conversion[ shortcut_key] modifiers = list(modifiers) modifiers.append(SHORTCUT_MODIFIER_KEYPAD) modifiers.sort() elif shortcut_key in wx_to_qt_numpad_conversion: shortcut_type = SHORTCUT_TYPE_KEYBOARD_SPECIAL shortcut_key = wx_to_qt_numpad_conversion[shortcut_key] modifiers = list(modifiers) modifiers.append(SHORTCUT_MODIFIER_KEYPAD) modifiers.sort() if shortcut_type == SHORTCUT_TYPE_KEYBOARD_CHARACTER: if ClientData.OrdIsAlphaUpper(shortcut_key): shortcut_key += 32 # convert 'A' to 'a' new_serialisable_info = (shortcut_type, shortcut_key, modifiers) return (2, new_serialisable_info) if version == 2: (shortcut_type, shortcut_key, modifiers) = old_serialisable_info shortcut_press_type = SHORTCUT_PRESS_TYPE_PRESS new_serialisable_info = (shortcut_type, shortcut_key, shortcut_press_type, modifiers) return (3, new_serialisable_info)