コード例 #1
0
 def GetAllSiblings( self, service_key, tag ) -> typing.Set[ str ]:
     
     if service_key == CC.COMBINED_TAG_SERVICE_KEY:
         
         return HydrusData.MassUnion( self.GetAllSiblings( s_k, tag ) for s_k in self._controller.services_manager.GetServiceKeys( HC.REAL_TAG_SERVICES ) )
         
     
     with self._lock:
         
         tags_to_ideals = self._service_keys_to_tags_to_ideals[ service_key ]
         ideals_to_all_tags = self._service_keys_to_ideals_to_all_tags[ service_key ]
         
         if tag in tags_to_ideals:
             
             ideal_tag = tags_to_ideals[ tag ]
             
         elif tag in ideals_to_all_tags:
             
             ideal_tag = tag
             
         else:
             
             return { tag }
             
         
         all_siblings = set( ideals_to_all_tags[ ideal_tag ] )
         
         all_siblings.add( ideal_tag )
         
         return all_siblings
コード例 #2
0
def UndeleteMedia( win, media ):
    
    media_deleted_service_keys = HydrusData.MassUnion( ( m.GetLocationsManager().GetDeleted() for m in media ) )
    
    local_file_services = HG.client_controller.services_manager.GetServices( ( HC.LOCAL_FILE_DOMAIN, ) )
    
    undeletable_services = [ local_file_service for local_file_service in local_file_services if local_file_service.GetServiceKey() in media_deleted_service_keys ]
    
    if len( undeletable_services ) > 0:
        
        do_it = False
        
        if len( undeletable_services ) > 1:
            
            choice_tuples = []
            
            for ( i, service ) in enumerate( undeletable_services ):
                
                choice_tuples.append( ( service.GetName(), service, 'Undelete back to {}.'.format( service.GetName() ) ) )
                
            
            if len( choice_tuples ) > 1:
                
                service = HG.client_controller.services_manager.GetService( CC.COMBINED_LOCAL_MEDIA_SERVICE_KEY )
                
                choice_tuples.append( ( 'all the above', service, 'Undelete back to all services the files have been deleted from.' ) )
                
            
            try:
                
                undelete_service = ClientGUIDialogsQuick.SelectFromListButtons( win, 'Undelete for?', choice_tuples )
                
                do_it = True
                
            except HydrusExceptions.CancelledException:
                
                return
                
            
        else:
    
            ( undelete_service, ) = undeletable_services
            
            if HC.options[ 'confirm_trash' ]:
                
                result = ClientGUIDialogsQuick.GetYesNo( win, 'Undelete this file back to {}?'.format( undelete_service.GetName() ) )
                
                if result == QW.QDialog.Accepted:
                    
                    do_it = True
                    
                
            else:
                
                do_it = True
                
            
        
        if do_it:
            
            for chunk_of_media in HydrusData.SplitIteratorIntoChunks( media, 64 ):
                
                service_keys_to_content_updates = collections.defaultdict( list )
                
                service_key = undelete_service.GetServiceKey()
                
                undeletee_hashes = [ m.GetHash() for m in chunk_of_media if service_key in m.GetLocationsManager().GetDeleted() ]
                
                service_keys_to_content_updates[ service_key ] = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_UNDELETE, undeletee_hashes ) ]
                
                HG.client_controller.Write( 'content_updates', service_keys_to_content_updates )
コード例 #3
0
    def _ProcessShortcut(self, shortcut: Shortcut):

        shortcut_processed = False

        command = shortcuts_manager().GetCommand(self._shortcuts_names,
                                                 shortcut)

        if command is None and shortcut.IsDoubleClick():

            # ok, so user double-clicked
            # if a parent wants to catch this (for instance the media viewer when we double-click a video), then we want that parent to have it
            # but if no parent wants it, we can try converting it to a single-click to see if that does anything

            ancestor_shortcuts_handlers = AncestorShortcutsHandlers(
                self._parent)

            all_ancestor_shortcut_names = HydrusData.MassUnion([
                ancestor_shortcuts_handler.GetShortcutNames()
                for ancestor_shortcuts_handler in ancestor_shortcuts_handlers
            ])

            ancestor_command = shortcuts_manager().GetCommand(
                all_ancestor_shortcut_names, shortcut)

            if ancestor_command is None:

                if HG.shortcut_report_mode:

                    message = 'Shortcut "' + shortcut.ToString(
                    ) + '" did not match any command. The single click version is now being attempted.'

                    HydrusData.ShowText(message)

                shortcut = shortcut.ConvertToSingleClick()

                command = shortcuts_manager().GetCommand(
                    self._shortcuts_names, shortcut)

            else:

                if HG.shortcut_report_mode:

                    message = 'Shortcut "' + shortcut.ToString(
                    ) + '" did not match any command. A parent seems to want it, however, so the single click version will not be attempted.'

                    HydrusData.ShowText(message)

        if command is not None:

            command_processed = self._parent.ProcessApplicationCommand(command)

            if command_processed:

                shortcut_processed = True

            if HG.shortcut_report_mode:

                message = 'Shortcut "' + shortcut.ToString(
                ) + '" matched to command "' + command.ToString(
                ) + '" on ' + repr(self._parent) + '.'

                if command_processed:

                    message += ' It was processed.'

                else:

                    message += ' It was not processed.'

                HydrusData.ShowText(message)

        return shortcut_processed