Exemple #1
0
    def update_view(self):
        # Dict of errors indexed by annotation
        errors = {}
        def custom_data(a):
            if a is None:
                return (str, )
            else:
                return ("\n".join(errors.get(a, [])), )

        for at in self.controller.package.annotationTypes:
            completions = set(helper.get_type_predefined_completions(at))
            if completions:
                # There are completions. Check for every annotation if
                # they use a keyword not predefined.
                for a in at.annotations:
                    def add_error(msg):
                        errors.setdefault(a, []).append(msg)

                    keywords = a.content.parsed()
                    if len(keywords) == 0 and keywords.get_comment() == "" and len(a.content.data) > 0:
                        # There seems to be a content, but we could find no keyword and no comment.
                        add_error("Unparsable content")
                        continue
                    # Parse keywords to detect syntax errors
                    for s in keywords_to_struct(list(keywords), add_error):
                        pass

        self.table.set_elements(list(errors.keys()), custom_data)
        self.table.model.set_sort_column_id(COLUMN_TYPE, Gtk.SortType.ASCENDING)
    def get_completions(self, prefix, context=None, predefined_only=False):
        """Return the list of possible completions.

        element is used as contextual information to refine the
        search. If it is an Annotation, completions will be searched
        in the annotation of the same type. If it is a view,
        completions will be searched for in other views.

        If element is a Gtk.TextBuffer, completions will be searched
        in its content.
        """
        if isinstance(context, View):
            s=self.index['views']
            # FIXME: maybe add ids (annotation-types, relations-types, views)
        elif isinstance(context, Annotation):
            s = []
            if predefined_only or config.data.preferences['completion-predefined-only']:
                s = helper.get_type_predefined_completions(context.type)
            if not s:
                # No predefined completion anyway
                s = self.index.get(context.type.id, [])
        elif isinstance(context, Gtk.TextBuffer):
            # The replace clause transforms the timestamp placeholders into spaces.
            args = context.get_bounds() + (False, )
            s=set(self.get_words(str(context.get_slice(*args).replace('\xef\xbf\xbc', ' '))))
            s.update(self.index['views'])
        elif isinstance(context, Gtk.Entry):
            s = set(self.get_words(context.get_text()))
            s.update(self.index['views'])
        else:
            s=self.index['views']

        res=[ w for w in s if w.startswith(prefix) and w != prefix ]
        return res
Exemple #3
0
 def element_update(self, element):
     """Update the collection on element modification.
     """
     if isinstance(element, View):
         s=self.index['views']
         atid=None
         s.add(element.id)
     elif isinstance(element, (Annotation, Relation)):
         atid=element.type.id
         s=self.index.get(atid, set())
     elif isinstance(element, (AnnotationType, RelationType, Query)):
         self.index['views'].add(element.id)
         self.index.get(element.id, set()).update(helper.get_type_predefined_completions(element))
         return True
     else:
         # Should not happen.
         logger.error("Should not happen for %s", element)
         s = set()
         atid = None
         # Do not try to index non-defined views (like Resources)
         return True
     s.update(self.get_words(element.content.data))
     if atid:
         self.index[atid]=s
     return True
