Exemple #1
0
class CompletionChecker(FeatureChecker):
    name = "Completions"
    description = _("For every annotation type that has predefined keywords, this table displays the annotations that contain unspecified keywords.")
    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller, custom_data=lambda a: (str, ))
        column = self.table.columns['custom0']
        column.props.title = _("Undef. keywords")
        return self.table.widget

    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 #2
0
class CompletionChecker(FeatureChecker):
    name = "Completions"
    description = _("For every annotation type that has predefined keywords, this table displays the annotations that contain unspecified keywords.")
    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller, custom_data=lambda a: (str, ))
        column = self.table.columns['custom0']
        column.props.title = _("Undef. keywords")
        return self.table.widget

    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 #3
0
 def build_widget(self):
     self.table = AnnotationTable(controller=self.controller)
     # Hijack Content column
     self.table.columns['content'].add_attribute(
         self.table.columns['content'].get_cells()[0], 'text',
         advene.gui.views.table.COLUMN_CUSTOM_FIRST)
     self.table.columns['content'].props.title = _("Undef. keywords")
     return self.table.widget
Exemple #4
0
class EmptyContentChecker(FeatureChecker):
    name = "Empty Content"
    description = _("This table presents the annotations that have an empty content.")
    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller)
        return self.table.widget

    def update_model(self, package=None):
        self.table.set_elements([ a for a in self.controller.package.annotations
                                  if not a.content.data ])
Exemple #5
0
class EmptyContentChecker(FeatureChecker):
    name = "EmptyContent"
    description = _("This table presents the annotations that have an empty content.")
    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller)
        return self.table.widget

    def update_model(self, package=None):
        self.table.set_elements([ a for a in self.controller.package.annotations
                                  if not a.content.data ])
Exemple #6
0
 def build_widget(self):
     self.table = AnnotationTable(controller=self.controller)
     # Set colors
     self.table.columns['begin'].add_attribute(self.table.columns['begin'].get_cells()[0],
                                               'cell-background',
                                               advene.gui.views.table.COLUMN_CUSTOM_FIRST)
     self.table.columns['end'].add_attribute(self.table.columns['end'].get_cells()[0],
                                             'cell-background',
                                             advene.gui.views.table.COLUMN_CUSTOM_FIRST + 1)
     return self.table.widget
Exemple #7
0
class DurationChecker(FeatureChecker):
    name = "Duration"
    description = _("This table presents the annotations that have a null duration.")
    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller)
        return self.table.widget

    def update_model(self, package=None):
        self.table.set_elements([ a for a in self.controller.package.annotations
                                  if not a.fragment.duration ])
Exemple #8
0
class DurationChecker(FeatureChecker):
    name = "Duration"
    description = _("This table presents the annotations that have a null duration.")
    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller)
        return self.table.widget

    def update_model(self, package=None):
        self.table.set_elements([ a for a in self.controller.package.annotations
                                  if not a.fragment.duration ])
class OverlappingChecker(FeatureChecker):
    name = "Overlapping"
    description = _(
        "This table presents for each type annotations that are overlapping.")

    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller)
        # Set colors
        self.table.columns['begin'].add_attribute(
            self.table.columns['begin'].get_cells()[0], 'cell-background',
            advene.gui.views.table.COLUMN_CUSTOM_FIRST)
        self.table.columns['end'].add_attribute(
            self.table.columns['end'].get_cells()[0], 'cell-background',
            advene.gui.views.table.COLUMN_CUSTOM_FIRST + 1)
        return self.table.widget

    def overlapping_annotations(self):
        """Return a list of overlapping annotations for each annotation type.

        It returns 2 sets of elements: the ones which have a potentialy
        bogus begin time, and the ones with a potentialy bogus end
        time.
        """
        begins = set()
        ends = set()
        for at in self.controller.package.annotationTypes:
            for a, b in zip(at.annotations, at.annotations[1:]):
                if a.fragment.end > b.fragment.begin:
                    ends.add(a)
                    begins.add(b)
        return begins, ends

    def update_model(self, package=None):
        begins, ends = self.overlapping_annotations()
        overlap = list(begins.union(ends))

        def custom_data(b):
            if b is None:
                return (str, str)
            begin, end = None, None
            if b in begins:
                begin = "#ff6666"
            if b in ends:
                end = "#ff6666"
            return (begin, end)

        self.table.set_elements(overlap, custom_data)
        self.table.model.set_sort_column_id(advene.gui.views.table.COLUMN_TYPE,
                                            Gtk.SortType.ASCENDING)
