2023-11-25 00:55:01 +00:00
|
|
|
#!/usr/bin/env python3
|
2023-11-21 17:13:30 +00:00
|
|
|
|
2023-11-25 00:55:01 +00:00
|
|
|
import argparse
|
2023-11-28 17:19:01 +00:00
|
|
|
import sys
|
2023-11-28 18:55:40 +00:00
|
|
|
from pathlib import Path
|
2023-11-21 17:13:30 +00:00
|
|
|
|
2023-11-25 00:55:01 +00:00
|
|
|
import gi
|
2023-11-21 17:13:30 +00:00
|
|
|
|
2023-11-25 00:55:01 +00:00
|
|
|
gi.require_version("Gtk", "3.0")
|
2023-11-28 17:19:01 +00:00
|
|
|
from gi.repository import Gio, Gtk
|
|
|
|
|
|
|
|
from .constants import constants
|
2023-11-28 18:55:40 +00:00
|
|
|
from .ui.clan_select_list import ClanSelectPage
|
2023-11-28 17:19:01 +00:00
|
|
|
|
2023-11-28 18:55:40 +00:00
|
|
|
|
|
|
|
class VM:
|
|
|
|
def __init__(self, url: str, autostart: bool, path: Path):
|
2023-11-28 17:19:01 +00:00
|
|
|
self.url = url
|
|
|
|
self.autostart = autostart
|
|
|
|
self.path = path
|
|
|
|
|
2023-11-28 09:23:49 +00:00
|
|
|
|
|
|
|
vms = [
|
2023-11-28 17:19:01 +00:00
|
|
|
VM("clan://clan.lol", True, "/home/user/my-clan"),
|
|
|
|
VM("clan://lassul.lol", False, "/home/user/my-clan"),
|
|
|
|
VM("clan://mic.lol", False, "/home/user/my-clan"),
|
2023-11-28 18:55:40 +00:00
|
|
|
VM("clan://dan.lol", False, "/home/user/my-clan"),
|
2023-11-28 09:23:49 +00:00
|
|
|
]
|
2023-11-28 18:52:29 +00:00
|
|
|
vms.extend(vms)
|
|
|
|
# vms.extend(vms)
|
|
|
|
# vms.extend(vms)
|
|
|
|
|
2023-11-28 17:19:01 +00:00
|
|
|
|
|
|
|
class ClanJoinPage(Gtk.Box):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.page = Gtk.Box()
|
|
|
|
self.set_border_width(10)
|
|
|
|
self.add(Gtk.Label(label="Add/Join another clan"))
|
|
|
|
|
2023-11-28 18:52:29 +00:00
|
|
|
|
2023-11-28 17:19:01 +00:00
|
|
|
class MainWindow(Gtk.ApplicationWindow):
|
|
|
|
def __init__(self, application: Gtk.Application) -> None:
|
|
|
|
super().__init__(application=application)
|
2023-11-28 09:23:49 +00:00
|
|
|
# Initialize the main window
|
|
|
|
self.set_title("Clan VM Manager")
|
2023-11-28 17:19:01 +00:00
|
|
|
self.connect("delete-event", self.on_quit)
|
|
|
|
|
2023-11-28 18:52:29 +00:00
|
|
|
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, expand=True)
|
2023-11-28 17:19:01 +00:00
|
|
|
self.add(vbox)
|
2023-11-28 09:23:49 +00:00
|
|
|
|
|
|
|
# Add a notebook layout
|
|
|
|
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html#notebook
|
|
|
|
self.notebook = Gtk.Notebook()
|
2023-11-28 17:19:01 +00:00
|
|
|
vbox.add(self.notebook)
|
2023-11-28 09:31:25 +00:00
|
|
|
|
2023-11-28 18:52:29 +00:00
|
|
|
self.notebook.append_page(ClanSelectPage(vms), Gtk.Label(label="Overview"))
|
2023-11-28 17:19:01 +00:00
|
|
|
self.notebook.append_page(ClanJoinPage(), Gtk.Label(label="Add/Join"))
|
2023-11-25 00:55:01 +00:00
|
|
|
|
2023-11-28 09:23:49 +00:00
|
|
|
# Must be called AFTER all components were added
|
|
|
|
self.show_all()
|
|
|
|
|
2023-11-28 17:19:01 +00:00
|
|
|
def on_quit(self, *args):
|
|
|
|
Gio.Application.quit(self.get_application())
|
|
|
|
|
2023-11-25 00:55:01 +00:00
|
|
|
|
2023-11-28 17:19:01 +00:00
|
|
|
class Application(Gtk.Application):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(
|
|
|
|
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
|
|
|
)
|
|
|
|
self.init_style()
|
|
|
|
|
|
|
|
def do_startup(self):
|
|
|
|
Gtk.Application.do_startup(self)
|
|
|
|
Gtk.init(sys.argv)
|
|
|
|
|
|
|
|
def do_activate(self):
|
|
|
|
win = self.props.active_window
|
|
|
|
if not win:
|
2023-11-28 18:55:40 +00:00
|
|
|
# win = SwitchTreeView(application=self)
|
2023-11-28 17:19:01 +00:00
|
|
|
win = MainWindow(application=self)
|
|
|
|
win.present()
|
|
|
|
|
|
|
|
# TODO: For css styling
|
|
|
|
def init_style(self):
|
|
|
|
pass
|
|
|
|
# css_provider = Gtk.CssProvider()
|
|
|
|
# css_provider.load_from_resource(constants['RESOURCEID'] + '/style.css')
|
|
|
|
# screen = Gdk.Screen.get_default()
|
|
|
|
# style_context = Gtk.StyleContext()
|
|
|
|
# style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
|
|
|
|
|
|
|
|
2023-11-25 00:55:01 +00:00
|
|
|
def start_app(args: argparse.Namespace) -> None:
|
2023-11-28 17:19:01 +00:00
|
|
|
app = Application()
|
|
|
|
return app.run(sys.argv)
|