示例#1
0
文件: rules.py 项目: cclauss/advene
    def build_parameter_widget(self, name, value, description):
        hbox = Gtk.HBox()
        label = Gtk.Label(label=name)
        hbox.pack_start(label, False, True, 0)

        ra = self.registeredaction
        if ra:
            # Get predefined values
            if callable(ra.predefined):
                predefined = ra.predefined(self.controller)[name]
            elif ra.predefined is not None:
                predefined = ra.predefined[name]
            else:
                predefined = None

        entry = TALESEntry(controller=self.controller, predefined=predefined)
        entry.set_text(value)
        entry.set_editable(self.editable)
        entry.entry.connect('changed', self.on_change_parameter, entry, name)

        entry.entry.set_tooltip_text(description)

        hbox.entry = entry

        hbox.pack_start(entry.widget, True, True, 0)
        hbox.show_all()
        return hbox
示例#2
0
文件: rules.py 项目: cclauss/advene
    def build_widget(self):
        hbox = Gtk.HBox()

        if self.parent is None or isinstance(self.parent, EditRule):
            predefined = [
                ('annotation/type/id', _('The annotation type')),
                ('annotation/content/data', _('The annotation content')),
            ] + [
                ('annotation/content/parsed/%s' % p,
                 _("The value of the %s attribute") % p)
                for p in set(a
                             for at in self.controller.package.annotationTypes
                             for a in getattr(at, '_fieldnames', []))
            ] + [
                ('annotation/fragment', _('The annotation fragment')),
                ('annotation/fragment/begin', _('The annotation begin time')),
                ('annotation/fragment/end', _('The annotation end time')),
                ('annotation/fragment/duration', _('The annotation duration')),
                ('annotation/content/mimetype', _('The annotation MIME-type')),
                ('annotation/incomingRelations',
                 _("The annotation's incoming relations")),
                ('annotation/outgoingRelations',
                 _("The annotation's outgoing relations")),
            ] + [('annotation/typedRelatedIn/%s' % rt.id,
                  _("The %s-related incoming annotations") %
                  self.controller.get_title(rt))
                 for rt in self.controller.package.relationTypes
                 ] + [('annotation/typedRelatedOut/%s' % rt.id,
                       _("The %s-related outgoing annotations") %
                       self.controller.get_title(rt))
                      for rt in self.controller.package.relationTypes]
        elif isinstance(self.parent, EditQuery):
            predefined = [
                ('element', _('The element')),
                ('element/content/data', _("The element's content")),
                ('element/fragment', _('The element fragment')),
                ('element/fragment/begin', _('The element begin time')),
                ('element/fragment/end', _('The element end time')),
                ('element/fragment/duration', _('The element duration')),
                ('element/type/id', _('The element type')),
                ('element/incomingRelations',
                 _("The element's incoming relations")),
                ('element/outgoingRelations',
                 _("The element's outgoing relations")),
                ('here', _('The context')),
                ('here/fragment', _('The context fragment')),
                ('here/annotations', _('The context annotations')),
                ('here/type/annotations',
                 _('The annotations of the context type')),
            ]
        self.lhs = TALESEntry(controller=self.controller,
                              predefined=predefined)
        self.lhs.set_text(self.model.lhs or "")
        self.lhs.set_editable(self.editable)
        self.lhs.show()
        self.lhs.set_no_show_all(True)

        if self.parent is None or isinstance(self.parent, EditRule):
            predef = [
                ('string:%s' % at.id,
                 _("annotation-type %s") % self.controller.get_title(at))
                for at in self.controller.package.annotationTypes
            ] + [('string:%s' % at.id,
                  _("relation-type %s") % self.controller.get_title(at))
                 for at in self.controller.package.relationTypes] + predefined
        elif isinstance(self.parent, EditQuery):
            predef = predefined
        self.rhs = TALESEntry(controller=self.controller, predefined=predef)
        self.rhs.set_text(self.model.rhs or "")
        self.rhs.set_editable(self.editable)
        self.rhs.hide()
        self.rhs.set_no_show_all(True)

        operators = {}
        operators.update(Condition.binary_operators)
        operators.update(Condition.unary_operators)

        def description_getter(element):
            if element in Condition.condition_categories:
                return Condition.condition_categories[element]
            else:
                return operators[element][0]

        self.selector = dialog.CategorizedSelector(
            title=_("Select a condition"),
            elements=list(operators),
            categories=list(Condition.condition_categories),
            current=self.current_operator,
            description_getter=description_getter,
            category_getter=lambda e: operators[e][1],
            callback=self.on_change_operator,
            editable=self.editable)
        self.operator = self.selector.get_button()

        hbox.add(self.lhs.widget)
        hbox.add(self.operator)
        hbox.add(self.rhs.widget)
        hbox.show()

        self.update_widget()

        return hbox
