Skip to content

Commit

Permalink
Version 147
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrusnetwork committed Feb 18, 2015
1 parent b85c9cc commit 7507e55
Show file tree
Hide file tree
Showing 18 changed files with 514 additions and 549 deletions.
15 changes: 15 additions & 0 deletions help/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
<div class="content">
<h3>changelog</h3>
<ul>
<li><h3>version 147</h3></li>
<ul>
<li>fixed a problem when trying to do a multi-release update that contained the v146 update</li>
<li>fixed the 'canvas not resizing after media removal' bug</li>
<li>when an autocomplete appears in a dialog, the dropdown window will integrate into the dialog (rather than being a popup), allowing mouse interaction</li>
<li>refitted the paths-to-tags dialog so the different static boxes and newly embedded A/C dropdowns fit better</li>
<li>fixes to and cleanup of sibling tag retrieval code</li>
<li>fixes to and cleanup of sibling tag filter code</li>
<li>fixes to and cleanup of sibling tag search code</li>
<li>fixes to and cleanup of sibling tag display code</li>
<li>fixed a couple bugs in READ autocomplete tag search caching that was stopping namespaced queries searching properly if typed in manually rather than pasted</li>
<li>fixed a similar bug in WRITE autocomplete tag search</li>
<li>fixed a bug that was ignoring namespace entirely in WRITE autocomplete</li>
<li>synchronised subscription popups' new file buttons with the text</li>
</ul>
<li><h3>version 146</h3></li>
<ul>
<li>manage tags and ratings dialogs will now OK on F3/F4, not CANCEL</li>
Expand Down
75 changes: 21 additions & 54 deletions include/ClientConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,19 @@ def CatchExceptionClient( etype, value, tb ):
HC.ShowText( text )


def FilterPredicates( search_entry, predicates, service_key = None, expand_parents = False ):

matches = [ predicate for predicate in predicates if HC.SearchEntryMatchesPredicate( search_entry, predicate ) ]

if service_key is not None and expand_parents:

parents_manager = HC.app.GetManager( 'tag_parents' )

matches = parents_manager.ExpandPredicates( service_key, matches )


return matches

def GenerateCollectByChoices( sort_by_choices ):

already_added = set()
Expand Down Expand Up @@ -485,7 +498,7 @@ def GenerateExportFilename( media, terms ):
if term_type == 'string': filename += term
elif term_type == 'namespace':

tags = tags_manager.GetNamespaceSlice( ( term, ) )
tags = tags_manager.GetNamespaceSlice( ( term, ), collapse_siblings = True )

filename += ', '.join( [ tag.split( ':' )[1] for tag in tags ] )

Expand Down Expand Up @@ -862,66 +875,20 @@ def ShowTextClient( text ):

HC.pubsub.pub( 'message', job_key )

class AutocompleteMatches( object ):
def SortPredicates( predicates, collapse_siblings = False ):

def __init__( self, matches ):
if collapse_siblings:

self._matches = matches
siblings_manager = HC.app.GetManager( 'tag_siblings' )

self._matches.sort()
predicates = siblings_manager.CollapsePredicates( predicates )


def GetMatches( self, search ): return [ match for match in self._matches if HC.SearchEntryMatchesTag( search, match ) ]
def cmp_func( x, y ): return cmp( x.GetCount(), y.GetCount() )

class AutocompleteMatchesCounted( object ):

def __init__( self, matches_to_count ):

self._matches_to_count = matches_to_count
self._matches = self._matches_to_count.keys()

def cmp_func( x, y ): return cmp( matches_to_count[ x ], matches_to_count[ y ] )

self._matches.sort( cmp = cmp_func, reverse = True )


def GetMatches( self, search ): return [ ( match, self._matches_to_count[ match ] ) for match in self._matches if HC.SearchEntryMatchesTag( search, match ) ]

class AutocompleteMatchesPredicates( object ):

def __init__( self, service_key, predicates, collapse = True ):

self._service_key = service_key
self._predicates = predicates
self._collapse = collapse

# do siblings

if self._collapse:

siblings_manager = HC.app.GetManager( 'tag_siblings' )

self._predicates = siblings_manager.CollapsePredicates( self._predicates )


def cmp_func( x, y ): return cmp( x.GetCount(), y.GetCount() )

self._predicates.sort( cmp = cmp_func, reverse = True )

predicates.sort( cmp = cmp_func, reverse = True )

def GetMatches( self, search ):

matches = [ predicate for predicate in self._predicates if HC.SearchEntryMatchesPredicate( search, predicate ) ]

if not self._collapse:

parents_manager = HC.app.GetManager( 'tag_parents' )

matches = parents_manager.ExpandPredicates( self._service_key, matches )


return matches

return predicates

class Booru( HC.HydrusYAMLBase ):

Expand Down
82 changes: 40 additions & 42 deletions include/ClientDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,7 @@ def _GetAutocompleteContacts( self, half_complete_name, name_to_exclude = None )

