Skip to content

Commit

Permalink
Sidequest - rewrite part 1 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawstorant authored Oct 1, 2024
1 parent 4e106da commit e1e3aa8
Show file tree
Hide file tree
Showing 41 changed files with 1,415 additions and 1,132 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@ cython_debug/

/.flatpak-builder
/app

.config
.vscode/*
!.vscode/launch.json
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Normal",
"type": "debugpy",
"request": "launch",
"program": "entrypoint.py",
"console": "integratedTerminal",
"args": [
"--local",
"--custom"
]
},
{
"name": "GTK Debug",
"type": "debugpy",
"request": "launch",
"program": "entrypoint.py",
"console": "internalConsole",
"env": {
"GTK_DEBUG": "interactive"
},
"args": [
"--local",
"--custom"
]
}
]
}
49 changes: 20 additions & 29 deletions boxflat/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import os

class MainWindow(Adw.ApplicationWindow):
def __init__(self, data_path: str, config_path: str, dry_run: bool, *args, **kwargs):
def __init__(self, data_path: str, config_path: str, dry_run: bool, custom: bool, *args, **kwargs):
super().__init__(*args, **kwargs)

self._hid_handler = HidHandler()
self._config_path = config_path

self._cm = MozaConnectionManager(os.path.join(data_path, "serial.yml"), self._hid_handler ,dry_run)
# self.connect('close-request', lambda w: self._cm.shutdown())
self._cm = MozaConnectionManager(os.path.join(data_path, "serial.yml"), dry_run)
self.connect('close-request', self._cm.shutdown)
self._cm.subscribe("hid-device-connected", self._hid_handler.add_device)

with open(os.path.join(data_path, "version"), "r") as version:
self._version = version.readline().strip()
Expand Down Expand Up @@ -55,6 +56,8 @@ def __init__(self, data_path: str, config_path: str, dry_run: bool, *args, **kwa
self.navigation = navigation

self._prepare_settings()
if custom:
self._panels["Other"].enable_custom_commands()

buttons = self._panel_buttons()
for button in buttons:
Expand All @@ -81,26 +84,24 @@ def __init__(self, data_path: str, config_path: str, dry_run: bool, *args, **kwa
self._alert.set_body_use_markup(True)
self._alert.connect("response", self._handle_udev_dialog)

self._cm.subscribe_no_access(self.show_udev_dialog)
self._cm.subscribe("no-accesss", self.show_udev_dialog)


def switch_panel(self, button) -> None:
def switch_panel(self, button):
new_title = button.get_child().get_label()
new_content = self._panels[new_title].content

if self.navigation.get_content() == new_content:
return

self._cm.reset_subscriptions()
self.navigation.set_content(new_content)
self._panels[new_title].activate_subs()


def set_content_title(self, title: str) -> None:
def set_content_title(self, title: str):
self.navigation.get_content().set_title(title)


def show_udev_dialog(self) -> None:
def show_udev_dialog(self):
self._alert.choose()


Expand All @@ -109,26 +110,24 @@ def _handle_udev_dialog(self, dialog, response):
self.open_url("https://github.com/Lawstorant/boxflat?tab=readme-ov-file#udev-rule-installation-for-flatpak")


def open_url(self, url: str) -> None:
def open_url(self, url: str):
launcher = Gtk.UriLauncher()
launcher.set_uri(url)
launcher.launch()


def _prepare_settings(self) -> None:
def _prepare_settings(self):
self._panels["Home"] = HomeSettings(self.switch_panel, self._dry_run, self._cm, self._hid_handler, self._version)
self._panels["Base"] = BaseSettings(self.switch_panel, self._cm, self._hid_handler)
self._panels["Wheel"] = WheelSettings(self.switch_panel, self._cm, self._hid_handler)
self._panels["Pedals"] = PedalsSettings(self.switch_panel, self._cm, self._hid_handler)
self._panels["H-Pattern Shifter"] = HPatternSettings(self.switch_panel, self._cm)
self._panels["Sequential Shifter"] = SequentialSettings(self.switch_panel, self._cm)
self._panels["Handbrake"] = HandbrakeSettings(self.switch_panel, self._cm, self._hid_handler)
self._panels["Other"] = OtherSettings(self.switch_panel, self._cm, self._hid_handler)
self._panels["Presets"] = PresetSettings(self.switch_panel, self._cm, self._config_path)
self._panels["Other"] = OtherSettings(self.switch_panel, self._cm, self._hid_handler, self._version)
self._panels["Presets"] = PresetSettings(self.switch_panel, self._cm, self._config_path, self._version)

self._panels["Other"].subscribe_brake_calibration(
self._panels["Pedals"].set_brake_calibration_active
)
self._panels["Other"].subscribe("brake-calibration-active", self._panels["Pedals"].set_brake_calibration_active)

for panel in self._panels.values():
panel.active(-2)
Expand All @@ -138,22 +137,15 @@ def _prepare_settings(self) -> None:
self._panels["Other"].active(1)
self._panels["Presets"].active(1)

for panel in self._panels.values():
panel.activate_subs_connected()
panel.activate_hid_subs()

if self._dry_run:
print("Dry run")
return

self._panels["Base"].activate_subs()
self._cm.set_rw_active(True)
self._hid_handler.start()
self._cm.set_write_active()


def _activate_default(self) -> SettingsPanel:
self._panels["Home"].button.set_active(True)
self._panels["Home"].activate_subs()
return self._panels["Home"]


Expand All @@ -166,17 +158,16 @@ def _panel_buttons(self) -> list:


class MyApp(Adw.Application):
def __init__(self, data_path: str, config_path: str, dry_run: bool, **kwargs):
def __init__(self, data_path: str, config_path: str, dry_run: bool, custom: bool, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
self._data_path = data_path
self._dry_run = dry_run
self._config_path = config_path
css_provider = Gtk.CssProvider()
css_provider.load_from_path(f"{data_path}/style.css")
Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

self.win = MainWindow(data_path, config_path, dry_run, custom)


def on_activate(self, app):
self.win = MainWindow(self._data_path, self._config_path, self._dry_run, application=app)
self.win.set_application(app)
self.win.present()
Loading

0 comments on commit e1e3aa8

Please sign in to comment.