Merge pull request 'clan-vm-manager: make joining clan url more logical' (#687) from Mic92-wayland-update into main
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from enum import StrEnum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -16,12 +17,17 @@ from gi.repository import GdkPixbuf
|
|||||||
from clan_vm_manager import assets
|
from clan_vm_manager import assets
|
||||||
|
|
||||||
|
|
||||||
|
class VMStatus(StrEnum):
|
||||||
|
RUNNING = "Running"
|
||||||
|
STOPPED = "Stopped"
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class VMBase:
|
class VMBase:
|
||||||
icon: Path | GdkPixbuf.Pixbuf
|
icon: Path | GdkPixbuf.Pixbuf
|
||||||
name: str
|
name: str
|
||||||
url: str
|
url: str
|
||||||
status: bool
|
status: VMStatus
|
||||||
_flake_attr: str
|
_flake_attr: str
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -31,7 +37,7 @@ class VMBase:
|
|||||||
"Icon": GdkPixbuf.Pixbuf,
|
"Icon": GdkPixbuf.Pixbuf,
|
||||||
"Name": str,
|
"Name": str,
|
||||||
"URL": str,
|
"URL": str,
|
||||||
"Online": bool,
|
"Status": str,
|
||||||
"_FlakeAttr": str,
|
"_FlakeAttr": str,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -46,7 +52,7 @@ class VMBase:
|
|||||||
"Icon": str(self.icon),
|
"Icon": str(self.icon),
|
||||||
"Name": self.name,
|
"Name": self.name,
|
||||||
"URL": self.url,
|
"URL": self.url,
|
||||||
"Online": self.status,
|
"Status": self.status,
|
||||||
"_FlakeAttr": self._flake_attr,
|
"_FlakeAttr": self._flake_attr,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -75,9 +81,9 @@ def get_initial_vms(
|
|||||||
if entry.flake.icon is not None:
|
if entry.flake.icon is not None:
|
||||||
icon = entry.flake.icon
|
icon = entry.flake.icon
|
||||||
|
|
||||||
status = False
|
status = VMStatus.STOPPED
|
||||||
if entry.flake.flake_url in running_vms:
|
if entry.flake.flake_url in running_vms:
|
||||||
status = True
|
status = VMStatus.RUNNING
|
||||||
|
|
||||||
base = VMBase(
|
base = VMBase(
|
||||||
icon=icon,
|
icon=icon,
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class ClanList(Gtk.Box):
|
|||||||
on_start_clicked=self.on_start_clicked,
|
on_start_clicked=self.on_start_clicked,
|
||||||
on_stop_clicked=self.on_stop_clicked,
|
on_stop_clicked=self.on_stop_clicked,
|
||||||
on_edit_clicked=self.on_edit_clicked,
|
on_edit_clicked=self.on_edit_clicked,
|
||||||
on_new_clicked=self.on_new_clicked,
|
on_join_clan_clicked=self.on_join_clan_clicked,
|
||||||
on_flash_clicked=self.on_flash_clicked,
|
on_flash_clicked=self.on_flash_clicked,
|
||||||
)
|
)
|
||||||
self.toolbar.set_is_selected(self.selected_vm is not None)
|
self.toolbar.set_is_selected(self.selected_vm is not None)
|
||||||
@@ -139,7 +139,7 @@ class ClanList(Gtk.Box):
|
|||||||
self.cbs.stop_vm(self.selected_vm.url, self.selected_vm._flake_attr)
|
self.cbs.stop_vm(self.selected_vm.url, self.selected_vm._flake_attr)
|
||||||
self.remount_list_view()
|
self.remount_list_view()
|
||||||
|
|
||||||
def on_new_clicked(self, widget: Gtk.Widget) -> None:
|
def on_join_clan_clicked(self, widget: Gtk.Widget) -> None:
|
||||||
self.show_join()
|
self.show_join()
|
||||||
|
|
||||||
def on_edit_clicked(self, widget: Gtk.Widget) -> None:
|
def on_edit_clicked(self, widget: Gtk.Widget) -> None:
|
||||||
@@ -163,7 +163,7 @@ class ClanListToolbar(Gtk.Toolbar):
|
|||||||
on_start_clicked: Callable[[Gtk.Widget], None],
|
on_start_clicked: Callable[[Gtk.Widget], None],
|
||||||
on_stop_clicked: Callable[[Gtk.Widget], None],
|
on_stop_clicked: Callable[[Gtk.Widget], None],
|
||||||
on_edit_clicked: Callable[[Gtk.Widget], None],
|
on_edit_clicked: Callable[[Gtk.Widget], None],
|
||||||
on_new_clicked: Callable[[Gtk.Widget], None],
|
on_join_clan_clicked: Callable[[Gtk.Widget], None],
|
||||||
on_flash_clicked: Callable[[Gtk.Widget], None],
|
on_flash_clicked: Callable[[Gtk.Widget], None],
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
|
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
|
||||||
@@ -180,9 +180,9 @@ class ClanListToolbar(Gtk.Toolbar):
|
|||||||
self.edit_button.connect("clicked", on_edit_clicked)
|
self.edit_button.connect("clicked", on_edit_clicked)
|
||||||
self.add(self.edit_button)
|
self.add(self.edit_button)
|
||||||
|
|
||||||
self.new_button = Gtk.ToolButton(label="New")
|
self.join_clan_button = Gtk.ToolButton(label="Join Clan")
|
||||||
self.new_button.connect("clicked", on_new_clicked)
|
self.join_clan_button.connect("clicked", on_join_clan_clicked)
|
||||||
self.add(self.new_button)
|
self.add(self.join_clan_button)
|
||||||
|
|
||||||
self.flash_button = Gtk.ToolButton(label="Write to USB")
|
self.flash_button = Gtk.ToolButton(label="Write to USB")
|
||||||
self.flash_button.connect("clicked", on_flash_clicked)
|
self.flash_button.connect("clicked", on_flash_clicked)
|
||||||
|
|||||||
@@ -38,15 +38,14 @@ class Trust(Gtk.Box):
|
|||||||
)
|
)
|
||||||
layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||||
layout.set_border_width(20)
|
layout.set_border_width(20)
|
||||||
|
layout.set_spacing(20)
|
||||||
upper = Gtk.Box(orientation="vertical")
|
|
||||||
upper.set_spacing(20)
|
|
||||||
|
|
||||||
if self.url is not None:
|
if self.url is not None:
|
||||||
self.entry = Gtk.Label(label=str(self.url))
|
self.entry = Gtk.Label(label=str(self.url))
|
||||||
upper.add(Gtk.Label(label="Clan URL"))
|
layout.add(icon)
|
||||||
|
layout.add(Gtk.Label(label="Clan URL"))
|
||||||
else:
|
else:
|
||||||
upper.add(Gtk.Label(label="Enter Clan URL"))
|
layout.add(Gtk.Label(label="Enter Clan URL"))
|
||||||
self.entry = Gtk.Entry()
|
self.entry = Gtk.Entry()
|
||||||
# Autocomplete
|
# Autocomplete
|
||||||
# TODO: provide intelligent suggestions
|
# TODO: provide intelligent suggestions
|
||||||
@@ -61,17 +60,16 @@ class Trust(Gtk.Box):
|
|||||||
self.entry.set_completion(completion)
|
self.entry.set_completion(completion)
|
||||||
self.entry.set_placeholder_text("clan://")
|
self.entry.set_placeholder_text("clan://")
|
||||||
|
|
||||||
upper.add(icon)
|
layout.add(self.entry)
|
||||||
upper.add(self.entry)
|
|
||||||
|
if self.url is None:
|
||||||
|
trust_button = Gtk.Button(label="Load cLAN-URL")
|
||||||
|
else:
|
||||||
|
trust_button = Gtk.Button(label="Trust cLAN-URL")
|
||||||
|
|
||||||
lower = Gtk.Box(orientation="vertical")
|
|
||||||
lower.set_spacing(20)
|
|
||||||
trust_button = Gtk.Button(label="Trust")
|
|
||||||
trust_button.connect("clicked", self.on_trust_clicked)
|
trust_button.connect("clicked", self.on_trust_clicked)
|
||||||
lower.add(trust_button)
|
layout.add(trust_button)
|
||||||
|
|
||||||
layout.pack_start(upper, expand=True, fill=True, padding=0)
|
|
||||||
layout.pack_end(lower, expand=True, fill=True, padding=0)
|
|
||||||
self.set_center_widget(layout)
|
self.set_center_widget(layout)
|
||||||
|
|
||||||
def on_trust_clicked(self, widget: Gtk.Widget) -> None:
|
def on_trust_clicked(self, widget: Gtk.Widget) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user