Example #1
0
 def __unicode__(self):
     extent = self._on
     criteria = self._criteria
     if criteria:
         field_spec = self._on.field_spec
         criteria = [
             # (field label, value label)
             (label(field_spec[name]), unicode(self.f[name]))
             for name in criteria
             ]
         criteria = ', '.join(
             '%s == %s' % (field_label, value_label)
             for field_label, value_label
             in criteria
             )
         return u'%s where (%s)' % (plural(extent), criteria)
     else:
         return u'all %s' % plural(extent)
Example #2
0
 def on_extent_grid__selection_changed(self, widget, extent):
     if extent is not None:
         with TemporaryCursor(self):
             icon_set = icon.iconset(widget, extent)
             size = gtk.ICON_SIZE_LARGE_TOOLBAR
             self.entity_grid_image.set_from_icon_set(icon_set, size)
             text = u'List of %s:' % plural(extent)
             self.entity_grid_label.set_text(text)
             self.entity_grid.set_extent(extent)
Example #3
0
 def test_extent_decoration(self):
     # These labels were assigned automatically.
     assert label.label(db.Avatar) == 'Avatar'
     assert label.label(db.Batch_Job) == 'Batch Job'
     assert label.label(db.Realm) == 'Realm'
     assert label.label(db.User) == 'User'
     assert label.label(db.Person) == 'Person'
     assert label.plural(db.Avatar) == 'Avatars'
     assert label.plural(db.Batch_Job) == 'Batch Jobs'
     assert label.plural(db.Realm) == 'Realms'
     assert label.plural(db.User) == 'Users'
     # These labels were assigned manually.
     assert label.plural(db.Person) == 'People'
     # The docstring for an extent is set to the docstring for the
     # entity.
     assert db.Person.__doc__ == 'Bank account owner.'
     # An extent may optionally be hidden from typical user
     # interfaces.
     assert db.AlphaAlpha.hidden
     assert not db.AlphaBravo.hidden
Example #4
0
 def test_many_pluralization(self):
     assert label(db.Goauld) == u"Goa\u2032uld"
     assert plural(db.Goauld) == u"Goa\u2032ulds"
     ex = db.execute
     something = ex(db.Something.t.create())
     goauld1 = ex(db.Goauld.t.create(something=something))
     goauld2 = ex(db.Goauld.t.create(something=something))
     goaulds = something.m.goaulds()
     assert len(goaulds) == 2
     assert goauld1 in goaulds
     assert goauld2 in goaulds
Example #5
0
 def __unicode__(self):
     if not self.queries:
         return u'the intersection of ()'
     last_on = None
     for query in self.queries:
         # Optimize length of string when results will be all
         # entities in an extent.
         if (isinstance(query, Match)
             and isinstance(query.on, base.Extent)
             and (query.on is last_on or not last_on)
             and (query.operator is o_any)
             ):
             last_on = query.on
             continue
         # Not a default query.
         return u'the intersection of (%s)' % (
             u', '.join(unicode(query) for query in self.queries)
             )
     # Was a default query.
     return u'all %s' % plural(last_on)
Example #6
0
 def rerun(self):
     """Re-run the query and update results."""
     db = self._db
     # Destroy existing results.
     class_expander = self._class_expander
     while class_expander:
         class_, expander = class_expander.pop()
         expander.destroy()
     # Re-run query.
     results = self._query()
     class_results = {}
     for result in results:
         L = class_results.setdefault(result.__class__, [])
         L.append(result)
     # Create expanders and listviews.
     if not class_results:
         no_results = gtk.Label('No results found.')
         self.pack_start(no_results, expand=False)
         class_expander.append((None, no_results))
     for class_, results in class_results.iteritems():
         extent = class_._extent
         expander_label = gtk.HBox()
         # Label for extent.
         extent_image = icon.small_image(self, extent)
         count = len(results)
         if count != 1:
             extent_label = gtk.Label(
                 u'%i %s found:' % (count, plural(extent)))
         else:
             extent_label = gtk.Label(
                 u'%i %s found:' % (count, label(extent)))
         expander_label.pack_start(extent_image, expand=False, padding=6)
         expander_label.pack_start(extent_label, expand=False, padding=6)
         expander = gtk.Expander()
         expander.props.label_widget = expander_label
         expander.props.expanded = True
         self.pack_start(expander, expand=True)
         listview = ResultsListView(class_, results)
         expander.add(listview)
         class_expander.append((class_, expander))
     self.show_all()
Example #7
0
 def __unicode__(self):
     FieldClass = self.FieldClass
     field = FieldClass(self, self.field_name)
     operator = self.operator
     on = self.on
     if isinstance(on, base.Extent):
         on_label = plural(on)
     else:
         on_label = unicode(on)
     s = u'%s where %s %s' % (
         on_label,
         label(field),
         label(self.operator),
         )
     if operator is not o_any:
         value = self.value
         if isinstance(value, Query):
             s += u' %s' % value
         else:
             field.set(value)
             s += u' %s' % field
     return s
Example #8
0
 def test_subclass_labels(self):
     assert plural(db.Something) == u'Somethingys'
