Exemple #1
0
    def create_relation_popup(self, source, dest):
        # FIXME: Idem as above: should be factorized with the original of timeline.py
        # Popup a menu to propose the drop options
        menu = gtk.Menu()

        def create_relation(item, s, d, t):
            self.create_relation(s, d, t)
            return True

        def create_relation_type_and_relation(item, s, d):
            if self.controller.gui:
                sc = self.controller.gui.ask_for_schema(text=_(
                    "Select the schema where you want to\ncreate the new relation type."
                ),
                                                        create=True)
                if sc is None:
                    return None
                cr = self.controller.gui.create_element_popup(
                    type_=RelationType, parent=sc, controller=self.controller)
                rt = cr.popup(modal=True)
                self.create_relation(s, d, rt)
            return True

        relationtypes = helper.matching_relationtypes(self.controller.package,
                                                      source.type, dest.type)
        item = gtk.MenuItem(_("Create a relation"))
        menu.append(item)

        sm = gtk.Menu()
        for rt in relationtypes:
            sitem = gtk.MenuItem(self.controller.get_title(rt),
                                 use_underline=False)
            sitem.connect('activate', create_relation, source, dest, rt)
            sm.append(sitem)
        if True:
            # Propose to create a new one
            sitem = gtk.MenuItem(_("Create a new relation-type."),
                                 use_underline=False)
            sitem.connect('activate', create_relation_type_and_relation,
                          source, dest)
            sm.append(sitem)
        item.set_submenu(sm)

        menu.show_all()
        menu.popup(None, None, None, 0, gtk.get_current_event_time())
Exemple #2
0
    def create_relation_popup(self, source, dest):
        # FIXME: Idem as above: should be factorized with the original of timeline.py
        # Popup a menu to propose the drop options
        menu=gtk.Menu()

        def create_relation(item, s, d, t):
            self.create_relation(s, d, t)
            return True

        def create_relation_type_and_relation(item, s, d):
            if self.controller.gui:
                sc=self.controller.gui.ask_for_schema(text=_("Select the schema where you want to\ncreate the new relation type."), create=True)
                if sc is None:
                    return None
                cr=self.controller.gui.create_element_popup(type_=RelationType,
                                                            parent=sc,
                                                            controller=self.controller)
                rt=cr.popup(modal=True)
                self.create_relation(s, d, rt)
            return True

        relationtypes=helper.matching_relationtypes(self.controller.package,
                                                    source.type,
                                                    dest.type)
        item=gtk.MenuItem(_("Create a relation"))
        menu.append(item)

        sm=gtk.Menu()
        for rt in relationtypes:
            sitem=gtk.MenuItem(self.controller.get_title(rt), use_underline=False)
            sitem.connect('activate', create_relation, source, dest, rt)
            sm.append(sitem)
        if True:
            # Propose to create a new one
            sitem=gtk.MenuItem(_("Create a new relation-type."), use_underline=False)
            sitem.connect('activate', create_relation_type_and_relation, source, dest)
            sm.append(sitem)
        item.set_submenu(sm)

        menu.show_all()
        menu.popup(None, None, None, 0, gtk.get_current_event_time())
Exemple #3
0
    def move_or_copy_annotations(self, sources, dest, action=gtk.gdk.ACTION_ASK):
        """Display a popup menu to move or copy the sources annotation to the dest annotation type.

        If action is specified, then the popup menu will be shortcircuited.
        """
        # FIXME: this method should be factorized with the original
        # one (from timeline.py) and used in other views (finder...)
        if not sources:
            return True
        source=sources[0]

        def move_annotation(i, an, typ, position=None):
            if an.relations and an.type != typ:
                dialog.message_dialog(_("Cannot delete the annotation : it has relations."),
                                      icon=gtk.MESSAGE_WARNING)
                return True

            self.transmuted_annotation=self.controller.transmute_annotation(an,
                                                                            typ,
                                                                            delete=True)
            return self.transmuted_annotation

        def copy_annotation(i, an, typ, position=None, relationtype=None):
            self.transmuted_annotation=self.controller.transmute_annotation(an,
                                                                            typ,
                                                                            delete=False)
            if relationtype is not None:
                # Directly create a relation
                self.create_relation(an, self.transmuted_annotation, relationtype)
            return self.transmuted_annotation

        def copy_selection(i, sel, typ, delete=False):
            for an in sel:
                if an.typ != typ:
                    self.transmuted_annotation=self.controller.transmute_annotation(an,
                                                                                    typ,
                                                                                    delete=delete)
            return self.transmuted_annotation

        # If there are compatible relation-types, propose to directly create a relation
        relationtypes = helper.matching_relationtypes(self.controller.package,
                                                      source.type,
                                                      dest)

        if action == gtk.gdk.ACTION_COPY:
            # Direct copy
            if len(sources) > 1:
                if source.type == dest:
                    return True
                copy_selection(None, sources, dest)
            else:
                copy_annotation(None, source, dest)
            return True
        elif action == gtk.gdk.ACTION_MOVE:
            if len(sources) > 1:
                if source.type == dest:
                    return True
                copy_selection(None, sources, dest, delete=True)
            else:
                move_annotation(None, source, dest)
            return True

        # ACTION_ASK: Popup a menu to propose the drop options
        menu=gtk.Menu()

        dest_title=self.controller.get_title(dest)

        if len(sources) > 1:
            if source.type == dest:
                return True
            item=gtk.MenuItem(_("Duplicate selection to type %s") % dest_title, use_underline=False)
            item.connect('activate', copy_selection, sources, dest)
            menu.append(item)
            item=gtk.MenuItem(_("Move selection to type %s") % dest_title, use_underline=False)
            item.connect('activate', copy_selection, sources, dest, True)
            menu.append(item)

            menu.show_all()
            menu.popup(None, None, None, 0, gtk.get_current_event_time())
            return True

        if source.type != dest:
            item=gtk.MenuItem(_("Duplicate annotation to type %s") % dest_title, use_underline=False)
            item.connect('activate', copy_annotation, source, dest)
            menu.append(item)

            item=gtk.MenuItem(_("Move annotation to type %s") % dest_title, use_underline=False)
            item.connect('activate', move_annotation, source, dest)
            menu.append(item)
            if source.relations:
                item.set_sensitive(False)

        relationtypes=helper.matching_relationtypes(self.controller.package,
                                                    source.type,
                                                    dest)
        if relationtypes:
            if source.type != dest:
                item=gtk.MenuItem(_("Duplicate and create a relation"), use_underline=False)
                # build a submenu
                sm=gtk.Menu()
                for rt in relationtypes:
                    sitem=gtk.MenuItem(self.controller.get_title(rt), use_underline=False)
                    sitem.connect('activate', copy_annotation, source, dest, None, rt)
                    sm.append(sitem)
                menu.append(item)
                item.set_submenu(sm)

        menu.show_all()
        menu.popup(None, None, None, 0, gtk.get_current_event_time())
