Commit e4e8dbbb authored by Roman Alifanov's avatar Roman Alifanov

flagsdialog: switch from lists to dictionaries

parent 9c6c9bb6
import re
from gi.repository import Gtk, Adw
class FlagRow(Adw.ActionRow):
__gtype_name__ = 'FlagRow'
def __init__(self, flag, flag_name, flag_description):
def __init__(self, flag_data):
super().__init__()
self.flag = flag
self.flag_name = flag_name
self.flag = flag_data['flag']
self.flag_name = flag_data['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_selectable(False)
self.set_activatable(True)
self.switch = Gtk.Switch(
halign=Gtk.Align.CENTER,
valign=Gtk.Align.CENTER
......@@ -59,11 +59,11 @@ class FlagsDialog(Adw.Dialog):
return full_command
def add_flags(self, flags):
for flag in flags:
if len(flag) != 3:
raise ValueError("Only three values are expected")
for flag_data in flags:
if not isinstance(flag_data, dict) or not all(key in flag_data for key in ['flag', 'name', 'description']):
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)
......
......@@ -61,23 +61,25 @@ class EepmPlayGuiWindow(Adw.ApplicationWindow):
self.flagsdialog = FlagsDialog()
self.flags_button.connect("clicked", lambda _: self.flagsdialog.present(self))
self.flagsdialog.add_flags([
self.flagsdialog.add_flags(
[
"--force",
"Force",
_("Sometimes it helps to get the latest version of the program. (Not recommended)")
],
[
"--auto",
"Auto",
_("The user will not be asked any questions")
],
[
"--ipfs",
"IPFS",
_("It helps to get resources that are unavailable from your network")
],
])
{
"flag": "--force",
"name": "Force",
"description": _("Sometimes it helps to get the latest version of the program. (Not recommended)"),
},
{
"flag": "--ipfs",
"name": "IPFS",
"description": _("It helps to get resources that are unavailable from your network"),
},
{
"flag": "--auto",
"name": "Auto",
"description": _("The user will not be asked any questions"),
},
]
)
self.connect("notify::is-loading", self.on_is_loading_changed)
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