diff --git a/app/ui/dialogs.glade b/app/ui/dialogs.glade index f491cf28..7b527556 100644 --- a/app/ui/dialogs.glade +++ b/app/ui/dialogs.glade @@ -75,41 +75,6 @@ Author: Dmitriy Yefremov - - 320 - False - False - True - 320 - 240 - True - accessories-text-editor - dialog - error - ok - - - - - - False - immediate - vertical - 2 - - - False - end - - - False - False - 0 - - - - - False False diff --git a/app/ui/dialogs.py b/app/ui/dialogs.py index 82507e10..08fc2c40 100644 --- a/app/ui/dialogs.py +++ b/app/ui/dialogs.py @@ -10,9 +10,6 @@ _IS_GNOME_SESSION = int(bool(os.environ.get("GNOME_DESKTOP_SESSION_ID"))) class Button(Enum): - def __str__(self): - return self.value - OK = """ @@ -38,14 +35,17 @@ class Button(Enum): """ - -class ButtonAction(Enum): def __str__(self): return self.value + +class ButtonAction(Enum): CANCEL = 'cancel_button' OK = 'ok_button' + def __str__(self): + return self.value + class Dialog(Enum): INPUT = """ @@ -60,6 +60,9 @@ class Dialog(Enum): {title} False dialog + True + True + center {cancel_button} {ok_button} @@ -97,18 +100,19 @@ class Dialog(Enum): MESSAGE = """ + {use_header} - 320 False - False True 320 - 240 True dialog - question - ok-cancel + True + True + center + {message_type} + {buttons_type} {text} @@ -121,13 +125,16 @@ class Action(Enum): class DialogType(Enum): - INPUT = "input_dialog" - CHOOSER = "path_chooser_dialog" - ERROR = "error_dialog" - QUESTION = "question_dialog" + INPUT = "input" + CHOOSER = "chooser" + ERROR = "error" + QUESTION = "question" + INFO = "info" ABOUT = "about_dialog" WAIT = "wait_dialog" - INFO = "info_dialog" + + def __str__(self): + return self.value class WaitDialog: @@ -152,22 +159,14 @@ class WaitDialog: def show_dialog(dialog_type: DialogType, transient, text=None, options=None, action_type=None, file_filter=None): """ Shows dialogs by name """ - if dialog_type is DialogType.INFO: - return get_info_dialog(transient, text) + if dialog_type in (DialogType.INFO, DialogType.ERROR): + return get_message_dialog(transient, dialog_type, Gtk.ButtonsType.OK, text) elif dialog_type is DialogType.CHOOSER and options: return get_file_chooser_dialog(transient, text, options, action_type, file_filter) elif dialog_type is DialogType.INPUT: return get_input_dialog(transient, text) elif dialog_type is DialogType.QUESTION: - return get_message_dialog(transient, DialogType.QUESTION) - else: - builder, dialog = get_dialog_from_xml(dialog_type, transient) - if text: - dialog.set_markup(get_message(text)) - response = dialog.run() - dialog.destroy() - - return response + return get_message_dialog(transient, DialogType.QUESTION, Gtk.ButtonsType.OK_CANCEL, "Are you sure?") def get_chooser_dialog(transient, options, pattern, name): @@ -204,16 +203,6 @@ def get_file_chooser_dialog(transient, text, options, action_type, file_filter): return response -def get_info_dialog(transient, text): - dialog = Gtk.MessageDialog(text=get_message(text), - parent=transient, - type=Gtk.MessageType.INFO, - buttons=Gtk.ButtonsType.OK, - use_header_bar=_IS_GNOME_SESSION) - dialog.run() - dialog.destroy() - - def get_input_dialog(transient, text): builder = Gtk.Builder() builder.add_from_string(Dialog.INPUT.value.format(use_header=_IS_GNOME_SESSION, title="", @@ -230,10 +219,13 @@ def get_input_dialog(transient, text): return txt if response == Gtk.ResponseType.OK else Gtk.ResponseType.CANCEL -def get_message_dialog(transient, dialog_type): +def get_message_dialog(transient, message_type, buttons_type, text): builder = Gtk.Builder() builder.set_translation_domain(TEXT_DOMAIN) - builder.add_from_string(Dialog.MESSAGE.value.format(use_header=0, text="Are you sure?")) + builder.add_from_string(Dialog.MESSAGE.value.format(use_header=0, + message_type=message_type, + buttons_type=int(buttons_type), + text=text)) dialog = builder.get_object("message_dialog") dialog.set_transient_for(transient) response = dialog.run()