Example #1
0
    def cut_items(self, no_confirm=False):
        if core_api.block_databases():
            # get_tree_selections() arguments must be compatible with the
            # ones used in self.delete_items()
            selection = wxgui_api.get_tree_selections(self.filename,
                                                none=False, descendants=True)

            if selection:
                items = []

                for item in selection:
                    id_ = wxgui_api.get_tree_item_id(self.filename, item)

                    if not wxgui_api.close_editor(self.filename, id_,
                                    ask='quiet' if no_confirm else 'discard'):
                        core_api.release_databases()
                        return False

                    items.append(id_)

                copypaste_api.copy_items(self.filename, items)

                wxgui_api.delete_items(self.filename, items,
                                description='Cut {} items'.format(len(items)))
                wxgui_api.refresh_history(self.filename)
                cut_items_event.signal()

            core_api.release_databases()
Example #2
0
    def paste_items_as_siblings(self, no_confirm=False):
        if core_api.block_databases():
            if no_confirm or copypaste_api.can_paste_safely(self.filename) or \
                    msgboxes.unsafe_paste_confirm().ShowModal() == wx.ID_OK:
                # Do not use none=False in order to allow pasting in an empty
                # database
                selection = wxgui_api.get_tree_selections(self.filename,
                                                                    many=False)

                # If multiple items are selected, selection will be False
                if selection is not False:
                    if len(selection) > 0:
                        baseid = wxgui_api.get_tree_item_id(self.filename,
                                                                selection[0])

                        roots, ids = copypaste_api.paste_items_as_siblings(
                            self.filename, baseid, description='Paste items')
                    else:
                        roots, ids = copypaste_api.paste_items_as_children(
                                self.filename, 0, description='Paste items')

                    wxgui_api.refresh_history(self.filename)

                    items_pasted_event.signal(filename=self.filename,
                                                        roots=roots, ids=ids)

            core_api.release_databases()
Example #3
0
    def cut_items(self, no_confirm=False):
        if core_api.block_databases():
            # get_tree_selections() arguments must be compatible with the
            # ones used in self.delete_items()
            selection = wxgui_api.get_tree_selections(self.filename,
                                                      none=False,
                                                      descendants=True)

            if selection:
                items = []

                for item in selection:
                    id_ = wxgui_api.get_tree_item_id(self.filename, item)

                    if not wxgui_api.close_editor(
                            self.filename,
                            id_,
                            ask='quiet' if no_confirm else 'discard'):
                        core_api.release_databases()
                        return False

                    items.append(id_)

                copypaste_api.copy_items(self.filename, items)

                wxgui_api.delete_items(self.filename,
                                       items,
                                       description='Cut {} items'.format(
                                           len(items)))
                wxgui_api.refresh_history(self.filename)
                cut_items_event.signal()

            core_api.release_databases()
Example #4
0
    def paste_items_as_siblings(self, no_confirm=False):
        if core_api.block_databases():
            if no_confirm or copypaste_api.can_paste_safely(self.filename) or \
                    msgboxes.unsafe_paste_confirm().ShowModal() == wx.ID_OK:
                # Do not use none=False in order to allow pasting in an empty
                # database
                selection = wxgui_api.get_tree_selections(self.filename,
                                                          many=False)

                # If multiple items are selected, selection will be False
                if selection is not False:
                    if len(selection) > 0:
                        baseid = wxgui_api.get_tree_item_id(
                            self.filename, selection[0])

                        roots, ids = copypaste_api.paste_items_as_siblings(
                            self.filename, baseid, description='Paste items')
                    else:
                        roots, ids = copypaste_api.paste_items_as_children(
                            self.filename, 0, description='Paste items')

                    wxgui_api.refresh_history(self.filename)

                    items_pasted_event.signal(filename=self.filename,
                                              roots=roots,
                                              ids=ids)

            core_api.release_databases()
