Added windows folder
This commit is contained in:
parent
a5caed0de9
commit
6b8216b3ac
@ -1,23 +1,11 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
from .app import Application
|
from .app import Application
|
||||||
|
from clan_cli.clan_uri import ClanURI
|
||||||
|
|
||||||
|
from .windows.join import register_join_parser
|
||||||
def join_command(args: argparse.Namespace) -> None:
|
from .windows.overview import show_overview, OverviewWindow
|
||||||
print("Joining the flake")
|
|
||||||
print(args.clan_uri)
|
|
||||||
app = Application()
|
|
||||||
return app.run()
|
|
||||||
|
|
||||||
|
|
||||||
def register_join_parser(parser: argparse.ArgumentParser) -> None:
|
|
||||||
parser.add_argument("clan_uri", type=str, help="clan URI to join")
|
|
||||||
parser.set_defaults(func=join_command)
|
|
||||||
|
|
||||||
|
|
||||||
def start_app(args: argparse.Namespace) -> None:
|
|
||||||
app = Application()
|
|
||||||
return app.run()
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
@ -32,6 +20,6 @@ def main() -> None:
|
|||||||
register_join_parser(subparser.add_parser("join", help="join a clan"))
|
register_join_parser(subparser.add_parser("join", help="join a clan"))
|
||||||
|
|
||||||
# Executed when no command is given
|
# Executed when no command is given
|
||||||
parser.set_defaults(func=start_app)
|
parser.set_defaults(func=show_overview)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
args.func(args)
|
args.func(args)
|
||||||
|
@ -15,96 +15,22 @@ from .ui.clan_join_page import ClanJoinPage
|
|||||||
from .ui.clan_select_list import ClanEdit, ClanList
|
from .ui.clan_select_list import ClanEdit, ClanList
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(Gtk.ApplicationWindow):
|
|
||||||
def __init__(self, application: Gtk.Application) -> None:
|
|
||||||
super().__init__(application=application)
|
|
||||||
# Initialize the main window
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Add a notebook layout
|
|
||||||
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html#notebook
|
|
||||||
self.notebook = Gtk.Notebook()
|
|
||||||
self.stack = Gtk.Stack()
|
|
||||||
# self.stack_switcher = Gtk.StackSwitcher()
|
|
||||||
|
|
||||||
self.list_hooks = {
|
|
||||||
"remount_list": self.remount_list_view,
|
|
||||||
"remount_edit": self.remount_edit_view,
|
|
||||||
"set_selected": self.set_selected,
|
|
||||||
}
|
|
||||||
clan_list = ClanList(**self.list_hooks, selected_vm=None) # type: ignore
|
|
||||||
# Add named stacks
|
|
||||||
self.stack.add_titled(clan_list, "list", "List")
|
|
||||||
self.stack.add_titled(
|
|
||||||
ClanJoinPage(stack=self.remount_list_view), "join", "Join"
|
|
||||||
)
|
|
||||||
self.stack.add_titled(
|
|
||||||
ClanEdit(remount_list=self.remount_list_view, selected_vm=None),
|
|
||||||
"edit",
|
|
||||||
"Edit",
|
|
||||||
)
|
|
||||||
|
|
||||||
vbox.add(self.stack)
|
|
||||||
|
|
||||||
# Must be called AFTER all components were added
|
|
||||||
self.show_all()
|
|
||||||
|
|
||||||
def set_selected(self, sel: VMBase | None) -> None:
|
|
||||||
self.selected_vm = sel
|
|
||||||
|
|
||||||
if self.selected_vm:
|
|
||||||
print(f"APP selected + {self.selected_vm.name}")
|
|
||||||
|
|
||||||
def remount_list_view(self) -> None:
|
|
||||||
widget = self.stack.get_child_by_name("list")
|
|
||||||
print("Remounting ClanListView")
|
|
||||||
if widget:
|
|
||||||
widget.destroy()
|
|
||||||
|
|
||||||
clan_list = ClanList(**self.list_hooks, selected_vm=self.selected_vm) # type: ignore
|
|
||||||
self.stack.add_titled(clan_list, "list", "List")
|
|
||||||
self.show_all()
|
|
||||||
self.stack.set_visible_child_name("list")
|
|
||||||
|
|
||||||
def remount_edit_view(self) -> None:
|
|
||||||
print("Remounting ClanEdit")
|
|
||||||
widget = self.stack.get_child_by_name("edit")
|
|
||||||
if widget:
|
|
||||||
widget.destroy()
|
|
||||||
|
|
||||||
self.stack.add_titled(
|
|
||||||
ClanEdit(remount_list=self.remount_list_view, selected_vm=self.selected_vm),
|
|
||||||
"edit",
|
|
||||||
"Edit",
|
|
||||||
)
|
|
||||||
self.show_all()
|
|
||||||
self.stack.set_visible_child_name("edit")
|
|
||||||
|
|
||||||
def on_quit(self, *args: Any) -> None:
|
|
||||||
Gio.Application.quit(self.get_application())
|
|
||||||
|
|
||||||
|
|
||||||
class Application(Gtk.Application):
|
class Application(Gtk.Application):
|
||||||
def __init__(self) -> None:
|
def __init__(self, window: Gtk.ApplicationWindow) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
||||||
)
|
)
|
||||||
self.init_style()
|
self.init_style()
|
||||||
|
self.window = window
|
||||||
|
|
||||||
def do_startup(self) -> None:
|
def do_startup(self) -> None:
|
||||||
Gtk.Application.do_startup(self)
|
Gtk.Application.do_startup(self)
|
||||||
Gtk.init(sys.argv)
|
Gtk.init()
|
||||||
|
|
||||||
def do_activate(self) -> None:
|
def do_activate(self) -> None:
|
||||||
win = self.props.active_window
|
win = self.props.active_window
|
||||||
if not win:
|
if not win:
|
||||||
# win = SwitchTreeView(application=self)
|
win = self.window(application=self)
|
||||||
win = MainWindow(application=self)
|
|
||||||
win.present()
|
win.present()
|
||||||
|
|
||||||
# TODO: For css styling
|
# TODO: For css styling
|
||||||
|
16
pkgs/clan-vm-manager/clan_vm_manager/windows/join.py
Normal file
16
pkgs/clan-vm-manager/clan_vm_manager/windows/join.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from ..app import Application
|
||||||
|
import argparse
|
||||||
|
from .overview import OverviewWindow
|
||||||
|
from clan_cli.clan_uri import ClanURI
|
||||||
|
|
||||||
|
|
||||||
|
def show_join(args: argparse.Namespace) -> None:
|
||||||
|
print(f"Joining clan {args.clan_uri}")
|
||||||
|
app = Application(OverviewWindow)
|
||||||
|
return app.run()
|
||||||
|
|
||||||
|
|
||||||
|
def register_join_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
|
parser.add_argument("clan_uri", type=ClanURI, help="clan URI to join")
|
||||||
|
parser.set_defaults(func=show_join)
|
||||||
|
|
103
pkgs/clan-vm-manager/clan_vm_manager/windows/overview.py
Normal file
103
pkgs/clan-vm-manager/clan_vm_manager/windows/overview.py
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
import sys
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
import gi
|
||||||
|
|
||||||
|
from ..models import VMBase
|
||||||
|
|
||||||
|
gi.require_version("Gtk", "3.0")
|
||||||
|
from gi.repository import Gio, Gtk
|
||||||
|
|
||||||
|
from ..constants import constants
|
||||||
|
from ..ui.clan_join_page import ClanJoinPage
|
||||||
|
from ..ui.clan_select_list import ClanEdit, ClanList
|
||||||
|
from ..app import Application
|
||||||
|
from clan_cli.clan_uri import ClanURI
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
class OverviewWindow(Gtk.ApplicationWindow):
|
||||||
|
def __init__(self, application: Gtk.Application) -> None:
|
||||||
|
super().__init__(application=application)
|
||||||
|
# Initialize the main window
|
||||||
|
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)
|
||||||
|
|
||||||
|
# Add a notebook layout
|
||||||
|
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html#notebook
|
||||||
|
self.notebook = Gtk.Notebook()
|
||||||
|
self.stack = Gtk.Stack()
|
||||||
|
# self.stack_switcher = Gtk.StackSwitcher()
|
||||||
|
|
||||||
|
self.list_hooks = {
|
||||||
|
"remount_list": self.remount_list_view,
|
||||||
|
"remount_edit": self.remount_edit_view,
|
||||||
|
"set_selected": self.set_selected,
|
||||||
|
}
|
||||||
|
clan_list = ClanList(**self.list_hooks, selected_vm=None) # type: ignore
|
||||||
|
# Add named stacks
|
||||||
|
self.stack.add_titled(clan_list, "list", "List")
|
||||||
|
self.stack.add_titled(
|
||||||
|
ClanJoinPage(stack=self.remount_list_view), "join", "Join"
|
||||||
|
)
|
||||||
|
self.stack.add_titled(
|
||||||
|
ClanEdit(remount_list=self.remount_list_view, selected_vm=None),
|
||||||
|
"edit",
|
||||||
|
"Edit",
|
||||||
|
)
|
||||||
|
|
||||||
|
vbox.add(self.stack)
|
||||||
|
|
||||||
|
# Must be called AFTER all components were added
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
def set_selected(self, sel: VMBase | None) -> None:
|
||||||
|
self.selected_vm = sel
|
||||||
|
|
||||||
|
if self.selected_vm:
|
||||||
|
print(f"APP selected + {self.selected_vm.name}")
|
||||||
|
|
||||||
|
def remount_list_view(self) -> None:
|
||||||
|
widget = self.stack.get_child_by_name("list")
|
||||||
|
print("Remounting ClanListView")
|
||||||
|
if widget:
|
||||||
|
widget.destroy()
|
||||||
|
|
||||||
|
clan_list = ClanList(**self.list_hooks, selected_vm=self.selected_vm) # type: ignore
|
||||||
|
self.stack.add_titled(clan_list, "list", "List")
|
||||||
|
self.show_all()
|
||||||
|
self.stack.set_visible_child_name("list")
|
||||||
|
|
||||||
|
def remount_edit_view(self) -> None:
|
||||||
|
print("Remounting ClanEdit")
|
||||||
|
widget = self.stack.get_child_by_name("edit")
|
||||||
|
if widget:
|
||||||
|
widget.destroy()
|
||||||
|
|
||||||
|
self.stack.add_titled(
|
||||||
|
ClanEdit(remount_list=self.remount_list_view, selected_vm=self.selected_vm),
|
||||||
|
"edit",
|
||||||
|
"Edit",
|
||||||
|
)
|
||||||
|
self.show_all()
|
||||||
|
self.stack.set_visible_child_name("edit")
|
||||||
|
|
||||||
|
def on_quit(self, *args: Any) -> None:
|
||||||
|
Gio.Application.quit(self.get_application())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def show_overview(args: argparse.Namespace) -> None:
|
||||||
|
app = Application(OverviewWindow)
|
||||||
|
return app.run()
|
||||||
|
|
||||||
|
def register_overview_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
|
parser.add_argument("clan_uri", type=ClanURI, help="clan URI to join")
|
||||||
|
parser.set_defaults(func=show_overview)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user