hydrus/include/ClientGUIPredicates.py

1136 lines
36 KiB
Python
Raw Normal View History

2015-04-08 18:10:50 +00:00
import ClientConstants as CC
2015-10-21 21:53:10 +00:00
import ClientData
2015-07-01 22:02:07 +00:00
import ClientGUICommon
2018-03-14 21:01:02 +00:00
import ClientGUIControls
2015-09-09 22:04:39 +00:00
import ClientGUIOptionsPanels
2015-07-01 22:02:07 +00:00
import ClientRatings
2015-12-09 23:16:41 +00:00
import ClientSearch
2018-01-31 22:58:15 +00:00
import datetime
2015-04-08 18:10:50 +00:00
import HydrusConstants as HC
import HydrusData
2017-05-10 21:33:58 +00:00
import HydrusGlobals as HG
2018-03-28 21:55:58 +00:00
import re
2015-04-08 18:10:50 +00:00
import string
import wx
2018-01-31 22:58:15 +00:00
import wx.adv
2015-04-08 18:10:50 +00:00
class PanelPredicateSystem( wx.Panel ):
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
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 )
self._sign = wx.RadioBox( self, choices = [ '<', u'\u2248', '=', '>' ] )
self._date = wx.adv.CalendarCtrl( self )
wx_dt = wx.DateTime.Today()
wx_dt.Subtract( wx.TimeSpan( 24 * 7 ) )
self._date.SetDate( wx_dt )
self._sign.SetStringSelection( '>' )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-02-07 23:40:33 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:time imported' ), CC.FLAGS_VCENTER )
2018-01-31 22:58:15 +00:00
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._date, CC.FLAGS_VCENTER )
self.SetSizer( hbox )
def GetInfo( self ):
wx_dt = self._date.GetDate()
year = wx_dt.year
month = wx_dt.month + 1 # month zero indexed, wew
day = wx_dt.day
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 )
2017-01-04 22:48:23 +00:00
self._sign = wx.RadioBox( self, choices = [ '<', u'\u2248', '>' ] )
2015-04-08 18:10:50 +00:00
self._years = wx.SpinCtrl( self, max = 30, size = ( 60, -1 ) )
self._months = wx.SpinCtrl( self, max = 60, size = ( 60, -1 ) )
self._days = wx.SpinCtrl( self, max = 90, size = ( 60, -1 ) )
self._hours = wx.SpinCtrl( self, max = 24, size = ( 60, -1 ) )
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
self._years.SetValue( years )
self._months.SetValue( months )
self._days.SetValue( days )
2015-04-22 22:57:25 +00:00
self._hours.SetValue( hours )
2015-04-08 18:10:50 +00:00
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-02-07 23:40:33 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:time imported' ), CC.FLAGS_VCENTER )
2018-01-03 22:37:30 +00:00
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._years, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'years' ), CC.FLAGS_VCENTER )
hbox.Add( self._months, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'months' ), CC.FLAGS_VCENTER )
hbox.Add( self._days, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'days' ), CC.FLAGS_VCENTER )
hbox.Add( self._hours, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'hours' ), CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._days.SetFocus )
def GetInfo( self ):
2018-01-31 22:58:15 +00:00
info = ( self._sign.GetStringSelection(), 'delta', ( self._years.GetValue(), self._months.GetValue(), self._days.GetValue(), self._hours.GetValue() ) )
2015-04-08 18:10:50 +00:00
return info
2017-05-24 20:28:24 +00:00
class PanelPredicateSystemDuplicateRelationships( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_DUPLICATE_RELATIONSHIPS
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
choices = [ '<', u'\u2248', '=', '>' ]
self._sign = wx.RadioBox( self, choices = choices, style = wx.RA_SPECIFY_COLS )
self._num = wx.SpinCtrl( self, min = 0, max = 65535 )
2017-06-07 22:05:15 +00:00
choices = [ ( HC.duplicate_type_string_lookup[ status ], status ) for status in ( HC.DUPLICATE_BETTER_OR_WORSE, HC.DUPLICATE_BETTER, HC.DUPLICATE_WORSE, HC.DUPLICATE_SAME_QUALITY, HC.DUPLICATE_ALTERNATE, HC.DUPLICATE_NOT_DUPLICATE, HC.DUPLICATE_UNKNOWN ) ]
2017-05-24 20:28:24 +00:00
self._dupe_type = ClientGUICommon.BetterRadioBox( self, choices = choices, style = wx.RA_SPECIFY_ROWS )
#
self._sign.SetStringSelection( '>' )
self._num.SetValue( 0 )
#
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:num duplicate relationships' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._num, CC.FLAGS_VCENTER )
hbox.Add( self._dupe_type, CC.FLAGS_VCENTER )
2017-05-24 20:28:24 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._num.SetFocus )
def GetInfo( self ):
info = ( self._sign.GetStringSelection(), self._num.GetValue(), self._dupe_type.GetChoice() )
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 )
2017-01-04 22:48:23 +00:00
choices = [ '<', u'\u2248', '=', '>' ]
self._sign = wx.RadioBox( self, choices = choices, style = wx.RA_SPECIFY_COLS )
2015-04-08 18:10:50 +00:00
self._duration_s = wx.SpinCtrl( self, max = 3599, size = ( 60, -1 ) )
self._duration_ms = wx.SpinCtrl( self, max = 999, size = ( 60, -1 ) )
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
2015-04-22 22:57:25 +00:00
s = ms / 1000
ms = ms % 1000
self._sign.SetStringSelection( sign )
2015-04-08 18:10:50 +00:00
self._duration_s.SetValue( s )
self._duration_ms.SetValue( ms )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:duration' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._duration_s, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 's' ), CC.FLAGS_VCENTER )
hbox.Add( self._duration_ms, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'ms' ), CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._duration_s.SetFocus )
def GetInfo( self ):
info = ( self._sign.GetStringSelection(), self._duration_s.GetValue() * 1000 + self._duration_ms.GetValue() )
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 )
2017-01-04 22:48:23 +00:00
self._sign = ClientGUICommon.BetterRadioBox( self, choices = [ ( 'is', True ), ( 'is not', False ) ], style = wx.RA_SPECIFY_ROWS )
2015-04-08 18:10:50 +00:00
2017-03-02 02:14:56 +00:00
self._current_pending = ClientGUICommon.BetterRadioBox( self, choices = [ ( 'currently in', HC.CONTENT_STATUS_CURRENT ), ( 'pending to', HC.CONTENT_STATUS_PENDING ) ], style = wx.RA_SPECIFY_ROWS )
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 ]
self._file_service_key = ClientGUICommon.BetterRadioBox( self, choices = choices, style = wx.RA_SPECIFY_ROWS )
2015-04-08 18:10:50 +00:00
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:file service:' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._current_pending, CC.FLAGS_VCENTER )
hbox.Add( self._file_service_key, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._sign.SetFocus )
def GetInfo( self ):
2017-01-04 22:48:23 +00:00
info = ( self._sign.GetChoice(), self._current_pending.GetChoice(), self._file_service_key.GetChoice() )
2015-04-08 18:10:50 +00:00
return info
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 )
2018-01-03 22:37:30 +00:00
self.SetToolTip( 'As this can only ever return one result, it overrules the active file domain and any other active predicate.' )
2017-01-04 22:48:23 +00:00
self._hash = wx.TextCtrl( self, size = ( 200, -1 ) )
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
2017-01-04 22:48:23 +00:00
self._hash_type = wx.RadioBox( self, choices = choices, style = wx.RA_SPECIFY_COLS )
2015-04-08 18:10:50 +00:00
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:hash=' ), CC.FLAGS_VCENTER )
hbox.Add( self._hash, CC.FLAGS_VCENTER )
hbox.Add( self._hash_type, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._hash.SetFocus )
def GetInfo( self ):
2017-03-08 23:23:12 +00:00
def hex_filter( c ):
return c in string.hexdigits
2015-04-08 18:10:50 +00:00
hash = filter( hex_filter, self._hash.GetValue().lower() )
if len( hash ) == 0: hash = '00'
elif len( hash ) % 2 == 1: hash += '0' # since we are later decoding to byte
2015-12-30 23:44:09 +00:00
hash = hash.decode( 'hex' )
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
return ( hash, 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 )
2017-01-04 22:48:23 +00:00
self._sign = wx.RadioBox( self, choices = [ '<', u'\u2248', '=', '>' ] )
2015-04-08 18:10:50 +00:00
self._height = wx.SpinCtrl( self, max = 200000, size = ( 60, -1 ) )
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
self._height.SetValue( height )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:height' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._height, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._height.SetFocus )
def GetInfo( self ):
info = ( self._sign.GetStringSelection(), self._height.GetValue() )
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 )
self._operator.Append( 'has', True )
self._operator.Append( 'does not have', False )
self._exact_url = wx.TextCtrl( self, size = ( 250, -1 ) )
hbox = wx.BoxSizer( wx.HORIZONTAL )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:known url' ), CC.FLAGS_VCENTER )
hbox.Add( self._operator, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'exact url:' ), CC.FLAGS_VCENTER )
hbox.Add( self._exact_url, CC.FLAGS_VCENTER )
self.SetSizer( hbox )
def GetInfo( self ):
operator = self._operator.GetChoice()
if operator:
operator_description = 'has this url: '
else:
operator_description = 'does not have this url: '
rule_type = 'regex'
exact_url = self._exact_url.GetValue()
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 )
self._operator.Append( 'has', True )
self._operator.Append( 'does not have', False )
self._domain = wx.TextCtrl( self, size = ( 250, -1 ) )
self._domain.SetValue( 'example.com' )
hbox = wx.BoxSizer( wx.HORIZONTAL )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:known url' ), CC.FLAGS_VCENTER )
hbox.Add( self._operator, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'a url with domain:' ), CC.FLAGS_VCENTER )
hbox.Add( self._domain, CC.FLAGS_VCENTER )
self.SetSizer( hbox )
def GetInfo( self ):
operator = self._operator.GetChoice()
if operator:
operator_description = 'has a url with domain: '
else:
operator_description = 'does not have a url with domain: '
rule_type = 'regex'
domain = self._domain.GetValue()
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 )
self._operator.Append( 'has', True )
self._operator.Append( 'does not have', False )
self._regex = wx.TextCtrl( self, size = ( 250, -1 ) )
hbox = wx.BoxSizer( wx.HORIZONTAL )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:known url' ), CC.FLAGS_VCENTER )
hbox.Add( self._operator, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'a url that matches this regex:' ), CC.FLAGS_VCENTER )
hbox.Add( self._regex, CC.FLAGS_VCENTER )
self.SetSizer( hbox )
def GetInfo( self ):
operator = self._operator.GetChoice()
if operator:
operator_description = 'has a url matching regex: '
else:
operator_description = 'does not have a url matching regex: '
rule_type = 'regex'
regex = self._regex.GetValue()
rule = regex
description = operator_description + regex
return ( operator, rule_type, rule, description )
class PanelPredicateSystemKnownURLsURLMatch( PanelPredicateSystem ):
PREDICATE_TYPE = HC.PREDICATE_TYPE_SYSTEM_KNOWN_URLS
def __init__( self, parent ):
PanelPredicateSystem.__init__( self, parent )
self._operator = ClientGUICommon.BetterChoice( self )
self._operator.Append( 'has', True )
self._operator.Append( 'does not have', False )
self._url_matches = ClientGUICommon.BetterChoice( self )
for url_match in HG.client_controller.network_engine.domain_manager.GetURLMatches():
2018-06-06 21:27:02 +00:00
if url_match.ShouldAssociateWithFiles():
2018-03-28 21:55:58 +00:00
self._url_matches.Append( url_match.GetName(), url_match )
hbox = wx.BoxSizer( wx.HORIZONTAL )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:known url' ), CC.FLAGS_VCENTER )
hbox.Add( self._operator, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, 'url matching this class:' ), CC.FLAGS_VCENTER )
hbox.Add( self._url_matches, CC.FLAGS_VCENTER )
self.SetSizer( hbox )
def GetInfo( self ):
operator = self._operator.GetChoice()
if operator:
operator_description = 'has '
else:
operator_description = 'does not have '
rule_type = 'url_match'
url_match = self._url_matches.GetChoice()
rule = url_match
description = operator_description + url_match.GetName() + ' url'
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 )
self._limit = wx.SpinCtrl( self, max = 1000000, size = ( 60, -1 ) )
system_predicates = HC.options[ 'file_system_predicates' ]
limit = system_predicates[ 'limit' ]
self._limit.SetValue( limit )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:limit=' ), CC.FLAGS_VCENTER )
hbox.Add( self._limit, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._limit.SetFocus )
def GetInfo( self ):
info = self._limit.GetValue()
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
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:mime' ), CC.FLAGS_VCENTER )
hbox.Add( self._mimes, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
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 )
2017-01-04 22:48:23 +00:00
self._sign = wx.RadioBox( self, choices = [ '<', u'\u2248', '=', '>' ] )
2015-04-08 18:10:50 +00:00
self._num_pixels = wx.SpinCtrl( self, max = 1048576, size = ( 60, -1 ) )
2017-01-04 22:48:23 +00:00
self._unit = wx.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
self._num_pixels.SetValue( num_pixels )
2015-04-22 22:57:25 +00:00
self._unit.SetStringSelection( HydrusData.ConvertIntToPixels( unit ) )
2015-04-08 18:10:50 +00:00
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:num_pixels' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._num_pixels, CC.FLAGS_VCENTER )
hbox.Add( self._unit, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._num_pixels.SetFocus )
def GetInfo( self ):
2015-04-22 22:57:25 +00:00
info = ( self._sign.GetStringSelection(), self._num_pixels.GetValue(), 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 )
2017-01-04 22:48:23 +00:00
self._sign = wx.RadioBox( self, choices = [ '<', u'\u2248', '=', '>' ] )
2015-04-08 18:10:50 +00:00
self._num_tags = wx.SpinCtrl( self, max = 2000, size = ( 60, -1 ) )
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
self._num_tags.SetValue( num_tags )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:num_tags' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._num_tags, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._num_tags.SetFocus )
def GetInfo( self ):
info = ( self._sign.GetStringSelection(), self._num_tags.GetValue() )
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 )
2017-01-04 22:48:23 +00:00
self._sign = wx.RadioBox( self, choices = [ '<', u'\u2248', '=', '>' ] )
2015-04-08 18:10:50 +00:00
self._num_words = wx.SpinCtrl( self, max = 1000000, size = ( 60, -1 ) )
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
self._num_words.SetValue( num_words )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:num_words' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._num_words, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._num_words.SetFocus )
def GetInfo( self ):
info = ( self._sign.GetStringSelection(), self._num_words.GetValue() )
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
2018-01-03 22:37:30 +00:00
gridbox = wx.FlexGridSizer( 5 )
2015-04-08 18:10:50 +00:00
2017-01-04 22:48:23 +00:00
gridbox.AddGrowableCol( 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()
rated_checkbox = wx.CheckBox( self, label = 'rated' )
not_rated_checkbox = wx.CheckBox( self, label = 'not rated' )
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
2018-01-03 22:37:30 +00:00
gridbox.Add( ClientGUICommon.BetterStaticText( self, name ), CC.FLAGS_VCENTER )
gridbox.Add( rated_checkbox, CC.FLAGS_VCENTER )
gridbox.Add( not_rated_checkbox, CC.FLAGS_VCENTER )
gridbox.Add( ( 20, 20 ), CC.FLAGS_EXPAND_SIZER_BOTH_WAYS )
gridbox.Add( 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()
rated_checkbox = wx.CheckBox( self, label = 'rated' )
not_rated_checkbox = wx.CheckBox( self, label = 'not rated' )
2017-01-04 22:48:23 +00:00
choice = wx.RadioBox( self, choices = [ '>', '<', '=', u'\u2248' ] )
2015-07-08 21:45:38 +00:00
rating_ctrl = ClientGUICommon.RatingNumericalDialog( self, service_key )
2017-01-04 22:48:23 +00:00
choice.SetSelection( 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
2018-01-03 22:37:30 +00:00
gridbox.Add( ClientGUICommon.BetterStaticText( self, name ), CC.FLAGS_VCENTER )
gridbox.Add( rated_checkbox, CC.FLAGS_VCENTER )
gridbox.Add( not_rated_checkbox, CC.FLAGS_VCENTER )
gridbox.Add( choice, CC.FLAGS_VCENTER )
gridbox.Add( rating_ctrl, CC.FLAGS_VCENTER )
2015-07-08 21:45:38 +00:00
#
vbox = wx.BoxSizer( wx.VERTICAL )
2018-01-03 22:37:30 +00:00
vbox.Add( gridbox, CC.FLAGS_EXPAND_SIZER_BOTH_WAYS )
2015-07-08 21:45:38 +00:00
self.SetSizer( 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
#
for ( checkbox, ( service_key, rating_state ) ) in self._like_checkboxes_to_info.items():
2015-07-01 22:02:07 +00:00
if checkbox.GetValue() == True:
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
2015-07-08 21:45:38 +00:00
for ( checkbox, ( service_key, rating_state ) ) in self._numerical_checkboxes_to_info.items():
2015-04-08 18:10:50 +00:00
2015-07-01 22:02:07 +00:00
if checkbox.GetValue() == True:
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
2015-07-08 21:45:38 +00:00
for ( ctrl, choice ) in 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 )
2017-01-04 22:48:23 +00:00
self._sign = wx.RadioBox( self, choices = [ '=', 'wider than', 'taller than', u'\u2248' ] )
2015-04-08 18:10:50 +00:00
self._width = wx.SpinCtrl( self, max = 50000, size = ( 60, -1 ) )
self._height = wx.SpinCtrl( self, max = 50000, size = ( 60, -1 ) )
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
self._width.SetValue( width )
self._height.SetValue( height )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:ratio' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._width, CC.FLAGS_VCENTER )
hbox.Add( ClientGUICommon.BetterStaticText( self, ':' ), CC.FLAGS_VCENTER )
hbox.Add( self._height, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._sign.SetFocus )
def GetInfo( self ):
info = ( self._sign.GetStringSelection(), self._width.GetValue(), self._height.GetValue() )
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 )
self._hash = wx.TextCtrl( self )
self._max_hamming = wx.SpinCtrl( self, max = 256, size = ( 60, -1 ) )
system_predicates = HC.options[ 'file_system_predicates' ]
self._hash.SetValue( 'enter hash' )
hamming_distance = system_predicates[ 'hamming_distance' ]
self._max_hamming.SetValue( hamming_distance )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:similar_to' ), CC.FLAGS_VCENTER )
hbox.Add( self._hash, CC.FLAGS_VCENTER )
hbox.Add( wx.StaticText( self, label=u'\u2248' ), CC.FLAGS_VCENTER )
hbox.Add( self._max_hamming, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._hash.SetFocus )
def GetInfo( self ):
2017-03-08 23:23:12 +00:00
def hex_filter( c ):
return c in string.hexdigits
2015-04-08 18:10:50 +00:00
hash = filter( hex_filter, self._hash.GetValue().lower() )
if len( hash ) == 0: hash = '00'
elif len( hash ) % 2 == 1: hash += '0' # since we are later decoding to byte
info = ( hash.decode( 'hex' ), self._max_hamming.GetValue() )
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 )
2017-01-04 22:48:23 +00:00
self._sign = wx.RadioBox( self, choices = [ '<', u'\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
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:size' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
2018-03-14 21:01:02 +00:00
hbox.Add( self._bytes, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
2018-03-14 21:01:02 +00:00
wx.CallAfter( self._bytes.SetFocus )
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 )
self._namespace = wx.TextCtrl( self )
choices = [ '<', u'\u2248', '>' ]
self._sign = wx.RadioBox( self, choices = choices, style = wx.RA_SPECIFY_COLS )
self._num = wx.SpinCtrl( self, min = -99999999, max = 99999999 )
#
self._namespace.SetValue( 'page' )
self._sign.SetStringSelection( '>' )
self._num.SetValue( 0 )
#
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:tag as number' ), CC.FLAGS_VCENTER )
hbox.Add( self._namespace, CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._num, CC.FLAGS_VCENTER )
2017-06-21 21:15:59 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._num.SetFocus )
def GetInfo( self ):
info = ( self._namespace.GetValue(), self._sign.GetStringSelection(), self._num.GetValue() )
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 )
2017-01-04 22:48:23 +00:00
self._sign = wx.RadioBox( self, choices = [ '<', u'\u2248', '=', '>' ] )
2015-04-08 18:10:50 +00:00
self._width = wx.SpinCtrl( self, max = 200000, size = ( 60, -1 ) )
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
self._width.SetValue( width )
hbox = wx.BoxSizer( wx.HORIZONTAL )
2018-01-03 22:37:30 +00:00
hbox.Add( ClientGUICommon.BetterStaticText( self, 'system:width' ), CC.FLAGS_VCENTER )
hbox.Add( self._sign, CC.FLAGS_VCENTER )
hbox.Add( self._width, CC.FLAGS_VCENTER )
2015-04-08 18:10:50 +00:00
self.SetSizer( hbox )
wx.CallAfter( self._width.SetFocus )
def GetInfo( self ):
info = ( self._sign.GetStringSelection(), self._width.GetValue() )
return info
2016-12-21 22:30:54 +00:00