Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
    def link_to_selection(self):
        filename = wxgui_api.get_selected_database_filename()

        if filename:
            selection = wxgui_api.get_tree_selections(filename, none=False,
                                                                    many=False)

            if selection:
                self.target = wxgui_api.get_tree_item_id(filename,
                                                                selection[0])
Ejemplo n.º 6
0
    def link_to_selection(self):
        filename = wxgui_api.get_selected_database_filename()

        if filename:
            selection = wxgui_api.get_tree_selections(filename, none=False,
                                                                    many=False)

            if selection:
                self.target = wxgui_api.get_tree_item_id(filename,
                                                                selection[0])
Ejemplo n.º 7
0
    def copy_items(self):
        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:
                    items.append(wxgui_api.get_tree_item_id(self.filename, item))

                copypaste_api.copy_items(self.filename, items)

            core_api.release_databases()
Ejemplo n.º 8
0
    def copy_items(self):
        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:
                    items.append(
                        wxgui_api.get_tree_item_id(self.filename, item))

                copypaste_api.copy_items(self.filename, items)

            core_api.release_databases()
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
def _select_items(many):
    filename = wxgui_api.get_selected_database_filename()
    ids = core_api.get_items_ids(filename)

    if ids:
        w = 0 if many else 1
        modes = ((40, 80)[w] * ['select_one'] +
                 (10, 0)[w] * ['reselect_many'] +
                 (10, 0)[w] * ['select_some'] + (10, 0)[w] * ['select_all'] +
                 (20, 0)[w] * ['unselect_some'] +
                 (10, 20)[w] * ['unselect_all'])
        mode = random.choice(modes)

        if mode == 'unselect_some':
            selection = wxgui_api.get_tree_selections(filename)
            if selection:
                sids = [
                    wxgui_api.get_tree_item_id(filename, i) for i in selection
                ]
                remids = random.sample(ids, random.randint(1, len(ids)))
                wxgui_api.simulate_remove_items_from_selection(
                    filename, remids)
        else:
            if mode in ('select_one', 'reselect_many', 'unselect_all'):
                wxgui_api.simulate_unselect_all_items(filename)

            addids = {
                'select_one': (random.choice(ids), ),
                'reselect_many':
                random.sample(
                    ids, random.randint(2 if len(ids) > 1 else 1, len(ids))),
                'select_some':
                random.sample(ids, random.randint(1, len(ids))),
                'select_all':
                ids,
                'unselect_all': (),
            }

            wxgui_api.simulate_add_items_to_selection(filename, addids[mode])

    return wxgui_api.get_tree_selections(filename)
Ejemplo n.º 11
0
def _select_items(many):
    filename = wxgui_api.get_selected_database_filename()
    ids = core_api.get_items_ids(filename)

    if ids:
        w = 0 if many else 1
        modes = (
            (40, 80)[w] * ['select_one'] +
            (10, 0)[w] * ['reselect_many'] +
            (10, 0)[w] * ['select_some'] +
            (10, 0)[w] * ['select_all'] +
            (20, 0)[w] * ['unselect_some'] +
            (10, 20)[w] * ['unselect_all']
        )
        mode = random.choice(modes)

        if mode == 'unselect_some':
            selection = wxgui_api.get_tree_selections(filename)
            if selection:
                sids = [wxgui_api.get_tree_item_id(filename, i) for i in
                                                                    selection]
                remids = random.sample(ids, random.randint(1, len(ids)))
                wxgui_api.simulate_remove_items_from_selection(filename,
                                                                        remids)
        else:
            if mode in ('select_one', 'reselect_many', 'unselect_all'):
                wxgui_api.simulate_unselect_all_items(filename)

            addids = {
                'select_one': (random.choice(ids), ),
                'reselect_many': random.sample(ids, random.randint(
                                        2 if len(ids) > 1 else 1, len(ids))),
                'select_some': random.sample(ids, random.randint(1, len(ids))),
                'select_all': ids,
                'unselect_all': (),
            }

            wxgui_api.simulate_add_items_to_selection(filename, addids[mode])

    return wxgui_api.get_tree_selections(filename)
Ejemplo n.º 12
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()