if name_to_exclude is not None: names = [ name for name in names if name != name_to_exclude ]

matches = CC.AutocompleteMatches( names )

return matches
return names


def _GetContact( self, parameter ):
Expand Down Expand Up @@ -1819,12 +1817,12 @@ def _FattenAutocompleteCache( self ):
tag_services = self._GetServices( ( HC.TAG_REPOSITORY, HC.LOCAL_TAG, HC.COMBINED_TAG ) )
file_services = self._GetServices( ( HC.FILE_REPOSITORY, HC.LOCAL_FILE, HC.COMBINED_FILE ) )

for ( tag_service, file_service ) in itertools.product( tag_services, file_services ): self._GetAutocompleteTags( tag_service_key = tag_service.GetServiceKey(), file_service_key = file_service.GetServiceKey(), collapse = False )
for ( tag_service, file_service ) in itertools.product( tag_services, file_services ): self._GetAutocompletePredicates( tag_service_key = tag_service.GetServiceKey(), file_service_key = file_service.GetServiceKey(), add_namespaceless = False )

self._c.execute( 'REPLACE INTO shutdown_timestamps ( shutdown_type, timestamp ) VALUES ( ?, ? );', ( CC.SHUTDOWN_TIMESTAMP_FATTEN_AC_CACHE, HC.GetNow() ) )


def _GetAutocompleteTags( self, tag_service_key = HC.COMBINED_TAG_SERVICE_KEY, file_service_key = HC.COMBINED_FILE_SERVICE_KEY, tag = '', half_complete_tag = '', include_current = True, include_pending = True, collapse = True ):
def _GetAutocompletePredicates( self, tag_service_key = HC.COMBINED_TAG_SERVICE_KEY, file_service_key = HC.COMBINED_FILE_SERVICE_KEY, tag = '', half_complete_tag = '', include_current = True, include_pending = True, add_namespaceless = False ):

tag_service_id = self._GetServiceId( tag_service_key )
file_service_id = self._GetServiceId( file_service_key )
Expand Down Expand Up @@ -1885,7 +1883,7 @@ def GetPossibleTagIds( h_c_t ):

( namespace, half_complete_tag ) = half_complete_tag.split( ':', 1 )

if half_complete_tag == '': return CC.AutocompleteMatchesCounted( {} )
if half_complete_tag == '': return []
else:

if '*' in namespace:
Expand All @@ -1899,7 +1897,7 @@ def GetPossibleTagIds( h_c_t ):

result = self._c.execute( 'SELECT namespace_id FROM namespaces WHERE namespace = ?;', ( namespace, ) ).fetchone()

if result is None: return CC.AutocompleteMatchesCounted( {} )
if result is None: return []
else:

( namespace_id, ) = result
Expand Down Expand Up @@ -1938,27 +1936,29 @@ def GetPossibleTagIds( h_c_t ):

results = { result for result in self._c.execute( 'SELECT namespace_id, tag_id FROM existing_tags WHERE ' + predicates_phrase + ';' ) }

if collapse:
# now fetch siblings, add to results set
siblings_manager = HC.app.GetManager( 'tag_siblings' )
if len( half_complete_tag ) > 0: all_associated_sibling_tags = siblings_manager.GetAutocompleteSiblings( half_complete_tag )
elif len( tag ) > 0: all_associated_sibling_tags = siblings_manager.GetAllSiblings( tag )
else: all_associated_sibling_tags = siblings_manager.GetAutocompleteSiblings( '' )
sibling_results = []
# now fetch siblings, add to results set

siblings_manager = HC.app.GetManager( 'tag_siblings' )

if len( half_complete_tag ) > 0: all_associated_sibling_tags = siblings_manager.GetAutocompleteSiblings( half_complete_tag )
elif len( tag ) > 0: all_associated_sibling_tags = siblings_manager.GetAllSiblings( tag )
else: all_associated_sibling_tags = siblings_manager.GetAutocompleteSiblings( '' )

sibling_results = []

for sibling_tag in all_associated_sibling_tags:

for sibling_tag in all_associated_sibling_tags:
try:

try: self._GetNamespaceIdTagId( sibling_tag )
except: continue
( namespace_id, tag_id ) = self._GetNamespaceIdTagId( sibling_tag )


results.update( sibling_results )
sibling_results.append( ( namespace_id, tag_id ) )

except: continue


results.update( sibling_results )

# fetch what we can from cache

cache_results = []
Expand Down Expand Up @@ -2019,7 +2019,7 @@ def GetPossibleTagIds( h_c_t ):
current_ids_to_count = collections.Counter()
pending_ids_to_count = collections.Counter()

if collapse and not there_was_a_namespace:
if not there_was_a_namespace and add_namespaceless:

added_namespaceless_current_ids_to_count = collections.Counter()
added_namespaceless_pending_ids_to_count = collections.Counter()
Expand All @@ -2033,7 +2033,7 @@ def GetPossibleTagIds( h_c_t ):