Exemple #10
0
class TypeChecker(FeatureChecker):
    name = "Type"
    description = _("This table presents annotation whose content types does not match their type's content-type")
    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller, custom_data=lambda a: (str, str))
        self.table.columns['custom0'].props.title = 'content mimetype'
        self.table.columns['custom1'].props.title = 'type mimetype'
        return self.table.widget

    def update_model(self, package=None):
        def custom_data(a):
            if a is None:
                return (str, str)
            else:
                return (a.content.mimetype, a.type.mimetype)
        self.table.set_elements([ a for a in self.controller.package.annotations
                                  if a.content.mimetype != a.type.mimetype ], custom_data)
Exemple #11
0
class OverlappingChecker(FeatureChecker):
    name = "Overlapping"
    description = _("This table presents for each type annotations that are overlapping.")
    def build_widget(self):
        self.table = AnnotationTable(controller=self.controller)
        # Set colors
        self.table.columns['begin'].add_attribute(self.table.columns['begin'].get_cells()[0],
                                             'cell-background',
                                             advene.gui.views.table.COLUMN_CUSTOM_FIRST)
        self.table.columns['end'].add_attribute(self.table.columns['end'].get_cells()[0],
                                           'cell-background',
                                           advene.gui.views.table.COLUMN_CUSTOM_FIRST + 1)
        return self.table.widget

    def overlapping_annotations(self):
        """Return a list of overlapping annotations for each annotation type.

        It returns 2 sets of elements: the ones which have a potentialy
        bogus begin time, and the ones with a potentialy bogus end
        time.
        """
        begins = set()
        ends = set()
        for at in self.controller.package.annotationTypes:
            for a, b in zip(at.annotations, at.annotations[1:]):
                if a.fragment.end > b.fragment.begin:
                    ends.add(a)
                    begins.add(b)
        return begins, ends

    def update_model(self, package=None):
        begins, ends = self.overlapping_annotations()
        overlap = list(begins.union(ends))

        def custom_data(b):
            if b is None:
                return (str, str)
            begin, end = None, None
            if b in begins:
                begin = "#ff6666"
            if b in ends:
                end = "#ff6666"
            return (begin, end)
        self.table.set_elements(overlap, custom_data)
        self.table.model.set_sort_column_id(advene.gui.views.table.COLUMN_TYPE, Gtk.SortType.ASCENDING)
Exemple #12
0
 def build_widget(self):
     self.table = AnnotationTable(controller=self.controller)
     # Set colors
     self.table.columns['begin'].add_attribute(self.table.columns['begin'].get_cells()[0],
                                          'cell-background',
                                          advene.gui.views.table.COLUMN_CUSTOM_FIRST)
     self.table.columns['end'].add_attribute(self.table.columns['end'].get_cells()[0],
                                        'cell-background',
                                        advene.gui.views.table.COLUMN_CUSTOM_FIRST + 1)
     return self.table.widget
Exemple #13
0
    def build_widget(self):
        mainbox = gtk.VBox()

        mainbox.pack_start(gtk.Label(_("List of possible issues in the current package")), expand=False)

        notebook=gtk.Notebook()
        notebook.set_tab_pos(gtk.POS_TOP)
        notebook.popup_disable()
        mainbox.add(notebook)

        table=AnnotationTable(controller=self.controller)
        self.overlap_table = table

        # Set colors
        table.columns['begin'].add_attribute(table.columns['begin'].get_cell_renderers()[0],
                                             'cell-background',
                                             advene.gui.views.table.COLUMN_CUSTOM_FIRST)
        table.columns['end'].add_attribute(table.columns['end'].get_cell_renderers()[0],
                                           'cell-background',
                                           advene.gui.views.table.COLUMN_CUSTOM_FIRST + 1)

        notebook.append_page(table.widget, gtk.Label(_("Overlapping")))

        return mainbox
