コード例 #1
0
ファイル: fieldwidget.py プロジェクト: Schevo/schevogtk
 def __init__(self, db, field):
     self.db = db
     self.field = field
     BaseComboBox.__init__(self)
     # Default to the field's current item.
     value = field.get()
     if self.autoselect_single_valid_value:
         if field.valid_values is not None:
             if len(field.valid_values) == 1:
                 # If the field has exactly one valid value, choose that.
                 value = iter(field.valid_values).next()
         else:
             if field.required and len(self.model) == 2:
                 # If the field has exactly one available value, choose it.
                 value = self.model[-1][-1]
     self.select_item_by_data(value)
     if value != field.get():
         gobject.timeout_add(0, self.emit, 'value-changed')
コード例 #2
0
ファイル: field.py プロジェクト: Schevo/schevogtk
 def reset(self):
     field = self._field
     if field.hidden:
         return
     field_value = field.get()
     widget_value = self.get_value()
     if (widget_value == field_value) and not field.metadata_changed:
         return
     field.reset_metadata_changed()
     self.set_field(self._db, field)
コード例 #3
0
ファイル: query.py プロジェクト: Schevo/schevo
 def _results(self):
     on = self.on
     if isinstance(on, base.Query):
         on = on()
     operator = self.operator
     field_name = self.field_name
     value = self.value
     if operator is o_in:
         if isinstance(value, base.Query):
             value = value()
         value = frozenset(value)
         return results(
             obj for obj in on if getattr(obj, field_name) in value)
     else:
         if operator is o_any:
             return results(on)
         elif operator is o_assigned:
             return results(
                 obj for obj in on
                 if getattr(obj, field_name) is not UNASSIGNED)
         elif operator is o_unassigned:
             if isinstance(on, base.Extent):
                 kw = {field_name: UNASSIGNED}
                 return results(on.find(**kw))
             else:
                 return results(
                     obj for obj in on
                     if getattr(obj, field_name) is UNASSIGNED)
         if value is not None:
             field = self.FieldClass(self, field_name)
             field.set(value)
             value = field.get()
         if isinstance(on, base.Extent) and operator is o_eq:
             kw = {field_name: value}
             return results(on.find(**kw))
         elif operator.operator:
             oper = operator.operator
             def generator():
                 for obj in on:
                     a = getattr(obj, field_name)
                     b = value
                     try:
                         result = oper(a, b)
                     except TypeError:
                         # Cannot compare e.g. UNASSIGNED with
                         # datetime; assume no match.
                         continue
                     if result:
                         yield obj
             return results(generator())
コード例 #4
0
ファイル: fieldwidget.py プロジェクト: Schevo/schevogtk
 def __init__(self, field):
     gtk.VBox.__init__(self)
     self._value = value = field.get()
     button_1 = gtk.RadioButton(None, field.true_description)
     button_2 = gtk.RadioButton(button_1, field.false_description)
     button_1.show()
     button_2.show()
     self.add(button_1)
     self.add(button_2)
     if value:
         button_1.set_active(True)
     else:
         button_2.set_active(True)
     button_1.connect('toggled', self._on_toggled, True)
     button_2.connect('toggled', self._on_toggled, False)
コード例 #5
0
ファイル: fieldwidget.py プロジェクト: Schevo/schevogtk
 def _populate(self):
     db = self.db
     field = self.field
     items = []
     values = []
     # Unassigned.
     items.append((self.unassigned_label, UNASSIGNED))
     values.append(UNASSIGNED)
     # Preferred values.
     preferred_values = field.preferred_values or []
     if preferred_values:
         values.extend(preferred_values)
         more = []
         for value in sorted(preferred_values):
             if value is UNASSIGNED:
                 continue
             more.append((unicode(value), value))
         items.extend(more)
         # Row separator.
         items.append((None, None))
     # Valid values.
     more = []
     valid_values = field.valid_values
     values.extend(valid_values)
     for value in sorted(valid_values):
         if value is UNASSIGNED:
             continue
         if value in preferred_values:
             continue
         more.append((unicode(value), value))
     items.extend(more)
     value = field.get()
     if value not in values:
         # Row separator.
         items.append((None, None))
         # Invalid, but current value.
         items.append((unicode(value), value))
     # Update the model.
     model = self.model
     model.clear()
     for text, value in items:
         model.append((text, value))
コード例 #6
0
ファイル: fieldwidget.py プロジェクト: Schevo/schevogtk
 def __init__(self, db, field):
     self.db = db
     self.field = field
     BaseComboBox.__init__(self)
     # Select the field's current item.
     self.select_item_by_data(field.get())
コード例 #7
0
ファイル: fieldwidget.py プロジェクト: Schevo/schevogtk
 def _populate(self):
     db = self.db
     field = self.field
     allow = field.allow
     entity_label = self.entity_label
     if len(allow) > 1:
         allow_multiple = True
     else:
         allow_multiple = False
     items = []
     values = []
     # Unassigned.
     items.append((self.unassigned_label, UNASSIGNED))
     values.append(UNASSIGNED)
     # Preferred values.
     preferred_values = field.preferred_values or []
     if preferred_values:
         values.extend(preferred_values)
         more = []
         for entity in sorted(preferred_values):
             if entity is UNASSIGNED:
                 continue
             if allow_multiple:
                 extent_text = label(entity.s.extent)
                 text = u'%s :: %s' % (entity_label(entity), extent_text)
             else:
                 text = u'%s' % (entity_label(entity), )
             more.append((text, entity))
         items.extend(more)
         # Row separator.
         items.append((None, None))
     # Valid values.
     more = []
     valid_values = field.valid_values
     if valid_values is not None:
         # Specific valid values.
         values.extend(valid_values)
         for entity in sorted(valid_values):
             if entity is UNASSIGNED:
                 continue
             if entity in preferred_values:
                 continue
             if allow_multiple:
                 extent_text = label(entity.s.extent)
                 text = u'%s :: %s' % (entity_label(entity), extent_text)
             else:
                 text = u'%s' % (entity_label(entity), )
             more.append((text, entity))
     else:
         # Other allowed values.
         for extent_name in field.allow:
             extent = db.extent(extent_name)
             for entity in sorted(extent):
                 if entity in preferred_values:
                     continue
                 values.append(entity)
                 if allow_multiple:
                     extent_text = label(extent)
                     text = u'%s :: %s' % (entity_label(entity), extent_text)
                 else:
                     text = u'%s' % (entity_label(entity), )
                 more.append((text, entity))
     items.extend(more)
     value = field.get()
     if value not in values:
         entity = value
         # Row separator.
         items.append((None, None))
         # Invalid, but current value.
         if allow_multiple:
             extent_text = label(entity.s.extent)
             text = u'%s :: %s' % (entity_label(entity), extent_text)
         else:
             text = u'%s' % (entity_label(entity), )
         items.append((text, entity))
     # Update the model.
     model = self.model
     model.clear()
     for text, entity in items:
         model.append((text, entity))
コード例 #8
0
ファイル: query.py プロジェクト: Schevo/schevo
 def _criteria(self):
     criteria = odict()
     for name, field in self.s.field_map().iteritems():
         if field.assigned:
             criteria[name] = field.get()
     return criteria