From 3636da60d6ea5470ddb55edbf64716acc2006ecb Mon Sep 17 00:00:00 2001 From: DYefremov Date: Wed, 8 May 2019 23:05:32 +0300 Subject: [PATCH] input dialog refactoring --- app/ui/dialogs.glade | 78 ---------------------------------- app/ui/dialogs.py | 99 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 80 deletions(-) diff --git a/app/ui/dialogs.glade b/app/ui/dialogs.glade index aa063d46..e675b23c 100644 --- a/app/ui/dialogs.glade +++ b/app/ui/dialogs.glade @@ -110,84 +110,6 @@ Author: Dmitriy Yefremov - - 320 - False - - dialog - - - - - - False - vertical - 2 - - - False - end - - - gtk-undo - True - True - True - True - - - True - True - 0 - - - - - gtk-ok - True - True - True - True - - - True - True - 1 - - - - - False - False - 0 - - - - - True - True - 5 - 5 - 5 - 5 - gtk-edit - False - False - False - - - False - True - 1 - - - - - - input_dialog_cancel_button - input_dialog_ok_button - - 320 False diff --git a/app/ui/dialogs.py b/app/ui/dialogs.py index 151ab88b..5ee9b4d4 100644 --- a/app/ui/dialogs.py +++ b/app/ui/dialogs.py @@ -6,7 +6,97 @@ from enum import Enum from app.commons import run_idle from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN -_IS_GNOME_SESSION = bool(os.environ.get("GNOME_DESKTOP_SESSION_ID")) +_IS_GNOME_SESSION = int(bool(os.environ.get("GNOME_DESKTOP_SESSION_ID"))) + + +class Button(Enum): + def __str__(self): + return self.value + + OK = """ + + + gtk-ok + True + True + True + True + True + + + """ + CANCEL = """ + + + gtk-cancel + True + True + True + True + True + + + """ + + +class ButtonAction(Enum): + def __str__(self): + return self.value + + CANCEL = 'cancel_button' + OK = 'ok_button' + + +class Dialog(Enum): + def __str__(self): + return self.value + + INPUT = """ + + + + + {use_header} + 320 + False + True + {title} + False + dialog + {cancel_button} + {ok_button} + + + + + + False + vertical + 2 + + + True + True + gtk-edit + False + False + False + + + False + True + 1 + + + + + + {cancel_action} + {ok_action} + + + + """ class Action(Enum): @@ -107,7 +197,12 @@ def get_info_dialog(transient, text): def get_input_dialog(transient, text): - builder, dialog = get_dialog_from_xml(DialogType.INPUT, transient) + builder = Gtk.Builder() + builder.add_from_string(Dialog.INPUT.format(use_header=_IS_GNOME_SESSION, title="", + ok_button=Button.OK, cancel_button=Button.CANCEL, + cancel_action=ButtonAction.CANCEL, ok_action=ButtonAction.OK)) + dialog = builder.get_object("input_dialog") + dialog.set_transient_for(transient) entry = builder.get_object("input_entry") entry.set_text(text if text else "") response = dialog.run()