2020-11-25 22:22:47 +00:00
|
|
|
import typing
|
|
|
|
|
|
|
|
from qtpy import QtWidgets as QW
|
|
|
|
|
|
|
|
from hydrus.core import HydrusData
|
|
|
|
from hydrus.core import HydrusExceptions
|
2022-03-23 20:57:10 +00:00
|
|
|
from hydrus.core import HydrusGlobals as HG
|
2023-04-19 20:38:13 +00:00
|
|
|
from hydrus.core import HydrusTime
|
2020-11-25 22:22:47 +00:00
|
|
|
|
|
|
|
from hydrus.client import ClientConstants as CC
|
2024-02-14 21:20:24 +00:00
|
|
|
from hydrus.client import ClientGlobals as CG
|
2022-04-13 21:39:26 +00:00
|
|
|
from hydrus.client.gui import ClientGUIFunctions
|
2020-11-25 22:22:47 +00:00
|
|
|
from hydrus.client.gui import QtPorting as QP
|
2023-05-31 20:54:09 +00:00
|
|
|
from hydrus.client.search import ClientSearch
|
2020-11-25 22:22:47 +00:00
|
|
|
|
|
|
|
# ultimately, rewrite acread to be two classes, acread and acreadthatsupportsor
|
|
|
|
# and then this guy only imports the base class, and only the supportsor will know about this
|
|
|
|
# otherwise we have jank imports, and also nested OR lmao
|
|
|
|
# also this should take file and tag domain
|
|
|
|
|
|
|
|
class ORPredicateControl( QW.QWidget ):
|
|
|
|
|
2024-02-21 21:09:02 +00:00
|
|
|
def __init__( self, parent: QW.QWidget, predicate: ClientSearch.Predicate, empty_file_search_context: typing.Optional[ ClientSearch.FileSearchContext ] = None ):
|
2020-11-25 22:22:47 +00:00
|
|
|
|
|
|
|
QW.QWidget.__init__( self, parent )
|
|
|
|
|
|
|
|
from hydrus.client.gui.search import ClientGUIACDropdown
|
|
|
|
|
|
|
|
if predicate.GetType() != ClientSearch.PREDICATE_TYPE_OR_CONTAINER:
|
|
|
|
|
|
|
|
raise Exception( 'Launched an ORPredicateControl without an OR Pred!' )
|
|
|
|
|
|
|
|
|
|
|
|
page_key = HydrusData.GenerateKey()
|
|
|
|
|
2024-02-21 21:09:02 +00:00
|
|
|
predicates = predicate.GetValue()
|
2021-05-27 00:09:06 +00:00
|
|
|
|
2024-02-21 21:09:02 +00:00
|
|
|
if empty_file_search_context is None:
|
|
|
|
|
|
|
|
location_context = CG.client_controller.new_options.GetDefaultLocalLocationContext()
|
|
|
|
|
|
|
|
file_search_context = ClientSearch.FileSearchContext( location_context = location_context, predicates = predicates )
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
empty_file_search_context = empty_file_search_context.Duplicate()
|
|
|
|
|
|
|
|
empty_file_search_context.SetPredicates( predicates )
|
|
|
|
|
|
|
|
file_search_context = empty_file_search_context
|
|
|
|
|
2020-11-25 22:22:47 +00:00
|
|
|
|
|
|
|
self._search_control = ClientGUIACDropdown.AutoCompleteDropdownTagsRead( self, page_key, file_search_context, hide_favourites_edit_actions = True )
|
|
|
|
|
2022-04-13 21:39:26 +00:00
|
|
|
self._search_control.setMinimumWidth( ClientGUIFunctions.ConvertTextToPixelWidth( self._search_control, 64 ) )
|
|
|
|
|
2020-11-25 22:22:47 +00:00
|
|
|
vbox = QP.VBoxLayout()
|
|
|
|
|
2021-04-14 21:54:17 +00:00
|
|
|
QP.AddToLayout( vbox, self._search_control, CC.FLAGS_EXPAND_BOTH_WAYS )
|
2020-11-25 22:22:47 +00:00
|
|
|
|
|
|
|
self.setLayout( vbox )
|
|
|
|
|
2022-04-13 21:39:26 +00:00
|
|
|
ClientGUIFunctions.SetFocusLater( self._search_control )
|
|
|
|
|
2020-11-25 22:22:47 +00:00
|
|
|
|
|
|
|
def CheckValid( self ):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
predicates = self.GetPredicates()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
raise HydrusExceptions.VetoException( str( e ) )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetPredicates( self ):
|
|
|
|
|
|
|
|
or_sub_predicates = self._search_control.GetPredicates()
|
|
|
|
|
|
|
|
if len( or_sub_predicates ) == 0:
|
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
elif len( or_sub_predicates ) == 1:
|
|
|
|
|
|
|
|
return or_sub_predicates
|
|
|
|
|
|
|
|
|
|
|
|
or_predicate = ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_OR_CONTAINER, or_sub_predicates )
|
|
|
|
|
|
|
|
return [ or_predicate ]
|
|
|
|
|
2022-09-28 17:15:23 +00:00
|
|
|
|