def __init__(self, parent: QW.QWidget, predicate: ClientSearch.Predicate): 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!') predicates = predicate.GetValue() page_key = HydrusData.GenerateKey() file_search_context = ClientSearch.FileSearchContext( file_service_key=CC.LOCAL_FILE_SERVICE_KEY, predicates=predicates) self._search_control = ClientGUIACDropdown.AutoCompleteDropdownTagsRead( self, page_key, file_search_context, hide_favourites_edit_actions=True) vbox = QP.VBoxLayout() QP.AddToLayout(vbox, self._search_control, CC.FLAGS_EXPAND_BOTH_WAYS) self.setLayout(vbox)
def ExpandPredicate( self, service_key: bytes, predicate: ClientSearch.Predicate, service_strict: bool = False ): if not service_strict and self._controller.new_options.GetBoolean( 'apply_all_siblings_to_all_services' ): service_key = CC.COMBINED_TAG_SERVICE_KEY ideal_sibling_predicate = predicate other_sibling_predicates = [] if predicate.GetType() == ClientSearch.PREDICATE_TYPE_TAG: tag = predicate.GetValue() ideal_sibling = self.CollapseTag( service_key, tag, service_strict = service_strict ) ideal_sibling_predicate = ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_TAG, ideal_sibling, predicate.IsInclusive() ) other_siblings = set( self.GetAllSiblings( service_key, tag, service_strict = service_strict ) ) other_siblings.discard( tag ) other_siblings.discard( ideal_sibling ) other_sibling_predicates = [ ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_TAG, sibling, predicate.IsInclusive() ) for sibling in other_siblings ] return ( ideal_sibling_predicate, other_sibling_predicates )
def _GenerateTermFromPredicate( self, predicate: ClientSearch.Predicate ) -> ClientGUIListBoxesData.ListBoxItemPredicate: predicate = predicate.GetCountlessCopy() return ClientGUIListBoxesData.ListBoxItemPredicate(predicate)
def _GenerateTermFromPredicate( self, predicate: ClientSearch.Predicate ) -> ClientGUIListBoxesData.ListBoxItemPredicate: predicate.ClearCounts() return ClientGUIListBoxesData.ListBoxItemPredicate(predicate)
def ExpandPredicate( self, service_key: bytes, predicate: ClientSearch.Predicate ): ideal_sibling_predicate = predicate other_sibling_predicates = [] if predicate.GetType() == ClientSearch.PREDICATE_TYPE_TAG: tag = predicate.GetValue() ideal_sibling = self.GetSibling( service_key, tag ) ideal_sibling_predicate = ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_TAG, ideal_sibling, predicate.IsInclusive() ) other_siblings = set( self.GetAllSiblings( service_key, tag ) ) other_siblings.discard( tag ) other_siblings.discard( ideal_sibling ) other_sibling_predicates = [ ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_TAG, sibling, predicate.IsInclusive() ) for sibling in other_siblings ] return ( ideal_sibling_predicate, other_sibling_predicates )
def __init__(self, parent: QW.QWidget, predicate: ClientSearch.Predicate): 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!') predicates = predicate.GetValue() page_key = HydrusData.GenerateKey() location_context = HG.client_controller.new_options.GetDefaultLocalLocationContext( ) file_search_context = ClientSearch.FileSearchContext( location_context=location_context, predicates=predicates) self._search_control = ClientGUIACDropdown.AutoCompleteDropdownTagsRead( self, page_key, file_search_context, hide_favourites_edit_actions=True) self._search_control.setMinimumWidth( ClientGUIFunctions.ConvertTextToPixelWidth(self._search_control, 64)) vbox = QP.VBoxLayout() QP.AddToLayout(vbox, self._search_control, CC.FLAGS_EXPAND_BOTH_WAYS) self.setLayout(vbox) ClientGUIFunctions.SetFocusLater(self._search_control)
def __init__(self, parent, predicate: ClientSearch.Predicate): ClientGUIScrolledPanels.EditPanel.__init__(self, parent) predicate_type = predicate.GetType() self._predicates = [] label = None editable_pred_panels = [] static_pred_buttons = [] recent_predicate_types = [predicate_type] if predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_AGE: static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_AGE, ('<', 'delta', (0, 0, 1, 0))), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_AGE, ('<', 'delta', (0, 0, 7, 0))), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_AGE, ('<', 'delta', (0, 1, 0, 0))), ))) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemAgeDelta, predicate)) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemAgeDate, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_MODIFIED_TIME: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle. PanelPredicateSystemModifiedDelta, predicate)) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemModifiedDate, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_DIMENSIONS: recent_predicate_types = [ ClientSearch.PREDICATE_TYPE_SYSTEM_HEIGHT, ClientSearch.PREDICATE_TYPE_SYSTEM_WIDTH, ClientSearch.PREDICATE_TYPE_SYSTEM_RATIO, ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_PIXELS ] static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_RATIO, ('=', 16, 9)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_RATIO, ('=', 9, 16)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_RATIO, ('=', 4, 3)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_RATIO, ('=', 1, 1)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_WIDTH, ('=', 1920)), ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HEIGHT, ('=', 1080))), forced_label='1080p')) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_WIDTH, ('=', 1280)), ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HEIGHT, ('=', 720))), forced_label='720p')) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_WIDTH, ('=', 3840)), ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HEIGHT, ('=', 2160))), forced_label='4k')) 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)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_DURATION: recent_predicate_types = [ ClientSearch.PREDICATE_TYPE_SYSTEM_DURATION, ClientSearch.PREDICATE_TYPE_SYSTEM_FRAMERATE, ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_FRAMES ] static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_DURATION, ('>', 0)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_DURATION, ('=', 0)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FRAMERATE, ('=', 30)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_FRAMERATE, ('=', 60)), ))) 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)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_SERVICE: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemFileService, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_KNOWN_URLS: 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)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_HAS_AUDIO: recent_predicate_types = [] static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HAS_AUDIO, True), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_HAS_AUDIO, False), ))) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_HASH: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemHash, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_LIMIT: 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.' static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_LIMIT, 64), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_LIMIT, 256), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_LIMIT, 1024), ))) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemLimit, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_MIME: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemMime, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_TAGS: static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_TAGS, (None, '>', 0)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_TAGS, (None, '=', 0)), ))) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemNumTags, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_NOTES: recent_predicate_types = [ ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_NOTES, ClientSearch.PREDICATE_TYPE_SYSTEM_HAS_NOTE_NAME ] static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_NOTES, ('>', 0)), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_NOTES, ('=', 0)), ))) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemNumNotes, predicate)) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemHasNoteName, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_NUM_WORDS: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemNumWords, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_RATING: 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: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesMultiple.PanelPredicateSystemRating, (predicate, ))) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_SIMILAR_TO: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemSimilarTo, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_SIZE: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemSize, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_TAG_AS_NUMBER: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle.PanelPredicateSystemTagAsNumber, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS: static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch. PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS_KING, False), ))) static_pred_buttons.append( ClientGUIPredicatesSingle.StaticSystemPredicateButton( self, self, (ClientSearch.Predicate( ClientSearch. PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS_KING, True), ))) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle. PanelPredicateSystemDuplicateRelationships, predicate)) elif predicate_type == ClientSearch.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS: editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle. PanelPredicateSystemFileViewingStatsViews, predicate)) editable_pred_panels.append( self._PredOKPanel( self, ClientGUIPredicatesSingle. PanelPredicateSystemFileViewingStatsViewtime, predicate)) vbox = QP.VBoxLayout() if label is not None: st = ClientGUICommon.BetterStaticText(self, label=label) st.setWordWrap(True) QP.AddToLayout(vbox, st, CC.FLAGS_EXPAND_PERPENDICULAR) recent_predicates = [] if len(recent_predicate_types) > 0: recent_predicates = HG.client_controller.new_options.GetRecentPredicates( recent_predicate_types) if len(recent_predicates) > 0: recent_predicates_box = ClientGUICommon.StaticBox( self, 'recent') for recent_predicate in recent_predicates: button = ClientGUIPredicatesSingle.StaticSystemPredicateButton( recent_predicates_box, self, (recent_predicate, )) recent_predicates_box.Add(button, CC.FLAGS_EXPAND_PERPENDICULAR) QP.AddToLayout(vbox, recent_predicates_box, CC.FLAGS_EXPAND_PERPENDICULAR) for button in static_pred_buttons: QP.AddToLayout(vbox, button, CC.FLAGS_EXPAND_PERPENDICULAR) for panel in editable_pred_panels: QP.AddToLayout(vbox, panel, CC.FLAGS_EXPAND_PERPENDICULAR) if len(static_pred_buttons) > 0 and len(editable_pred_panels) == 0: HG.client_controller.CallAfterQtSafe( static_pred_buttons[0], static_pred_buttons[0].setFocus, QC.Qt.OtherFocusReason) self.widget().setLayout(vbox)