Skip to content

Commit

Permalink
#4064 we have to use program_context early on MS Windows
Browse files Browse the repository at this point in the history
as this sets up the environment properly and allows us to import the gi bindings
  • Loading branch information
totaam committed Mar 8, 2024
1 parent cfc435b commit 35dffe5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 50 deletions.
6 changes: 0 additions & 6 deletions xpra/gtk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@
# Copyright (C) 2013-2020 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from xpra.os_util import gi_import
gi_import("Gdk")
gi_import("Gtk")
gi_import("Pango")
gi_import("GdkPixbuf")
5 changes: 2 additions & 3 deletions xpra/gtk/configure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

log = Logger("util")

GLib = gi_import("GLib")
Gtk = gi_import("Gtk")


DISCLAIMER = """
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Expand Down Expand Up @@ -102,6 +99,7 @@ def with_config(cb: Callable) -> None:
# then run the callback in the UI thread
def load_config():
defaults = make_defaults_struct()
GLib = gi_import("GLib")
GLib.idle_add(cb, defaults)

start_thread(load_config, "load-config", daemon=True)
Expand All @@ -120,6 +118,7 @@ def run_gui(gui_class) -> int:
install_signal_handlers("xpra-configure-gui", gui.app_signal)
ready()
gui.show()
Gtk = gi_import("Gtk")
Gtk.main()
log("do_main() gui.exit_code=%i", gui.exit_code)
return 0
54 changes: 54 additions & 0 deletions xpra/gtk/configure/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This file is part of Xpra.
# Copyright (C) 2018-2024 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from importlib import import_module

from xpra.gtk.configure.common import run_gui
from xpra.os_util import LINUX
from xpra.gtk.dialogs.base_gui_window import BaseGUIWindow
from xpra.gtk.widget import label


class HomeGUI(BaseGUIWindow):

def __init__(self):
super().__init__(
"Configure Xpra",
"toolbox.png",
wm_class=("xpra-configure-gui", "Xpra Configure GUI"),
default_size=(480, 300),
header_bar=(False, False),
)
self.dialogs: dict[str, BaseGUIWindow] = {}

def populate(self):
self.vbox.add(label("Configure Xpra", font="sans 20"))
self.vbox.add(label("Tune your xpra configuration:", font="sans 14"))
if LINUX:
self.sub("Packages", "package.png", "Install or remove xpra packages", "packages")
self.sub("Features", "features.png", "Enable or disable feature groups", "features")
self.sub("Picture compression", "encoding.png", "Encodings, speed and quality", "encodings")
self.sub("GStreamer", "gstreamer.png", "Configure the GStreamer codecs", "gstreamer")
self.sub("OpenGL acceleration", "opengl.png", "Test and validate OpenGL renderer", "opengl")

def sub(self, title="", icon_name="browse.png", tooltip="", configure: str = "") -> None:

def callback(_btn):
dialog = self.dialogs.get(configure)
if dialog is None:
mod = import_module(f"xpra.gtk.configure.{configure}")
dialog = mod.ConfigureGUI(self)
self.dialogs[configure] = dialog
dialog.show()
self.ib(title, icon_name, tooltip, callback=callback)


def main(_args) -> int:
return run_gui(HomeGUI)


if __name__ == "__main__":
import sys
sys.exit(main(sys.argv[1:]))
45 changes: 4 additions & 41 deletions xpra/gtk/configure/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,16 @@
import os.path
from importlib import import_module

from xpra.gtk.configure.common import get_user_config_file, run_gui
from xpra.platform import program_context
from xpra.gtk.configure.common import get_user_config_file
from xpra.scripts.config import InitExit
from xpra.exit_codes import ExitCode, ExitValue
from xpra.os_util import LINUX
from xpra.gtk.dialogs.base_gui_window import BaseGUIWindow
from xpra.gtk.widget import label


class ConfigureGUI(BaseGUIWindow):

def __init__(self):
super().__init__(
"Configure Xpra",
"toolbox.png",
wm_class=("xpra-configure-gui", "Xpra Configure GUI"),
default_size=(480, 300),
header_bar=(False, False),
)
self.dialogs: dict[str, BaseGUIWindow] = {}

def populate(self):
self.vbox.add(label("Configure Xpra", font="sans 20"))
self.vbox.add(label("Tune your xpra configuration:", font="sans 14"))
if LINUX:
self.sub("Packages", "package.png", "Install or remove xpra packages", "packages")
self.sub("Features", "features.png", "Enable or disable feature groups", "features")
self.sub("Picture compression", "encoding.png", "Encodings, speed and quality", "encodings")
self.sub("GStreamer", "gstreamer.png", "Configure the GStreamer codecs", "gstreamer")
self.sub("OpenGL acceleration", "opengl.png", "Test and validate OpenGL renderer", "opengl")

def sub(self, title="", icon_name="browse.png", tooltip="", configure: str = "") -> None:

def callback(_btn):
dialog = self.dialogs.get(configure)
if dialog is None:
mod = import_module(f"xpra.gtk.configure.{configure}")
dialog = mod.ConfigureGUI(self)
self.dialogs[configure] = dialog
dialog.show()
self.ib(title, icon_name, tooltip, callback=callback)


def main(args) -> ExitValue:
if args:
with program_context("Configure", "Configure"):
conf = get_user_config_file()
subcommand = args[0]
subcommand = args[0] if args else "home"
if subcommand == "reset":
import datetime
now = datetime.datetime.now()
Expand Down Expand Up @@ -81,7 +45,6 @@ def main(args) -> ExitValue:
if not mod:
raise InitExit(ExitCode.FILE_NOT_FOUND, f"unknown configure subcommand {subcommand!r}")
return mod.main(args[1:])
return run_gui(ConfigureGUI)


if __name__ == "__main__":
Expand Down

0 comments on commit 35dffe5

Please sign in to comment.