clan-vm-manager: Added join subcommand
This commit is contained in:
@@ -1,13 +1,37 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from collections.abc import Callable
|
import sys
|
||||||
|
|
||||||
start_app: Callable | None = None
|
import gi
|
||||||
|
|
||||||
from .app import start_app
|
from .app import Application
|
||||||
|
|
||||||
|
gi.require_version("Gtk", "3.0")
|
||||||
|
|
||||||
|
|
||||||
|
def join_command(args: argparse.Namespace) -> None:
|
||||||
|
print("Joining the flake")
|
||||||
|
print(args.clan_uri)
|
||||||
|
|
||||||
|
|
||||||
|
def register_join_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
|
parser.add_argument("clan_uri", type=str, help="machine in the flake to run")
|
||||||
|
parser.set_defaults(func=join_command)
|
||||||
|
|
||||||
|
|
||||||
|
def start_app(args: argparse.Namespace) -> None:
|
||||||
|
app = Application(args)
|
||||||
|
return app.run(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
parser = argparse.ArgumentParser(description="clan-vm-manager")
|
parser = argparse.ArgumentParser(description="clan-vm-manager")
|
||||||
|
subparser = parser.add_subparsers(
|
||||||
|
title="command",
|
||||||
|
description="command to execute",
|
||||||
|
help="the command to execute",
|
||||||
|
required=True,
|
||||||
|
)
|
||||||
|
register_join_parser(subparser.add_parser("join", help="join a clan"))
|
||||||
parser.set_defaults(func=start_app)
|
parser.set_defaults(func=start_app)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
|||||||
@@ -6,34 +6,16 @@ from typing import Any
|
|||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
from clan_vm_manager.models import VMBase
|
from .models import VMBase
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gio, Gtk
|
from gi.repository import Gio, Gtk
|
||||||
|
|
||||||
from .constants import constants
|
from .constants import constants
|
||||||
|
from .ui.clan_join_page import ClanJoinPage
|
||||||
from .ui.clan_select_list import ClanEdit, ClanList
|
from .ui.clan_select_list import ClanEdit, ClanList
|
||||||
|
|
||||||
|
|
||||||
class ClanJoinPage(Gtk.Box):
|
|
||||||
def __init__(self, *, stack: Gtk.Stack) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self.page = Gtk.Box(
|
|
||||||
orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True
|
|
||||||
)
|
|
||||||
self.set_border_width(10)
|
|
||||||
self.stack = stack
|
|
||||||
|
|
||||||
button = Gtk.Button(label="Back to list", margin_left=10)
|
|
||||||
button.connect("clicked", self.switch)
|
|
||||||
self.add(button)
|
|
||||||
|
|
||||||
self.add(Gtk.Label("Join cLan"))
|
|
||||||
|
|
||||||
def switch(self, widget: Gtk.Widget) -> None:
|
|
||||||
self.stack.set_visible_child_name("list")
|
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(Gtk.ApplicationWindow):
|
class MainWindow(Gtk.ApplicationWindow):
|
||||||
def __init__(self, application: Gtk.Application) -> None:
|
def __init__(self, application: Gtk.Application) -> None:
|
||||||
super().__init__(application=application)
|
super().__init__(application=application)
|
||||||
@@ -109,7 +91,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
|
|
||||||
|
|
||||||
class Application(Gtk.Application):
|
class Application(Gtk.Application):
|
||||||
def __init__(self) -> None:
|
def __init__(self, args: argparse.Namespace) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
||||||
)
|
)
|
||||||
@@ -134,9 +116,3 @@ class Application(Gtk.Application):
|
|||||||
# screen = Gdk.Screen.get_default()
|
# screen = Gdk.Screen.get_default()
|
||||||
# style_context = Gtk.StyleContext()
|
# style_context = Gtk.StyleContext()
|
||||||
# style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
# style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||||
|
|
||||||
|
|
||||||
def start_app(args: argparse.Namespace) -> None:
|
|
||||||
print(sys.argv)
|
|
||||||
app = Application()
|
|
||||||
return app.run(sys.argv)
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from typing import Any
|
|||||||
|
|
||||||
import clan_cli
|
import clan_cli
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("GdkPixbuf", "2.0")
|
gi.require_version("GdkPixbuf", "2.0")
|
||||||
from gi.repository import GdkPixbuf
|
from gi.repository import GdkPixbuf
|
||||||
|
|
||||||
|
|||||||
26
pkgs/clan-vm-manager/clan_vm_manager/ui/clan_join_page.py
Normal file
26
pkgs/clan-vm-manager/clan_vm_manager/ui/clan_join_page.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version("Gtk", "3.0")
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
|
||||||
|
class ClanJoinPage(Gtk.Box):
|
||||||
|
def __init__(self, *, stack: Gtk.Stack) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.page = Gtk.Box(
|
||||||
|
orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True
|
||||||
|
)
|
||||||
|
self.set_border_width(10)
|
||||||
|
self.stack = stack
|
||||||
|
|
||||||
|
button = Gtk.Button(label="Back to list", margin_left=10)
|
||||||
|
button.connect("clicked", self.switch)
|
||||||
|
self.add(button)
|
||||||
|
|
||||||
|
self.add(Gtk.Label("Join cLan"))
|
||||||
|
|
||||||
|
def switch(self, widget: Gtk.Widget) -> None:
|
||||||
|
self.stack.set_visible_child_name("list")
|
||||||
@@ -252,7 +252,7 @@ class ClanListView(Gtk.Box):
|
|||||||
vm = VMBase(*model[row])
|
vm = VMBase(*model[row])
|
||||||
vm.run()
|
vm.run()
|
||||||
|
|
||||||
|
|
||||||
def setColRenderers(tree_view: Gtk.TreeView) -> None:
|
def setColRenderers(tree_view: Gtk.TreeView) -> None:
|
||||||
for idx, (key, gtype) in enumerate(VMBase.name_to_type_map().items()):
|
for idx, (key, gtype) in enumerate(VMBase.name_to_type_map().items()):
|
||||||
col: Gtk.TreeViewColumn = None
|
col: Gtk.TreeViewColumn = None
|
||||||
@@ -263,11 +263,10 @@ def setColRenderers(tree_view: Gtk.TreeView) -> None:
|
|||||||
case GdkPixbuf.Pixbuf:
|
case GdkPixbuf.Pixbuf:
|
||||||
renderer = Gtk.CellRendererPixbuf()
|
renderer = Gtk.CellRendererPixbuf()
|
||||||
col = Gtk.TreeViewColumn(key, renderer, pixbuf=idx)
|
col = Gtk.TreeViewColumn(key, renderer, pixbuf=idx)
|
||||||
case str:
|
case str: # noqa
|
||||||
renderer = Gtk.CellRendererText()
|
renderer = Gtk.CellRendererText()
|
||||||
col = Gtk.TreeViewColumn(key, renderer, text=idx)
|
col = Gtk.TreeViewColumn(key, renderer, text=idx)
|
||||||
|
|
||||||
|
|
||||||
# CommonSetup for all columns
|
# CommonSetup for all columns
|
||||||
if col:
|
if col:
|
||||||
col.set_resizable(True)
|
col.set_resizable(True)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ mkShell {
|
|||||||
# install desktop file
|
# install desktop file
|
||||||
cp -f ${clan-vm-manager}/share/applications/clan-vm-manager.desktop ~/.local/share/applications/clan-vm-manager.desktop
|
cp -f ${clan-vm-manager}/share/applications/clan-vm-manager.desktop ~/.local/share/applications/clan-vm-manager.desktop
|
||||||
sleep 2
|
sleep 2
|
||||||
sed -i "s|Exec=.*|Exec=${clan-vm-manager}/bin/clan-vm-manager|" ~/.local/share/applications/clan-vm-manager.desktop
|
sed -i "s|Exec=.*clan-vm-manager|Exec=${clan-vm-manager}/bin/clan-vm-manager|" ~/.local/share/applications/clan-vm-manager.desktop
|
||||||
xdg-mime default clan-vm-manager.desktop x-scheme-handler/clan
|
xdg-mime default clan-vm-manager.desktop x-scheme-handler/clan
|
||||||
set +x
|
set +x
|
||||||
'';
|
'';
|
||||||
|
|||||||
Reference in New Issue
Block a user