Exemple #14
0
 def build_widget(self):
     self.table = AnnotationTable(controller=self.controller)
     return self.table.widget
Exemple #15
0
 def build_widget(self):
     self.table = AnnotationTable(controller=self.controller, custom_data=lambda a: (str, ))
     column = self.table.columns['custom0']
     column.props.title = _("Undef. keywords")
     return self.table.widget
Exemple #16
0
    def build_widget(self):
        v=Gtk.VBox()

        tb=Gtk.Toolbar()
        tb.set_style(Gtk.ToolbarStyle.ICONS)
        v.pack_start(tb, False, True, 0)

        top_box=Gtk.HBox()
        v.pack_start(top_box, False, True, 0)

        if hasattr(self.query, 'container') and self.query.container.id == '_interactive':
            b=Gtk.Button(_("Edit query again"))
            b.connect('clicked', self.edit_query)
            top_box.pack_start(b, False, True, 0)
        elif isinstance(self.query, SimpleQuery):
            b=Gtk.Button(_("Edit query"))
            b.connect('clicked', lambda b: self.controller.gui.edit_element(self.query))
            top_box.pack_start(b, False, True, 0)
        elif isinstance(self.query, Quicksearch):
            e=Gtk.Entry()
            e.set_text(self.query.searched)
            e.set_width_chars(12)
            e.connect('activate', self.redo_quicksearch, e)
            b=get_small_stock_button(Gtk.STOCK_FIND, self.redo_quicksearch, e)
            e.set_tooltip_text(_('String to search'))
            b.set_tooltip_text(_('Search again'))
            top_box.pack_start(e, False, True, 0)
            top_box.pack_start(b, False, True, 0)

        # Present choices to display the result
        if not self.result:
            v.add(Gtk.Label(label=_("Empty result")))
        elif isinstance(self.result, (list, tuple, AbstractBundle)):
            # Check if there are annotations
            l=[ a for a in self.result if isinstance(a, Annotation) ]
            cr=len(self.result)
            cl=len(l)

            if cr == cl:
                t=_("Result is a list of %d annotations.") % cr
            else:
                t=_("Result is a list of  %(number)d elements with %(elements)s.") % {
                    'elements': helper.format_element_name("annotation", len(l)),
                    'number': len(self.result)}

            label=Gtk.Label(label=t)
            label.set_ellipsize(Pango.EllipsizeMode.END)
            label.set_line_wrap(True)
            top_box.add(label)

            def toggle_highlight(b, annotation_list):
                if not hasattr(b, 'highlight') or b.highlight:
                    event="AnnotationActivate"
                    label= _("Unhighlight annotations")
                    b.highlight=False
                else:
                    event="AnnotationDeactivate"
                    label=_("Highlight annotations")
                    b.highlight=True
                b.set_tooltip_text(label)
                for a in annotation_list:
                    self.controller.notify(event, annotation=a)
                return True

            if l:
                # Instanciate a table view
                table=AnnotationTable(controller=self.controller, elements=l)

                if cr == cl:
                    # Only annotations.
                    v.add(table.widget)
                else:
                    # Mixed annotations + other elements
                    notebook=Gtk.Notebook()
                    notebook.set_tab_pos(Gtk.PositionType.TOP)
                    notebook.popup_disable()
                    v.add(notebook)

                    notebook.append_page(table.widget, Gtk.Label(label=_("Annotations")))

                    gtable=GenericTable(controller=self.controller, elements=[ e
                                                                               for e in self.result
                                                                               if not isinstance(e, Annotation) ])
                    notebook.append_page(gtable.widget, Gtk.Label(label=_("Other elements")))


                for (icon, tip, action) in (
                        ('timeline.png' , _("Display annotations in timeline"), lambda b: self.open_in_timeline(l)),
                        ('transcription.png', _("Display annotations as transcription"), lambda b:
                         self.controller.gui.open_adhoc_view('transcription',
                                                             label=self._label,
                                                             destination=self._destination,
                                                             elements=l)),
                        ('highlight.png', _("Highlight annotations"), lambda b: toggle_highlight(b, l)),
                        (Gtk.STOCK_CONVERT, _("Export table"), lambda b: table.csv_export()),
                        (Gtk.STOCK_NEW, _("Create annotations from the result"), self.create_annotations),
                        ('montage.png', _("Define a montage with the result"), self.create_montage),
                        ('comment.png', _("Create a comment view with the result"), self.create_comment),
                        (Gtk.STOCK_FIND_AND_REPLACE, _("Search and replace strings in the annotations content"), self.search_replace),
                ):
                    if icon.endswith('.png'):
                        ti=get_pixmap_toolbutton(icon)
                    else:
                        ti=Gtk.ToolButton(stock_id=icon)
                    ti.connect('clicked', action)
                    ti.set_tooltip_text(tip)
                    tb.insert(ti, -1)

                self.table=table
            else:
                # Only Instanciate a generic table view
                gtable=GenericTable(controller=self.controller, elements=self.result)
                v.add(gtable.widget)

                ti=Gtk.ToolButton(Gtk.STOCK_CONVERT)
                ti.connect('clicked', lambda b: gtable.csv_export())
                ti.set_tooltip_text(_("Export table"))
                tb.insert(ti, -1)
                self.table=gtable


            ti=get_pixmap_toolbutton('editaccumulator.png',
                                     lambda b: self.open_in_edit_accumulator(self.table.get_elements()))
            ti.set_tooltip_text(_("Edit elements"))
            tb.insert(ti, -1)

            if config.data.preferences['expert-mode']:
                ti=get_pixmap_toolbutton('python.png',
                                         lambda b: self.open_in_evaluator(self.table.get_elements()))
                ti.set_tooltip_text(_("Open in python evaluator"))
                tb.insert(ti, -1)
        else:
            v.add(Gtk.Label(label=_("Result:\n%s") % str(self.result)))
        v.show_all()
        return v
