102 lines
2.8 KiB
Python
102 lines
2.8 KiB
Python
from . import instance
|
|
import os
|
|
from gi.repository import Gtk, Gio
|
|
|
|
|
|
def __loader_helper():
|
|
import gi
|
|
gi.require_version("Gtk", "3.0")
|
|
|
|
|
|
__loader_helper()
|
|
|
|
|
|
# Templates
|
|
_template_file = os.path.join(os.path.split(__file__)[0], "templates.glade")
|
|
|
|
|
|
@Gtk.Template(filename=_template_file)
|
|
class _StartWidget(Gtk.OffscreenWindow):
|
|
__gtype_name__ = "StartWidget"
|
|
template_type = "StartWidget"
|
|
|
|
__image = Gtk.Template.Child("start_image")
|
|
__name: Gtk.Label = Gtk.Template.Child("start_name")
|
|
__settings = Gtk.Template.Child("start_settings")
|
|
__run = Gtk.Template.Child("start_run")
|
|
__add_snapshot = Gtk.Template.Child("start_add_snapshot")
|
|
__snapshots = Gtk.Template.Child("start_snapshots")
|
|
|
|
def __init__(self, name, *args, **kargs):
|
|
super(*args, **kargs)
|
|
self.__name.set_label(name)
|
|
|
|
|
|
@Gtk.Template(filename=_template_file)
|
|
class _AboutDialog(Gtk.AboutDialog):
|
|
__gtype_name__ = "AboutDialog"
|
|
template_type = "AboutDialog"
|
|
|
|
|
|
# Application
|
|
class _Application(Gtk.Application):
|
|
_builder: Gtk.Builder
|
|
_window: Gtk.ApplicationWindow
|
|
_stack: Gtk.Stack
|
|
_configsSource: list
|
|
_instance: str
|
|
_configs: dict
|
|
_inited = None
|
|
|
|
def __init__(self, inited, configs: list = [], instance: str = None, *args, **kargs):
|
|
super().__init__(*args, application_id="de.marko10_000.WineStarter", **kargs)
|
|
self._configsSource = list(configs)
|
|
self._instance = str(instance)
|
|
self._inited = inited
|
|
|
|
def do_startup(self):
|
|
# Load configs
|
|
configs = self._configs = {}
|
|
for i in self._configsSource:
|
|
tmp = instance.gen_instance(i)
|
|
configs[tmp.get_instance()] = tmp
|
|
|
|
# Start gtk application
|
|
Gtk.Application.do_startup(self)
|
|
|
|
def do_activate(self):
|
|
# Load gui
|
|
self._builder = builder = Gtk.Builder()
|
|
builder.add_from_file(os.path.join(
|
|
os.path.split(__file__)[0], "gui.glade"))
|
|
|
|
# Gen gui
|
|
self._window = builder.get_object("main_window")
|
|
self._stack = builder.get_object("main_content")
|
|
if len(self._configs) == 1:
|
|
self._window.remove(self._window.get_child())
|
|
else:
|
|
for i in self._stack.get_children():
|
|
self._stack.remove(i)
|
|
|
|
# Add main window callbacks
|
|
def show_about(menu_entry):
|
|
_AboutDialog(parent=self._window).show_all()
|
|
builder.get_object("mainMenuAbout").connect("activate", show_about)
|
|
|
|
# Show main window
|
|
self._window.set_application(self)
|
|
self._window.show_all()
|
|
|
|
# Notify init end
|
|
self._inited()
|
|
|
|
|
|
app: _Application
|
|
|
|
|
|
def run_gui(inited=lambda: None, configs: list = None):
|
|
global app
|
|
app = _Application(inited=inited, configs=configs)
|
|
app.run()
|