Exemple #4
0
    def get_completions(self, prefix, context=None, predefined_only=False):
        """Return the list of possible completions.

        element is used as contextual information to refine the
        search. If it is an Annotation, completions will be searched
        in the annotation of the same type. If it is a view,
        completions will be searched for in other views.

        If element is a Gtk.TextBuffer, completions will be searched
        in its content.
        """
        if isinstance(context, View):
            s=self.index['views']
            # FIXME: maybe add ids (annotation-types, relations-types, views)
        elif isinstance(context, Annotation):
            s = []
            if predefined_only or config.data.preferences['completion-predefined-only']:
                s = helper.get_type_predefined_completions(context.type)
            if not s:
                # No predefined completion anyway
                s = self.index.get(context.type.id, [])
        elif isinstance(context, Gtk.TextBuffer):
            # The replace clause transforms the timestamp placeholders into spaces.
            args = context.get_bounds() + (False, )
            s=set(self.get_words(str(context.get_slice(*args).replace('\xef\xbf\xbc', ' '))))
            s.update(self.index['views'])
        elif isinstance(context, Gtk.Entry):
            s = set(self.get_words(context.get_text()))
            s.update(self.index['views'])
        else:
            s=self.index['views']

        res=[ w for w in s if w.startswith(prefix) and w != prefix ]
        return res
    def update_model(self, package=None):
        # Dictionary indexed by annotation, where values are the
        # keyword diff
        diff_dict = {}

        def custom_data(a):
            if a is None:
                return (str, )
            else:
                return (diff_dict.get(a, ""), )

        for at in self.controller.package.annotationTypes:
            completions = set(helper.get_type_predefined_completions(at))
            if completions:
                # There are completions. Check for every annotation if
                # they use a keyword not predefined.
                for a in at.annotations:
                    kws = set(a.content.parsed())
                    diff = kws - completions
                    if diff:
                        # There are used keywords that are not completions
                        diff_dict[a] = ",".join(diff)
        self.table.set_elements(list(diff_dict.keys()), custom_data)
        self.table.model.set_sort_column_id(advene.gui.views.table.COLUMN_TYPE,
                                            Gtk.SortType.ASCENDING)
Exemple #6
0
 def element_update(self, element):
     """Update the collection on element modification.
     """
     if isinstance(element, View):
         s = self.index['views']
         atid = None
         s.add(element.id)
     elif isinstance(element, Annotation):
         atid = element.type.id
         s = self.index.get(atid, set())
     elif isinstance(element, (AnnotationType, RelationType, Query)):
         self.index['views'].add(element.id)
         self.index.get(element.id, set()).update(
             helper.get_type_predefined_completions(element))
         return True
     s.update(self.get_words(element.content.data))
     if atid:
         self.index[atid] = s
     return True
Exemple #7
0
    def tree_view_key_cb(self, widget=None, event=None):
        if event.keyval == Gdk.KEY_space:
            # Space: goto annotation
            ann = self.get_selected_node ()
            if ann is not None:
                self.controller.update_status (status="seek", position=ann.fragment.begin)
                self.controller.gui.set_current_annotation(ann)
                return True
        elif event.keyval == Gdk.KEY_Return and event.get_state() & Gdk.ModifierType.CONTROL_MASK:
            # Control-return: edit annotation
            ann = self.get_selected_node ()
            if ann is not None:
                self.controller.gui.edit_element(ann)
                return True
        elif event.keyval == Gdk.KEY_less and event.get_state() & Gdk.ModifierType.CONTROL_MASK:
            # Control-< : set begin time
            self.set_time('begin')
            return True
        elif event.keyval == Gdk.KEY_greater and event.get_state() & Gdk.ModifierType.CONTROL_MASK:
            # Control-> : set end time
            self.set_time('end')
            return True
        elif event.keyval in (Gdk.KEY_1,
                              Gdk.KEY_2,
                              Gdk.KEY_3,
                              Gdk.KEY_4,
                              Gdk.KEY_5,
                              Gdk.KEY_6,
                              Gdk.KEY_7,
                              Gdk.KEY_8,
                              Gdk.KEY_9):
            ann, path = self.get_selected_node(with_path=True)
            if  helper.get_type_predefined_completions(ann.type):
                # Shortcut for 1 key edition
                index = event.keyval - 48 - 1
                ret = self.controller.quick_completion_fill_annotation(ann, index)
                if ret:
                    self.last_edited_path = path
                # Gtk.TreePath.new_from_string(path_string)
                return ret
            return False

        return False
