hydrus/include/ClientGUIPredicates.py

1633 lines
53 KiB
Python
Raw Normal View History

2019-01-09 22:59:03 +00:00
from . import ClientConstants as CC
from . import ClientData
from . import ClientGUICommon
from . import ClientGUIControls
2019-08-07 22:59:53 +00:00
from . import ClientGUIFunctions
2019-01-09 22:59:03 +00:00
from . import ClientGUIOptionsPanels
from . import ClientGUIScrolledPanels
from . import ClientGUIShortcuts
from . import ClientGUITime
from . import ClientRatings
from . import ClientSearch
2018-01-31 22:58:15 +00:00
import datetime
2019-01-09 22:59:03 +00:00
from . import HydrusConstants as HC
from . import HydrusData
from . import HydrusGlobals as HG
2019-02-06 22:41:35 +00:00
from . import HydrusText
2019-12-05 05:29:32 +00:00
import os
2018-03-28 21:55:58 +00:00
import re
2015-04-08 18:10:50 +00:00
import string
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
from . import QtPorting as QP
2015-04-08 18:10:50 +00:00
2018-11-21 22:22:36 +00:00
class InputFileSystemPredicate( ClientGUIScrolledPanels.EditPanel ):
def __init__( self, parent, predicate_type ):
ClientGUIScrolledPanels.EditPanel.__init__( self, parent )
self._predicates = []
2019-12-05 05:29:32 +00:00
label = None
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes = []
static_pred_buttons = []
2018-11-21 22:22:36 +00:00
if predicate_type == HC.PREDICATE_TYPE_SYSTEM_AGE:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemAgeDelta )
editable_pred_panel_classes.append( PanelPredicateSystemAgeDate )
2018-11-21 22:22:36 +00:00
2019-10-02 23:38:59 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_MODIFIED_TIME:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemModifiedDelta )
editable_pred_panel_classes.append( PanelPredicateSystemModifiedDate )
2019-10-02 23:38:59 +00:00
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_DIMENSIONS:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemHeight )
editable_pred_panel_classes.append( PanelPredicateSystemWidth )
editable_pred_panel_classes.append( PanelPredicateSystemRatio )
editable_pred_panel_classes.append( PanelPredicateSystemNumPixels )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_DURATION:
2019-11-14 03:56:30 +00:00
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_DURATION, ( '>', 0 ) ), ) ) )
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_DURATION, ( '=', 0 ) ), ) ) )
editable_pred_panel_classes.append( PanelPredicateSystemDuration )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_FILE_SERVICE:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemFileService )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_KNOWN_URLS:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemKnownURLsExactURL )
editable_pred_panel_classes.append( PanelPredicateSystemKnownURLsDomain )
editable_pred_panel_classes.append( PanelPredicateSystemKnownURLsRegex )
editable_pred_panel_classes.append( PanelPredicateSystemKnownURLsURLClass )
2018-11-21 22:22:36 +00:00
2019-08-07 22:59:53 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_HAS_AUDIO:
2019-11-14 03:56:30 +00:00
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_HAS_AUDIO, True ), ) ) )
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_HAS_AUDIO, False ), ) ) )
2019-08-07 22:59:53 +00:00
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_HASH:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemHash )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_LIMIT:
2019-12-05 05:29:32 +00:00
label = 'Please note that, for now, system:limit generally samples randomly from the full search results.'
label += os.linesep
label += 'It will not clip the n largest/longest/most tagged files given a particular file sort.'
2019-11-14 03:56:30 +00:00
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_LIMIT, 64 ), ) ) )
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_LIMIT, 256 ), ) ) )
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_LIMIT, 1024 ), ) ) )
editable_pred_panel_classes.append( PanelPredicateSystemLimit )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_MIME:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemMime )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_NUM_TAGS:
2019-11-14 03:56:30 +00:00
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_NUM_TAGS, ( '>', 0 ) ), ) ) )
static_pred_buttons.append( StaticSystemPredicateButton( self, ( ClientSearch.Predicate( HC.PREDICATE_TYPE_SYSTEM_NUM_TAGS, ( '=', 0 ) ), ) ) )
editable_pred_panel_classes.append( PanelPredicateSystemNumTags )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_NUM_WORDS:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemNumWords )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.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:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemRating )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_SIMILAR_TO:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemSimilarTo )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_SIZE:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemSize )
2018-11-21 22:22:36 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_TAG_AS_NUMBER:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemTagAsNumber )
2018-11-21 22:22:36 +00:00
2019-07-24 21:39:02 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS:
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemDuplicateRelationships )
editable_pred_panel_classes.append( PanelPredicateSystemDuplicateKing )
2018-11-21 22:22:36 +00:00
2018-12-12 22:15:46 +00:00
elif predicate_type == HC.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS:
2019-11-14 03:56:30 +00:00
editable_pred_panel_classes.append( PanelPredicateSystemFileViewingStatsViews )
editable_pred_panel_classes.append( PanelPredicateSystemFileViewingStatsViewtime )
2018-12-12 22:15:46 +00:00
2018-11-21 22:22:36 +00:00
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 )
QP.AddToLayout( vbox, st, CC.FLAGS_EXPAND_BOTH_WAYS )
2019-11-14 03:56:30 +00:00
for button in static_pred_buttons:
QP.AddToLayout( vbox, button, CC.FLAGS_EXPAND_PERPENDICULAR )
for pred_class in editable_pred_panel_classes:
panel = self._EditablePredPanel( self, pred_class )
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( vbox, panel, CC.FLAGS_EXPAND_PERPENDICULAR )
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
if len( static_pred_buttons ) > 0 and len( editable_pred_panel_classes ) == 0:
QP.CallAfter( static_pred_buttons[0].setFocus, QC.Qt.OtherFocusReason )
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
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
2019-11-14 03:56:30 +00:00
class _EditablePredPanel( QW.QWidget ):
2018-11-21 22:22:36 +00:00
def __init__( self, parent, predicate_class ):
2019-11-14 03:56:30 +00:00
QW.QWidget.__init__( self, parent )
2018-11-21 22:22:36 +00:00
self._predicate_panel = predicate_class( self )
2019-11-14 03:56:30 +00:00
self._parent = parent
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
self._ok = QW.QPushButton( 'OK', self )
self._ok.clicked.connect( self._DoOK )
QP.SetForegroundColour( self._ok, (0,128,0) )
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
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, self._predicate_panel, CC.FLAGS_EXPAND_SIZER_BOTH_WAYS )
QP.AddToLayout( hbox, self._ok, CC.FLAGS_VCENTER )
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
2019-11-14 03:56:30 +00:00
QP.CallAfter( self._ok.setFocus, QC.Qt.OtherFocusReason )
2018-11-21 22:22:36 +00:00
def _DoOK( self ):
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
class StaticSystemPredicateButton( QW.QPushButton ):
def __init__( self, parent, predicates ):
QW.QPushButton.__init__( self, parent )
self._parent = parent
self._predicates = predicates
label = ', '.join( ( predicate.ToString() for predicate in self._predicates ) )
self.setText( label )
self.clicked.connect( self.DoOK )
def DoOK( self ):
self._parent.SubPanelOK( self._predicates )
2018-11-21 22:22:36 +00:00
2019-11-14 03:56:30 +00:00
class PanelPredicateSystem( QW.QWidget ):
2015-04-08 18:10:50 +00:00
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = None
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
raise NotImplementedError()
2015-07-01 22:02:07 +00:00
def GetPredicates( self ):
2015-04-08 18:10:50 +00:00
info = self.GetInfo()
2015-12-09 23:16:41 +00:00
predicates = ( ClientSearch.Predicate( self.PREDICATE_TYPE, info ), )
2015-04-08 18:10:50 +00:00
2015-07-01 22:02:07 +00:00
return predicates
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
2018-01-31 22:58:15 +00:00
class PanelPredicateSystemAgeDate( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_AGE
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2018-01-31 22:58:15 +00:00
2019-11-14 03:56:30 +00:00
self._date = QW.QCalendarWidget( self )
2018-01-31 22:58:15 +00:00
2019-11-14 03:56:30 +00:00
qt_dt = QC.QDate.currentDate()
2018-01-31 22:58:15 +00:00
2019-11-14 03:56:30 +00:00
qt_dt.addDays( -7 )
2018-01-31 22:58:15 +00:00
2019-11-14 03:56:30 +00:00
self._date.setSelectedDate( qt_dt )
2018-01-31 22:58:15 +00:00
self._sign.SetStringSelection( '>' )
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:time imported'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._date, CC.FLAGS_VCENTER )
2018-01-31 22:58:15 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2018-01-31 22:58:15 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2018-01-31 22:58:15 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
qt_dt = self._date.selectedDate()
2018-01-31 22:58:15 +00:00
2019-11-14 03:56:30 +00:00
year = qt_dt.year()
month = qt_dt.month()
day = qt_dt.day()
2018-01-31 22:58:15 +00:00
info = ( self._sign.GetStringSelection(), 'date', ( year, month, day ) )
return info
class PanelPredicateSystemAgeDelta( PanelPredicateSystem ):
2015-04-08 18:10:50 +00:00
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_AGE
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','>'] )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._years = QP.MakeQSpinBox( self, max=30, width = 60 )
self._months = QP.MakeQSpinBox( self, max=60, width = 60 )
self._days = QP.MakeQSpinBox( self, max=90, width = 60 )
self._hours = QP.MakeQSpinBox( self, max=24, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
2018-02-07 23:40:33 +00:00
try:
( sign, age_type, ( years, months, days, hours ) ) = system_predicates[ 'age' ]
except:
# wew lad. replace this all with proper system pred saving on new_options in future
sign = '<'
years = 0
months = 0
days = 7
hours = 0
2015-04-08 18:10:50 +00:00
2015-04-22 22:57:25 +00:00
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._years.setValue( years )
self._months.setValue( months )
self._days.setValue( days )
self._hours.setValue( hours )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:time imported'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._years, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'years'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._months, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'months'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._days, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'days'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._hours, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'hours'), CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = ( self._sign.GetStringSelection(), 'delta', (self._years.value(), self._months.value(), self._days.value(), self._hours.value()))
2019-10-02 23:38:59 +00:00
return info
class PanelPredicateSystemModifiedDate( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_MODIFIED_TIME
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
self._date = QW.QCalendarWidget( self )
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
qt_dt = QC.QDate.currentDate()
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
qt_dt.addDays( -7 )
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
self._date.setSelectedDate( qt_dt )
2019-10-02 23:38:59 +00:00
self._sign.SetStringSelection( '>' )
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:modified date'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._date, CC.FLAGS_VCENTER )
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
self.setLayout( hbox )
2019-10-02 23:38:59 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
qt_dt = self._date.selectedDate()
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
year = qt_dt.year()
month = qt_dt.month()
day = qt_dt.day()
2019-10-02 23:38:59 +00:00
info = ( self._sign.GetStringSelection(), 'date', ( year, month, day ) )
return info
class PanelPredicateSystemModifiedDelta( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_MODIFIED_TIME
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','>'] )
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
self._years = QP.MakeQSpinBox( self, max=30 )
self._months = QP.MakeQSpinBox( self, max=60 )
self._days = QP.MakeQSpinBox( self, max=90 )
self._hours = QP.MakeQSpinBox( self, max=24 )
2019-10-02 23:38:59 +00:00
# wew lad. replace this all with proper system pred saving on new_options in future
sign = '<'
years = 0
months = 0
days = 7
hours = 0
self._sign.SetStringSelection( sign )
2019-11-14 03:56:30 +00:00
self._years.setValue( years )
self._months.setValue( months )
self._days.setValue( days )
self._hours.setValue( hours )
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:modified date'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._years, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'years'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._months, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'months'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._days, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'days'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._hours, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'hours'), CC.FLAGS_VCENTER )
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2019-10-02 23:38:59 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2019-10-02 23:38:59 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = ( self._sign.GetStringSelection(), 'delta', ( self._years.value(), self._months.value(), self._days.value(), self._hours.value() ) )
2015-04-08 18:10:50 +00:00
return info
2019-07-24 21:39:02 +00:00
class PanelPredicateSystemDuplicateKing( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS_KING
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
choices = [ 'is the best quality file of its group', 'is not the best quality file of its group' ]
2019-11-14 03:56:30 +00:00
self._king = QP.RadioBox( self, choices = choices, vertical = True )
2019-07-24 21:39:02 +00:00
#
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2019-07-24 21:39:02 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._king, CC.FLAGS_VCENTER )
2019-07-24 21:39:02 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2019-07-24 21:39:02 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2019-07-24 21:39:02 +00:00
def GetInfo( self ):
king_str = self._king.GetStringSelection()
king = 'is the' in king_str
info = king
return info
2017-05-24 20:28:24 +00:00
class PanelPredicateSystemDuplicateRelationships( PanelPredicateSystem ):
2019-07-24 21:39:02 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_FILE_RELATIONSHIPS_COUNT
2017-05-24 20:28:24 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-01-09 22:59:03 +00:00
choices = [ '<', '\u2248', '=', '>' ]
2017-05-24 20:28:24 +00:00
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices = choices )
2017-05-24 20:28:24 +00:00
2019-11-14 03:56:30 +00:00
self._num = QP.MakeQSpinBox( self, min=0, max=65535 )
2017-05-24 20:28:24 +00:00
2019-06-19 22:08:48 +00:00
choices = [ ( HC.duplicate_type_string_lookup[ status ], status ) for status in ( HC.DUPLICATE_MEMBER, HC.DUPLICATE_ALTERNATE, HC.DUPLICATE_FALSE_POSITIVE, HC.DUPLICATE_POTENTIAL ) ]
2017-05-24 20:28:24 +00:00
2019-11-14 03:56:30 +00:00
self._dupe_type = ClientGUICommon.BetterRadioBox( self, choices = choices, vertical = True )
2017-05-24 20:28:24 +00:00
#
self._sign.SetStringSelection( '>' )
2019-11-14 03:56:30 +00:00
self._num.setValue( 0 )
2017-05-24 20:28:24 +00:00
#
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2017-05-24 20:28:24 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:num file relationships'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._num, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._dupe_type, CC.FLAGS_VCENTER )
2017-05-24 20:28:24 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2017-05-24 20:28:24 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2017-05-24 20:28:24 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = (self._sign.GetStringSelection(), self._num.value(), self._dupe_type.GetValue())
2017-05-24 20:28:24 +00:00
return info
2015-04-08 18:10:50 +00:00
class PanelPredicateSystemDuration( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_DURATION
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-01-09 22:59:03 +00:00
choices = [ '<', '\u2248', '=', '>' ]
2017-01-04 22:48:23 +00:00
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices = choices )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._duration_s = QP.MakeQSpinBox( self, max=3599, width = 60 )
self._duration_ms = QP.MakeQSpinBox( self, max=999, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
2015-04-22 22:57:25 +00:00
( sign, ms ) = system_predicates[ 'duration' ]
2015-04-08 18:10:50 +00:00
2019-01-09 22:59:03 +00:00
s = ms // 1000
2015-04-22 22:57:25 +00:00
ms = ms % 1000
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._duration_s.setValue( s )
self._duration_ms.setValue( ms )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:duration'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._duration_s, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'s'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._duration_ms, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'ms'), CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = (self._sign.GetStringSelection(), self._duration_s.value() * 1000 + self._duration_ms.value())
2015-04-08 18:10:50 +00:00
return info
class PanelPredicateSystemFileService( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_FILE_SERVICE
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = ClientGUICommon.BetterRadioBox( self, choices = [ ( 'is', True ), ( 'is not', False ) ], vertical = True )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._current_pending = ClientGUICommon.BetterRadioBox( self, choices = [ ( 'currently in', HC.CONTENT_STATUS_CURRENT ), ( 'pending to', HC.CONTENT_STATUS_PENDING ) ], vertical = True )
2015-04-08 18:10:50 +00:00
2017-06-28 20:23:21 +00:00
services = HG.client_controller.services_manager.GetServices( HC.FILE_SERVICES )
2015-04-08 18:10:50 +00:00
2017-01-04 22:48:23 +00:00
choices = [ ( service.GetName(), service.GetServiceKey() ) for service in services ]
2019-11-14 03:56:30 +00:00
self._file_service_key = ClientGUICommon.BetterRadioBox( self, choices = choices, vertical = True )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:file service:'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._current_pending, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._file_service_key, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-07-24 21:39:02 +00:00
info = ( self._sign.GetValue(), self._current_pending.GetValue(), self._file_service_key.GetValue() )
2017-01-04 22:48:23 +00:00
2015-04-08 18:10:50 +00:00
return info
2018-12-12 22:15:46 +00:00
class PanelPredicateSystemFileViewingStatsViews( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._viewing_locations = QP.CheckListBox( self )
2018-12-12 22:15:46 +00:00
self._viewing_locations.Append( 'media views', 'media' )
self._viewing_locations.Append( 'preview views', 'preview' )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2018-12-12 22:15:46 +00:00
2019-11-14 03:56:30 +00:00
self._value = QP.MakeQSpinBox( self, min=0, max=1000000 )
2018-12-12 22:15:46 +00:00
#
self._viewing_locations.Check( 0 )
self._sign.Select( 3 )
2019-11-14 03:56:30 +00:00
self._value.setValue( 10 )
hbox = QP.HBoxLayout()
2018-12-12 22:15:46 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._viewing_locations, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._value, CC.FLAGS_VCENTER )
2018-12-12 22:15:46 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2018-12-12 22:15:46 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2018-12-12 22:15:46 +00:00
def GetInfo( self ):
viewing_locations = self._viewing_locations.GetChecked()
if len( viewing_locations ) == 0:
viewing_locations = [ 'media' ]
sign = self._sign.GetStringSelection()
2019-11-14 03:56:30 +00:00
value = self._value.value()
2018-12-12 22:15:46 +00:00
info = ( 'views', tuple( viewing_locations ), sign, value )
return info
class PanelPredicateSystemFileViewingStatsViewtime( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_FILE_VIEWING_STATS
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._viewing_locations = QP.CheckListBox( self )
2018-12-12 22:15:46 +00:00
self._viewing_locations.Append( 'media viewtime', 'media' )
self._viewing_locations.Append( 'preview viewtime', 'preview' )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2018-12-12 22:15:46 +00:00
self._time_delta = ClientGUITime.TimeDeltaCtrl( self, min = 0, days = True, hours = True, minutes = True, seconds = True )
#
self._viewing_locations.Check( 0 )
self._sign.Select( 3 )
self._time_delta.SetValue( 600 )
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._viewing_locations, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._time_delta, CC.FLAGS_VCENTER )
2018-12-12 22:15:46 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2018-12-12 22:15:46 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2018-12-12 22:15:46 +00:00
def GetInfo( self ):
viewing_locations = self._viewing_locations.GetChecked()
if len( viewing_locations ) == 0:
viewing_locations = [ 'media' ]
sign = self._sign.GetStringSelection()
time_delta = self._time_delta.GetValue()
info = ( 'viewtime', tuple( viewing_locations ), sign, time_delta )
return info
2015-04-08 18:10:50 +00:00
class PanelPredicateSystemHash( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_HASH
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._hashes = QW.QPlainTextEdit( self )
2017-01-04 22:48:23 +00:00
2019-08-07 22:59:53 +00:00
init_size = ClientGUIFunctions.ConvertTextToPixels( self._hashes, ( 66, 10 ) )
2019-11-14 03:56:30 +00:00
self._hashes.setMinimumSize( QP.TupleToQSize( init_size ) )
2015-04-08 18:10:50 +00:00
2017-01-04 22:48:23 +00:00
choices = [ 'sha256', 'md5', 'sha1', 'sha512' ]
2015-12-30 23:44:09 +00:00
2019-11-14 03:56:30 +00:00
self._hash_type = QP.RadioBox( self, choices = choices, vertical = True )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._hashes.setPlaceholderText( 'enter hash (paste newline-separated for multiple hashes)' )
2019-08-07 22:59:53 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:hash='), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._hashes, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._hash_type, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
hex_hashes_raw = self._hashes.toPlainText()
2015-04-08 18:10:50 +00:00
2019-08-07 22:59:53 +00:00
hex_hashes = HydrusText.DeserialiseNewlinedTexts( hex_hashes_raw )
2015-04-08 18:10:50 +00:00
2019-08-07 22:59:53 +00:00
hex_hashes = [ HydrusText.HexFilter( hex_hash ) for hex_hash in hex_hashes ]
hex_hashes = HydrusData.DedupeList( hex_hashes )
2015-04-08 18:10:50 +00:00
2019-08-07 22:59:53 +00:00
hashes = tuple( [ bytes.fromhex( hex_hash ) for hex_hash in hex_hashes ] )
2015-04-08 18:10:50 +00:00
2017-01-04 22:48:23 +00:00
hash_type = self._hash_type.GetStringSelection()
2015-12-30 23:44:09 +00:00
2019-08-07 22:59:53 +00:00
return ( hashes, hash_type )
2015-04-08 18:10:50 +00:00
class PanelPredicateSystemHeight( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_HEIGHT
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._height = QP.MakeQSpinBox( self, max=200000, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
( sign, height ) = system_predicates[ 'height' ]
2015-04-22 22:57:25 +00:00
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._height.setValue( height )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:height'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._height, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = ( self._sign.GetStringSelection(), self._height.value())
2015-04-08 18:10:50 +00:00
return info
2018-03-28 21:55:58 +00:00
class PanelPredicateSystemKnownURLsExactURL( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_KNOWN_URLS
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
self._operator = ClientGUICommon.BetterChoice( self )
2019-11-14 03:56:30 +00:00
self._operator.addItem( 'has', True )
self._operator.addItem( 'does not have', False )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
self._exact_url = QW.QLineEdit( self )
self._exact_url.setFixedWidth( 250 )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:known url'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._operator, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'exact url:'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._exact_url, CC.FLAGS_VCENTER )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
self.setLayout( hbox )
2018-03-28 21:55:58 +00:00
def GetInfo( self ):
2019-07-24 21:39:02 +00:00
operator = self._operator.GetValue()
2018-03-28 21:55:58 +00:00
if operator:
operator_description = 'has this url: '
else:
operator_description = 'does not have this url: '
rule_type = 'regex'
2019-11-14 03:56:30 +00:00
exact_url = self._exact_url.text()
2018-03-28 21:55:58 +00:00
rule = re.escape( exact_url )
description = operator_description + exact_url
return ( operator, rule_type, rule, description )
class PanelPredicateSystemKnownURLsDomain( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_KNOWN_URLS
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
self._operator = ClientGUICommon.BetterChoice( self )
2019-11-14 03:56:30 +00:00
self._operator.addItem( 'has', True )
self._operator.addItem( 'does not have', False )
self._domain = QW.QLineEdit( self )
self._domain.setFixedWidth( 250 )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
self._domain.setPlaceholderText( 'example.com' )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:known url'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._operator, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'a url with domain:'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._domain, CC.FLAGS_VCENTER )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2018-03-28 21:55:58 +00:00
def GetInfo( self ):
2019-07-24 21:39:02 +00:00
operator = self._operator.GetValue()
2018-03-28 21:55:58 +00:00
if operator:
operator_description = 'has a url with domain: '
else:
operator_description = 'does not have a url with domain: '
rule_type = 'regex'
2019-11-14 03:56:30 +00:00
domain = self._domain.text()
2018-03-28 21:55:58 +00:00
2018-04-25 22:07:52 +00:00
rule = r'^https?\:\/\/(www[^\.]*\.)?' + re.escape( domain ) + r'\/.*'
2018-03-28 21:55:58 +00:00
description = operator_description + domain
return ( operator, rule_type, rule, description )
class PanelPredicateSystemKnownURLsRegex( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_KNOWN_URLS
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
self._operator = ClientGUICommon.BetterChoice( self )
2019-11-14 03:56:30 +00:00
self._operator.addItem( 'has', True )
self._operator.addItem( 'does not have', False )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
self._regex = QW.QLineEdit( self )
self._regex.setFixedWidth( 250 )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:known url'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._operator, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'a url that matches this regex:'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._regex, CC.FLAGS_VCENTER )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
self.setLayout( hbox )
2018-03-28 21:55:58 +00:00
def GetInfo( self ):
2019-07-24 21:39:02 +00:00
operator = self._operator.GetValue()
2018-03-28 21:55:58 +00:00
if operator:
operator_description = 'has a url matching regex: '
else:
operator_description = 'does not have a url matching regex: '
rule_type = 'regex'
2019-11-14 03:56:30 +00:00
regex = self._regex.text()
2018-03-28 21:55:58 +00:00
rule = regex
description = operator_description + regex
return ( operator, rule_type, rule, description )
2019-05-08 21:06:42 +00:00
class PanelPredicateSystemKnownURLsURLClass( PanelPredicateSystem ):
2018-03-28 21:55:58 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_KNOWN_URLS
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
self._operator = ClientGUICommon.BetterChoice( self )
2019-11-14 03:56:30 +00:00
self._operator.addItem( 'has', True )
self._operator.addItem( 'does not have', False )
2018-03-28 21:55:58 +00:00
2019-05-08 21:06:42 +00:00
self._url_classes = ClientGUICommon.BetterChoice( self )
2018-03-28 21:55:58 +00:00
2019-05-08 21:06:42 +00:00
for url_class in HG.client_controller.network_engine.domain_manager.GetURLClasses():
2018-03-28 21:55:58 +00:00
2019-05-08 21:06:42 +00:00
if url_class.ShouldAssociateWithFiles():
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
self._url_classes.addItem( url_class.GetName(), url_class )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:known url'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._operator, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'url matching this class:'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._url_classes, CC.FLAGS_VCENTER )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2018-03-28 21:55:58 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2018-03-28 21:55:58 +00:00
def GetInfo( self ):
2019-07-24 21:39:02 +00:00
operator = self._operator.GetValue()
2018-03-28 21:55:58 +00:00
if operator:
operator_description = 'has '
else:
operator_description = 'does not have '
2019-05-08 21:06:42 +00:00
rule_type = 'url_class'
2018-03-28 21:55:58 +00:00
2019-07-24 21:39:02 +00:00
url_class = self._url_classes.GetValue()
2018-03-28 21:55:58 +00:00
2019-05-08 21:06:42 +00:00
rule = url_class
2018-03-28 21:55:58 +00:00
2019-05-08 21:06:42 +00:00
description = operator_description + url_class.GetName() + ' url'
2018-03-28 21:55:58 +00:00
return ( operator, rule_type, rule, description )
2015-04-08 18:10:50 +00:00
class PanelPredicateSystemLimit( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_LIMIT
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._limit = QP.MakeQSpinBox( self, max=1000000, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
limit = system_predicates[ 'limit' ]
2019-11-14 03:56:30 +00:00
self._limit.setValue( limit )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:limit='), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._limit, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = self._limit.value()
2015-04-08 18:10:50 +00:00
return info
class PanelPredicateSystemMime( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_MIME
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2015-09-09 22:04:39 +00:00
self._mimes = ClientGUIOptionsPanels.OptionsPanelMimes( self, HC.SEARCHABLE_MIMES )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
2015-09-09 22:04:39 +00:00
mimes = system_predicates[ 'mime' ]
2015-04-08 18:10:50 +00:00
2016-01-13 22:08:19 +00:00
if isinstance( mimes, int ):
2015-09-09 22:04:39 +00:00
mimes = ( mimes, )
2017-02-01 21:11:17 +00:00
self._mimes.SetValue( mimes )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:filetype'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._mimes, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2017-02-01 21:11:17 +00:00
mimes = self._mimes.GetValue()
2015-04-22 22:57:25 +00:00
2015-09-09 22:04:39 +00:00
return mimes
2015-04-22 22:57:25 +00:00
2015-04-08 18:10:50 +00:00
class PanelPredicateSystemNumPixels( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_NUM_PIXELS
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._num_pixels = QP.MakeQSpinBox( self, max=1048576, width = 60 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._unit = QP.RadioBox( self, choices=['pixels','kilopixels','megapixels'] )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
( sign, num_pixels, unit ) = system_predicates[ 'num_pixels' ]
2015-04-22 22:57:25 +00:00
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._num_pixels.setValue( num_pixels )
2015-04-08 18:10:50 +00:00
2015-04-22 22:57:25 +00:00
self._unit.SetStringSelection( HydrusData.ConvertIntToPixels( unit ) )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:num_pixels'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._num_pixels, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._unit, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = (self._sign.GetStringSelection(), self._num_pixels.value(), HydrusData.ConvertPixelsToInt( self._unit.GetStringSelection() ))
2015-04-08 18:10:50 +00:00
return info
class PanelPredicateSystemNumTags( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_NUM_TAGS
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._num_tags = QP.MakeQSpinBox( self, max=2000, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
( sign, num_tags ) = system_predicates[ 'num_tags' ]
2015-04-22 22:57:25 +00:00
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._num_tags.setValue( num_tags )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:num_tags'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._num_tags, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = ( self._sign.GetStringSelection(), self._num_tags.value())
2015-04-08 18:10:50 +00:00
return info
class PanelPredicateSystemNumWords( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_NUM_WORDS
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._num_words = QP.MakeQSpinBox( self, max=1000000, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
( sign, num_words ) = system_predicates[ 'num_words' ]
2015-04-22 22:57:25 +00:00
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._num_words.setValue( num_words )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:num_words'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._num_words, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = ( self._sign.GetStringSelection(), self._num_words.value())
2015-04-08 18:10:50 +00:00
return info
2015-07-08 21:45:38 +00:00
class PanelPredicateSystemRating( PanelPredicateSystem ):
2015-04-08 18:10:50 +00:00
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_RATING
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2015-07-08 21:45:38 +00:00
#
2017-06-28 20:23:21 +00:00
local_like_services = HG.client_controller.services_manager.GetServices( ( HC.LOCAL_RATING_LIKE, ), randomised = False )
2015-04-08 18:10:50 +00:00
2015-07-08 21:45:38 +00:00
self._like_checkboxes_to_info = {}
2015-04-08 18:10:50 +00:00
2015-07-08 21:45:38 +00:00
self._like_rating_ctrls = []
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
gridbox = QP.GridLayout( cols = 5 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
gridbox.setColumnStretch( 0, 1 )
2015-04-08 18:10:50 +00:00
2015-07-01 22:02:07 +00:00
for service in local_like_services:
name = service.GetName()
service_key = service.GetServiceKey()
2019-11-14 03:56:30 +00:00
rated_checkbox = QW.QCheckBox( 'rated', self )
not_rated_checkbox = QW.QCheckBox( 'not rated', self )
2015-07-01 22:02:07 +00:00
rating_ctrl = ClientGUICommon.RatingLikeDialog( self, service_key )
2015-07-08 21:45:38 +00:00
self._like_checkboxes_to_info[ rated_checkbox ] = ( service_key, ClientRatings.SET )
self._like_checkboxes_to_info[ not_rated_checkbox ] = ( service_key, ClientRatings.NULL )
self._like_rating_ctrls.append( rating_ctrl )
2015-07-01 22:02:07 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( gridbox, ClientGUICommon.BetterStaticText(self,name), CC.FLAGS_VCENTER )
QP.AddToLayout( gridbox, rated_checkbox, CC.FLAGS_VCENTER )
QP.AddToLayout( gridbox, not_rated_checkbox, CC.FLAGS_VCENTER )
QP.AddToLayout( gridbox, (20,20), CC.FLAGS_EXPAND_SIZER_BOTH_WAYS )
QP.AddToLayout( gridbox, rating_ctrl, CC.FLAGS_VCENTER )
2015-07-01 22:02:07 +00:00
2015-04-08 18:10:50 +00:00
2015-07-08 21:45:38 +00:00
#
2017-06-28 20:23:21 +00:00
local_numerical_services = HG.client_controller.services_manager.GetServices( ( HC.LOCAL_RATING_NUMERICAL, ), randomised = False )
2015-07-08 21:45:38 +00:00
self._numerical_checkboxes_to_info = {}
self._numerical_rating_ctrls_to_info = {}
for service in local_numerical_services:
name = service.GetName()
service_key = service.GetServiceKey()
2019-11-14 03:56:30 +00:00
rated_checkbox = QW.QCheckBox( 'rated', self )
not_rated_checkbox = QW.QCheckBox( 'not rated', self )
choice = QP.RadioBox( self, choices=['>','<','=','\u2248'] )
2015-07-08 21:45:38 +00:00
rating_ctrl = ClientGUICommon.RatingNumericalDialog( self, service_key )
2019-11-14 03:56:30 +00:00
choice.Select( 2 )
2015-07-08 21:45:38 +00:00
self._numerical_checkboxes_to_info[ rated_checkbox ] = ( service_key, ClientRatings.SET )
self._numerical_checkboxes_to_info[ not_rated_checkbox ] = ( service_key, ClientRatings.NULL )
self._numerical_rating_ctrls_to_info[ rating_ctrl ] = choice
2019-11-14 03:56:30 +00:00
QP.AddToLayout( gridbox, ClientGUICommon.BetterStaticText(self,name), CC.FLAGS_VCENTER )
QP.AddToLayout( gridbox, rated_checkbox, CC.FLAGS_VCENTER )
QP.AddToLayout( gridbox, not_rated_checkbox, CC.FLAGS_VCENTER )
QP.AddToLayout( gridbox, choice, CC.FLAGS_VCENTER )
QP.AddToLayout( gridbox, rating_ctrl, CC.FLAGS_VCENTER )
2015-07-08 21:45:38 +00:00
#
2019-11-14 03:56:30 +00:00
vbox = QP.VBoxLayout()
2015-07-08 21:45:38 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( vbox, gridbox, CC.FLAGS_EXPAND_SIZER_BOTH_WAYS )
2015-07-08 21:45:38 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( vbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2015-07-01 22:02:07 +00:00
infos = []
2015-04-08 18:10:50 +00:00
2015-07-08 21:45:38 +00:00
#
2019-01-09 22:59:03 +00:00
for ( checkbox, ( service_key, rating_state ) ) in list(self._like_checkboxes_to_info.items()):
2015-07-01 22:02:07 +00:00
2019-11-14 03:56:30 +00:00
if checkbox.isChecked():
2015-07-01 22:02:07 +00:00
if rating_state == ClientRatings.SET:
value = 'rated'
elif rating_state == ClientRatings.NULL:
value = 'not rated'
infos.append( ( '=', value, service_key ) )
2015-04-08 18:10:50 +00:00
2015-07-08 21:45:38 +00:00
for ctrl in self._like_rating_ctrls:
2015-07-01 22:02:07 +00:00
rating_state = ctrl.GetRatingState()
if rating_state in ( ClientRatings.LIKE, ClientRatings.DISLIKE ):
if rating_state == ClientRatings.LIKE:
2017-04-05 21:16:40 +00:00
value = 1
2015-07-01 22:02:07 +00:00
elif rating_state == ClientRatings.DISLIKE:
2017-04-05 21:16:40 +00:00
value = 0
2015-07-01 22:02:07 +00:00
service_key = ctrl.GetServiceKey()
infos.append( ( '=', value, service_key ) )
2015-04-08 18:10:50 +00:00
2015-07-08 21:45:38 +00:00
#
2015-04-08 18:10:50 +00:00
2019-01-09 22:59:03 +00:00
for ( checkbox, ( service_key, rating_state ) ) in list(self._numerical_checkboxes_to_info.items()):
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
if checkbox.isChecked():
2015-07-01 22:02:07 +00:00
if rating_state == ClientRatings.SET:
value = 'rated'
elif rating_state == ClientRatings.NULL:
value = 'not rated'
infos.append( ( '=', value, service_key ) )
2015-04-08 18:10:50 +00:00
2015-07-01 22:02:07 +00:00
2019-01-09 22:59:03 +00:00
for ( ctrl, choice ) in list(self._numerical_rating_ctrls_to_info.items()):
2015-04-08 18:10:50 +00:00
2015-07-01 22:02:07 +00:00
rating_state = ctrl.GetRatingState()
2015-04-08 18:10:50 +00:00
2015-07-01 22:02:07 +00:00
if rating_state == ClientRatings.SET:
operator = choice.GetStringSelection()
value = ctrl.GetRating()
service_key = ctrl.GetServiceKey()
infos.append( ( operator, value, service_key ) )
2015-04-08 18:10:50 +00:00
2015-07-08 21:45:38 +00:00
#
2015-07-01 22:02:07 +00:00
return infos
2015-06-03 21:05:13 +00:00
2015-07-01 22:02:07 +00:00
def GetPredicates( self ):
2015-04-08 18:10:50 +00:00
2015-07-01 22:02:07 +00:00
infos = self.GetInfo()
2015-12-09 23:16:41 +00:00
predicates = [ ClientSearch.Predicate( self.PREDICATE_TYPE, info ) for info in infos ]
2015-07-01 22:02:07 +00:00
return predicates
2015-04-08 18:10:50 +00:00
class PanelPredicateSystemRatio( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_RATIO
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['=','wider than','taller than','\u2248'] )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._width = QP.MakeQSpinBox( self, max=50000, width = 60 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._height = QP.MakeQSpinBox( self, max=50000, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
( sign, width, height ) = system_predicates[ 'ratio' ]
2015-04-22 22:57:25 +00:00
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._width.setValue( width )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._height.setValue( height )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:ratio'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._width, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,':'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._height, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = (self._sign.GetStringSelection(), self._width.value(), self._height.value())
2015-04-08 18:10:50 +00:00
return info
class PanelPredicateSystemSimilarTo( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_SIMILAR_TO
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._hashes = QW.QPlainTextEdit( self )
2019-08-07 22:59:53 +00:00
init_size = ClientGUIFunctions.ConvertTextToPixels( self._hashes, ( 66, 10 ) )
2019-11-14 03:56:30 +00:00
self._hashes.setMinimumSize( QP.TupleToQSize( init_size ) )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._max_hamming = QP.MakeQSpinBox( self, max=256, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
2019-11-14 03:56:30 +00:00
self._hashes.setPlaceholderText( 'enter hash (paste newline-separated for multiple hashes)' )
2015-04-08 18:10:50 +00:00
hamming_distance = system_predicates[ 'hamming_distance' ]
2019-11-14 03:56:30 +00:00
self._max_hamming.setValue( hamming_distance )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:similar_to'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._hashes, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, QW.QLabel( '\u2248', self ), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._max_hamming, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
hex_hashes_raw = self._hashes.toPlainText()
2015-04-08 18:10:50 +00:00
2019-08-07 22:59:53 +00:00
hex_hashes = HydrusText.DeserialiseNewlinedTexts( hex_hashes_raw )
2015-04-08 18:10:50 +00:00
2019-08-07 22:59:53 +00:00
hex_hashes = [ HydrusText.HexFilter( hex_hash ) for hex_hash in hex_hashes ]
hex_hashes = HydrusData.DedupeList( hex_hashes )
hashes = tuple( [ bytes.fromhex( hex_hash ) for hex_hash in hex_hashes ] )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
info = ( hashes, self._max_hamming.value())
2015-04-08 18:10:50 +00:00
return info
class PanelPredicateSystemSize( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_SIZE
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2015-04-08 18:10:50 +00:00
2018-03-14 21:01:02 +00:00
self._bytes = ClientGUIControls.BytesControl( self )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
( sign, size, unit ) = system_predicates[ 'size' ]
2015-04-22 22:57:25 +00:00
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2018-03-14 21:01:02 +00:00
self._bytes.SetSeparatedValue( size, unit )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:filesize'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._bytes, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2018-03-14 21:01:02 +00:00
( size, unit ) = self._bytes.GetSeparatedValue()
info = ( self._sign.GetStringSelection(), size, unit )
2015-04-08 18:10:50 +00:00
return info
2017-06-21 21:15:59 +00:00
class PanelPredicateSystemTagAsNumber( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_TAG_AS_NUMBER
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._namespace = QW.QLineEdit( self )
2017-06-21 21:15:59 +00:00
2019-01-09 22:59:03 +00:00
choices = [ '<', '\u2248', '>' ]
2017-06-21 21:15:59 +00:00
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices = choices )
2017-06-21 21:15:59 +00:00
2019-11-14 03:56:30 +00:00
self._num = QP.MakeQSpinBox( self, min=-99999999, max=99999999 )
2017-06-21 21:15:59 +00:00
#
2019-11-14 03:56:30 +00:00
self._namespace.setText( 'page' )
2017-06-21 21:15:59 +00:00
self._sign.SetStringSelection( '>' )
2019-11-14 03:56:30 +00:00
self._num.setValue( 0 )
2017-06-21 21:15:59 +00:00
#
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2017-06-21 21:15:59 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:tag as number'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._namespace, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._num, CC.FLAGS_VCENTER )
2017-06-21 21:15:59 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2017-06-21 21:15:59 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2017-06-21 21:15:59 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = ( self._namespace.text(), self._sign.GetStringSelection(), self._num.value())
2017-06-21 21:15:59 +00:00
return info
2015-04-08 18:10:50 +00:00
class PanelPredicateSystemWidth( PanelPredicateSystem ):
2015-06-24 22:10:14 +00:00
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_WIDTH
2015-04-08 18:10:50 +00:00
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
2019-11-14 03:56:30 +00:00
self._sign = QP.RadioBox( self, choices=['<','\u2248','=','>'] )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._width = QP.MakeQSpinBox( self, max=200000, width = 60 )
2015-04-08 18:10:50 +00:00
system_predicates = HC.options[ 'file_system_predicates' ]
( sign, width ) = system_predicates[ 'width' ]
2015-04-22 22:57:25 +00:00
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self._width.setValue( width )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox = QP.HBoxLayout()
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
QP.AddToLayout( hbox, ClientGUICommon.BetterStaticText(self,'system:width'), CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._sign, CC.FLAGS_VCENTER )
QP.AddToLayout( hbox, self._width, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
hbox.addStretch( 1 )
2015-04-08 18:10:50 +00:00
2019-11-14 03:56:30 +00:00
self.setLayout( hbox )
2015-04-08 18:10:50 +00:00
def GetInfo( self ):
2019-11-14 03:56:30 +00:00
info = ( self._sign.GetStringSelection(), self._width.value())
2015-04-08 18:10:50 +00:00
return info
2016-12-21 22:30:54 +00:00