# prepare to add any namespaced counts to the namespaceless count

if collapse and not there_was_a_namespace and ( current_count > 0 or pending_count > 0 ):
if not there_was_a_namespace and add_namespaceless and ( current_count > 0 or pending_count > 0 ):

tag_ids_to_incidence_count[ tag_id ] += 1

Expand All @@ -2049,7 +2049,7 @@ def GetPossibleTagIds( h_c_t ):
# e.g. 'series:evangelion (300)' is not benefitted by adding 'evangelion (300)'
# so do not add them

if collapse and not there_was_a_namespace:
if not there_was_a_namespace and add_namespaceless:

for ( tag_id, incidence ) in tag_ids_to_incidence_count.items():

Expand Down Expand Up @@ -2080,9 +2080,7 @@ def GetPossibleTagIds( h_c_t ):

predicates = [ HC.Predicate( HC.PREDICATE_TYPE_TAG, tag, counts = { HC.CURRENT : current_count, HC.PENDING : pending_count } ) for ( tag, current_count, pending_count ) in tag_info if tag in filtered_tags ]

matches = CC.AutocompleteMatchesPredicates( tag_service_key, predicates, collapse = collapse )

return matches
return predicates


def _GetDownloads( self ): return { hash for ( hash, ) in self._c.execute( 'SELECT hash FROM file_transfers, hashes USING ( hash_id ) WHERE service_id = ?;', ( self._local_file_service_id, ) ) }
Expand Down Expand Up @@ -5697,7 +5695,7 @@ def _UpdateDB( self, version ):

if version == 125:

( HC.options, ) = self._c.execute( 'SELECT options FROM options;' ).fetchone()
options = self._GetOptions()

HC.options[ 'default_tag_repository' ] = HC.options[ 'default_tag_repository' ].GetServiceKey()

Expand Down Expand Up @@ -5765,7 +5763,7 @@ def _UpdateDB( self, version ):

#

( HC.options, ) = self._c.execute( 'SELECT options FROM options;' ).fetchone()
options = self._GetOptions()

client_size = HC.options[ 'client_size' ]

Expand Down Expand Up @@ -5865,7 +5863,7 @@ def _UpdateDB( self, version ):

if version == 143:

( HC.options, ) = self._c.execute( 'SELECT options FROM options;' ).fetchone()
options = self._GetOptions()

HC.options[ 'shortcuts' ][ wx.ACCEL_CTRL ][ ord( 'E' ) ] = 'open_externally'

Expand All @@ -5874,7 +5872,7 @@ def _UpdateDB( self, version ):

if version == 145:

( HC.options, ) = self._c.execute( 'SELECT options FROM options;' ).fetchone()
options = self._GetOptions()

HC.options[ 'gui_colours' ][ 'tags_box' ] = ( 255, 255, 255 )

Expand Down Expand Up @@ -5944,7 +5942,7 @@ def ProcessRead( action, args, kwargs ):
elif action == 'tag_archive_info': result = self._GetTagArchiveInfo( *args, **kwargs )
elif action == 'tag_archive_tags': result = self._GetTagArchiveTags( *args, **kwargs )
elif action == 'autocomplete_contacts': result = self._GetAutocompleteContacts( *args, **kwargs )
elif action == 'autocomplete_tags': result = self._GetAutocompleteTags( *args, **kwargs )
elif action == 'autocomplete_predicates': result = self._GetAutocompletePredicates( *args, **kwargs )
elif action == 'contact_names': result = self._GetContactNames( *args, **kwargs )
elif action == 'do_message_query': result = self._DoMessageQuery( *args, **kwargs )
elif action == 'downloads': result = self._GetDownloads( *args, **kwargs )
Expand Down Expand Up @@ -7346,6 +7344,13 @@ def DAEMONSynchroniseSubscriptions():
job_key.SetVariable( 'popup_message_text_1', x_out_of_y + 'checking url status' )
job_key.SetVariable( 'popup_message_gauge_1', ( i, len( all_url_args ) ) )

if len( successful_hashes ) > 0:

job_key_s_h = set( successful_hashes )

job_key.SetVariable( 'popup_message_files', job_key_s_h )


( status, hash ) = HC.app.ReadDaemon( 'url_status', url )

if status == 'deleted' and 'exclude_deleted_files' not in advanced_import_options: status = 'new'
Expand Down Expand Up @@ -7392,14 +7397,7 @@ def DAEMONSynchroniseSubscriptions():
try: os.remove( temp_path )
except: pass # sometimes this fails, I think due to old handles not being cleaned up fast enough. np--it'll be cleaned up later

if status in ( 'successful', 'redundant' ):

successful_hashes.add( hash )

job_key_s_h = set( successful_hashes )

job_key.SetVariable( 'popup_message_files', job_key_s_h )

if status in ( 'successful', 'redundant' ): successful_hashes.add( hash )


except Exception as e:
Expand Down
Loading

0 comments on commit 7507e55

Please sign in to comment.