forked from clan/clan-core
prepare flash usb window
This commit is contained in:
parent
d39d3a9a45
commit
36e7488da1
@ -6,6 +6,8 @@ from pathlib import Path
|
||||
import gi
|
||||
from clan_cli import vms
|
||||
|
||||
from clan_vm_manager.windows.flash import FlashUSBWindow
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
|
||||
from clan_cli.clan_uri import ClanURI
|
||||
@ -13,7 +15,7 @@ from gi.repository import Gio, Gtk
|
||||
|
||||
from .constants import constants
|
||||
from .executor import ProcessManager, spawn
|
||||
from .interfaces import Callbacks, InitialJoinValues
|
||||
from .interfaces import Callbacks, InitialFlashValues, InitialJoinValues
|
||||
from .windows.join import JoinWindow
|
||||
from .windows.overview import OverviewWindow
|
||||
|
||||
@ -22,6 +24,7 @@ from .windows.overview import OverviewWindow
|
||||
class ClanWindows:
|
||||
join: type[JoinWindow]
|
||||
overview: type[OverviewWindow]
|
||||
flash_usb: type[FlashUSBWindow]
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -42,6 +45,7 @@ class Application(Gtk.Application):
|
||||
self.cbs = Callbacks(
|
||||
show_list=self.show_list,
|
||||
show_join=self.show_join,
|
||||
show_flash=self.show_flash,
|
||||
spawn_vm=self.spawn_vm,
|
||||
stop_vm=self.stop_vm,
|
||||
running_vms=self.running_vms,
|
||||
@ -100,6 +104,13 @@ class Application(Gtk.Application):
|
||||
)
|
||||
prev.hide()
|
||||
|
||||
def show_flash(self) -> None:
|
||||
prev = self.window
|
||||
self.window = self.windows.__dict__["flash_usb"](
|
||||
cbs=self.cbs, initial_values=FlashUSBWindow(InitialFlashValues(None))
|
||||
)
|
||||
prev.hide()
|
||||
|
||||
def do_startup(self) -> None:
|
||||
Gtk.Application.do_startup(self)
|
||||
Gtk.init()
|
||||
@ -124,7 +135,9 @@ class Application(Gtk.Application):
|
||||
def show_join(args: argparse.Namespace) -> None:
|
||||
print(f"Joining clan {args.clan_uri}")
|
||||
app = Application(
|
||||
windows=ClanWindows(join=JoinWindow, overview=OverviewWindow),
|
||||
windows=ClanWindows(
|
||||
join=JoinWindow, overview=OverviewWindow, flash_usb=FlashUSBWindow
|
||||
),
|
||||
config=ClanConfig(url=args.clan_uri, initial_window="join"),
|
||||
)
|
||||
return app.run()
|
||||
@ -137,7 +150,9 @@ def register_join_parser(parser: argparse.ArgumentParser) -> None:
|
||||
|
||||
def show_overview(args: argparse.Namespace) -> None:
|
||||
app = Application(
|
||||
windows=ClanWindows(join=JoinWindow, overview=OverviewWindow),
|
||||
windows=ClanWindows(
|
||||
join=JoinWindow, overview=OverviewWindow, flash_usb=FlashUSBWindow
|
||||
),
|
||||
config=ClanConfig(url=None, initial_window="overview"),
|
||||
)
|
||||
return app.run()
|
||||
|
@ -11,10 +11,16 @@ class InitialJoinValues:
|
||||
url: ClanURI | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class InitialFlashValues:
|
||||
selected: str | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Callbacks:
|
||||
show_list: Callable[[], None]
|
||||
show_join: Callable[[], None]
|
||||
show_flash: Callable[[], None]
|
||||
spawn_vm: Callable[[str, str], None]
|
||||
stop_vm: Callable[[str, str], None]
|
||||
running_vms: Callable[[], list[str]]
|
||||
|
@ -107,7 +107,8 @@ class ClanList(Gtk.Box):
|
||||
on_start_clicked=self.on_start_clicked,
|
||||
on_stop_clicked=self.on_stop_clicked,
|
||||
on_edit_clicked=self.on_edit_clicked,
|
||||
on_join_clicked=self.on_join_clicked,
|
||||
on_new_clicked=self.on_new_clicked,
|
||||
on_flash_clicked=self.on_flash_clicked,
|
||||
)
|
||||
self.toolbar.set_is_selected(self.selected_vm is not None)
|
||||
self.add(self.toolbar)
|
||||
@ -121,6 +122,10 @@ class ClanList(Gtk.Box):
|
||||
)
|
||||
)
|
||||
|
||||
def on_flash_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("Flash clicked")
|
||||
self.cbs.show_flash()
|
||||
|
||||
def on_double_click(self, vm: VMBase) -> None:
|
||||
print(f"on_double_click: {vm.name}")
|
||||
self.on_start_clicked(self)
|
||||
@ -138,8 +143,8 @@ class ClanList(Gtk.Box):
|
||||
self.cbs.stop_vm(self.selected_vm.url, self.selected_vm._flake_attr)
|
||||
self.remount_list_view()
|
||||
|
||||
def on_join_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("Join clicked")
|
||||
def on_new_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("New clicked")
|
||||
self.show_join()
|
||||
|
||||
def on_edit_clicked(self, widget: Gtk.Widget) -> None:
|
||||
@ -165,7 +170,8 @@ class ClanListToolbar(Gtk.Toolbar):
|
||||
on_start_clicked: Callable[[Gtk.Widget], None],
|
||||
on_stop_clicked: Callable[[Gtk.Widget], None],
|
||||
on_edit_clicked: Callable[[Gtk.Widget], None],
|
||||
on_join_clicked: Callable[[Gtk.Widget], None],
|
||||
on_new_clicked: Callable[[Gtk.Widget], None],
|
||||
on_flash_clicked: Callable[[Gtk.Widget], None],
|
||||
) -> None:
|
||||
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
|
||||
@ -181,9 +187,13 @@ class ClanListToolbar(Gtk.Toolbar):
|
||||
self.edit_button.connect("clicked", on_edit_clicked)
|
||||
self.add(self.edit_button)
|
||||
|
||||
self.join_button = Gtk.ToolButton(label="New")
|
||||
self.join_button.connect("clicked", on_join_clicked)
|
||||
self.add(self.join_button)
|
||||
self.new_button = Gtk.ToolButton(label="New")
|
||||
self.new_button.connect("clicked", on_new_clicked)
|
||||
self.add(self.new_button)
|
||||
|
||||
self.flash_button = Gtk.ToolButton(label="Write to USB")
|
||||
self.flash_button.connect("clicked", on_flash_clicked)
|
||||
self.add(self.flash_button)
|
||||
|
||||
def set_is_selected(self, s: bool) -> None:
|
||||
if s:
|
||||
|
65
pkgs/clan-vm-manager/clan_vm_manager/windows/flash.py
Normal file
65
pkgs/clan-vm-manager/clan_vm_manager/windows/flash.py
Normal file
@ -0,0 +1,65 @@
|
||||
from typing import Any
|
||||
|
||||
import gi
|
||||
from clan_cli.errors import ClanError
|
||||
|
||||
from clan_vm_manager.errors.show_error import show_error_dialog
|
||||
|
||||
from ..interfaces import InitialFlashValues
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
|
||||
from gi.repository import Gio, Gtk
|
||||
|
||||
|
||||
class Details(Gtk.Box):
|
||||
def __init__(self, initial: InitialFlashValues, stack: Gtk.Stack) -> None:
|
||||
super().__init__()
|
||||
|
||||
def on_confirm(self, widget: Gtk.Widget) -> None:
|
||||
show_error_dialog(ClanError("Feature not ready yet."), "Info")
|
||||
|
||||
def on_cancel(self, widget: Gtk.Widget) -> None:
|
||||
show_error_dialog(ClanError("Feature not ready yet."), "Info")
|
||||
|
||||
|
||||
class FlashUSBWindow(Gtk.ApplicationWindow):
|
||||
def __init__(self, initial_values: InitialFlashValues) -> None:
|
||||
super().__init__()
|
||||
# Initialize the main wincbsdow
|
||||
# self.cbs = cbs
|
||||
self.set_title("cLAN Manager")
|
||||
self.connect("delete-event", self.on_quit)
|
||||
self.set_default_size(800, 600)
|
||||
|
||||
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True)
|
||||
self.add(vbox)
|
||||
|
||||
button = Gtk.ToolButton()
|
||||
button.set_icon_name("go-previous")
|
||||
button.connect("clicked", self.switch)
|
||||
|
||||
toolbar = Gtk.Toolbar(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
toolbar.add(button)
|
||||
vbox.add(toolbar)
|
||||
|
||||
self.stack = Gtk.Stack()
|
||||
|
||||
print("initial_values", initial_values)
|
||||
self.stack.add_titled(
|
||||
Details(initial_values, stack=self.stack),
|
||||
"details",
|
||||
"Details",
|
||||
)
|
||||
|
||||
vbox.add(self.stack)
|
||||
|
||||
# Must be called AFTER all components were added
|
||||
self.show_all()
|
||||
|
||||
def switch(self, widget: Gtk.Widget) -> None:
|
||||
pass
|
||||
# self.cbs.show_list()
|
||||
|
||||
def on_quit(self, *args: Any) -> None:
|
||||
Gio.Application.quit(self.get_application())
|
Loading…
Reference in New Issue
Block a user