Exemple #17
0
 def build_widget(self):
     self.table = AnnotationTable(controller=self.controller, custom_data=lambda a: (str, str))
     self.table.columns['custom0'].props.title = 'content mimetype'
     self.table.columns['custom1'].props.title = 'type mimetype'
     return self.table.widget
Exemple #18
0
 def build_widget(self):
     self.table = AnnotationTable(controller=self.controller, custom_data=lambda a: (str, ))
     column = self.table.columns['custom0']
     column.props.title = _("Undef. keywords")
     return self.table.widget
Exemple #19
0
    def build_widget(self):
        v=Gtk.VBox()

        tb=Gtk.Toolbar()
        tb.set_style(Gtk.ToolbarStyle.ICONS)
        v.pack_start(tb, False, True, 0)

        top_box=Gtk.HBox()
        v.pack_start(top_box, False, True, 0)

        if hasattr(self.query, 'container') and self.query.container.id == '_interactive':
            b=Gtk.Button(_("Edit query again"))
            b.connect('clicked', self.edit_query)
            top_box.pack_start(b, False, True, 0)
        elif isinstance(self.query, SimpleQuery):
            b=Gtk.Button(_("Edit query"))
            b.connect('clicked', lambda b: self.controller.gui.edit_element(self.query))
            top_box.pack_start(b, False, True, 0)
        elif isinstance(self.query, Quicksearch):
            e=Gtk.Entry()
            e.set_text(self.query.searched)
            e.set_width_chars(12)
            e.connect('activate', self.redo_quicksearch, e)
            b=get_small_stock_button(Gtk.STOCK_FIND, self.redo_quicksearch, e)
            e.set_tooltip_text(_('String to search'))
            b.set_tooltip_text(_('Search again'))
            top_box.pack_start(e, False, True, 0)
            top_box.pack_start(b, False, True, 0)

        # Present choices to display the result
        if not self.result:
            v.add(Gtk.Label(label=_("Empty result")))
        elif (isinstance(self.result, list) or isinstance(self.result, tuple)
            or isinstance(self.result, AbstractBundle)):
            # Check if there are annotations
            l=[ a for a in self.result if isinstance(a, Annotation) ]
            cr=len(self.result)
            cl=len(l)

            if cr == cl:
                t=_("Result is a list of %d annotations.") % cr
            else:
                t=_("Result is a list of  %(number)d elements with %(elements)s.") % {
                    'elements': helper.format_element_name("annotation", len(l)),
                    'number': len(self.result)}

            label=Gtk.Label(label=t)
            label.set_ellipsize(Pango.EllipsizeMode.END)
            label.set_line_wrap(True)
            top_box.add(label)

            def toggle_highlight(b, annotation_list):
                if not hasattr(b, 'highlight') or b.highlight:
                    event="AnnotationActivate"
                    label= _("Unhighlight annotations")
                    b.highlight=False
                else:
                    event="AnnotationDeactivate"
                    label=_("Highlight annotations")
                    b.highlight=True
                b.set_tooltip_text(label)
                for a in annotation_list:
                    self.controller.notify(event, annotation=a)
                return True

            if l:
                # Instanciate a table view
                table=AnnotationTable(controller=self.controller, elements=l)

                if cr == cl:
                    # Only annotations.
                    v.add(table.widget)
                else:
                    # Mixed annotations + other elements
                    notebook=Gtk.Notebook()
                    notebook.set_tab_pos(Gtk.PositionType.TOP)
                    notebook.popup_disable()
                    v.add(notebook)

                    notebook.append_page(table.widget, Gtk.Label(label=_("Annotations")))

                    gtable=GenericTable(controller=self.controller, elements=[ e
                                                                               for e in self.result
                                                                               if not isinstance(e, Annotation) ]
                                                                               )
                    notebook.append_page(gtable.widget, Gtk.Label(label=_("Other elements")))


                for (icon, tip, action) in (
                    ('timeline.png' , _("Display annotations in timeline"), lambda b: self.open_in_timeline(l)),
                    ('transcription.png', _("Display annotations as transcription"), lambda b:
                         self.controller.gui.open_adhoc_view('transcription',
                                                             label=self._label,
                                                             destination=self._destination,
                                                             elements=l)),
                    ('highlight.png', _("Highlight annotations"), lambda b: toggle_highlight(b, l)),
                    (Gtk.STOCK_CONVERT, _("Export table"), lambda b: table.csv_export()),
                    (Gtk.STOCK_NEW, _("Create annotations from the result"), self.create_annotations),
                    ('montage.png', _("Define a montage with the result"), self.create_montage),
                    ('comment.png', _("Create a comment view with the result"), self.create_comment),
                    (Gtk.STOCK_FIND_AND_REPLACE, _("Search and replace strings in the annotations content"), self.search_replace),
                    ):
                    if icon.endswith('.png'):
                        ti=get_pixmap_toolbutton(icon)
                    else:
                        ti=Gtk.ToolButton(stock_id=icon)
                    ti.connect('clicked', action)
                    ti.set_tooltip_text(tip)
                    tb.insert(ti, -1)

                self.table=table
            else:
                # Only Instanciate a generic table view
                gtable=GenericTable(controller=self.controller, elements=self.result)
                v.add(gtable.widget)

                ti=Gtk.ToolButton(Gtk.STOCK_CONVERT)
                ti.connect('clicked', lambda b: gtable.csv_export())
                ti.set_tooltip_text(_("Export table"))
                tb.insert(ti, -1)
                self.table=gtable


            ti=get_pixmap_toolbutton('editaccumulator.png',
                                     lambda b: self.open_in_edit_accumulator(self.table.get_elements()))
            ti.set_tooltip_text(_("Edit elements"))
            tb.insert(ti, -1)

            if config.data.preferences['expert-mode']:
                ti=get_pixmap_toolbutton('python.png',
                                         lambda b: self.open_in_evaluator(self.table.get_elements()))
                ti.set_tooltip_text(_("Open in python evaluator"))
                tb.insert(ti, -1)
        else:
            v.add(Gtk.Label(label=_("Result:\n%s") % str(self.result)))
        v.show_all()
        return v
Exemple #20
0
 def build_widget(self):
     self.table = AnnotationTable(controller=self.controller)
     return self.table.widget