[SCRIPT] Updated
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from .quick_settings import QuickSettings
|
||||
|
||||
__all__ = ["QuickSettings"]
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,87 @@
|
||||
from ignis.widgets import Widget
|
||||
from ...qs_button import QSButton
|
||||
from ...menu import Menu
|
||||
from ....shared_widgets import ToggleBox
|
||||
from ignis.services.bluetooth import BluetoothService, BluetoothDevice
|
||||
|
||||
bluetooth = BluetoothService.get_default()
|
||||
|
||||
|
||||
class BluetoothDeviceItem(Widget.Button):
|
||||
def __init__(self, device: BluetoothDevice):
|
||||
super().__init__(
|
||||
css_classes=["network-item", "unset"],
|
||||
on_click=lambda x: device.disconnect_from()
|
||||
if device.connected
|
||||
else device.connect_to(),
|
||||
child=Widget.Box(
|
||||
child=[
|
||||
Widget.Icon(
|
||||
image=device.bind("icon_name"),
|
||||
),
|
||||
Widget.Label(
|
||||
label=device.alias,
|
||||
halign="start",
|
||||
css_classes=["wifi-network-label"],
|
||||
),
|
||||
Widget.Icon(
|
||||
image="object-select-symbolic",
|
||||
halign="end",
|
||||
hexpand=True,
|
||||
visible=device.bind("connected"),
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class BluetoothMenu(Menu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
name="bluetooth",
|
||||
child=[
|
||||
ToggleBox(
|
||||
label="Bluetooth",
|
||||
active=bluetooth.powered,
|
||||
on_change=lambda x, state: bluetooth.set_powered(state),
|
||||
css_classes=["network-header-box"],
|
||||
),
|
||||
Widget.Box(
|
||||
vertical=True,
|
||||
child=bluetooth.bind(
|
||||
"devices",
|
||||
transform=lambda value: [BluetoothDeviceItem(i) for i in value],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class BluetoothButton(QSButton):
|
||||
def __init__(self):
|
||||
menu = BluetoothMenu()
|
||||
|
||||
def get_label(devices: list[BluetoothDevice]) -> str:
|
||||
if len(devices) == 0:
|
||||
return "Bluetooth"
|
||||
elif len(devices) == 1:
|
||||
return devices[0].alias
|
||||
else:
|
||||
return f"{len(devices)} pairs"
|
||||
|
||||
def toggle_menu(x) -> None:
|
||||
bluetooth.set_setup_mode(True)
|
||||
menu.toggle()
|
||||
|
||||
super().__init__(
|
||||
label=bluetooth.bind("connected_devices", get_label),
|
||||
icon_name="bluetooth-active-symbolic",
|
||||
on_activate=toggle_menu,
|
||||
on_deactivate=toggle_menu,
|
||||
active=bluetooth.bind("powered"),
|
||||
menu=menu,
|
||||
)
|
||||
|
||||
|
||||
def bluetooth_control() -> list[QSButton]:
|
||||
return [] if bluetooth.state == "absent" else [BluetoothButton()]
|
||||
@@ -0,0 +1,15 @@
|
||||
from ...qs_button import QSButton
|
||||
from user_options import user_options
|
||||
|
||||
|
||||
class DarkModeButton(QSButton):
|
||||
__gtype_name__ = "DarkModeButton"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
label="Dark",
|
||||
icon_name="night-light-symbolic",
|
||||
on_activate=lambda x: user_options.material.set_dark_mode(True),
|
||||
on_deactivate=lambda x: user_options.material.set_dark_mode(False),
|
||||
active=user_options.material.bind("dark_mode"),
|
||||
)
|
||||
@@ -0,0 +1,28 @@
|
||||
from ...qs_button import QSButton
|
||||
from ignis.services.notifications import NotificationService
|
||||
from ignis.options import options
|
||||
|
||||
notifications = NotificationService.get_default()
|
||||
|
||||
|
||||
class DNDButton(QSButton):
|
||||
__gtype_name__ = "DNDButton"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
label=options.notifications.bind(
|
||||
"dnd", lambda value: "Silent" if value else "Noisy"
|
||||
),
|
||||
icon_name=options.notifications.bind(
|
||||
"dnd",
|
||||
transform=lambda value: "notification-disabled-symbolic"
|
||||
if value
|
||||
else "notification-symbolic",
|
||||
),
|
||||
on_activate=lambda x: self.__activate(True),
|
||||
on_deactivate=lambda x: self.__activate(False),
|
||||
active=options.notifications.bind("dnd"),
|
||||
)
|
||||
|
||||
def __activate(self, state: bool) -> None:
|
||||
options.notifications.dnd = state
|
||||
@@ -0,0 +1,102 @@
|
||||
import asyncio
|
||||
from ignis.widgets import Widget
|
||||
from ignis.utils import Utils
|
||||
from ...qs_button import QSButton
|
||||
from ...menu import Menu
|
||||
from ignis.services.network import NetworkService, EthernetDevice
|
||||
|
||||
network = NetworkService.get_default()
|
||||
|
||||
|
||||
class EthernetConnectionItem(Widget.Button):
|
||||
def __init__(self, device: EthernetDevice):
|
||||
super().__init__(
|
||||
css_classes=["network-item", "unset"],
|
||||
on_click=lambda x: asyncio.create_task(device.disconnect_from())
|
||||
if device.is_connected
|
||||
else asyncio.create_task(device.connect_to()),
|
||||
child=Widget.Box(
|
||||
child=[
|
||||
Widget.Icon(image="network-wired-symbolic"),
|
||||
Widget.Label(
|
||||
label=device.name,
|
||||
ellipsize="end",
|
||||
max_width_chars=20,
|
||||
halign="start",
|
||||
),
|
||||
Widget.Button(
|
||||
child=Widget.Label(
|
||||
label=device.bind(
|
||||
"is_connected",
|
||||
lambda value: "Disconnect" if value else "Connect",
|
||||
)
|
||||
),
|
||||
css_classes=["connect-label", "unset"],
|
||||
halign="end",
|
||||
hexpand=True,
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class EthernetMenu(Menu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
name="ethernet",
|
||||
child=[
|
||||
Widget.Box(
|
||||
css_classes=["network-header-box"],
|
||||
child=[
|
||||
Widget.Icon(icon_name="network-wired-symbolic", pixel_size=28),
|
||||
Widget.Label(
|
||||
label="Wired connections",
|
||||
css_classes=["network-header-label"],
|
||||
),
|
||||
],
|
||||
),
|
||||
Widget.Box(
|
||||
vertical=True,
|
||||
child=network.ethernet.bind(
|
||||
"devices",
|
||||
lambda value: [EthernetConnectionItem(i) for i in value],
|
||||
),
|
||||
),
|
||||
Widget.Separator(),
|
||||
Widget.Button(
|
||||
css_classes=["network-item", "unset"],
|
||||
style="margin-bottom: 0;",
|
||||
on_click=lambda x: asyncio.create_task(Utils.exec_sh_async("nm-connection-editor")),
|
||||
child=Widget.Box(
|
||||
child=[
|
||||
Widget.Icon(image="preferences-system-symbolic"),
|
||||
Widget.Label(
|
||||
label="Network Settings",
|
||||
halign="start",
|
||||
),
|
||||
]
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class EthernetButton(QSButton):
|
||||
def __init__(self):
|
||||
menu = EthernetMenu()
|
||||
|
||||
super().__init__(
|
||||
label="Wired",
|
||||
icon_name="network-wired-symbolic",
|
||||
on_activate=lambda x: menu.toggle(),
|
||||
on_deactivate=lambda x: menu.toggle(),
|
||||
menu=menu,
|
||||
active=network.ethernet.bind("is_connected"),
|
||||
)
|
||||
|
||||
|
||||
def ethernet_control() -> list[QSButton]:
|
||||
if len(network.ethernet.devices) > 0:
|
||||
return [EthernetButton()]
|
||||
else:
|
||||
return []
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
from ignis.widgets import Widget
|
||||
from .wifi import wifi_control
|
||||
from .record import RecordButton
|
||||
from .dnd import DNDButton
|
||||
from .dark_mode import DarkModeButton
|
||||
from .ethernet import ethernet_control
|
||||
from .vpn import vpn_control
|
||||
from .bluetooth import bluetooth_control
|
||||
from ...qs_button import QSButton
|
||||
from ignis.services.network import NetworkService
|
||||
|
||||
network = NetworkService.get_default()
|
||||
|
||||
|
||||
class QuickSettings(Widget.Box):
|
||||
def __init__(self):
|
||||
super().__init__(vertical=True, css_classes=["qs-main-box"])
|
||||
network.wifi.connect("notify::devices", lambda x, y: self.__refresh())
|
||||
network.ethernet.connect("notify::devices", lambda x, y: self.__refresh())
|
||||
network.vpn.connect("notify::connections", lambda x, y: self.__refresh())
|
||||
|
||||
self.__refresh()
|
||||
|
||||
def __refresh(self) -> None:
|
||||
self.child = []
|
||||
self.__configure()
|
||||
|
||||
def __configure(self) -> None:
|
||||
self.__qs_fabric(
|
||||
*wifi_control(),
|
||||
*ethernet_control(),
|
||||
*vpn_control(),
|
||||
*bluetooth_control(),
|
||||
DNDButton(),
|
||||
DarkModeButton(),
|
||||
RecordButton(),
|
||||
)
|
||||
|
||||
def __qs_fabric(self, *buttons: QSButton) -> None:
|
||||
for i in range(0, len(buttons), 2):
|
||||
self.__add_row(buttons, i)
|
||||
|
||||
def __add_row(self, buttons: tuple[QSButton, ...], i: int) -> None:
|
||||
row = Widget.Box(homogeneous=True)
|
||||
if len(self.child) > 0:
|
||||
row.style = "margin-top: 0.5rem;"
|
||||
|
||||
self.append(row)
|
||||
|
||||
button1 = buttons[i]
|
||||
|
||||
self.__add_button(row, button1, buttons, i)
|
||||
|
||||
if i + 1 < len(buttons):
|
||||
button2 = buttons[i + 1]
|
||||
button2.style = "margin-left: 0.5rem;"
|
||||
self.__add_button(row, button2, buttons, i)
|
||||
|
||||
def __add_button(
|
||||
self, row: Widget.Box, button: QSButton, buttons: tuple[QSButton, ...], i: int
|
||||
) -> None:
|
||||
row.append(button)
|
||||
|
||||
if button.menu:
|
||||
self.append(button.menu)
|
||||
|
||||
if i == len(buttons) - 1 or i == len(buttons) - 2:
|
||||
button.menu.box.add_css_class("control-center-menu-last-row")
|
||||
@@ -0,0 +1,102 @@
|
||||
from ignis.widgets import Widget
|
||||
from ...qs_button import QSButton
|
||||
from ...menu import Menu
|
||||
from ignis.services.recorder import RecorderService
|
||||
|
||||
recorder = RecorderService.get_default()
|
||||
|
||||
|
||||
class RecordMenu(Menu):
|
||||
def __init__(self):
|
||||
self._audio_switch = Widget.Switch(halign="end", hexpand=True, valign="center")
|
||||
self._dropdown = Widget.DropDown(
|
||||
items=["Internal audio", "Microphone", "Both sources"],
|
||||
css_classes=["record-dropdown"],
|
||||
)
|
||||
|
||||
super().__init__(
|
||||
name="recording",
|
||||
child=[
|
||||
Widget.Icon(
|
||||
image="media-record-symbolic",
|
||||
pixel_size=36,
|
||||
halign="center",
|
||||
css_classes=["record-icon"],
|
||||
),
|
||||
Widget.Label(
|
||||
label="Start recording?",
|
||||
halign="center",
|
||||
style="font-size: 1.2rem;",
|
||||
),
|
||||
Widget.Box(
|
||||
style="margin-top: 0.5rem;",
|
||||
child=[
|
||||
Widget.Icon(
|
||||
image="microphone-sensitivity-medium-symbolic",
|
||||
pixel_size=20,
|
||||
style="margin-right: 0.5rem;",
|
||||
),
|
||||
Widget.Box(
|
||||
vertical=True,
|
||||
child=[
|
||||
Widget.Label(
|
||||
label="Record audio",
|
||||
style="font-size: 1.1rem;",
|
||||
halign="start",
|
||||
),
|
||||
self._dropdown,
|
||||
],
|
||||
),
|
||||
self._audio_switch,
|
||||
],
|
||||
),
|
||||
Widget.Box(
|
||||
style="margin-top: 1rem;",
|
||||
child=[
|
||||
Widget.Button(
|
||||
child=Widget.Label(label="Cancel"),
|
||||
css_classes=["record-cancel-button", "unset"],
|
||||
on_click=lambda x: self.set_reveal_child(False), # type: ignore
|
||||
),
|
||||
Widget.Button(
|
||||
child=Widget.Label(label="Start recording"),
|
||||
halign="end",
|
||||
hexpand=True,
|
||||
css_classes=["record-start-button", "unset"],
|
||||
on_click=lambda x: self.__start_recording(), # type: ignore
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def __start_recording(self) -> None:
|
||||
self.set_reveal_child(False)
|
||||
microphone = False
|
||||
internal = False
|
||||
if self._audio_switch.active:
|
||||
if self._dropdown.selected == "Internal audio":
|
||||
internal = True
|
||||
elif self._dropdown.selected == "Microphone":
|
||||
microphone = True
|
||||
else:
|
||||
internal = True
|
||||
microphone = True
|
||||
|
||||
recorder.start_recording(
|
||||
record_microphone=microphone, record_internal_audio=internal
|
||||
)
|
||||
|
||||
|
||||
class RecordButton(QSButton):
|
||||
def __init__(self):
|
||||
record_menu = RecordMenu()
|
||||
|
||||
super().__init__(
|
||||
label="Recording",
|
||||
icon_name="media-record-symbolic",
|
||||
on_activate=lambda x: record_menu.toggle(),
|
||||
on_deactivate=lambda x: recorder.stop_recording(),
|
||||
active=recorder.bind("active"),
|
||||
menu=record_menu,
|
||||
)
|
||||
@@ -0,0 +1,112 @@
|
||||
import asyncio
|
||||
from ignis.widgets import Widget
|
||||
from ignis.utils import Utils
|
||||
from ...qs_button import QSButton
|
||||
from ...menu import Menu
|
||||
from ignis.services.network import NetworkService, VpnConnection
|
||||
|
||||
|
||||
network = NetworkService.get_default()
|
||||
|
||||
|
||||
class VpnNetworkItem(Widget.Button):
|
||||
def __init__(self, conn: VpnConnection):
|
||||
super().__init__(
|
||||
css_classes=["network-item", "unset"],
|
||||
on_click=lambda x: asyncio.create_task(conn.toggle_connection()),
|
||||
child=Widget.Box(
|
||||
child=[
|
||||
Widget.Label(
|
||||
label=conn.name,
|
||||
ellipsize="end",
|
||||
max_width_chars=20,
|
||||
halign="start",
|
||||
),
|
||||
Widget.Button(
|
||||
child=Widget.Label(
|
||||
label=conn.bind(
|
||||
"is_connected",
|
||||
lambda value: "Disconnect" if value else "Connect",
|
||||
)
|
||||
),
|
||||
css_classes=["connect-label", "unset"],
|
||||
halign="end",
|
||||
hexpand=True,
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class VpnMenu(Menu):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
name="vpn",
|
||||
child=[
|
||||
Widget.Box(
|
||||
css_classes=["network-header-box"],
|
||||
child=[
|
||||
Widget.Icon(icon_name="network-vpn-symbolic", pixel_size=28),
|
||||
Widget.Label(
|
||||
label="VPN connections",
|
||||
css_classes=["network-header-label"],
|
||||
),
|
||||
],
|
||||
),
|
||||
Widget.Box(
|
||||
vertical=True,
|
||||
child=network.vpn.bind(
|
||||
"connections",
|
||||
transform=lambda value: [VpnNetworkItem(i) for i in value],
|
||||
),
|
||||
),
|
||||
Widget.Separator(),
|
||||
Widget.Button(
|
||||
css_classes=["network-item", "unset"],
|
||||
on_click=lambda x: asyncio.create_task(Utils.exec_sh_async("nm-connection-editor")),
|
||||
style="margin-bottom: 0;",
|
||||
child=Widget.Box(
|
||||
child=[
|
||||
Widget.Icon(image="preferences-system-symbolic"),
|
||||
Widget.Label(
|
||||
label="Network Manager",
|
||||
halign="start",
|
||||
),
|
||||
]
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class VpnButton(QSButton):
|
||||
def __init__(self):
|
||||
menu = VpnMenu()
|
||||
|
||||
def get_label(id: str) -> str:
|
||||
if id:
|
||||
return id
|
||||
else:
|
||||
return "VPN"
|
||||
|
||||
def get_icon(icon_name: str) -> str:
|
||||
if network.vpn.is_connected:
|
||||
return icon_name
|
||||
else:
|
||||
return "network-vpn-symbolic"
|
||||
|
||||
super().__init__(
|
||||
label=network.vpn.bind("active_vpn_id", get_label),
|
||||
icon_name=network.vpn.bind("icon-name", get_icon),
|
||||
on_activate=lambda x: menu.toggle(),
|
||||
on_deactivate=lambda x: menu.toggle(),
|
||||
active=network.vpn.bind("is-connected"),
|
||||
menu=menu,
|
||||
)
|
||||
|
||||
|
||||
def vpn_control() -> list[QSButton]:
|
||||
if len(network.vpn.connections) > 0:
|
||||
return [VpnButton()]
|
||||
else:
|
||||
return []
|
||||
@@ -0,0 +1,107 @@
|
||||
import asyncio
|
||||
from ignis.widgets import Widget
|
||||
from ignis.utils import Utils
|
||||
from ...qs_button import QSButton
|
||||
from ...menu import Menu
|
||||
from ....shared_widgets import ToggleBox
|
||||
from ignis.services.network import NetworkService, WifiAccessPoint, WifiDevice
|
||||
|
||||
network = NetworkService.get_default()
|
||||
|
||||
|
||||
class WifiNetworkItem(Widget.Button):
|
||||
def __init__(self, access_point: WifiAccessPoint):
|
||||
super().__init__(
|
||||
css_classes=["network-item", "unset"],
|
||||
on_click=lambda x: asyncio.create_task(access_point.connect_to_graphical()),
|
||||
child=Widget.Box(
|
||||
child=[
|
||||
Widget.Icon(
|
||||
image=access_point.bind(
|
||||
"strength", transform=lambda value: access_point.icon_name
|
||||
),
|
||||
),
|
||||
Widget.Label(
|
||||
label=access_point.ssid,
|
||||
halign="start",
|
||||
),
|
||||
Widget.Icon(
|
||||
image="object-select-symbolic",
|
||||
halign="end",
|
||||
hexpand=True,
|
||||
visible=access_point.bind("is_connected"),
|
||||
),
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class WifiMenu(Menu):
|
||||
def __init__(self, device: WifiDevice):
|
||||
super().__init__(
|
||||
name="wifi",
|
||||
child=[
|
||||
ToggleBox(
|
||||
label="Wi-Fi",
|
||||
active=network.wifi.enabled,
|
||||
on_change=lambda x, state: network.wifi.set_enabled(state),
|
||||
css_classes=["network-header-box"],
|
||||
),
|
||||
Widget.Box(
|
||||
vertical=True,
|
||||
child=device.bind(
|
||||
"access_points",
|
||||
transform=lambda value: [WifiNetworkItem(i) for i in value],
|
||||
),
|
||||
),
|
||||
Widget.Separator(),
|
||||
Widget.Button(
|
||||
css_classes=["network-item", "unset"],
|
||||
on_click=lambda x: asyncio.create_task(Utils.exec_sh_async("nm-connection-editor")),
|
||||
style="margin-bottom: 0;",
|
||||
child=Widget.Box(
|
||||
child=[
|
||||
Widget.Icon(image="preferences-system-symbolic"),
|
||||
Widget.Label(
|
||||
label="Network Settings",
|
||||
halign="start",
|
||||
),
|
||||
]
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class WifiButton(QSButton):
|
||||
def __init__(self, device: WifiDevice):
|
||||
menu = WifiMenu(device)
|
||||
|
||||
def get_label(ssid: str) -> str:
|
||||
if ssid:
|
||||
return ssid
|
||||
else:
|
||||
return "Wi-Fi"
|
||||
|
||||
def get_icon(icon_name: str) -> str:
|
||||
if device.ap.is_connected:
|
||||
return icon_name
|
||||
else:
|
||||
return "network-wireless-symbolic"
|
||||
|
||||
def toggle_list(x) -> None:
|
||||
asyncio.create_task(device.scan())
|
||||
menu.toggle()
|
||||
|
||||
super().__init__(
|
||||
label=device.ap.bind("ssid", get_label),
|
||||
icon_name=device.ap.bind("icon-name", get_icon),
|
||||
on_activate=toggle_list,
|
||||
on_deactivate=toggle_list,
|
||||
active=network.wifi.bind("enabled"),
|
||||
menu=menu,
|
||||
)
|
||||
|
||||
|
||||
def wifi_control() -> list[QSButton]:
|
||||
return [WifiButton(dev) for dev in network.wifi.devices]
|
||||
Reference in New Issue
Block a user