2016-08-03 22:15:54 +00:00
|
|
|
import collections
|
2020-04-22 21:00:35 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
from qtpy import QtCore as QC
|
|
|
|
from qtpy import QtWidgets as QW
|
|
|
|
from qtpy import QtGui as QG
|
2020-04-22 21:00:35 +00:00
|
|
|
|
|
|
|
from hydrus.core import HydrusConstants as HC
|
|
|
|
from hydrus.core import HydrusData
|
|
|
|
from hydrus.core import HydrusGlobals as HG
|
|
|
|
from hydrus.core import HydrusSerialisable
|
|
|
|
from hydrus.client import ClientConstants as CC
|
|
|
|
from hydrus.client import ClientData
|
|
|
|
from hydrus.client import ClientMedia
|
|
|
|
from hydrus.client import ClientParsing
|
|
|
|
from hydrus.client import ClientSearch
|
|
|
|
from hydrus.client import ClientTags
|
|
|
|
from hydrus.client import ClientThreading
|
|
|
|
from hydrus.client.gui import ClientGUICommon
|
|
|
|
from hydrus.client.gui import ClientGUIDialogs
|
|
|
|
from hydrus.client.gui import ClientGUIListBoxes
|
|
|
|
from hydrus.client.gui import ClientGUIParsing
|
|
|
|
from hydrus.client.gui import QtPorting as QP
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2017-02-01 21:11:17 +00:00
|
|
|
class ListBoxTagsSuggestionsFavourites( ClientGUIListBoxes.ListBoxTagsStrings ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2016-09-21 19:54:04 +00:00
|
|
|
def __init__( self, parent, activate_callable, sort_tags = True ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2017-02-01 21:11:17 +00:00
|
|
|
ClientGUIListBoxes.ListBoxTagsStrings.__init__( self, parent, sort_tags = sort_tags )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
self._activate_callable = activate_callable
|
|
|
|
|
2017-12-06 22:06:56 +00:00
|
|
|
width = HG.client_controller.new_options.GetInteger( 'suggested_tags_width' )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
if width is not None:
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self.setMinimumWidth( width )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
def _Activate( self ):
|
|
|
|
|
|
|
|
if len( self._selected_terms ) > 0:
|
|
|
|
|
|
|
|
tags = set( self._selected_terms )
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
self._activate_callable( tags, only_add = True )
|
|
|
|
|
|
|
|
self._RemoveSelectedTerms()
|
|
|
|
|
|
|
|
self._DataHasChanged()
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
2016-11-16 20:21:43 +00:00
|
|
|
|
|
|
|
def ActivateAll( self ):
|
|
|
|
|
2016-11-23 20:37:53 +00:00
|
|
|
self._activate_callable( self.GetTags(), only_add = True )
|
2016-11-16 20:21:43 +00:00
|
|
|
|
2017-05-24 20:28:24 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
def TakeFocusForUser( self ):
|
|
|
|
|
|
|
|
if len( self._selected_terms ) == 0 and len( self._terms ) > 0:
|
|
|
|
|
|
|
|
self._Hit( False, False, 0 )
|
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self.setFocus( QC.Qt.OtherFocusReason )
|
2019-06-05 19:42:39 +00:00
|
|
|
|
|
|
|
|
2017-03-22 22:38:15 +00:00
|
|
|
class ListBoxTagsSuggestionsRelated( ClientGUIListBoxes.ListBoxTagsPredicates ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
def __init__( self, parent, activate_callable ):
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
ClientGUIListBoxes.ListBoxTagsPredicates.__init__( self, parent )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
self._activate_callable = activate_callable
|
|
|
|
|
2017-12-06 22:06:56 +00:00
|
|
|
width = HG.client_controller.new_options.GetInteger( 'suggested_tags_width' )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self.setMinimumWidth( width )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _Activate( self ):
|
|
|
|
|
|
|
|
if len( self._selected_terms ) > 0:
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
tags = { predicate.GetValue() for predicate in self._selected_terms }
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
self._activate_callable( tags )
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
self._RemoveSelectedTerms()
|
|
|
|
|
|
|
|
self._DataHasChanged()
|
|
|
|
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
2017-03-29 19:39:34 +00:00
|
|
|
def _GetTextFromTerm( self, term ):
|
|
|
|
|
|
|
|
predicate = term
|
|
|
|
|
2019-01-09 22:59:03 +00:00
|
|
|
return predicate.ToString( with_count = False )
|
2017-03-29 19:39:34 +00:00
|
|
|
|
|
|
|
|
2016-08-03 22:15:54 +00:00
|
|
|
def SetPredicates( self, predicates ):
|
|
|
|
|
2017-03-22 22:38:15 +00:00
|
|
|
self._Clear()
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
for predicate in predicates:
|
|
|
|
|
2017-03-22 22:38:15 +00:00
|
|
|
self._AppendTerm( predicate )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
2017-03-22 22:38:15 +00:00
|
|
|
self._DataHasChanged()
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
def TakeFocusForUser( self ):
|
|
|
|
|
|
|
|
if len( self._selected_terms ) == 0 and len( self._terms ) > 0:
|
|
|
|
|
|
|
|
self._Hit( False, False, 0 )
|
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self.setFocus( QC.Qt.OtherFocusReason )
|
2019-06-05 19:42:39 +00:00
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
class RecentTagsPanel( QW.QWidget ):
|
2016-08-31 19:55:14 +00:00
|
|
|
|
|
|
|
def __init__( self, parent, service_key, activate_callable, canvas_key = None ):
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QW.QWidget.__init__( self, parent )
|
2016-08-31 19:55:14 +00:00
|
|
|
|
|
|
|
self._service_key = service_key
|
|
|
|
self._canvas_key = canvas_key
|
|
|
|
|
2017-12-06 22:06:56 +00:00
|
|
|
self._new_options = HG.client_controller.new_options
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
vbox = QP.VBoxLayout()
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
clear_button = QW.QPushButton( 'clear', self )
|
|
|
|
clear_button.clicked.connect( self.EventClear )
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2016-09-21 19:54:04 +00:00
|
|
|
self._recent_tags = ListBoxTagsSuggestionsFavourites( self, activate_callable, sort_tags = False )
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.AddToLayout( vbox, clear_button, CC.FLAGS_EXPAND_PERPENDICULAR )
|
|
|
|
QP.AddToLayout( vbox, self._recent_tags, CC.FLAGS_EXPAND_BOTH_WAYS )
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self.setLayout( vbox )
|
2016-08-31 19:55:14 +00:00
|
|
|
|
|
|
|
self._RefreshRecentTags()
|
|
|
|
|
|
|
|
|
|
|
|
def _RefreshRecentTags( self ):
|
|
|
|
|
2018-01-31 22:58:15 +00:00
|
|
|
def do_it( service_key ):
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
def qt_code():
|
2018-01-31 22:58:15 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
if not self or not QP.isValid( self ):
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
self._recent_tags.SetTags( recent_tags )
|
|
|
|
|
|
|
|
|
|
|
|
recent_tags = HG.client_controller.Read( 'recent_tags', service_key )
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.CallAfter( qt_code )
|
2018-01-31 22:58:15 +00:00
|
|
|
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2018-01-31 22:58:15 +00:00
|
|
|
HG.client_controller.CallToThread( do_it, self._service_key )
|
2016-08-31 19:55:14 +00:00
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
def EventClear( self ):
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2020-04-22 21:00:35 +00:00
|
|
|
from hydrus.client.gui import ClientGUIDialogsQuick
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2020-04-16 00:09:42 +00:00
|
|
|
result = ClientGUIDialogsQuick.GetYesNo( self, 'Clear recent tags?' )
|
|
|
|
|
|
|
|
if result == QW.QDialog.Accepted:
|
|
|
|
|
|
|
|
HG.client_controller.Write( 'push_recent_tags', self._service_key, None )
|
|
|
|
|
|
|
|
self._RefreshRecentTags()
|
|
|
|
|
2016-08-31 19:55:14 +00:00
|
|
|
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
def RefreshRecentTags( self ):
|
|
|
|
|
|
|
|
self._RefreshRecentTags()
|
|
|
|
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
def TakeFocusForUser( self ):
|
|
|
|
|
|
|
|
self._recent_tags.TakeFocusForUser()
|
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
class RelatedTagsPanel( QW.QWidget ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2016-08-10 19:04:08 +00:00
|
|
|
def __init__( self, parent, service_key, media, activate_callable, canvas_key = None ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QW.QWidget.__init__( self, parent )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
self._service_key = service_key
|
|
|
|
self._media = media
|
2016-08-10 19:04:08 +00:00
|
|
|
self._canvas_key = canvas_key
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._have_fetched = False
|
|
|
|
|
2017-12-06 22:06:56 +00:00
|
|
|
self._new_options = HG.client_controller.new_options
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
vbox = QP.VBoxLayout()
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._button_2 = QW.QPushButton( 'medium', self )
|
|
|
|
self._button_2.clicked.connect( self.EventSuggestedRelatedTags2 )
|
|
|
|
self._button_2.setMinimumWidth( 30 )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._button_3 = QW.QPushButton( 'thorough', self )
|
|
|
|
self._button_3.clicked.connect( self.EventSuggestedRelatedTags3 )
|
|
|
|
self._button_3.setMinimumWidth( 30 )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
self._related_tags = ListBoxTagsSuggestionsRelated( self, activate_callable )
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
button_hbox = QP.HBoxLayout()
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.AddToLayout( button_hbox, self._button_2, CC.FLAGS_EXPAND_SIZER_BOTH_WAYS )
|
|
|
|
QP.AddToLayout( button_hbox, self._button_3, CC.FLAGS_EXPAND_SIZER_BOTH_WAYS )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.AddToLayout( vbox, button_hbox, CC.FLAGS_EXPAND_PERPENDICULAR )
|
|
|
|
QP.AddToLayout( vbox, self._related_tags, CC.FLAGS_EXPAND_BOTH_WAYS )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self.setLayout( vbox )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _FetchRelatedTags( self, max_time_to_take ):
|
|
|
|
|
2018-01-31 22:58:15 +00:00
|
|
|
def do_it( service_key ):
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
def qt_code():
|
2018-01-31 22:58:15 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
if not self or not QP.isValid( self ):
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
self._related_tags.SetPredicates( predicates )
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._have_fetched = True
|
|
|
|
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
predicates = HG.client_controller.Read( 'related_tags', service_key, hash, search_tags, max_results, max_time_to_take )
|
|
|
|
|
|
|
|
predicates = ClientSearch.SortPredicates( predicates )
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.CallAfter( qt_code )
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
self._related_tags.SetPredicates( [] )
|
|
|
|
|
2016-08-03 22:15:54 +00:00
|
|
|
( m, ) = self._media
|
|
|
|
|
|
|
|
hash = m.GetHash()
|
|
|
|
|
2019-10-02 23:38:59 +00:00
|
|
|
( current_tags_to_count, deleted_tags_to_count, pending_tags_to_count, petitioned_tags_to_count ) = ClientMedia.GetMediasTagCount( self._media, self._service_key, ClientTags.TAG_DISPLAY_STORAGE )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
tags_to_count = collections.Counter()
|
|
|
|
|
|
|
|
tags_to_count.update( current_tags_to_count )
|
|
|
|
tags_to_count.update( pending_tags_to_count )
|
|
|
|
|
|
|
|
search_tags = set( tags_to_count.keys() )
|
|
|
|
|
|
|
|
max_results = 100
|
|
|
|
|
2018-01-31 22:58:15 +00:00
|
|
|
HG.client_controller.CallToThread( do_it, self._service_key )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
2016-08-10 19:04:08 +00:00
|
|
|
def _QuickSuggestedRelatedTags( self ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
max_time_to_take = self._new_options.GetInteger( 'related_tags_search_1_duration_ms' ) / 1000.0
|
|
|
|
|
|
|
|
self._FetchRelatedTags( max_time_to_take )
|
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
def EventSuggestedRelatedTags2( self ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
max_time_to_take = self._new_options.GetInteger( 'related_tags_search_2_duration_ms' ) / 1000.0
|
|
|
|
|
|
|
|
self._FetchRelatedTags( max_time_to_take )
|
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
def EventSuggestedRelatedTags3( self ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
max_time_to_take = self._new_options.GetInteger( 'related_tags_search_3_duration_ms' ) / 1000.0
|
|
|
|
|
|
|
|
self._FetchRelatedTags( max_time_to_take )
|
|
|
|
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
def SetMedia( self, media ):
|
|
|
|
|
|
|
|
self._media = media
|
|
|
|
|
|
|
|
self._QuickSuggestedRelatedTags()
|
|
|
|
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
def TakeFocusForUser( self ):
|
|
|
|
|
|
|
|
self._related_tags.TakeFocusForUser()
|
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
class FileLookupScriptTagsPanel( QW.QWidget ):
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2016-11-16 20:21:43 +00:00
|
|
|
def __init__( self, parent, service_key, media, activate_callable, canvas_key = None ):
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QW.QWidget.__init__( self, parent )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
self._service_key = service_key
|
|
|
|
self._media = media
|
2016-11-16 20:21:43 +00:00
|
|
|
self._canvas_key = canvas_key
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
self._script_choice = ClientGUICommon.BetterChoice( self )
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._script_choice.setEnabled( False )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._have_fetched = False
|
|
|
|
|
2018-01-31 22:58:15 +00:00
|
|
|
self._fetch_button = ClientGUICommon.BetterButton( self, 'fetch tags', self.FetchTags )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._fetch_button.setEnabled( False )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2016-11-16 20:21:43 +00:00
|
|
|
self._script_management = ClientGUIParsing.ScriptManagementControl( self )
|
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
self._tags = ListBoxTagsSuggestionsFavourites( self, activate_callable, sort_tags = True )
|
|
|
|
|
2016-11-16 20:21:43 +00:00
|
|
|
self._add_all = ClientGUICommon.BetterButton( self, 'add all', self._tags.ActivateAll )
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
vbox = QP.VBoxLayout()
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.AddToLayout( vbox, self._script_choice, CC.FLAGS_EXPAND_PERPENDICULAR )
|
|
|
|
QP.AddToLayout( vbox, self._fetch_button, CC.FLAGS_EXPAND_PERPENDICULAR )
|
|
|
|
QP.AddToLayout( vbox, self._script_management, CC.FLAGS_EXPAND_PERPENDICULAR )
|
|
|
|
QP.AddToLayout( vbox, self._add_all, CC.FLAGS_EXPAND_PERPENDICULAR )
|
|
|
|
QP.AddToLayout( vbox, self._tags, CC.FLAGS_EXPAND_BOTH_WAYS )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2016-11-16 20:21:43 +00:00
|
|
|
self._SetTags( [] )
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self.setLayout( vbox )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2018-01-31 22:58:15 +00:00
|
|
|
self._FetchScripts()
|
|
|
|
|
|
|
|
|
|
|
|
def _FetchScripts( self ):
|
|
|
|
|
|
|
|
def do_it():
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
def qt_code():
|
2018-01-31 22:58:15 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
if not self or not QP.isValid( self ):
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
script_names_to_scripts = { script.GetName() : script for script in scripts }
|
|
|
|
|
2019-01-09 22:59:03 +00:00
|
|
|
for ( name, script ) in list(script_names_to_scripts.items()):
|
2018-01-31 22:58:15 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._script_choice.addItem( script.GetName(), script )
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
new_options = HG.client_controller.new_options
|
|
|
|
|
|
|
|
favourite_file_lookup_script = new_options.GetNoneableString( 'favourite_file_lookup_script' )
|
|
|
|
|
|
|
|
if favourite_file_lookup_script in script_names_to_scripts:
|
|
|
|
|
2019-07-24 21:39:02 +00:00
|
|
|
self._script_choice.SetValue( script_names_to_scripts[ favourite_file_lookup_script ] )
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._script_choice.setCurrentIndex( 0 )
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._script_choice.setEnabled( True )
|
|
|
|
self._fetch_button.setEnabled( True )
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
scripts = HG.client_controller.Read( 'serialisable_named', HydrusSerialisable.SERIALISABLE_TYPE_PARSE_ROOT_FILE_LOOKUP )
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.CallAfter( qt_code )
|
2018-01-31 22:58:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
HG.client_controller.CallToThread( do_it )
|
|
|
|
|
2016-11-16 20:21:43 +00:00
|
|
|
|
|
|
|
def _SetTags( self, tags ):
|
|
|
|
|
|
|
|
self._tags.SetTags( tags )
|
|
|
|
|
|
|
|
if len( tags ) == 0:
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._add_all.setEnabled( False )
|
2016-11-16 20:21:43 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._add_all.setEnabled( True )
|
2016-11-16 20:21:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
def FetchTags( self ):
|
|
|
|
|
2019-07-24 21:39:02 +00:00
|
|
|
script = self._script_choice.GetValue()
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
if script.UsesUserInput():
|
|
|
|
|
|
|
|
message = 'Enter the custom input for the file lookup script.'
|
|
|
|
|
|
|
|
with ClientGUIDialogs.DialogTextEntry( self, message ) as dlg:
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
if dlg.exec() != QW.QDialog.Accepted:
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
file_identifier = dlg.GetValue()
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
( m, ) = self._media
|
|
|
|
|
|
|
|
file_identifier = script.ConvertMediaToFileIdentifier( m )
|
|
|
|
|
|
|
|
|
2016-11-16 20:21:43 +00:00
|
|
|
stop_time = HydrusData.GetNow() + 30
|
|
|
|
|
|
|
|
job_key = ClientThreading.JobKey( cancellable = True, stop_time = stop_time )
|
|
|
|
|
|
|
|
self._script_management.SetJobKey( job_key )
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
self._SetTags( set() )
|
|
|
|
|
2017-12-13 22:33:07 +00:00
|
|
|
HG.client_controller.CallToThread( self.THREADFetchTags, script, job_key, file_identifier )
|
2016-11-16 20:21:43 +00:00
|
|
|
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
def SetMedia( self, media ):
|
|
|
|
|
|
|
|
self._media = media
|
|
|
|
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
def TakeFocusForUser( self ):
|
|
|
|
|
|
|
|
if self._have_fetched:
|
|
|
|
|
|
|
|
self._tags.TakeFocusForUser()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._fetch_button.setFocus( QC.Qt.OtherFocusReason )
|
2019-06-05 19:42:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-13 22:33:07 +00:00
|
|
|
def THREADFetchTags( self, script, job_key, file_identifier ):
|
2016-11-16 20:21:43 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
def qt_code( tags ):
|
2018-01-24 23:09:42 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
if not self or not QP.isValid( self ):
|
2018-01-24 23:09:42 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
self._SetTags( tags )
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._have_fetched = True
|
|
|
|
|
2018-01-24 23:09:42 +00:00
|
|
|
|
2018-02-07 23:40:33 +00:00
|
|
|
parse_results = script.DoQuery( job_key, file_identifier )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2018-02-07 23:40:33 +00:00
|
|
|
tags = ClientParsing.GetTagsFromParseResults( parse_results )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.CallAfter( qt_code, tags )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
class SuggestedTagsPanel( QW.QWidget ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2016-08-10 19:04:08 +00:00
|
|
|
def __init__( self, parent, service_key, media, activate_callable, canvas_key = None ):
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QW.QWidget.__init__( self, parent )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
self._service_key = service_key
|
|
|
|
self._media = media
|
2016-08-10 19:04:08 +00:00
|
|
|
self._canvas_key = canvas_key
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2017-12-06 22:06:56 +00:00
|
|
|
self._new_options = HG.client_controller.new_options
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
layout_mode = self._new_options.GetNoneableString( 'suggested_tags_layout' )
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._notebook = None
|
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
if layout_mode == 'notebook':
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._notebook = ClientGUICommon.BetterNotebook( self )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
panel_parent = self._notebook
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
panel_parent = self
|
|
|
|
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
panels = []
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
favourites = self._new_options.GetSuggestedTagsFavourites( service_key )
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._favourite_tags = None
|
|
|
|
|
2016-08-03 22:15:54 +00:00
|
|
|
if len( favourites ) > 0:
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._favourite_tags = ListBoxTagsSuggestionsFavourites( panel_parent, activate_callable )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._favourite_tags.SetTags( favourites )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
panels.append( ( 'favourites', self._favourite_tags ) )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._related_tags = None
|
|
|
|
|
2016-08-03 22:15:54 +00:00
|
|
|
if self._new_options.GetBoolean( 'show_related_tags' ) and len( media ) == 1:
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._related_tags = RelatedTagsPanel( panel_parent, service_key, media, activate_callable, canvas_key = self._canvas_key )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
panels.append( ( 'related', self._related_tags ) )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._file_lookup_script_tags = None
|
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
if self._new_options.GetBoolean( 'show_file_lookup_script_tags' ) and len( media ) == 1:
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._file_lookup_script_tags = FileLookupScriptTagsPanel( panel_parent, service_key, media, activate_callable, canvas_key = self._canvas_key )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
panels.append( ( 'file lookup scripts', self._file_lookup_script_tags ) )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._recent_tags = None
|
|
|
|
|
2016-08-31 19:55:14 +00:00
|
|
|
if self._new_options.GetNoneableInteger( 'num_recent_tags' ) is not None:
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
self._recent_tags = RecentTagsPanel( panel_parent, service_key, activate_callable, canvas_key = self._canvas_key )
|
2016-08-31 19:55:14 +00:00
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
panels.append( ( 'recent', self._recent_tags ) )
|
2016-08-31 19:55:14 +00:00
|
|
|
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
hbox = QP.HBoxLayout()
|
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
if layout_mode == 'notebook':
|
|
|
|
|
|
|
|
for ( name, panel ) in panels:
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self._notebook.addTab( panel, name )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.AddToLayout( hbox, self._notebook, CC.FLAGS_EXPAND_BOTH_WAYS )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
elif layout_mode == 'columns':
|
|
|
|
|
|
|
|
for ( name, panel ) in panels:
|
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
QP.AddToLayout( hbox, panel, CC.FLAGS_EXPAND_PERPENDICULAR )
|
2016-11-09 23:13:22 +00:00
|
|
|
|
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
|
|
|
|
self.setLayout( hbox )
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2016-11-09 23:13:22 +00:00
|
|
|
if len( panels ) == 0:
|
2016-08-03 22:15:54 +00:00
|
|
|
|
2019-11-14 03:56:30 +00:00
|
|
|
self.hide()
|
2016-08-03 22:15:54 +00:00
|
|
|
|
|
|
|
|
2017-02-01 21:11:17 +00:00
|
|
|
|
2020-04-01 21:51:42 +00:00
|
|
|
def SetMedia( self, media ):
|
|
|
|
|
|
|
|
self._media = media
|
|
|
|
|
2020-04-01 22:52:48 +00:00
|
|
|
if self._recent_tags is not None:
|
2020-04-01 21:51:42 +00:00
|
|
|
|
2020-04-01 22:52:48 +00:00
|
|
|
self._recent_tags.RefreshRecentTags()
|
|
|
|
|
|
|
|
|
|
|
|
if self._file_lookup_script_tags is not None:
|
|
|
|
|
|
|
|
self._file_lookup_script_tags.SetMedia( media )
|
|
|
|
|
|
|
|
|
|
|
|
if self._related_tags is not None:
|
|
|
|
|
|
|
|
self._related_tags.SetMedia( media )
|
2020-04-01 21:51:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-05 19:42:39 +00:00
|
|
|
def TakeFocusForUser( self, command ):
|
|
|
|
|
|
|
|
if command == 'show_and_focus_manage_tags_favourite_tags':
|
|
|
|
|
|
|
|
panel = self._favourite_tags
|
|
|
|
|
|
|
|
elif command == 'show_and_focus_manage_tags_related_tags':
|
|
|
|
|
|
|
|
panel = self._related_tags
|
|
|
|
|
|
|
|
elif command == 'show_and_focus_manage_tags_file_lookup_script_tags':
|
|
|
|
|
|
|
|
panel = self._file_lookup_script_tags
|
|
|
|
|
|
|
|
elif command == 'show_and_focus_manage_tags_recent_tags':
|
|
|
|
|
|
|
|
panel = self._recent_tags
|
|
|
|
|
|
|
|
|
|
|
|
if panel is not None:
|
|
|
|
|
|
|
|
if self._notebook is not None:
|
|
|
|
|
|
|
|
self._notebook.SelectPage( panel )
|
|
|
|
|
|
|
|
|
|
|
|
panel.TakeFocusForUser()
|
|
|
|
|
|
|
|
|
|
|
|
|