Example #9
0
 def __init__(self, db):
     gtk.VBox.__init__(self)
     self._db = db
     ##         exp_ext = self._expander_extent = {}
     ##         ext_exp = self._extent_expander = {}
     for extent in db.extents():
         expander = gtk.Expander()
         extent_label = plural(extent)
         iset = icon.iconset(self, extent)
         image_label = icon.small_image(self, extent)
         ##             text_label = gtk.Label(u'<b>%s</b>' % extent_label)
         ##             text_label.props.use_markup = True
         text_label = gtk.Label(extent_label)
         label_widget = gtk.HBox()
         label_widget.pack_start(image_label, expand=False, padding=6)
         label_widget.pack_start(text_label, expand=False)
         expander.props.label_widget = label_widget
         self.pack_start(expander)
         # Children of expander.
         hbox = gtk.HBox()
         expander.add(hbox)
         # Padding on left.
         padding = gtk.VBox()
         padding.props.width_request = 20
         hbox.pack_start(padding, expand=False)
         # Buttons.
         buttons = gtk.VBox()
         hbox.add(buttons)
         # Query buttons.
         q = extent.q
         for q_name in q:
             q_method = q[q_name]
             ##                 q_label = label(q_method)
             q_label = gtk.Label(label(q_method))
             q_button = gtk.Button()
             ##                 q_button.props.label = q_label
             ##                 q_button.props.image = icon.small_image(
             ##                     self, db, 'q.%s' % q_name)
             q_image = icon.small_image(self, db, "q.%s" % q_name)
             q_hbox = gtk.HBox(spacing=2)
             q_hbox.pack_start(q_image, expand=False)
             q_hbox.pack_start(q_label, expand=False, padding=1)
             q_button.add(q_hbox)
             ##                 q_button.props.relief = gtk.RELIEF_NONE
             q_button.props.xalign = 0.0
             q_button.connect("clicked", self.on_q_button_clicked, extent, q_name)
             buttons.add(q_button)
         # Transaction buttons.
         t = extent.t
         for t_name in t:
             t_method = t[t_name]
             t_label = label(t_method)
             t_button = gtk.Button()
             t_button.props.label = t_label
             t_button.props.image = icon.small_image(self, db, "t.%s" % t_name)
             ##                 t_button.props.relief = gtk.RELIEF_NONE
             t_button.props.xalign = 0.0
             t_button.connect("clicked", self.on_t_button_clicked, extent, t_name)
             buttons.add(t_button)
         # Padding on bottom.
         padding = gtk.VBox()
         padding.props.height_request = 11
         buttons.add(padding)
     self.show_all()
Example #10
0
def show_error(parent, exc_type, exc_val, exc_tb):
    try:
        markup = None
        for handler in ERROR_HANDLERS:
            markup = handler(exc_type, exc_val, exc_tb)
            if markup is not None:
                break
        if markup is None:
            if issubclass(exc_type, schevo.error.DatabaseFileLocked):
                markup = [
                    u'The file or library you are trying to open is already\n'
                    u'in use by another application.  Please close the file\n'
                    u'in the other application to open it here.\n'
                    ]
            elif issubclass(exc_type, schevo.error.DeleteRestricted):
                markup = [
                    u'The object was not deleted from the database.\n'
                    u'\n'
                    u'It is referred to by the following types of objects.\n'
                    u'Delete them first before deleting this object.\n'
                    u'\n'
                    ]
                restrictions = sorted(exc_val.restrictions)
                ref_extents = set()
                for entity, ref_entity, ref_field_name in restrictions:
                    ref_extents.add(ref_entity.s.extent)
                for extent in sorted(ref_extents):
                    markup.append(BULLET + '<b>%s</b>\n' % plural(extent))
            elif issubclass(exc_type, schevo.error.FieldReadonly):
                markup = [
                    u'The <b>%s</b> field is readonly and cannot be changed.'
                    % escape(label(exc_val.field))
                    ]
            elif issubclass(exc_type, schevo.error.FieldRequired):
                markup = [
                    u'The <b>%s</b> field is required. Please provide a value.'
                    % escape(label(exc_val.field))
                    ]
            elif issubclass(exc_type, schevo.error.KeyCollision):
                markup = [
                    u'Your changes were not saved.\n'
                    u'\n'
                    u'There is already an object of this type that has\n'
                    u'the following values, which must be unique:\n'
                    u'\n'
                    ]
                for field_name, field_value in zip(exc_val.key_spec,
                                                   exc_val.field_values):
                    markup.append(BULLET + '<b>%s</b>: %s\n'
                                  % (escape(field_name),
                                     escape(dereference(field_value))))
            elif issubclass(exc_type, schevo.error.TransactionExpired):
                markup = [
                    u'The transaction has expired.\n'
                    u'\n'
                    u'The most common reason for this is performing\n'
                    u'another transaction that results in this object\n'
                    u'being updated.\n'
                    u'\n'
                    u'Cancel this transaction, then re-open it, to\n'
                    u'complete the desired operation.'
                    ]
            elif issubclass(exc_type, schevo.error.TransactionRuleViolation):
                markup = [
                    u'Your changes were not saved.\n'
                    u'\n'
                    u'The following transaction rule was violated when\n'
                    u'attempting to save:\n'
                    u'\n'
                    ]
                markup.append(BULLET + u'<b>%s</b>\n' % escape(exc_val.message))
            elif issubclass(exc_type, schevo.error.TransactionFieldsNotChanged):
                markup = [
                    u'No fields changed.\n'
                    u'\n'
                    u'Change at least one field to update this object,\n'
                    u'or click <b>Cancel</b> to leave it unchanged.'
                    ]
            else:
                # By default, just show the error message verbatim.
                markup = [escape(str(exc_val))]
        markup = u''.join(markup)
    except:
        markup = 'See "Diagnostics" tab for information.'
    # Show the dialog.
    flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
    win = ErrorMessage(title='ATFG Error', parent=parent, flags=flags,
                       buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_ACCEPT),
                       markup=markup,
                       exc_type=exc_type, exc_val=exc_val, exc_tb=exc_tb)
    win.run()
    win.destroy()