2019-12-05 05:29:32 +00:00
import os
2020-03-04 22:12:53 +00:00
import typing
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
2020-04-22 21:00:35 +00:00
from hydrus . core import HydrusConstants as HC
2020-11-18 22:15:21 +00:00
from hydrus . core import HydrusExceptions
2020-04-22 21:00:35 +00:00
from hydrus . core import HydrusGlobals as HG
2020-07-29 20:52:44 +00:00
2020-04-22 21:00:35 +00:00
from hydrus . client import ClientConstants as CC
from hydrus . client import ClientSearch
from hydrus . client . gui import ClientGUICore as CGC
2021-06-23 21:11:38 +00:00
from hydrus . client . gui import ClientGUIFunctions
2020-04-22 21:00:35 +00:00
from hydrus . client . gui import ClientGUIMenus
from hydrus . client . gui import ClientGUIScrolledPanels
from hydrus . client . gui import ClientGUIShortcuts
from hydrus . client . gui import QtPorting as QP
2020-11-25 22:22:47 +00:00
from hydrus . client . gui . search import ClientGUIPredicatesMultiple
from hydrus . client . gui . search import ClientGUIPredicatesSingle
from hydrus . client . gui . search import ClientGUIPredicatesOR
2021-03-17 21:59:28 +00:00
from hydrus . client . gui . widgets import ClientGUICommon
2015-04-08 18:10:50 +00:00
2020-05-13 19:03:16 +00:00
FLESH_OUT_SYSTEM_PRED_TYPES = {
ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_TAGS ,
ClientSearch . PREDICATE_TYPE_SYSTEM_LIMIT ,
ClientSearch . PREDICATE_TYPE_SYSTEM_SIZE ,
2022-11-09 22:24:07 +00:00
ClientSearch . PREDICATE_TYPE_SYSTEM_EMBEDDED_METADATA ,
2020-05-13 19:03:16 +00:00
ClientSearch . PREDICATE_TYPE_SYSTEM_DIMENSIONS ,
ClientSearch . PREDICATE_TYPE_SYSTEM_AGE ,
ClientSearch . PREDICATE_TYPE_SYSTEM_MODIFIED_TIME ,
ClientSearch . PREDICATE_TYPE_SYSTEM_KNOWN_URLS ,
ClientSearch . PREDICATE_TYPE_SYSTEM_HASH ,
ClientSearch . PREDICATE_TYPE_SYSTEM_DURATION ,
ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_AUDIO ,
2022-11-09 22:24:07 +00:00
ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_EXIF ,
ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_HUMAN_READABLE_EMBEDDED_METADATA ,
2021-12-08 22:40:59 +00:00
ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_ICC_PROFILE ,
2020-05-13 19:03:16 +00:00
ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_WORDS ,
ClientSearch . PREDICATE_TYPE_SYSTEM_MIME ,
ClientSearch . PREDICATE_TYPE_SYSTEM_RATING ,
ClientSearch . PREDICATE_TYPE_SYSTEM_SIMILAR_TO ,
ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_SERVICE ,
ClientSearch . PREDICATE_TYPE_SYSTEM_TAG_AS_NUMBER ,
ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS ,
ClientSearch . PREDICATE_TYPE_SYSTEM_NOTES ,
2022-01-26 21:57:04 +00:00
ClientSearch . PREDICATE_TYPE_SYSTEM_TIME ,
2020-05-13 19:03:16 +00:00
ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS
}
2020-11-18 22:15:21 +00:00
def EditPredicates ( widget : QW . QWidget , predicates : typing . Collection [ ClientSearch . Predicate ] ) - > typing . List [ ClientSearch . Predicate ] :
2022-09-28 17:15:23 +00:00
( editable_predicates , only_invertible_predicates , non_editable_predicates ) = GetEditablePredicates ( predicates )
2020-03-04 22:12:53 +00:00
window = widget . window ( )
2020-11-18 22:15:21 +00:00
from hydrus . client . gui import ClientGUITopLevelWindowsPanels
2022-09-28 17:15:23 +00:00
if len ( editable_predicates ) == 0 and len ( only_invertible_predicates ) == 1 :
2020-11-25 22:22:47 +00:00
result = list ( non_editable_predicates )
2022-09-28 17:15:23 +00:00
result . append ( only_invertible_predicates [ 0 ] . GetInverseCopy ( ) )
2020-11-25 22:22:47 +00:00
return result
2022-09-28 17:15:23 +00:00
elif len ( editable_predicates ) > 0 or len ( only_invertible_predicates ) > 0 :
2020-11-18 22:15:21 +00:00
2022-04-13 21:39:26 +00:00
title = ' edit predicates '
if len ( editable_predicates ) == 1 :
if list ( editable_predicates ) [ 0 ] . GetType ( ) == ClientSearch . PREDICATE_TYPE_OR_CONTAINER :
title = ' edit OR predicate '
with ClientGUITopLevelWindowsPanels . DialogEdit ( window , title ) as dlg :
2020-11-18 22:15:21 +00:00
panel = EditPredicatesPanel ( dlg , predicates )
dlg . SetPanel ( panel )
if dlg . exec ( ) == QW . QDialog . Accepted :
edited_predicates = panel . GetValue ( )
2020-11-25 22:22:47 +00:00
HG . client_controller . new_options . PushRecentPredicates ( edited_predicates )
2020-11-18 22:15:21 +00:00
result = list ( non_editable_predicates )
result . extend ( edited_predicates )
return result
raise HydrusExceptions . CancelledException ( )
def FilterAndConvertLabelPredicates ( predicates : typing . Collection [ ClientSearch . Predicate ] ) - > typing . List [ ClientSearch . Predicate ] :
2020-03-04 22:12:53 +00:00
good_predicates = [ ]
for predicate in predicates :
predicate = predicate . GetCountlessCopy ( )
2020-11-18 22:15:21 +00:00
predicate_type = predicate . GetType ( )
if predicate_type in ( ClientSearch . PREDICATE_TYPE_LABEL , ClientSearch . PREDICATE_TYPE_PARENT ) :
continue
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_UNTAGGED :
2022-09-28 17:15:23 +00:00
predicate = ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_TAGS , ( ' * ' , ' = ' , 0 ) )
2020-11-18 22:15:21 +00:00
good_predicates . append ( predicate )
return good_predicates
def FleshOutPredicates ( widget : QW . QWidget , predicates : typing . Collection [ ClientSearch . Predicate ] ) - > typing . List [ ClientSearch . Predicate ] :
2021-12-08 22:40:59 +00:00
window = None
2020-11-18 22:15:21 +00:00
predicates = FilterAndConvertLabelPredicates ( predicates )
good_predicates = [ ]
for predicate in predicates :
value = predicate . GetValue ( )
predicate_type = predicate . GetType ( )
2020-03-04 22:12:53 +00:00
2020-05-13 19:03:16 +00:00
if value is None and predicate_type in FLESH_OUT_SYSTEM_PRED_TYPES :
2020-03-04 22:12:53 +00:00
2021-12-08 22:40:59 +00:00
if window is None :
if QP . isValid ( widget ) :
window = widget . window ( )
2020-04-29 21:44:12 +00:00
from hydrus . client . gui import ClientGUITopLevelWindowsPanels
2020-03-04 22:12:53 +00:00
2020-04-29 21:44:12 +00:00
with ClientGUITopLevelWindowsPanels . DialogEdit ( window , ' input predicate ' , hide_buttons = True ) as dlg :
2020-03-04 22:12:53 +00:00
2020-11-18 22:15:21 +00:00
panel = FleshOutPredicatePanel ( dlg , predicate )
2020-03-04 22:12:53 +00:00
dlg . SetPanel ( panel )
if dlg . exec ( ) == QW . QDialog . Accepted :
2020-11-25 22:22:47 +00:00
preds = panel . GetValue ( )
HG . client_controller . new_options . PushRecentPredicates ( preds )
good_predicates . extend ( preds )
2020-03-04 22:12:53 +00:00
else :
good_predicates . append ( predicate )
return good_predicates
2020-11-25 22:22:47 +00:00
def GetEditablePredicates ( predicates : typing . Collection [ ClientSearch . Predicate ] ) :
2020-03-11 21:52:11 +00:00
2022-09-28 17:15:23 +00:00
editable_predicates = [ predicate for predicate in predicates if predicate . IsEditable ( ) ]
only_invertible_predicates = [ predicate for predicate in predicates if predicate . IsInvertible ( ) and not predicate . IsEditable ( ) ]
non_editable_predicates = [ predicate for predicate in predicates if not predicate . IsInvertible ( ) and not predicate . IsEditable ( ) ]
2020-03-11 21:52:11 +00:00
2022-09-28 17:15:23 +00:00
return ( editable_predicates , only_invertible_predicates , non_editable_predicates )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
class EditPredicatesPanel ( ClientGUIScrolledPanels . EditPanel ) :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
def __init__ ( self , parent , predicates : typing . Collection [ ClientSearch . Predicate ] ) :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
ClientGUIScrolledPanels . EditPanel . __init__ ( self , parent )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
predicates = list ( predicates )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
predicates . sort ( key = lambda p : p . ToString ( with_count = False ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _uneditable_predicates = [ ]
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _invertible_pred_buttons = [ ]
self . _editable_pred_panels = [ ]
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
rating_preds = [ ]
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
# I hate this pred comparison stuff, but let's hang in there until we split this stuff up by type mate
# then we can just have a dict type->panel_class lookup or whatever
# also it would be nice to have proper rating editing here, think about it
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
AGE_DELTA_PRED = ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_AGE , ( ' > ' , ' delta ' , ( 2000 , 1 , 1 , 1 ) ) )
2022-01-26 21:57:04 +00:00
LAST_VIEWED_DELTA_PRED = ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_LAST_VIEWED_TIME , ( ' > ' , ' delta ' , ( 2000 , 1 , 1 , 1 ) ) )
2020-11-25 22:22:47 +00:00
MODIFIED_DELTA_PRED = ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_MODIFIED_TIME , ( ' > ' , ' delta ' , ( 2000 , 1 , 1 , 1 ) ) )
KNOWN_URL_EXACT = ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_KNOWN_URLS , ( True , ' exact_match ' , ' ' , ' ' ) )
KNOWN_URL_DOMAIN = ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_KNOWN_URLS , ( True , ' domain ' , ' ' , ' ' ) )
KNOWN_URL_REGEX = ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_KNOWN_URLS , ( True , ' regex ' , ' ' , ' ' ) )
FILE_VIEWS_PRED = ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS , ( ' views ' , ( ' media ' , ) , ' > ' , 0 ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
for predicate in predicates :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
predicate_type = predicate . GetType ( )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
if predicate_type == ClientSearch . PREDICATE_TYPE_OR_CONTAINER :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesOR . ORPredicateControl ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2022-09-28 17:15:23 +00:00
elif predicate_type in ( ClientSearch . PREDICATE_TYPE_TAG , ClientSearch . PREDICATE_TYPE_NAMESPACE , ClientSearch . PREDICATE_TYPE_WILDCARD ) :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSimpleTagTypes ( self , predicate ) )
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_AGE :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
if predicate . IsUIEditable ( AGE_DELTA_PRED ) :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemAgeDelta ( self , predicate ) )
else :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemAgeDate ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2022-01-26 21:57:04 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_LAST_VIEWED_TIME :
if predicate . IsUIEditable ( LAST_VIEWED_DELTA_PRED ) :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemLastViewedDelta ( self , predicate ) )
else :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemLastViewedDate ( self , predicate ) )
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_MODIFIED_TIME :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
if predicate . IsUIEditable ( MODIFIED_DELTA_PRED ) :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemModifiedDelta ( self , predicate ) )
2020-03-11 21:52:11 +00:00
else :
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemModifiedDate ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_HEIGHT :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemHeight ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_WIDTH :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemWidth ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_RATIO :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemRatio ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_PIXELS :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemNumPixels ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_DURATION :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemDuration ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_FRAMERATE :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemFramerate ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_FRAMES :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemNumFrames ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_SERVICE :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemFileService ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_KNOWN_URLS :
if predicate . IsUIEditable ( KNOWN_URL_EXACT ) :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemKnownURLsExactURL ( self , predicate ) )
elif predicate . IsUIEditable ( KNOWN_URL_DOMAIN ) :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemKnownURLsDomain ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate . IsUIEditable ( KNOWN_URL_REGEX ) :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemKnownURLsRegex ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
else :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemKnownURLsURLClass ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_HASH :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemHash ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_LIMIT :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemLimit ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_MIME :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemMime ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_TAGS :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemNumTags ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_NOTES :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemNumNotes ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_NOTE_NAME :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemHasNoteName ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_WORDS :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemNumWords ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_SIMILAR_TO :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemSimilarTo ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_SIZE :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemSize ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_TAG_AS_NUMBER :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemTagAsNumber ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS_COUNT :
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemDuplicateRelationships ( self , predicate ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS :
if predicate . IsUIEditable ( FILE_VIEWS_PRED ) :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemFileViewingStatsViews ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
else :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesSingle . PanelPredicateSystemFileViewingStatsViewtime ( self , predicate ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_RATING :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
rating_preds . append ( predicate )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
elif predicate . IsInvertible ( ) :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _invertible_pred_buttons . append ( ClientGUIPredicatesSingle . InvertiblePredicateButton ( self , predicate ) )
2020-03-11 21:52:11 +00:00
else :
2020-11-25 22:22:47 +00:00
self . _uneditable_predicates . append ( predicate )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
if len ( rating_preds ) > 0 :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . _editable_pred_panels . append ( ClientGUIPredicatesMultiple . PanelPredicateSystemRating ( self , rating_preds ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
vbox = QP . VBoxLayout ( )
for button in self . _invertible_pred_buttons :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
QP . AddToLayout ( vbox , button , CC . FLAGS_EXPAND_PERPENDICULAR )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
for panel in self . _editable_pred_panels :
2020-03-11 21:52:11 +00:00
2021-04-14 21:54:17 +00:00
if isinstance ( panel , ClientGUIPredicatesOR . ORPredicateControl ) :
flags = CC . FLAGS_EXPAND_BOTH_WAYS
else :
flags = CC . FLAGS_EXPAND_PERPENDICULAR
QP . AddToLayout ( vbox , panel , flags )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
self . widget ( ) . setLayout ( vbox )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
def CheckValid ( self ) :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
for panel in self . _editable_pred_panels :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
panel . CheckValid ( )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
def GetValue ( self ) :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
return_predicates = list ( self . _uneditable_predicates )
for button in self . _invertible_pred_buttons :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
return_predicates . append ( button . GetPredicate ( ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
for panel in self . _editable_pred_panels :
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
return_predicates . extend ( panel . GetPredicates ( ) )
2020-03-11 21:52:11 +00:00
2020-11-25 22:22:47 +00:00
return return_predicates
2020-11-18 22:15:21 +00:00
class FleshOutPredicatePanel ( ClientGUIScrolledPanels . EditPanel ) :
def __init__ ( self , parent , predicate : ClientSearch . Predicate ) :
ClientGUIScrolledPanels . EditPanel . __init__ ( self , parent )
predicate_type = predicate . GetType ( )
2018-11-21 22:22:36 +00:00
self . _predicates = [ ]
2019-12-05 05:29:32 +00:00
label = None
2022-01-26 21:57:04 +00:00
page_name = ' page '
pages = [ ]
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
recent_predicate_types = [ predicate_type ]
2022-01-26 21:57:04 +00:00
static_pred_buttons = [ ]
editable_pred_panels = [ ]
2020-11-25 22:22:47 +00:00
2020-03-11 21:52:11 +00:00
if predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_AGE :
2018-11-21 22:22:36 +00:00
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_AGE , ( ' < ' , ' delta ' , ( 0 , 0 , 1 , 0 ) ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_AGE , ( ' < ' , ' delta ' , ( 0 , 0 , 7 , 0 ) ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_AGE , ( ' < ' , ' delta ' , ( 0 , 1 , 0 , 0 ) ) ) , ) , show_remove_button = False ) )
2020-05-20 21:36:02 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemAgeDelta , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemAgeDate , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_MODIFIED_TIME :
2019-10-02 23:38:59 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemModifiedDelta , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemModifiedDate , predicate ) )
2019-10-02 23:38:59 +00:00
2022-01-26 21:57:04 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_TIME :
recent_predicate_types = [ ClientSearch . PREDICATE_TYPE_SYSTEM_AGE ]
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_AGE , ( ' < ' , ' delta ' , ( 0 , 0 , 1 , 0 ) ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_AGE , ( ' < ' , ' delta ' , ( 0 , 0 , 7 , 0 ) ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_AGE , ( ' < ' , ' delta ' , ( 0 , 1 , 0 , 0 ) ) ) , ) , show_remove_button = False ) )
2022-01-26 21:57:04 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemAgeDelta , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemAgeDate , predicate ) )
pages . append ( ( ' import ' , recent_predicate_types , static_pred_buttons , editable_pred_panels ) )
recent_predicate_types = [ ClientSearch . PREDICATE_TYPE_SYSTEM_MODIFIED_TIME ]
static_pred_buttons = [ ]
editable_pred_panels = [ ]
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemModifiedDelta , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemModifiedDate , predicate ) )
pages . append ( ( ' modified ' , recent_predicate_types , static_pred_buttons , editable_pred_panels ) )
recent_predicate_types = [ ClientSearch . PREDICATE_TYPE_SYSTEM_LAST_VIEWED_TIME ]
static_pred_buttons = [ ]
editable_pred_panels = [ ]
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemLastViewedDelta , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemLastViewedDate , predicate ) )
page_name = ' last viewed '
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_DIMENSIONS :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
recent_predicate_types = [ ClientSearch . PREDICATE_TYPE_SYSTEM_HEIGHT , ClientSearch . PREDICATE_TYPE_SYSTEM_WIDTH , ClientSearch . PREDICATE_TYPE_SYSTEM_RATIO , ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_PIXELS ]
2020-05-06 21:31:41 +00:00
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_RATIO , ( ' = ' , 16 , 9 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_RATIO , ( ' = ' , 9 , 16 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_RATIO , ( ' = ' , 4 , 3 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_RATIO , ( ' = ' , 1 , 1 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_WIDTH , ( ' = ' , 1920 ) ) , ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HEIGHT , ( ' = ' , 1080 ) ) ) , forced_label = ' 1080p ' , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_WIDTH , ( ' = ' , 1280 ) ) , ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HEIGHT , ( ' = ' , 720 ) ) ) , forced_label = ' 720p ' , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_WIDTH , ( ' = ' , 3840 ) ) , ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HEIGHT , ( ' = ' , 2160 ) ) ) , forced_label = ' 4k ' , show_remove_button = False ) )
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemHeight , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemWidth , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemRatio , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemNumPixels , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_DURATION :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
recent_predicate_types = [ ClientSearch . PREDICATE_TYPE_SYSTEM_DURATION , ClientSearch . PREDICATE_TYPE_SYSTEM_FRAMERATE , ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_FRAMES ]
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_DURATION , ( ' > ' , 0 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_DURATION , ( ' = ' , 0 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_FRAMERATE , ( ' = ' , 30 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_FRAMERATE , ( ' = ' , 60 ) ) , ) , show_remove_button = False ) )
2019-11-14 03:56:30 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemDuration , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemFramerate , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemNumFrames , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_SERVICE :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemFileService , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_KNOWN_URLS :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemKnownURLsExactURL , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemKnownURLsDomain , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemKnownURLsRegex , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemKnownURLsURLClass , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_AUDIO :
2019-08-07 22:59:53 +00:00
2020-11-25 22:22:47 +00:00
recent_predicate_types = [ ]
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_AUDIO , True ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_AUDIO , False ) , ) , show_remove_button = False ) )
2019-08-07 22:59:53 +00:00
2022-11-09 22:24:07 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_EMBEDDED_METADATA :
recent_predicate_types = [ ]
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_EXIF , True ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_EXIF , False ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_HUMAN_READABLE_EMBEDDED_METADATA , True ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_HUMAN_READABLE_EMBEDDED_METADATA , False ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_ICC_PROFILE , True ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_ICC_PROFILE , False ) , ) , show_remove_button = False ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_EXIF :
recent_predicate_types = [ ]
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_EXIF , True ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_EXIF , False ) , ) , show_remove_button = False ) )
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_HUMAN_READABLE_EMBEDDED_METADATA :
recent_predicate_types = [ ]
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_HUMAN_READABLE_EMBEDDED_METADATA , True ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_HUMAN_READABLE_EMBEDDED_METADATA , False ) , ) , show_remove_button = False ) )
2021-12-08 22:40:59 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_ICC_PROFILE :
recent_predicate_types = [ ]
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_ICC_PROFILE , True ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_ICC_PROFILE , False ) , ) , show_remove_button = False ) )
2021-12-08 22:40:59 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_HASH :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemHash , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_LIMIT :
2018-11-21 22:22:36 +00:00
2020-01-02 03:05:35 +00:00
label = ' system:limit clips a large search result down to the given number of files. It is very useful for processing in smaller batches. '
label + = os . linesep * 2
label + = ' For all the simpler sorts (filesize, duration, etc...), it will select the n largest/smallest in the result set appropriate for that sort. For complicated sorts like tags, it will sample randomly. '
2019-12-05 05:29:32 +00:00
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_LIMIT , 64 ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_LIMIT , 256 ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_LIMIT , 1024 ) , ) , show_remove_button = False ) )
2019-11-14 03:56:30 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemLimit , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_MIME :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemMime , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_TAGS :
2018-11-21 22:22:36 +00:00
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_TAGS , ( ' * ' , ' > ' , 0 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_TAGS , ( ' * ' , ' = ' , 0 ) ) , ) , show_remove_button = False ) )
2019-11-14 03:56:30 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemNumTags , predicate ) )
2018-11-21 22:22:36 +00:00
2020-05-13 19:03:16 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_NOTES :
2020-05-06 21:31:41 +00:00
2020-11-25 22:22:47 +00:00
recent_predicate_types = [ ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_NOTES , ClientSearch . PREDICATE_TYPE_SYSTEM_HAS_NOTE_NAME ]
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_NOTES , ( ' > ' , 0 ) ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_NOTES , ( ' = ' , 0 ) ) , ) , show_remove_button = False ) )
2020-05-06 21:31:41 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemNumNotes , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemHasNoteName , predicate ) )
2020-05-06 21:31:41 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_NUM_WORDS :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemNumWords , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_RATING :
2018-11-21 22:22:36 +00:00
services_manager = HG . client_controller . services_manager
ratings_services = services_manager . GetServices ( ( HC . LOCAL_RATING_LIKE , HC . LOCAL_RATING_NUMERICAL ) )
if len ( ratings_services ) > 0 :
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesMultiple . PanelPredicateSystemRating , ( predicate , ) ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_SIMILAR_TO :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemSimilarTo , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_SIZE :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemSize , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_TAG_AS_NUMBER :
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemTagAsNumber , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS :
2018-11-21 22:22:36 +00:00
2022-10-12 20:18:22 +00:00
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS_KING , False ) , ) , show_remove_button = False ) )
static_pred_buttons . append ( ClientGUIPredicatesSingle . StaticSystemPredicateButton ( self , ( ClientSearch . Predicate ( ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS_KING , True ) , ) , show_remove_button = False ) )
2020-11-18 22:15:21 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemDuplicateRelationships , predicate ) )
2018-11-21 22:22:36 +00:00
2020-03-11 21:52:11 +00:00
elif predicate_type == ClientSearch . PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS :
2018-12-12 22:15:46 +00:00
2020-11-25 22:22:47 +00:00
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemFileViewingStatsViews , predicate ) )
editable_pred_panels . append ( self . _PredOKPanel ( self , ClientGUIPredicatesSingle . PanelPredicateSystemFileViewingStatsViewtime , predicate ) )
2018-12-12 22:15:46 +00:00
2018-11-21 22:22:36 +00:00
2022-01-26 21:57:04 +00:00
pages . append ( ( page_name , recent_predicate_types , static_pred_buttons , editable_pred_panels ) )
2019-11-14 03:56:30 +00:00
vbox = QP . VBoxLayout ( )
2018-11-21 22:22:36 +00:00
2019-12-05 05:29:32 +00:00
if label is not None :
st = ClientGUICommon . BetterStaticText ( self , label = label )
2020-01-02 03:05:35 +00:00
st . setWordWrap ( True )
QP . AddToLayout ( vbox , st , CC . FLAGS_EXPAND_PERPENDICULAR )
2019-12-05 05:29:32 +00:00
2022-01-26 21:57:04 +00:00
page_parent = self
if len ( pages ) > 1 :
self . _notebook = ClientGUICommon . BetterNotebook ( self )
QP . AddToLayout ( vbox , self . _notebook , CC . FLAGS_EXPAND_BOTH_WAYS )
page_parent = self . _notebook
2020-11-25 22:22:47 +00:00
2022-01-26 21:57:04 +00:00
for ( i , ( page_name , recent_predicate_types , static_pred_buttons , editable_pred_panels ) ) in enumerate ( pages ) :
page_panel = QW . QWidget ( page_parent )
2020-11-25 22:22:47 +00:00
2022-01-26 21:57:04 +00:00
page_vbox = QP . VBoxLayout ( )
2020-11-25 22:22:47 +00:00
2022-01-26 21:57:04 +00:00
recent_predicates = [ ]
if len ( recent_predicate_types ) > 0 :
2020-11-25 22:22:47 +00:00
2022-01-26 21:57:04 +00:00
recent_predicates = HG . client_controller . new_options . GetRecentPredicates ( recent_predicate_types )
2020-11-25 22:22:47 +00:00
2022-01-26 21:57:04 +00:00
if len ( recent_predicates ) > 0 :
2020-11-25 22:22:47 +00:00
2022-01-26 21:57:04 +00:00
recent_predicates_box = ClientGUICommon . StaticBox ( page_panel , ' recent ' )
2020-11-25 22:22:47 +00:00
2022-01-26 21:57:04 +00:00
for recent_predicate in recent_predicates :
2022-10-12 20:18:22 +00:00
button = ClientGUIPredicatesSingle . StaticSystemPredicateButton ( recent_predicates_box , ( recent_predicate , ) )
button . predicatesChosen . connect ( self . StaticButtonClicked )
button . predicatesRemoved . connect ( self . StaticRemoveButtonClicked )
2022-01-26 21:57:04 +00:00
recent_predicates_box . Add ( button , CC . FLAGS_EXPAND_PERPENDICULAR )
QP . AddToLayout ( page_vbox , recent_predicates_box , CC . FLAGS_EXPAND_PERPENDICULAR )
2020-11-25 22:22:47 +00:00
2019-11-14 03:56:30 +00:00
2022-01-26 21:57:04 +00:00
for button in static_pred_buttons :
QP . AddToLayout ( page_vbox , button , CC . FLAGS_EXPAND_PERPENDICULAR )
2022-10-12 20:18:22 +00:00
button . predicatesChosen . connect ( self . StaticButtonClicked )
button . predicatesRemoved . connect ( self . StaticRemoveButtonClicked )
2019-11-14 03:56:30 +00:00
2022-01-26 21:57:04 +00:00
for panel in editable_pred_panels :
QP . AddToLayout ( page_vbox , panel , CC . FLAGS_EXPAND_PERPENDICULAR )
2018-11-21 22:22:36 +00:00
2022-01-26 21:57:04 +00:00
page_panel . setLayout ( page_vbox )
2018-11-21 22:22:36 +00:00
2022-01-26 21:57:04 +00:00
if i == 0 and len ( static_pred_buttons ) > 0 and len ( editable_pred_panels ) == 0 :
ClientGUIFunctions . SetFocusLater ( static_pred_buttons [ 0 ] )
2019-11-14 03:56:30 +00:00
2022-01-26 21:57:04 +00:00
if len ( pages ) > 1 :
self . _notebook . addTab ( page_panel , page_name )
else :
QP . AddToLayout ( vbox , page_panel , CC . FLAGS_EXPAND_BOTH_WAYS )
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
self . widget ( ) . setLayout ( vbox )
2018-11-21 22:22:36 +00:00
def GetValue ( self ) :
return self . _predicates
2022-10-12 20:18:22 +00:00
def StaticButtonClicked ( self , button : ClientGUIPredicatesSingle . StaticSystemPredicateButton ) :
predicates = button . GetPredicates ( )
self . SubPanelOK ( predicates )
def StaticRemoveButtonClicked ( self , button : ClientGUIPredicatesSingle . StaticSystemPredicateButton ) :
predicates = button . GetPredicates ( )
for predicate in predicates :
HG . client_controller . new_options . RemoveRecentPredicate ( predicate )
button . hide ( )
recent_static_box = button . parentWidget ( )
static_buttons = [ w for w in recent_static_box . children ( ) if isinstance ( w , ClientGUIPredicatesSingle . StaticSystemPredicateButton ) ]
if True not in ( w . isVisible ( ) for w in static_buttons ) :
recent_static_box . hide ( )
2018-11-21 22:22:36 +00:00
def SubPanelOK ( self , predicates ) :
self . _predicates = predicates
2019-11-14 03:56:30 +00:00
self . parentWidget ( ) . DoOK ( )
2018-11-21 22:22:36 +00:00
2020-11-18 22:15:21 +00:00
class _PredOKPanel ( QW . QWidget ) :
2018-11-21 22:22:36 +00:00
2020-11-18 22:15:21 +00:00
def __init__ ( self , parent , predicate_panel_class , predicate ) :
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
QW . QWidget . __init__ ( self , parent )
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
self . _defaults_button = ClientGUICommon . BetterBitmapButton ( self , CC . global_pixmaps ( ) . star , self . _DefaultsMenu )
self . _defaults_button . setToolTip ( ' Set a new default. ' )
2020-11-18 22:15:21 +00:00
self . _predicate_panel = predicate_panel_class ( self , predicate )
2019-11-14 03:56:30 +00:00
self . _parent = parent
2018-11-21 22:22:36 +00:00
2019-12-11 23:18:37 +00:00
self . _ok = QW . QPushButton ( ' ok ' , self )
2019-11-14 03:56:30 +00:00
self . _ok . clicked . connect ( self . _DoOK )
2020-02-26 22:28:52 +00:00
self . _ok . setObjectName ( ' HydrusAccept ' )
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP . HBoxLayout ( )
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
QP . AddToLayout ( hbox , self . _defaults_button , CC . FLAGS_CENTER_PERPENDICULAR )
2019-11-14 03:56:30 +00:00
QP . AddToLayout ( hbox , self . _predicate_panel , CC . FLAGS_EXPAND_SIZER_BOTH_WAYS )
2020-07-29 20:52:44 +00:00
QP . AddToLayout ( hbox , self . _ok , CC . FLAGS_CENTER_PERPENDICULAR )
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
self . setLayout ( hbox )
2018-11-21 22:22:36 +00:00
2021-06-23 21:11:38 +00:00
ClientGUIFunctions . SetFocusLater ( self . _ok )
2018-11-21 22:22:36 +00:00
2020-11-25 22:22:47 +00:00
def _DefaultsMenu ( self ) :
menu = QW . QMenu ( )
ClientGUIMenus . AppendMenuItem ( menu , ' set this as new default ' , ' Set the current value of this as the new default for this predicate. ' , self . _predicate_panel . SaveCustomDefault )
if self . _predicate_panel . UsesCustomDefault ( ) :
ClientGUIMenus . AppendSeparator ( menu )
ClientGUIMenus . AppendMenuItem ( menu , ' reset to original default ' , ' Clear the custom default value for this predicate. ' , self . _predicate_panel . ClearCustomDefault )
CGC . core ( ) . PopupMenu ( self , menu )
2018-11-21 22:22:36 +00:00
def _DoOK ( self ) :
2019-12-11 23:18:37 +00:00
try :
2020-11-25 22:22:47 +00:00
self . _predicate_panel . CheckValid ( )
2019-12-11 23:18:37 +00:00
except Exception as e :
2020-11-25 22:22:47 +00:00
QW . QMessageBox . warning ( self , ' Predicate not valid! ' , str ( e ) )
2019-12-11 23:18:37 +00:00
return
2018-11-21 22:22:36 +00:00
predicates = self . _predicate_panel . GetPredicates ( )
2019-11-14 03:56:30 +00:00
self . _parent . SubPanelOK ( predicates )
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
def keyPressEvent ( self , event ) :
2018-11-21 22:22:36 +00:00
( modifier , key ) = ClientGUIShortcuts . ConvertKeyEventToSimpleTuple ( event )
2019-11-14 03:56:30 +00:00
if key in ( QC . Qt . Key_Enter , QC . Qt . Key_Return ) :
2018-11-21 22:22:36 +00:00
self . _DoOK ( )
else :
2019-11-14 03:56:30 +00:00
event . ignore ( )
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
2022-07-20 19:17:03 +00:00
class TagContextButton ( ClientGUICommon . BetterButton ) :
valueChanged = QC . Signal ( ClientSearch . TagContext )
def __init__ ( self , parent : QW . QWidget , tag_context : ClientSearch . TagContext , use_short_label = False ) :
self . _tag_context = ClientSearch . TagContext ( )
self . _use_short_label = use_short_label
ClientGUICommon . BetterButton . __init__ ( self , parent , ' initialising ' , self . _Edit )
self . SetValue ( tag_context )
def _Edit ( self ) :
services_manager = HG . client_controller . services_manager
service_types_in_order = [ HC . LOCAL_TAG , HC . TAG_REPOSITORY , HC . COMBINED_TAG ]
services = services_manager . GetServices ( service_types_in_order )
menu = QW . QMenu ( )
2023-02-01 21:20:47 +00:00
last_seen_service_type = None
2022-07-20 19:17:03 +00:00
for service in services :
2023-02-01 21:20:47 +00:00
if last_seen_service_type is not None and last_seen_service_type != service . GetServiceType ( ) :
ClientGUIMenus . AppendSeparator ( menu )
2022-07-20 19:17:03 +00:00
tag_context = ClientSearch . TagContext ( service_key = service . GetServiceKey ( ) )
ClientGUIMenus . AppendMenuItem ( menu , service . GetName ( ) , ' Change the current tag domain to {} . ' . format ( service . GetName ( ) ) , self . SetValue , tag_context )
2023-02-01 21:20:47 +00:00
last_seen_service_type = service . GetServiceType ( )
2022-07-20 19:17:03 +00:00
CGC . core ( ) . PopupMenu ( self , menu )
def GetValue ( self ) - > ClientSearch . TagContext :
return self . _tag_context
def SetValue ( self , tag_context : ClientSearch . TagContext ) :
original_tag_context = self . _tag_context
tag_context = tag_context . Duplicate ( )
tag_context . FixMissingServices ( HG . client_controller . services_manager . FilterValidServiceKeys )
self . _tag_context = tag_context
label = self . _tag_context . ToString ( HG . client_controller . services_manager . GetName )
if self . _use_short_label :
self . setText ( ' tags ' )
else :
self . setText ( label )
self . setToolTip ( label )
if self . _tag_context != original_tag_context :
self . valueChanged . emit ( self . _tag_context )