def __init__(self, parent): PanelPredicateSystem.__init__(self, parent) self._sign = wx.Choice(self, choices=['<', u'\u2248', '=', '>']) self._num_pixels = wx.SpinCtrl(self, max=1048576, size=(60, -1)) self._unit = wx.Choice(self, choices=['pixels', 'kilopixels', 'megapixels']) system_predicates = HC.options['file_system_predicates'] (sign, num_pixels, unit) = system_predicates['num_pixels'] self._sign.SetStringSelection(sign) self._num_pixels.SetValue(num_pixels) self._unit.SetStringSelection(HydrusData.ConvertIntToPixels(unit)) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.AddF(wx.StaticText(self, label='system:num_pixels'), CC.FLAGS_MIXED) hbox.AddF(self._sign, CC.FLAGS_MIXED) hbox.AddF(self._num_pixels, CC.FLAGS_MIXED) hbox.AddF(self._unit, CC.FLAGS_MIXED) self.SetSizer(hbox) wx.CallAfter(self._num_pixels.SetFocus)
def GetUnicode(self, with_count=True, sibling_service_key=None, render_for_user=False): count_text = u'' if with_count: if self._min_current_count > 0: number_text = HydrusData.ConvertIntToPrettyString( self._min_current_count) if self._max_current_count is not None: number_text += u'-' + HydrusData.ConvertIntToPrettyString( self._max_current_count) count_text += u' (' + number_text + u')' if self._min_pending_count > 0: number_text = HydrusData.ConvertIntToPrettyString( self._min_pending_count) if self._max_pending_count is not None: number_text += u'-' + HydrusData.ConvertIntToPrettyString( self._max_pending_count) count_text += u' (+' + number_text + u')' if self._predicate_type in HC.SYSTEM_PREDICATES: if self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_EVERYTHING: base = u'everything' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_INBOX: base = u'inbox' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_ARCHIVE: base = u'archive' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_UNTAGGED: base = u'untagged' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_LOCAL: base = u'local' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_NOT_LOCAL: base = u'not local' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_DIMENSIONS: base = u'dimensions' elif self._predicate_type in (HC.PREDICATE_TYPE_SYSTEM_NUM_TAGS, HC.PREDICATE_TYPE_SYSTEM_WIDTH, HC.PREDICATE_TYPE_SYSTEM_HEIGHT, HC.PREDICATE_TYPE_SYSTEM_NUM_WORDS): if self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_NUM_TAGS: base = u'number of tags' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_WIDTH: base = u'width' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_HEIGHT: base = u'height' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_NUM_WORDS: base = u'number of words' if self._value is not None: (operator, value) = self._value base += u' ' + operator + u' ' + HydrusData.ConvertIntToPrettyString( value) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_DURATION: base = u'duration' if self._value is not None: (operator, value) = self._value base += u' ' + operator + u' ' + HydrusData.ConvertMillisecondsToPrettyTime( value) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_RATIO: base = u'ratio' if self._value is not None: (operator, ratio_width, ratio_height) = self._value base += u' ' + operator + u' ' + str( ratio_width) + u':' + str(ratio_height) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_SIZE: base = u'size' if self._value is not None: (operator, size, unit) = self._value base += u' ' + operator + u' ' + str( size) + HydrusData.ConvertIntToUnit(unit) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_LIMIT: base = u'limit' if self._value is not None: value = self._value base += u' is ' + HydrusData.ConvertIntToPrettyString( value) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_AGE: base = u'age' if self._value is not None: (operator, years, months, days, hours) = self._value base += u' ' + operator + u' ' + str(years) + u'y' + str( months) + u'm' + str(days) + u'd' + str(hours) + u'h' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_NUM_PIXELS: base = u'num_pixels' if self._value is not None: (operator, num_pixels, unit) = self._value base += u' ' + operator + u' ' + str( num_pixels) + ' ' + HydrusData.ConvertIntToPixels(unit) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_HASH: base = u'hash' if self._value is not None: (hash, hash_type) = self._value base = hash_type + ' hash is ' + hash.encode('hex') elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_MIME: base = u'mime' if self._value is not None: mimes = self._value if set(mimes) == set(HC.SEARCHABLE_MIMES): mime_text = 'anything' elif set(mimes) == set(HC.SEARCHABLE_MIMES).intersection( set(HC.APPLICATIONS)): mime_text = 'application' elif set(mimes) == set(HC.SEARCHABLE_MIMES).intersection( set(HC.AUDIO)): mime_text = 'audio' elif set(mimes) == set(HC.SEARCHABLE_MIMES).intersection( set(HC.IMAGES)): mime_text = 'image' elif set(mimes) == set(HC.SEARCHABLE_MIMES).intersection( set(HC.VIDEO)): mime_text = 'video' else: mime_text = ', '.join( [HC.mime_string_lookup[mime] for mime in mimes]) base += u' is ' + mime_text elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_RATING: base = u'rating' if self._value is not None: (operator, value, service_key) = self._value service = HydrusGlobals.client_controller.GetServicesManager( ).GetService(service_key) base += u' for ' + service.GetName( ) + u' ' + operator + u' ' + HydrusData.ToUnicode(value) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_SIMILAR_TO: base = u'similar to' if self._value is not None: (hash, max_hamming) = self._value base += u' ' + hash.encode( 'hex') + u' using max hamming of ' + str(max_hamming) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_FILE_SERVICE: if self._value is None: base = 'file service' else: (operator, current_or_pending, service_key) = self._value if operator == True: base = u'is' else: base = u'is not' if current_or_pending == HC.CONTENT_STATUS_PENDING: base += u' pending to ' else: base += u' currently in ' service = HydrusGlobals.client_controller.GetServicesManager( ).GetService(service_key) base += service.GetName() base += count_text base = HydrusTags.CombineTag('system', base) elif self._predicate_type == HC.PREDICATE_TYPE_TAG: tag = self._value if not self._inclusive: base = u'-' else: base = u'' base += tag base += count_text if sibling_service_key is not None: siblings_manager = HydrusGlobals.client_controller.GetManager( 'tag_siblings') sibling = siblings_manager.GetSibling(sibling_service_key, tag) if sibling is not None: sibling = ClientTags.RenderTag(sibling, render_for_user) base += u' (will display as ' + sibling + ')' elif self._predicate_type == HC.PREDICATE_TYPE_PARENT: base = ' ' tag = self._value base += tag base += count_text elif self._predicate_type == HC.PREDICATE_TYPE_NAMESPACE: namespace = self._value if not self._inclusive: base = u'-' else: base = u'' rendered_tag = HydrusTags.CombineTag(namespace, '*anything*') base += rendered_tag elif self._predicate_type == HC.PREDICATE_TYPE_WILDCARD: wildcard = self._value if not self._inclusive: base = u'-' else: base = u'' base += wildcard base = ClientTags.RenderTag(base, render_for_user) return base
def GetUnicode(self, with_count=True, sibling_service_key=None, render_for_user=False): count_text = u'' if with_count: if self._min_current_count > 0: number_text = HydrusData.ConvertIntToPrettyString( self._min_current_count) if self._max_current_count is not None: number_text += u'-' + HydrusData.ConvertIntToPrettyString( self._max_current_count) count_text += u' (' + number_text + u')' if self._min_pending_count > 0: number_text = HydrusData.ConvertIntToPrettyString( self._min_pending_count) if self._max_pending_count is not None: number_text += u'-' + HydrusData.ConvertIntToPrettyString( self._max_pending_count) count_text += u' (+' + number_text + u')' if self._predicate_type in HC.SYSTEM_PREDICATES: if self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_EVERYTHING: base = u'everything' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_INBOX: base = u'inbox' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_ARCHIVE: base = u'archive' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_UNTAGGED: base = u'untagged' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_LOCAL: base = u'local' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_NOT_LOCAL: base = u'not local' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_DIMENSIONS: base = u'dimensions' elif self._predicate_type in (HC.PREDICATE_TYPE_SYSTEM_NUM_TAGS, HC.PREDICATE_TYPE_SYSTEM_WIDTH, HC.PREDICATE_TYPE_SYSTEM_HEIGHT, HC.PREDICATE_TYPE_SYSTEM_NUM_WORDS): if self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_NUM_TAGS: base = u'number of tags' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_WIDTH: base = u'width' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_HEIGHT: base = u'height' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_NUM_WORDS: base = u'number of words' if self._value is not None: (operator, value) = self._value base += u' ' + operator + u' ' + HydrusData.ConvertIntToPrettyString( value) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_DURATION: base = u'duration' if self._value is not None: (operator, value) = self._value base += u' ' + operator + u' ' + HydrusData.ConvertMillisecondsToPrettyTime( value) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_RATIO: base = u'ratio' if self._value is not None: (operator, ratio_width, ratio_height) = self._value base += u' ' + operator + u' ' + str( ratio_width) + u':' + str(ratio_height) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_SIZE: base = u'size' if self._value is not None: (operator, size, unit) = self._value base += u' ' + operator + u' ' + str( size) + HydrusData.ConvertIntToUnit(unit) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_LIMIT: base = u'limit' if self._value is not None: value = self._value base += u' is ' + HydrusData.ConvertIntToPrettyString( value) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_AGE: base = u'age' if self._value is not None: (operator, years, months, days, hours) = self._value base += u' ' + operator + u' ' + str(years) + u'y' + str( months) + u'm' + str(days) + u'd' + str(hours) + u'h' elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_NUM_PIXELS: base = u'num_pixels' if self._value is not None: (operator, num_pixels, unit) = self._value base += u' ' + operator + u' ' + str( num_pixels) + ' ' + HydrusData.ConvertIntToPixels(unit) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_HASH: base = u'hash' if self._value is not None: (hash, hash_type) = self._value base = hash_type + ' hash is ' + hash.encode('hex') elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_MIME: base = u'mime' if self._value is not None: mimes = self._value if set(mimes) == set(HC.SEARCHABLE_MIMES): mime_text = 'anything' elif set(mimes) == set(HC.SEARCHABLE_MIMES).intersection( set(HC.APPLICATIONS)): mime_text = 'application' elif set(mimes) == set(HC.SEARCHABLE_MIMES).intersection( set(HC.AUDIO)): mime_text = 'audio' elif set(mimes) == set(HC.SEARCHABLE_MIMES).intersection( set(HC.IMAGES)): mime_text = 'image' elif set(mimes) == set(HC.SEARCHABLE_MIMES).intersection( set(HC.VIDEO)): mime_text = 'video' else: mime_text = ', '.join( [HC.mime_string_lookup[mime] for mime in mimes]) base += u' is ' + mime_text elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_RATING: base = u'rating' if self._value is not None: (operator, value, service_key) = self._value service = HG.client_controller.services_manager.GetService( service_key) service_type = service.GetServiceType() pretty_value = HydrusData.ToUnicode(value) if service_type == HC.LOCAL_RATING_LIKE: if value == 0: pretty_value = 'dislike' elif value == 1: pretty_value = 'like' elif service_type == HC.LOCAL_RATING_NUMERICAL: if isinstance(value, float): allow_zero = service.AllowZero() num_stars = service.GetNumStars() if allow_zero: star_range = num_stars else: star_range = num_stars - 1 pretty_x = int(round(value * star_range)) pretty_y = num_stars if not allow_zero: pretty_x += 1 pretty_value = HydrusData.ConvertValueRangeToPrettyString( pretty_x, pretty_y) base += u' for ' + service.GetName( ) + u' ' + operator + u' ' + pretty_value elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_SIMILAR_TO: base = u'similar to' if self._value is not None: (hash, max_hamming) = self._value base += u' ' + hash.encode( 'hex') + u' using max hamming of ' + str(max_hamming) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_FILE_SERVICE: if self._value is None: base = 'file service' else: (operator, current_or_pending, service_key) = self._value if operator == True: base = u'is' else: base = u'is not' if current_or_pending == HC.CONTENT_STATUS_PENDING: base += u' pending to ' else: base += u' currently in ' service = HG.client_controller.services_manager.GetService( service_key) base += service.GetName() elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_TAG_AS_NUMBER: if self._value is None: base = 'tag as number' else: (namespace, operator, num) = self._value if namespace == '': n_text = 'tag' else: n_text = namespace if operator == u'\u2248': o_text = ' about ' elif operator == '<': o_text = ' less than ' elif operator == '>': o_text = ' more than ' base = n_text + o_text + HydrusData.ConvertIntToPrettyString( num) elif self._predicate_type == HC.PREDICATE_TYPE_SYSTEM_DUPLICATE_RELATIONSHIPS: base = 'num duplicate relationships' if self._value is not None: (operator, num_relationships, dupe_type) = self._value if operator == u'\u2248': o_text = ' about ' elif operator == '<': o_text = ' less than ' elif operator == '>': o_text = ' more than ' elif operator == '=': o_text = ' ' base += u' - has' + o_text + HydrusData.ConvertIntToPrettyString( num_relationships ) + u' ' + HC.duplicate_type_string_lookup[dupe_type] base = HydrusTags.CombineTag('system', base) base = ClientTags.RenderTag(base, render_for_user) base += count_text elif self._predicate_type == HC.PREDICATE_TYPE_TAG: tag = self._value if not self._inclusive: base = u'-' else: base = u'' base += ClientTags.RenderTag(tag, render_for_user) base += count_text if sibling_service_key is not None: siblings_manager = HG.client_controller.GetManager( 'tag_siblings') sibling = siblings_manager.GetSibling(sibling_service_key, tag) if sibling is not None: sibling = ClientTags.RenderTag(sibling, render_for_user) base += u' (will display as ' + sibling + ')' elif self._predicate_type == HC.PREDICATE_TYPE_PARENT: base = ' ' tag = self._value base += ClientTags.RenderTag(tag, render_for_user) base += count_text elif self._predicate_type == HC.PREDICATE_TYPE_NAMESPACE: namespace = self._value if not self._inclusive: base = u'-' else: base = u'' anything_tag = HydrusTags.CombineTag(namespace, '*anything*') anything_tag = ClientTags.RenderTag(anything_tag, render_for_user) base += anything_tag elif self._predicate_type == HC.PREDICATE_TYPE_WILDCARD: wildcard = self._value if not self._inclusive: base = u'-' else: base = u'' base += wildcard return base