This commit is contained in:
t
2025-02-05 19:25:48 +01:00
parent cbe4355c3d
commit 810f54cb65
258 changed files with 4730 additions and 3 deletions
@@ -0,0 +1,20 @@
from .row import SettingsRow
from .page import SettingsPage
from .group import SettingsGroup
from .switchrow import SwitchRow
from .filerow import FileRow
from .spinrow import SpinRow
from .entryrow import EntryRow
from .entry import SettingsEntry
__all__ = [
"SettingsRow",
"SettingsPage",
"SettingsGroup",
"SettingsRow",
"SwitchRow",
"FileRow",
"SpinRow",
"EntryRow",
"SettingsEntry",
]
@@ -0,0 +1,31 @@
from ignis.widgets import Widget
from .page import SettingsPage
from options import settings_last_page
class SettingsEntry(Widget.ListBoxRow):
def __init__(
self,
icon: str,
label: str,
active_page,
page: SettingsPage,
**kwargs,
):
def callback(x):
active_page.page = page
active_page.name = label
if self in self.parent.rows:
settings_last_page.set_value(self.parent.rows.index(self))
super().__init__(
child=Widget.Box(
child=[
Widget.Icon(image=icon, pixel_size=20),
Widget.Label(label=label, style="margin-left: 0.75rem;"),
],
),
css_classes=["settings-sidebar-entry"],
on_activate=callback,
**kwargs,
)
@@ -0,0 +1,24 @@
from ignis.widgets import Widget
from .row import SettingsRow
from typing import Callable
from ignis.gobject import Binding
class EntryRow(SettingsRow):
def __init__(
self,
text: str | Binding | None = None,
on_change: Callable | None = None,
width: int | None = None,
**kwargs,
):
super().__init__(**kwargs)
self._entry = Widget.Entry(
on_change=on_change,
text=text,
halign="end",
valign="center",
width_request=width,
hexpand=True,
)
self.child.append(self._entry)
@@ -0,0 +1,23 @@
from ignis.widgets import Widget
from .row import SettingsRow
from ignis.gobject import Binding
class FileRow(SettingsRow):
def __init__(
self,
dialog: Widget.FileDialog,
button_label: str | Binding | None = None,
**kwargs,
):
super().__init__(**kwargs)
self._button = Widget.FileChooserButton(
dialog=dialog,
label=Widget.Label(
label=button_label, ellipsize="start", max_width_chars=20
),
hexpand=True,
halign="end",
)
self.child.append(self._button)
@@ -0,0 +1,24 @@
from typing import List
from ignis.widgets import Widget
from .row import SettingsRow
from ignis.base_widget import BaseWidget
class SettingsGroup(Widget.Box):
def __init__(
self, name: str | None, rows: List[SettingsRow | BaseWidget] = [], **kwargs
):
super().__init__(
vertical=True,
css_classes=["settings-group"],
child=[
Widget.Label(
label=name,
css_classes=["settings-group-name"],
halign="start",
visible=True if name else False,
),
Widget.ListBox(rows=[*rows]),
],
**kwargs,
)
@@ -0,0 +1,24 @@
from ignis.widgets import Widget
from typing import List
from .group import SettingsGroup
from ignis.base_widget import BaseWidget
class SettingsPage(Widget.Scroll):
def __init__(self, name: str, groups: List[SettingsGroup | BaseWidget] = []):
super().__init__(
hexpand=True,
vexpand=True,
child=Widget.Box(
vertical=True,
hexpand=True,
vexpand=True,
css_classes=["settings-page"],
child=[
Widget.Label(
label=name, css_classes=["settings-page-name"], halign="start"
),
*groups,
],
),
)
@@ -0,0 +1,34 @@
from ignis.widgets import Widget
class SettingsRow(Widget.ListBoxRow):
def __init__(self, label: str | None = None, sublabel: str | None = None, **kwargs):
super().__init__(
css_classes=["settings-row"],
child=Widget.Box(
child=[
Widget.Box(
vertical=True,
child=[
Widget.Label(
label=label,
css_classes=["settings-row-label"],
halign="start",
vexpand=True,
wrap=True,
visible=True if label else False,
),
Widget.Label(
label=sublabel,
css_classes=["settings-row-sublabel"],
halign="start",
vexpand=True,
wrap=True,
visible=True if sublabel else False,
),
],
)
]
),
**kwargs,
)
@@ -0,0 +1,30 @@
from ignis.widgets import Widget
from .row import SettingsRow
from typing import Callable
from ignis.gobject import Binding
class SpinRow(SettingsRow):
def __init__(
self,
value: int | Binding = 0,
on_change: Callable | None = None,
min: int = 0,
max: int = 100,
step: int = 1,
width: int = 0,
**kwargs,
):
super().__init__(**kwargs)
self._spin_button = Widget.SpinButton(
value=value,
on_change=on_change,
min=min,
max=max,
halign="end",
valign="center",
width_request=width,
hexpand=True,
step=step,
)
self.child.append(self._spin_button)
@@ -0,0 +1,25 @@
from ignis.widgets import Widget
from .row import SettingsRow
from typing import Callable
from ignis.gobject import Binding
class SwitchRow(SettingsRow):
def __init__(
self,
active: bool | Binding = False,
on_change: Callable | None = None,
**kwargs,
):
super().__init__(**kwargs)
self._switch = Widget.Switch(
active=active,
on_change=on_change,
halign="end",
valign="center",
hexpand=True,
)
self.on_activate = lambda x: self._switch.emit(
"activate"
) # if set "active" property animation will not work
self.child.append(self._switch)