aboutsummaryrefslogtreecommitdiff
path: root/src/ui/entry_list.py
diff options
context:
space:
mode:
authorJoris Guyonvarch2025-12-26 18:41:26 +0100
committerJoris Guyonvarch2025-12-27 20:41:44 +0100
commita110c200e86d2325af07167531fac0f61d9681a0 (patch)
tree90e843f915a2e153ba735849afd83710d90560bf /src/ui/entry_list.py
parenta26d92ad5055fa057647158eb79511e7b1841162 (diff)
Switch to GUI to manage the library
Allow to regroup the CLI and the view into one unique tool.
Diffstat (limited to 'src/ui/entry_list.py')
-rw-r--r--src/ui/entry_list.py42
1 files changed, 42 insertions, 0 deletions
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