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(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.create_view(id=ident, mimetype='application/x-advene-ruleset') v.title=_("Caption %s annotations") % self.controller.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 get_view (self, compact=False): """Generate a view widget to edit the ruleset.""" rs=RuleSet() f=self.element.as_file rs.from_xml(f, catalog=self.controller.event_handler.catalog) f.close() self.edit=EditRuleSet(rs, catalog=self.controller.event_handler.catalog, editable=self.editable, controller=self.controller) self.view = self.edit.get_packed_widget() scroll_win = gtk.ScrolledWindow () scroll_win.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroll_win.add_with_viewport(self.view) return scroll_win
def get_view (self, compact=False): """Generate a view widget to edit the ruleset.""" rs=RuleSet() rs.from_xml(self.element.stream, catalog=self.controller.event_handler.catalog) self.edit=EditRuleSet(rs, catalog=self.controller.event_handler.catalog, editable=self.editable, controller=self.controller) self.view = self.edit.get_packed_widget() scroll_win = Gtk.ScrolledWindow () scroll_win.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scroll_win.add_with_viewport(self.view) return scroll_win
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 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 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
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
def do_create_element(self): """Create the element according to the widget data. @return: the created element, None if an error occurred """ id_ = self.dialog.id_entry.get_text() title_ = 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.controller.package else: parent=self.parent el=parent.create_annotation( id=id_, type=t, media=self.controller.current_media, begin=0, end=self.controller.player.stream_duration) if el.type._fieldnames: el.content.data="\n".join( "%s=" % f for f in sorted(el.type._fieldnames) ) self.controller.notify('AnnotationCreate', annotation=el) elif self.type_ == Query: el=self.parent.create_query(id=id_, mimetype=t.id) el.title=title_ if t.id == 'application/x-advene-simplequery': # Create a basic query q=SimpleQuery(source="here") el.content.data=q.xml_repr() self.controller.notify('QueryCreate', query=el) elif self.type_ == View: el=self.parent.create_view(id=id_, 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.controller.notify('ViewCreate', view=el) elif self.type_ == Schema: el=self.parent.create_schema(id=id_) el.title=title_ 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.controller.package.create_annotation_type(id=id_) el.title=title_ el.mimetype=t.id el.color=self.controller.package._color_palette.next() el.element_color='here/tag_color' 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.controller.package.create_relation_type(id=id_) el.title=title_ el.mimetype=t.id el.color=self.controller.package._color_palette.next() el.element_color='here/tag_color' self.controller.notify('RelationTypeCreate', relationtype=el) elif self.type_ == Resource: # Create a new resource file # FIXME: to implement 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