Beispiel #1
0
 def update_value(self):
     if not self.editable:
         return False
     ra = self.catalog.get_action(self.current_name)
     self.model = Action(registeredaction=ra, catalog=self.catalog)
     regexp = re.compile('^(\(.+\)|)$')
     for n, v in self.current_parameters.items():
         # We ignore parameters fields that are empty or that match '^\(.+\)$'
         if not regexp.match(v):
             self.model.add_parameter(n, v)
     return True
Beispiel #2
0
 def add_rule_cb(button=None):
     if not self.editable:
         return True
     # Create a new default Rule
     event=Event("AnnotationBegin")
     ra=self.catalog.get_action("Message")
     action=Action(registeredaction=ra, catalog=self.catalog)
     for p in ra.parameters:
         action.add_parameter(p, ra.defaults.get(p, ''))
     # Find the next rulename index
     l=[ int(i) for i in re.findall(_('Rule')+r'\s*(\d+)', ''.join(r.name for r in self.model)) ]
     idx=max(l or [ 0 ] ) + 1
     rule=Rule(name=_("Rule") + str(idx),
               event=event,
               action=action)
     self.add_rule(rule)
     return True
Beispiel #3
0
    def create_follow_dynamic_view(self, rt):
        """Create a dynamic view for the given relation-type.
        """
        p = self.controller.package
        ident = 'v_follow_%s' % rt.id
        if p.get_element_by_id(ident) is not None:
            dialog.message_dialog(
                _("A follow dynamic view for %s already seems to exist.") %
                self.get_title(rt))
            return True
        v = p.createView(ident=ident,
                         author=config.data.userid,
                         date=self.controller.get_timestamp(),
                         clazz='package',
                         content_mimetype='application/x-advene-ruleset')
        v.title = _("Follow %s relation-type") % self.get_title(rt)

        # Build the ruleset
        r = RuleSet()
        catalog = self.controller.event_handler.catalog

        ra = catalog.get_action("PlayerGoto")
        action = Action(registeredaction=ra, catalog=catalog)
        action.add_parameter(
            'position',
            'annotation/typedRelatedOut/%s/first/fragment/begin' % rt.id)
        rule = Rule(name=_("Follow the relation"),
                    event=Event("AnnotationEnd"),
                    condition=Condition(lhs='annotation/typedRelatedOut/%s' %
                                        rt.id,
                                        operator='value'),
                    action=action)
        r.add_rule(rule)

        v.content.data = r.xml_repr()

        p.views.append(v)
        self.controller.notify('ViewCreate', view=v)
        self.controller.activate_stbv(v)
        return True
Beispiel #4
0
    def create_dynamic_view(self, at):
        """Create a caption dynamic view for the given annotation-type.
        """
        p = self.controller.package
        ident = 'v_caption_%s' % at.id
        if p.get_element_by_id(ident) is not None:
            dialog.message_dialog(
                _("A caption dynamic view for %s already seems to exist.") %
                self.get_title(at))
            return True
        v = p.createView(ident=ident,
                         author=config.data.userid,
                         date=self.controller.get_timestamp(),
                         clazz='package',
                         content_mimetype='application/x-advene-ruleset')
        v.title = _("Caption %s annotations") % self.get_title(at)

        # Build the ruleset
        r = RuleSet()
        catalog = self.controller.event_handler.catalog

        ra = catalog.get_action("AnnotationCaption")
        action = Action(registeredaction=ra, catalog=catalog)
        action.add_parameter('message', 'annotation/content/data')

        rule = Rule(name=_("Caption the annotation"),
                    event=Event("AnnotationBegin"),
                    condition=Condition(lhs='annotation/type/id',
                                        operator='equals',
                                        rhs='string:%s' % at.id),
                    action=action)
        r.add_rule(rule)

        v.content.data = r.xml_repr()

        p.views.append(v)
        self.controller.notify('ViewCreate', view=v)
        self.controller.activate_stbv(v)
        return True
Beispiel #5
0
 def add_action(self, widget, actionsbox):
     """Callback for the Add action button."""
     ra = self.catalog.get_action("Message")
     action = Action(registeredaction=ra, catalog=self.catalog)
     self.add_action_widget(action, actionsbox)
