Add an input dialog to the dialog module

This commit adds an input dialog to the dialog module. This dialog
allows to prompt the user for a simple string input.
This commit is contained in:
Riccardo Paolo Bestetti 2023-05-02 22:32:37 +02:00
parent 3f0db9303f
commit d04174cb99
No known key found for this signature in database
GPG Key ID: 19AA545A29857BEB
2 changed files with 547 additions and 307 deletions

View File

@ -215,6 +215,50 @@ class QuestionDialog3:
return (-1 if response == Gtk.ResponseType.DELETE_EVENT return (-1 if response == Gtk.ResponseType.DELETE_EVENT
else response == Gtk.ResponseType.ACCEPT) else response == Gtk.ResponseType.ACCEPT)
class InputDialog:
def __init__(self, msg, default_input=None, parent=None):
self.xml = Glade(toplevel='inputdialog')
self.top = self.xml.toplevel
self.top.set_icon(ICON)
self.top.set_title("%s - Gramps" % msg)
self.top.set_default_response(Gtk.ResponseType.OK)
label = self.xml.get_object('qd_label')
label.set_text('<span weight="bold" size="larger">%s</span>' %
html.escape(msg))
label.set_use_markup(True)
self.xml.get_object('ok').set_use_underline(True)
self.xml.get_object('cancel').set_use_underline(True)
self.entry_box = self.xml.get_object('entry_box')
if default_input is not None:
self.entry_box.set_text(default_input)
self.entry_box.set_placeholder_text(default_input)
# dirty fix for default action not working by default - not sure why
self.entry_box.connect('activate',
lambda _: self.top.response(Gtk.ResponseType.OK))
self.parent = parent
if parent:
self.top.set_transient_for(parent)
self.parent_modal = parent.get_modal()
if self.parent_modal:
parent.set_modal(False)
self.top.show()
def run(self):
response = self.top.run()
input_text = self.entry_box.get_text()
self.top.destroy()
if self.parent and self.parent_modal:
self.parent.set_modal(True)
if response == Gtk.ResponseType.OK:
return input_text
return None
class OptionDialog: class OptionDialog:
def __init__(self, msg1, msg2, btnmsg1, task1, btnmsg2, task2, parent=None): def __init__(self, msg1, msg2, btnmsg1, task1, btnmsg2, task2, parent=None):
self.xml = Glade(toplevel='optiondialog') self.xml = Glade(toplevel='optiondialog')

File diff suppressed because it is too large Load Diff