示例#3
0
文件: rules.py 项目: cclauss/advene
    def build_widget(self):
        frame = Gtk.Frame()

        vbox = Gtk.VBox()
        frame.add(vbox)
        vbox.show()

        # Event
        ef = Gtk.Frame.new(_("For all elements in "))
        predef = [('package/annotations', _("All annotations of the package")),
                  ('package/views', _("All views of the package")),
                  ('here/annotations', _("The context annotations")),
                  ('here/type/annotations',
                   _("The annotations of the context type"))]
        for at in self.controller.package.annotationTypes:
            predef.append(
                ('package/annotationTypes/%s/annotations' % at.id,
                 _("Annotations of type %s") % self.controller.get_title(at)))
        self.sourceentry = TALESEntry(context=self.model,
                                      controller=self.controller,
                                      predefined=predef)
        self.sourceentry.set_text(";".join(self.model.sources))
        self.sourceentry.set_editable(self.editable)
        ef.add(self.sourceentry.widget)
        ef.show_all()
        vbox.pack_start(ef, False, True, 0)

        if config.data.preferences['expert-mode']:
            # Return value
            vf = Gtk.Frame.new(_("Return "))
            self.valueentry = TALESEntry(context=self.model,
                                         predefined=[
                                             ('element', _("The element")),
                                             ('element/content/data',
                                              _("The element's content"))
                                         ],
                                         controller=self.controller)
            v = self.model.rvalue
            if v is None or v == '':
                v = 'element'
            self.valueentry.set_text(v)
            self.valueentry.set_editable(self.editable)
            vf.add(self.valueentry.widget)
            vf.show_all()
            vbox.pack_start(vf, False, True, 0)
        else:
            self.valueentry = None

        # Conditions
        if config.data.preferences['expert-mode']:
            cf = Gtk.Frame.new(_("If the element matches "))
        else:
            cf = Gtk.Frame.new(_("Return the element if it matches "))
        conditionsbox = Gtk.VBox()
        cf.add(conditionsbox)

        # "Add condition" button
        hb = Gtk.HBox()
        b = Gtk.Button(stock=Gtk.STOCK_ADD)
        b.connect('clicked', self.add_condition, conditionsbox)
        b.set_sensitive(self.editable)
        hb.pack_start(b, False, True, 0)
        hb.set_homogeneous(False)

        hb.add(Gtk.HBox())

        def change_composition(combo):
            self.composition = combo.get_current_element()
            return True

        c = dialog.list_selector_widget(
            [('and', _("All conditions must be met")),
             ('or', _("Any condition can be met"))],
            preselect=self.composition,
            callback=change_composition)
        hb.pack_start(c, False, True, 0)

        conditionsbox.pack_start(hb, False, False, 0)

        cf.show_all()

        if isinstance(self.model.condition,
                      advene.rules.elements.ConditionList):
            for c in self.model.condition:
                self.add_condition_widget(c, conditionsbox)

        vbox.pack_start(cf, False, True, 0)

        frame.show()

        return frame