Beispiel #6
0
    def do_create_element(self):
        """Create the element according to the widget data.

        @return: the created element, None if an error occurred
        """
        id_ = unicode(self.dialog.id_entry.get_text())
        title_ = unicode(self.dialog.title_entry.get_text())
        # Check validity of id.
        if not self.is_valid_id(id_):
            dialog.message_dialog(
                _("The identifier %s is not valid.\nIt must be composed of non-accentuated alphabetic characters\nUnderscore is allowed."
                  ) % id_)
            return None

        if self.controller.package._idgenerator.exists(id_):
            dialog.message_dialog(
                _("The identifier %s is already defined.") % id_)
            return None
        else:
            self.controller.package._idgenerator.add(id_)

        if self.dialog.type_combo:
            t = self.dialog.type_combo.get_current_element()

        if self.type_ == Annotation:
            if isinstance(self.parent, AnnotationType):
                parent = self.parent.rootPackage
            else:
                parent = self.parent
            el = parent.createAnnotation(
                ident=id_,
                type=t,
                author=config.data.userid,
                date=self.get_date(),
                fragment=MillisecondFragment(
                    begin=0, duration=self.controller.player.stream_duration))
            if el.type._fieldnames:
                el.content.data = "\n".join(sorted(el.type._fieldnames))
            parent.annotations.append(el)
            self.controller.notify('AnnotationCreate', annotation=el)
        elif self.type_ == Relation:
            # Unused code: relations can not be created without annotations
            if isinstance(self.parent, RelationType):
                parent = self.parent.rootPackage
            else:
                parent = self.parent
            el = parent.createRelation(ident=id_,
                                       type=t,
                                       author=config.data.userid,
                                       date=self.get_date(),
                                       members=())
            parent.relations.append(el)
            self.controller.notify('RelationCreate', relation=el)
        elif self.type_ == Query:
            el = self.parent.createQuery(ident=id_)
            el.author = config.data.userid
            el.date = self.get_date()
            el.title = title_
            el.content.mimetype = t.id
            if t.id == 'application/x-advene-simplequery':
                # Create a basic query
                q = advene.rules.elements.SimpleQuery(sources=["here"])
                el.content.data = q.xml_repr()
                el.content.mimetype = t.id
            self.parent.queries.append(el)
            self.controller.notify('QueryCreate', query=el)
        elif self.type_ == View:
            el = self.parent.createView(
                ident=id_,
                author=config.data.userid,
                date=self.get_date(),
                clazz=self.parent.viewableClass,
                content_mimetype=t.id,
            )
            el.title = title_
            if t.id == 'application/x-advene-ruleset':
                # Create an empty ruleset to begin with
                r = RuleSet()

                # Create a new default Rule
                rule = SubviewList(name=_("Subviews"), elements=[])
                r.add_rule(rule)

                event = Event("AnnotationBegin")
                catalog = self.controller.event_handler.catalog
                ra = catalog.get_action("Message")
                action = Action(registeredaction=ra, catalog=catalog)
                for p in ra.parameters:
                    action.add_parameter(p, ra.defaults.get(p, ''))
                rule = Rule(name=_("Rule") + '1', event=event, action=action)
                r.add_rule(rule)

                el.content.data = r.xml_repr()

            self.parent.views.append(el)
            self.controller.notify('ViewCreate', view=el)
        elif self.type_ == Schema:
            el = self.parent.createSchema(ident=id_)
            el.author = config.data.userid
            el.date = self.get_date()
            el.title = title_
            self.parent.schemas.append(el)
            self.controller.notify('SchemaCreate', schema=el)
        elif self.type_ == AnnotationType:
            if not isinstance(self.parent, Schema):
                print "Error: bad invocation of CreateElementPopup"
                el = None
            else:
                el = self.parent.createAnnotationType(ident=id_)
                el.author = config.data.userid
                el.date = self.get_date()
                el.title = title_
                el.mimetype = t.id
                el.setMetaData(config.data.namespace, 'color',
                               self.parent.rootPackage._color_palette.next())
                el.setMetaData(config.data.namespace, 'item_color',
                               'here/tag_color')
            self.parent.annotationTypes.append(el)
            self.controller.notify('AnnotationTypeCreate', annotationtype=el)
        elif self.type_ == RelationType:
            if not isinstance(self.parent, Schema):
                print "Error: bad invocation of CreateElementPopup"
                el = None
            else:
                el = self.parent.createRelationType(ident=id_)
                el.author = config.data.userid
                el.date = self.get_date()
                el.title = title_
                el.mimetype = t.id
                el.setMetaData(config.data.namespace, 'color',
                               self.parent.rootPackage._color_palette.next())
                el.setMetaData(config.data.namespace, 'item_color',
                               'here/tag_color')
                # Create a generic binary relationType
                el.hackedMemberTypes = (u'', u'')
            self.parent.relationTypes.append(el)
            self.controller.notify('RelationTypeCreate', relationtype=el)
        elif self.type_ == Resources:
            # Create a new dir.
            # Parent should be a Resources
            self.parent[id_] = Resources.DIRECTORY_TYPE
            el = self.parent[id_]
            self.controller.notify('ResourceCreate', resource=el)
        elif self.type_ == ResourceData:
            # Create a new resource file
            self.parent[id_] = _("New resource data")
            el = self.parent[id_]
            self.controller.notify('ResourceCreate', resource=el)

        else:
            el = None
            print "Not implemented yet."
        return el