Example #5
0
    def populate_tree(self, event):
        if core_api.block_databases():
            filename = wxgui_api.get_selected_database_filename()

            # This method may be launched even if no database is open
            if filename:
                group = core_api.get_next_history_group(filename)
                description = 'Populate tree'
                i = 0

                while i < 10:
                    dbitems = core_api.get_items_ids(filename)

                    try:
                        itemid = random.choice(dbitems)
                    except IndexError:
                        # No items in the database yet
                        itemid = 0
                        mode = 'child'
                    else:
                        mode = random.choice(('child', 'sibling'))

                        # See the comment in wxgui.tree.expand_item_ancestors
                        #  for the reason why calling this method is necessary
                        wxgui_api.expand_item_ancestors(filename, itemid)


                    text = self._populate_tree_text()

                    id_ = self._populate_tree_item(mode, filename, itemid,
                                                    group, text, description)

                    # It should also be checked if the database supports
                    #  organism_basicrules (bug #330)
                    if organism_api and wxscheduler_basicrules_api and \
                            filename in \
                            organism_api.get_supported_open_databases():
                        self._populate_tree_rules(filename, id_, group,
                                                            description)

                    if links_api and wxlinks_api and len(dbitems) > 0 and \
                                    filename in \
                                    links_api.get_supported_open_databases():
                        self._populate_tree_link(filename, id_, dbitems, group,
                                                                description)

                    i += 1

                wxgui_api.refresh_history(filename)
            core_api.release_databases()
Example #6
0
    def populate_tree(self, event):
        if core_api.block_databases():
            filename = wxgui_api.get_selected_database_filename()

            # This method may be launched even if no database is open
            if filename:
                group = core_api.get_next_history_group(filename)
                description = 'Populate tree'
                i = 0

                while i < 10:
                    dbitems = core_api.get_items_ids(filename)

                    try:
                        itemid = random.choice(dbitems)
                    except IndexError:
                        # No items in the database yet
                        itemid = 0
                        mode = 'child'
                    else:
                        mode = random.choice(('child', 'sibling'))

                        # See the comment in wxgui.tree.expand_item_ancestors
                        #  for the reason why calling this method is necessary
                        wxgui_api.expand_item_ancestors(filename, itemid)

                    text = self._populate_tree_text()

                    id_ = self._populate_tree_item(mode, filename, itemid,
                                                   group, text, description)

                    # It should also be checked if the database supports
                    #  organism_basicrules (bug #330)
                    if organism_api and wxscheduler_basicrules_api and \
                            filename in \
                            organism_api.get_supported_open_databases():
                        self._populate_tree_rules(filename, id_, group,
                                                  description)

                    if links_api and wxlinks_api and len(dbitems) > 0 and \
                                    filename in \
                                    links_api.get_supported_open_databases():
                        self._populate_tree_link(filename, id_, dbitems, group,
                                                 description)

                    i += 1

                wxgui_api.refresh_history(filename)
            core_api.release_databases()
Example #7
0
    def paste_items_as_children(self, no_confirm=False):
        if core_api.block_databases():
            selection = wxgui_api.get_tree_selections(self.filename, none=False, many=False)

            if selection and (
                no_confirm
                or copypaste_api.can_paste_safely(self.filename)
                or msgboxes.unsafe_paste_confirm().ShowModal() == wx.ID_OK
            ):
                baseid = wxgui_api.get_tree_item_id(self.filename, selection[0])

                roots, ids = copypaste_api.paste_items_as_children(self.filename, baseid, description="Paste sub-items")

                wxgui_api.refresh_history(self.filename)

                items_pasted_event.signal(filename=self.filename, roots=roots, ids=ids)

            core_api.release_databases()
Example #8
0
    def paste_items_as_children(self, no_confirm=False):
        if core_api.block_databases():
            selection = wxgui_api.get_tree_selections(self.filename,
                                                      none=False,
                                                      many=False)

            if selection and (no_confirm
                              or copypaste_api.can_paste_safely(self.filename)
                              or msgboxes.unsafe_paste_confirm().ShowModal()
                              == wx.ID_OK):
                baseid = wxgui_api.get_tree_item_id(self.filename,
                                                    selection[0])

                roots, ids = copypaste_api.paste_items_as_children(
                    self.filename, baseid, description='Paste sub-items')

                wxgui_api.refresh_history(self.filename)

                items_pasted_event.signal(filename=self.filename,
                                          roots=roots,
                                          ids=ids)

            core_api.release_databases()