Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _Delete( self ):
num_selected = self._listbox.GetNumSelected()
if num_selected == 0:
return
from hydrus.client.gui import ClientGUIDialogsQuick
result = ClientGUIDialogsQuick.GetYesNo( self, 'Remove {} selected?'.format( HydrusData.ToHumanInt( num_selected ) ) )
if result != QW.QDialog.Accepted:
return
self._listbox.DeleteSelected()
self.listBoxChanged.emit()
self._current.discard( CC.TRASH_SERVICE_KEY )
self._pending.discard( CC.COMBINED_LOCAL_FILE_SERVICE_KEY )
if CC.COMBINED_LOCAL_FILE_SERVICE_KEY not in self._current:
self.inbox = True
self._current.add( CC.COMBINED_LOCAL_FILE_SERVICE_KEY )
self._deleted.discard( CC.COMBINED_LOCAL_FILE_SERVICE_KEY )
self._current_to_timestamps[ CC.COMBINED_LOCAL_FILE_SERVICE_KEY ] = HydrusData.GetNow()
self._current_to_timestamps[ service_key ] = HydrusData.GetNow()
elif action == HC.CONTENT_UPDATE_DELETE:
self._deleted.add( service_key )
self._current.discard( service_key )
self._petitioned.discard( service_key )
if service_key == CC.LOCAL_FILE_SERVICE_KEY:
self._current.add( CC.TRASH_SERVICE_KEY )
self._current_to_timestamps[ CC.TRASH_SERVICE_KEY ] = HydrusData.GetNow()
elif service_key == CC.TRASH_SERVICE_KEY:
def ShowSnapshot( self ):
with self._lock:
sub_names = sorted( self._names_to_subscriptions.keys() )
running = sorted( self._names_to_running_subscription_info.keys() )
cannot_run = sorted( self._names_that_cannot_run )
next_times = sorted( self._names_to_next_work_time.items(), key = lambda n, nwt: nwt )
message = '{} subs: {}'.format( HydrusData.ToHumanInt( len( self._names_to_subscriptions ) ), ', '.join( sub_names ) )
message += os.linesep * 2
message += '{} running: {}'.format( HydrusData.ToHumanInt( len( self._names_to_running_subscription_info ) ), ', '.join( running ) )
message += os.linesep * 2
message += '{} not runnable: {}'.format( HydrusData.ToHumanInt( len( self._names_that_cannot_run ) ), ', '.join( cannot_run ) )
message += os.linesep * 2
message += '{} next times: {}'.format( HydrusData.ToHumanInt( len( self._names_to_next_work_time ) ), ', '.join( ( '{}: {}'.format( name, ClientData.TimestampToPrettyTimeDelta( next_work_time ) ) for ( name, next_work_time ) in next_times ) ) )
HydrusData.ShowText( message )
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 )
# convert this GMT TIMESTAMP to a pretty local string
base += ': ' + pretty_operator + HydrusData.ConvertTimestampToPrettyTime( timestamp, include_24h_time = False )
elif self._predicate_type == PREDICATE_TYPE_SYSTEM_NUM_PIXELS:
base = 'num_pixels'
if self._value is not None:
( operator, num_pixels, unit ) = self._value
base += ' ' + operator + ' ' + str( num_pixels ) + ' ' + HydrusData.ConvertIntToPixels( unit )
elif self._predicate_type == PREDICATE_TYPE_SYSTEM_KNOWN_URLS:
base = 'known url'
if self._value is not None:
( operator, rule_type, rule, description ) = self._value
base = description
elif self._predicate_type == PREDICATE_TYPE_SYSTEM_HAS_AUDIO:
base = 'has audio'
def moveEvent( self, event ):
if HydrusData.TimeHasPassedFloat( self._last_move_pub + 0.1 ):
HG.client_controller.pub( 'top_level_window_move_event' )
self._last_move_pub = HydrusData.GetNowPrecise()
event.ignore()
HydrusData.ShowText( 'Thumbnail {} too small due to small source file.'.format( hash.hex() ) )
pass
else:
numpy_image = HydrusImageHandling.ResizeNumPyImage( numpy_image, ( expected_width, expected_height ) )
if locations_manager.IsLocal():
# we have the master file, so we should regen the thumb from source
if HG.file_report_mode:
HydrusData.ShowText( 'Thumbnail {} too small, scheduling regeneration from source.'.format( hash.hex() ) )
delayed_item = display_media.GetMediaResult()
with self._lock:
if delayed_item not in self._delayed_regeneration_queue_quick:
self._delayed_regeneration_queue_quick.add( delayed_item )
self._delayed_regeneration_queue.append( delayed_item )
else:
self._bad_error_occurred = True
#
missing_dict = HydrusData.BuildKeyToListDict( self._missing_locations )
missing_locations = sorted( missing_dict.keys() )
missing_string = ''
for missing_location in missing_locations:
missing_prefixes = sorted( missing_dict[ missing_location ] )
missing_prefixes_string = ' ' + os.linesep.join( ( ', '.join( block ) for block in HydrusData.SplitListIntoChunks( missing_prefixes, 32 ) ) )
missing_string += os.linesep
missing_string += missing_location
missing_string += os.linesep
missing_string += missing_prefixes_string
#
if len( self._missing_locations ) > 4:
text = 'When initialising the client files manager, some file locations did not exist! They have all been written to the log!'
text += os.linesep * 2
text += 'If this is happening on client boot, you should now be presented with a dialog to correct this manually!'
self._controller.SafeShowCriticalMessage( 'missing locations', text )
def __init__( self ):
self._id = HydrusData.GenerateKey()
self._id_hash = self._id.__hash__()
def DiscardBlankPerceptualHashes( phashes ):
phashes = { phash for phash in phashes if HydrusData.Get64BitHammingDistance( phash, CC.BLANK_PHASH ) > 4 }
return phashes