def update_value(self): if not self.editable: return False self.editevent.update_value() for w in self.editactionlist: w.update_value() for w in self.editconditionlist: w.update_value() self.model.name = self.name_entry.get_text() self.model.event = Event(self.editevent.current_event) if self.editconditionlist: self.model.condition = ConditionList( [e.model for e in self.editconditionlist]) else: self.model.condition = self.model.default_condition self.model.condition.composition = self.composition # Rebuild actionlist from editactionlist self.model.action = ActionList([e.model for e in self.editactionlist]) return True
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
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
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
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