NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

formComponent.py (12330B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\forms\formComponent.py
      2 import signals
      3 from carbonui.control.forms import formValidators
      4 from carbonui.control.forms.form import FormComponentInterface
      5 
      6 class BaseComponent(FormComponentInterface):
      7 
      8     def __init__(self, name, label, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None):
      9         super(BaseComponent, self).__init__()
     10         self.name = name
     11         self.label = label
     12         self.icon = icon
     13         self._value = value
     14         self.get_value_func = None
     15         self.validators = validators or []
     16         self.hint = hint
     17         self.field_cls = field_cls
     18         self.is_visible = is_visible
     19         self.indent_level = indent_level
     20         if form:
     21             form.add_component(self)
     22 
     23     def get_value(self):
     24         return self._value
     25 
     26     def init_value(self, value):
     27         self._value = value
     28 
     29     def set_value(self, value):
     30         self._value = value
     31         self.on_value_set(value)
     32 
     33     def clear_value(self):
     34         self.set_value(None)
     35         self.on_value_cleared()
     36 
     37     def get_id(self):
     38         return self.name
     39 
     40     def get_label(self):
     41         return self.label
     42 
     43     def set_label(self, value):
     44         self.label = value
     45         self.on_label_changed(self)
     46 
     47     def set_icon(self, value):
     48         self.icon = value
     49         self.on_icon_changed(self)
     50 
     51     def set_hint(self, value):
     52         self.hint = value
     53         self.on_hint_changed(self)
     54 
     55     def get_name(self):
     56         return self.name
     57 
     58     def get_invalid_reason(self):
     59         reasons = self.get_invalid_reasons()
     60         if not reasons:
     61             return
     62         reason = ', '.join(reasons)
     63         if self.label:
     64             reason = u'{}: {}'.format(self.label, reason)
     65         return reason
     66 
     67     def get_invalid_reasons(self):
     68         reasons = [ validator.get_invalid_reason(self.get_value()) for validator in self.validators ]
     69         return [ r for r in reasons if r ]
     70 
     71     def is_valid(self):
     72         is_valid = self.get_invalid_reason() is None
     73         self.on_validated(self, is_valid)
     74         return is_valid
     75 
     76     def on_field_value_changed(self, value):
     77         self._value = value
     78         self.on_value_set_by_user(self)
     79 
     80     def set_visible(self):
     81         if not self.is_visible:
     82             self.is_visible = True
     83             self.on_visibility_changed(self)
     84 
     85     def set_hidden(self):
     86         if self.is_visible:
     87             self.is_visible = False
     88             self.on_visibility_changed(self)
     89 
     90 
     91 class Text(BaseComponent):
     92 
     93     def __init__(self, name, label, value = None, placeholder = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = None, form = None):
     94         super(Text, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
     95         self.placeholder = placeholder
     96 
     97     def get_max_characters(self):
     98         for validator in self.validators:
     99             if isinstance(validator, formValidators.Length):
    100                 return validator.max_length
    101 
    102 
    103 class Label(BaseComponent):
    104 
    105     def __init__(self, name, label, hint = None):
    106         super(Label, self).__init__(name, label, hint=hint)
    107 
    108 
    109 class TextMultiLine(BaseComponent):
    110 
    111     def __init__(self, name, label, value = None, placeholder = None, num_lines = 4, show_formatting_panel = False, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = None, form = None):
    112         super(TextMultiLine, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    113         self.placeholder = placeholder
    114         self.num_lines = num_lines
    115         self.show_formatting_panel = show_formatting_panel
    116 
    117     def get_max_characters(self):
    118         for validator in self.validators:
    119             if isinstance(validator, formValidators.Length):
    120                 return validator.max_length
    121 
    122 
    123 class Integer(BaseComponent):
    124 
    125     def __init__(self, name, label, value = None, min_value = 0, max_value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, placeholder = None, indent_level = None, form = None):
    126         super(Integer, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    127         self.min_value = min_value
    128         self.max_value = max_value
    129         self.placeholder = placeholder
    130         self._value = _clamp_with_none_checks(value, min_value, max_value)
    131         self.min_value_changed_signal = signals.Signal('component_min_value_changed')
    132         self.max_value_changed_signal = signals.Signal('component_max_value_changed')
    133 
    134     def min_value_changed(self, value):
    135         self.min_value = value
    136         self.min_value_changed_signal(self.min_value)
    137 
    138     def max_value_changed(self, value):
    139         self.max_value = value
    140         self.max_value_changed_signal(self.max_value)
    141 
    142 
    143 class Float(BaseComponent):
    144 
    145     def __init__(self, name, label, value = 0.0, min_value = 0.0, max_value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = None, form = None):
    146         super(Float, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    147         self.min_value = min_value
    148         self.max_value = max_value
    149         self._value = _clamp_with_none_checks(value, min_value, max_value)
    150 
    151 
    152 class Enum(BaseComponent):
    153 
    154     def __init__(self, name, label, options, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = None, form = None):
    155         super(Enum, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    156         self.placeholder = placeholder
    157         self.options = options
    158 
    159 
    160 class Boolean(BaseComponent):
    161     pass
    162 
    163 
    164 class BooleanButton(BaseComponent):
    165     pass
    166 
    167 
    168 class EveType(BaseComponent):
    169 
    170     def __init__(self, name, label, placeholder = None, type_filter = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None):
    171         super(EveType, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    172         self.placeholder = placeholder
    173         self.type_filter = type_filter
    174 
    175 
    176 class EveGroup(BaseComponent):
    177 
    178     def __init__(self, name, label, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None):
    179         super(EveGroup, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    180         self.placeholder = placeholder
    181 
    182 
    183 class EveCategory(BaseComponent):
    184 
    185     def __init__(self, name, label, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None):
    186         super(EveCategory, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    187         self.placeholder = placeholder
    188 
    189 
    190 class MixedHierarchy(BaseComponent):
    191 
    192     def __init__(self, name, label, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None, type_filter = None, group_filter = None, category_filter = None, include_type = True, include_group = True, include_category = True):
    193         super(MixedHierarchy, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    194         self.placeholder = placeholder
    195         self.type_filter = type_filter
    196         self.group_filter = group_filter
    197         self.category_filter = category_filter
    198         self.include_type = include_type
    199         self.include_group = include_group
    200         self.include_category = include_category
    201 
    202 
    203 class SolarSystem(BaseComponent):
    204 
    205     def __init__(self, name, label, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None):
    206         super(SolarSystem, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    207         self.placeholder = placeholder
    208 
    209 
    210 class NPCFaction(BaseComponent):
    211 
    212     def __init__(self, name, label, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None):
    213         super(NPCFaction, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    214         self.placeholder = placeholder
    215 
    216 
    217 class PlayerCorporation(BaseComponent):
    218 
    219     def __init__(self, name, label, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None):
    220         super(PlayerCorporation, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    221         self.placeholder = placeholder
    222 
    223 
    224 class NPCCorporation(BaseComponent):
    225 
    226     def __init__(self, name, label, filter = None, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0):
    227         super(NPCCorporation, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level)
    228         self.placeholder = placeholder
    229         self.filter = filter
    230 
    231 
    232 class Organization(BaseComponent):
    233 
    234     def __init__(self, name, label, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None, include_character = True, include_corporation = True, include_alliance = True, include_faction = True):
    235         super(Organization, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    236         self.placeholder = placeholder
    237         self.include_character = include_character
    238         self.include_corporation = include_corporation
    239         self.include_alliance = include_alliance
    240         self.include_faction = include_faction
    241 
    242 
    243 class PlayerOrPlayerOrganization(Organization):
    244     pass
    245 
    246 
    247 class AccessList(BaseComponent):
    248 
    249     def __init__(self, name, label, options, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = False, icon = None, indent_level = 0, form = None):
    250         super(AccessList, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    251         self.placeholder = placeholder
    252         self.options = options
    253 
    254 
    255 class DateTime(BaseComponent):
    256 
    257     def __init__(self, name, label = None, value = None, duration_datetime = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None, time_options = None, year_range = None, timeparts = 4, time_padding = 0):
    258         super(DateTime, self).__init__(name, label, value, validators, hint, field_cls, is_visible, icon, indent_level, form)
    259         self.time_options = time_options
    260         self.year_range = year_range
    261         self.timeparts = timeparts
    262         self.time_padding = time_padding
    263         self.duration_datetime = duration_datetime
    264 
    265 
    266 class Divider(BaseComponent):
    267 
    268     def __init__(self, name):
    269         super(Divider, self).__init__(name, label='')
    270 
    271 
    272 def _clamp_with_none_checks(value, min_value, max_value):
    273     if value is None:
    274         return value
    275     if min_value is not None:
    276         value = max(min_value, value)
    277     if max_value is not None:
    278         value = min(max_value, value)
    279     return value
    280 
    281 
    282 class MultiValueFormComponentBase(BaseComponent):
    283     field_cls = None
    284 
    285     def __init__(self, name, label, placeholder = None, value = None, validators = None, hint = None, field_cls = None, is_visible = True, icon = None, indent_level = 0, form = None, max_entries = 1):
    286         super(MultiValueFormComponentBase, self).__init__(name, label, value, validators, hint, self.field_cls if field_cls is None else field_cls, is_visible, icon, indent_level, form)
    287         self.max_entries = max_entries
    288         self.placeholder = placeholder