Commit e4e8dbbb authored by Roman Alifanov's avatar Roman Alifanov

flagsdialog: switch from lists to dictionaries

parent 9c6c9bb6
import re import re
from gi.repository import Gtk, Adw from gi.repository import Gtk, Adw
class FlagRow(Adw.ActionRow): class FlagRow(Adw.ActionRow):
__gtype_name__ = 'FlagRow' __gtype_name__ = 'FlagRow'
def __init__(self, flag, flag_name, flag_description): def __init__(self, flag_data):
super().__init__() super().__init__()
self.flag = flag self.flag = flag_data['flag']
self.flag_name = flag_name
self.flag_name = flag_data['name']
self.set_title(self.flag_name) self.set_title(self.flag_name)
self.flag_description = flag_description self.flag_description = flag_data['description']
self.set_subtitle(self.flag_description) self.set_subtitle(self.flag_description)
self.set_selectable(False) self.set_selectable(False)
self.set_activatable(True) self.set_activatable(True)
self.switch = Gtk.Switch( self.switch = Gtk.Switch(
halign=Gtk.Align.CENTER, halign=Gtk.Align.CENTER,
valign=Gtk.Align.CENTER valign=Gtk.Align.CENTER
...@@ -59,11 +59,11 @@ class FlagsDialog(Adw.Dialog): ...@@ -59,11 +59,11 @@ class FlagsDialog(Adw.Dialog):
return full_command return full_command
def add_flags(self, flags): def add_flags(self, flags):
for flag in flags: for flag_data in flags:
if len(flag) != 3: if not isinstance(flag_data, dict) or not all(key in flag_data for key in ['flag', 'name', 'description']):
raise ValueError("Only three values are expected") raise ValueError("Each flag must be a dictionary with 'flag', 'name', and 'description' keys")
row = FlagRow(*flag) row = FlagRow(flag_data)
self.rows.append(row) self.rows.append(row)
......
...@@ -61,23 +61,25 @@ class EepmPlayGuiWindow(Adw.ApplicationWindow): ...@@ -61,23 +61,25 @@ class EepmPlayGuiWindow(Adw.ApplicationWindow):
self.flagsdialog = FlagsDialog() self.flagsdialog = FlagsDialog()
self.flags_button.connect("clicked", lambda _: self.flagsdialog.present(self)) self.flags_button.connect("clicked", lambda _: self.flagsdialog.present(self))
self.flagsdialog.add_flags([ self.flagsdialog.add_flags(
[ [
"--force", {
"Force", "flag": "--force",
_("Sometimes it helps to get the latest version of the program. (Not recommended)") "name": "Force",
], "description": _("Sometimes it helps to get the latest version of the program. (Not recommended)"),
[ },
"--auto", {
"Auto", "flag": "--ipfs",
_("The user will not be asked any questions") "name": "IPFS",
], "description": _("It helps to get resources that are unavailable from your network"),
[ },
"--ipfs", {
"IPFS", "flag": "--auto",
_("It helps to get resources that are unavailable from your network") "name": "Auto",
], "description": _("The user will not be asked any questions"),
]) },
]
)
self.connect("notify::is-loading", self.on_is_loading_changed) self.connect("notify::is-loading", self.on_is_loading_changed)
self.search_bar.connect_entry(self.search_entry) self.search_bar.connect_entry(self.search_entry)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment