From 3ae1901757cbd69805f0cf37731d39b0fc090cb3 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Thu, 20 Dec 2018 22:59:01 +0300 Subject: [PATCH] simple implementation of backups removing --- app/ui/backup.py | 59 +++++++++++-- app/ui/backup_dialog.glade | 166 +++++++++++++++++++++++++++++++------ app/ui/main_window.glade | 2 +- 3 files changed, 194 insertions(+), 33 deletions(-) diff --git a/app/ui/backup.py b/app/ui/backup.py index 45ef8f37..8c1a1188 100644 --- a/app/ui/backup.py +++ b/app/ui/backup.py @@ -1,21 +1,29 @@ import os -from .uicommons import Gtk, UI_RESOURCES_PATH +from app.commons import run_idle +from app.ui.dialogs import show_dialog, DialogType +from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH class BackupDialog: def __init__(self, transient, backup_path): - handlers = {"on_extract": self.on_extract, "on_remove": self.on_remove} + handlers = {"on_extract": self.on_extract, + "on_remove": self.on_remove, + "on_view_popup_menu": self.on_view_popup_menu, + "on_info_bar_close": self.on_info_bar_close} builder = Gtk.Builder() builder.set_translation_domain("demon-editor") builder.add_from_file(UI_RESOURCES_PATH + "backup_dialog.glade") builder.connect_signals(handlers) + self._backup_path = backup_path self._dialog_window = builder.get_object("dialog_window") self._dialog_window.set_transient_for(transient) self._model = builder.get_object("main_list_store") - self._backup_path = backup_path + self._main_view = builder.get_object("main_view") + self._info_bar = builder.get_object("info_bar") + self._message_label = builder.get_object("message_label") self.init_data() def show(self): @@ -25,16 +33,55 @@ class BackupDialog: try: files = os.listdir(self._backup_path) except FileNotFoundError as e: - print(e) + self.show_info_message(str(e), Gtk.MessageType.ERROR) else: for file in filter(lambda x: x.endswith(".zip"), files): self._model.append((file.rstrip(".zip"), False)) def on_extract(self, item): - pass + model, paths = self._main_view.get_selection().get_selected_rows() + if not paths: + show_dialog(DialogType.ERROR, self._dialog_window, "No selected item!") + return + + if len(paths) > 1: + show_dialog(DialogType.ERROR, self._dialog_window, "Please, select only one item!") + return + + if show_dialog(DialogType.QUESTION, self._dialog_window) == Gtk.ResponseType.CANCEL: + return def on_remove(self, item): - pass + model, paths = self._main_view.get_selection().get_selected_rows() + if not paths: + show_dialog(DialogType.ERROR, self._dialog_window, "No selected item!") + return + + if show_dialog(DialogType.QUESTION, self._dialog_window) == Gtk.ResponseType.CANCEL: + return + + for path in paths: + itr = model.get_iter(path) + file_name = model.get_value(itr, 0) + try: + os.remove("{}{}{}".format(self._backup_path, file_name, ".zip")) + except FileNotFoundError as e: + self.show_info_message(str(e), Gtk.MessageType.ERROR) + else: + model.remove(model.get_iter(path)) + + def on_view_popup_menu(self, menu, event): + if event.get_event_type() == Gdk.EventType.BUTTON_PRESS and event.button == Gdk.BUTTON_SECONDARY: + menu.popup(None, None, None, None, event.button, event.time) + + @run_idle + def show_info_message(self, text, message_type): + self._info_bar.set_visible(True) + self._info_bar.set_message_type(message_type) + self._message_label.set_text(text) + + def on_info_bar_close(self, bar=None, resp=None): + self._info_bar.set_visible(False) if __name__ == "__main__": diff --git a/app/ui/backup_dialog.glade b/app/ui/backup_dialog.glade index ecacb3bf..4dc5a000 100644 --- a/app/ui/backup_dialog.glade +++ b/app/ui/backup_dialog.glade @@ -21,7 +21,7 @@ True False - Backup tool + Backups 2 True @@ -35,7 +35,7 @@ True False - extract-archive-symbolic + drive-harddisk-symbolic @@ -65,42 +65,156 @@ - - 480 + True - True - in + False + vertical - + + 480 True True - main_list_store - False - 0 - True - - - + in - - Backup - True - 0.5 - True - 0 - - - 10 + + True + True + main_list_store + False + 0 + True + + + + multiple + + + + + Backup + True + 0.5 + True + 0 + + + 10 + + + 0 + + - - 0 - + + True + True + 0 + + + + + False + True + + + + False + 6 + end + + + False + False + 0 + + + + + False + 16 + + + True + False + message + + + False + True + 0 + + + + + False + False + 0 + + + + + False + True + 2 + + + True + False + gtk-revert-to-saved + + + True + False + gtk-revert-to-saved + + + True + False + + + Restore bouquets + True + False + restore_popup_menu_item_image + False + + + + + + + Restore all + True + False + restore_popup_menu_item_image2 + False + + + + + + True + False + + + + + gtk-remove + True + False + True + True + + + + + diff --git a/app/ui/main_window.glade b/app/ui/main_window.glade index 962f4868..c7e1576c 100644 --- a/app/ui/main_window.glade +++ b/app/ui/main_window.glade @@ -1270,7 +1270,7 @@ Author: Dmitriy Yefremov True False - extract-archive-symbolic + drive-harddisk-symbolic