Exemple #8
0
    def tree_view_key_cb(self, widget=None, event=None):
        if event.keyval == Gdk.KEY_space:
            # Space: goto annotation
            ann = self.get_selected_node()
            if ann is not None:
                self.controller.update_status(status="seek",
                                              position=ann.fragment.begin)
                self.controller.gui.set_current_annotation(ann)
                return True
        elif event.keyval == Gdk.KEY_Return and event.get_state(
        ) & Gdk.ModifierType.CONTROL_MASK:
            # Control-return: edit annotation
            ann = self.get_selected_node()
            if ann is not None:
                self.controller.gui.edit_element(ann)
                return True
        elif event.keyval == Gdk.KEY_less and event.get_state(
        ) & Gdk.ModifierType.CONTROL_MASK:
            # Control-< : set begin time
            self.set_time('begin')
            return True
        elif event.keyval == Gdk.KEY_greater and event.get_state(
        ) & Gdk.ModifierType.CONTROL_MASK:
            # Control-> : set end time
            self.set_time('end')
            return True
        elif event.keyval in (Gdk.KEY_1, Gdk.KEY_2, Gdk.KEY_3, Gdk.KEY_4,
                              Gdk.KEY_5, Gdk.KEY_6, Gdk.KEY_7, Gdk.KEY_8,
                              Gdk.KEY_9):
            ann, path = self.get_selected_node(with_path=True)
            if helper.get_type_predefined_completions(ann.type):
                # Shortcut for 1 key edition
                index = event.keyval - 48 - 1
                ret = self.controller.quick_completion_fill_annotation(
                    ann, index)
                if ret:
                    self.last_edited_path = path
                # Gtk.TreePath.new_from_string(path_string)
                return ret
            return False

        return False
    def initialize(self):
        """Initialize the indexer on package load.
        """
        s=self.index['views']
        for v in self.package.views:
            s.update(self.get_words(v.content.data))
        s.update([ at.id for at in self.package.annotationTypes ])
        s.update([ rt.id for rt in self.package.relationTypes ])
        s.update([ q.id for q in self.package.queries ])
        s.update([ v.id for v in self.package.views ])

        for at in self.package.annotationTypes:
            s=self.index.get(at.id, set())

            s.update(helper.get_type_predefined_completions(at))
            for a in at.annotations:
                s.update(self.get_words(a.content.data))

            self.index[at.id]=s
        return True
Exemple #10
0
    def initialize(self):
        """Initialize the indexer on package load.
        """
        s=self.index['views']
        for v in self.package.views:
            s.update(self.get_words(v.content.data))
        s.update([ at.id for at in self.package.annotationTypes ])
        s.update([ rt.id for rt in self.package.relationTypes ])
        s.update([ q.id for q in self.package.queries ])
        s.update([ v.id for v in self.package.views ])

        for at in self.package.annotationTypes:
            s=self.index.get(at.id, set())

            s.update(helper.get_type_predefined_completions(at))
            for a in at.annotations:
                s.update(self.get_words(a.content.data))

            self.index[at.id]=s
        return True
Exemple #11
0
    def update_model(self, package=None):
        # Dictionary indexed by annotation, where values are the
        # keyword diff
        diff_dict = {}
        def custom_data(a):
            if a is None:
                return (str, )
            else:
                return (diff_dict.get(a, ""), )

        for at in self.controller.package.annotationTypes:
            completions = set(helper.get_type_predefined_completions(at))
            if completions:
                # There are completions. Check for every annotation if
                # they use a keyword not predefined.
                for a in at.annotations:
                    kws = set(a.content.parsed())
                    diff = kws - completions
                    if diff:
                        # There are used keywords that are not completions
                        diff_dict[a] = ",".join(diff)
        self.table.set_elements(list(diff_dict.keys()), custom_data)
        self.table.model.set_sort_column_id(advene.gui.views.table.COLUMN_TYPE, Gtk.SortType.ASCENDING)
Exemple #12
0
 def element_update(self, element):
     """Update the collection on element modification.
     """
     if isinstance(element, View):
         s=self.index['views']
         atid=None
         s.add(element.id)
     elif isinstance(element, (Annotation, Relation)):
         atid=element.type.id
         s=self.index.get(atid, set())
     elif isinstance(element, (AnnotationType, RelationType, Query)):
         self.index['views'].add(element.id)
         self.index.get(element.id, set()).update(helper.get_type_predefined_completions(element))
         return True
     else:
         # Should not happen.
         logger.error("Should not happen for %s", element)
         s = set()
         atid = None
     s.update(self.get_words(element.content.data))
     if atid:
         self.index[atid]=s
     return True