From a110c200e86d2325af07167531fac0f61d9681a0 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Fri, 26 Dec 2025 18:41:26 +0100 Subject: Switch to GUI to manage the library Allow to regroup the CLI and the view into one unique tool. --- src/ui/entry_list.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/ui/entry_list.py (limited to 'src/ui/entry_list.py') diff --git a/src/ui/entry_list.py b/src/ui/entry_list.py new file mode 100644 index 0000000..c0c355d --- /dev/null +++ b/src/ui/entry_list.py @@ -0,0 +1,42 @@ +import gi +gi.require_version('Gtk', '4.0') +from gi.repository import Gtk + +import src.utils as utils + +class EntryList(Gtk.Box): + + def __init__(self, name): + Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=10) + + header = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10) + header.append(get_label(name)) + add_button = Gtk.Button(label='+') + add_button.connect('clicked', lambda _: self.add_entry()) + header.append(add_button) + self.append(header) + + self._entries = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10) + self.append(self._entries) + + def get_entry_texts(self): + res = [] + for entry in self._entries: + res.append(entry.get_first_child().get_buffer().get_text()) + return res + + def add_entry(self, value=''): + line = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10) + entry = Gtk.Entry() + entry.set_text(value) + entry.set_hexpand(True) + line.append(entry) + remove_button = Gtk.Button(label='-') + remove_button.connect('clicked', lambda _: self._entries.remove(line)) + line.append(remove_button) + self._entries.append(line) + +def get_label(text): + label = Gtk.Label() + label.set_text(text) + return label -- cgit v1.2.3