Exemple #4
0
    def move_or_copy_annotations(self,
                                 sources,
                                 dest,
                                 action=gtk.gdk.ACTION_ASK):
        """Display a popup menu to move or copy the sources annotation to the dest annotation type.

        If action is specified, then the popup menu will be shortcircuited.
        """
        # FIXME: this method should be factorized with the original
        # one (from timeline.py) and used in other views (finder...)
        if not sources:
            return True
        source = sources[0]

        def move_annotation(i, an, typ, position=None):
            if an.relations and an.type != typ:
                dialog.message_dialog(
                    _("Cannot delete the annotation : it has relations."),
                    icon=gtk.MESSAGE_WARNING)
                return True

            self.transmuted_annotation = self.controller.transmute_annotation(
                an, typ, delete=True)
            return self.transmuted_annotation

        def copy_annotation(i, an, typ, position=None, relationtype=None):
            self.transmuted_annotation = self.controller.transmute_annotation(
                an, typ, delete=False)
            if relationtype is not None:
                # Directly create a relation
                self.create_relation(an, self.transmuted_annotation,
                                     relationtype)
            return self.transmuted_annotation

        def copy_selection(i, sel, typ, delete=False):
            for an in sel:
                if an.typ != typ:
                    self.transmuted_annotation = self.controller.transmute_annotation(
                        an, typ, delete=delete)
            return self.transmuted_annotation

        # If there are compatible relation-types, propose to directly create a relation
        relationtypes = helper.matching_relationtypes(self.controller.package,
                                                      source.type, dest)

        if action == gtk.gdk.ACTION_COPY:
            # Direct copy
            if len(sources) > 1:
                if source.type == dest:
                    return True
                copy_selection(None, sources, dest)
            else:
                copy_annotation(None, source, dest)
            return True
        elif action == gtk.gdk.ACTION_MOVE:
            if len(sources) > 1:
                if source.type == dest:
                    return True
                copy_selection(None, sources, dest, delete=True)
            else:
                move_annotation(None, source, dest)
            return True

        # ACTION_ASK: Popup a menu to propose the drop options
        menu = gtk.Menu()

        dest_title = self.controller.get_title(dest)

        if len(sources) > 1:
            if source.type == dest:
                return True
            item = gtk.MenuItem(_("Duplicate selection to type %s") %
                                dest_title,
                                use_underline=False)
            item.connect('activate', copy_selection, sources, dest)
            menu.append(item)
            item = gtk.MenuItem(_("Move selection to type %s") % dest_title,
                                use_underline=False)
            item.connect('activate', copy_selection, sources, dest, True)
            menu.append(item)

            menu.show_all()
            menu.popup(None, None, None, 0, gtk.get_current_event_time())
            return True

        if source.type != dest:
            item = gtk.MenuItem(_("Duplicate annotation to type %s") %
                                dest_title,
                                use_underline=False)
            item.connect('activate', copy_annotation, source, dest)
            menu.append(item)

            item = gtk.MenuItem(_("Move annotation to type %s") % dest_title,
                                use_underline=False)
            item.connect('activate', move_annotation, source, dest)
            menu.append(item)
            if source.relations:
                item.set_sensitive(False)

        relationtypes = helper.matching_relationtypes(self.controller.package,
                                                      source.type, dest)
        if relationtypes:
            if source.type != dest:
                item = gtk.MenuItem(_("Duplicate and create a relation"),
                                    use_underline=False)
                # build a submenu
                sm = gtk.Menu()
                for rt in relationtypes:
                    sitem = gtk.MenuItem(self.controller.get_title(rt),
                                         use_underline=False)
                    sitem.connect('activate', copy_annotation, source, dest,
                                  None, rt)
                    sm.append(sitem)
                menu.append(item)
                item.set_submenu(sm)

        menu.show_all()
        menu.popup(None, None, None, 0, gtk.get_current_event_time())