From a46cccac0156f17c0eabeb39dc5021470792d16d Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 7 Dec 2023 17:21:27 +0700 Subject: [PATCH] #4064 move more code to common make encodings gui usable --- xpra/gtk/configure/common.py | 35 +++++++++++++++++++++++++++-- xpra/gtk/configure/features.py | 23 ++++++------------- xpra/gtk/configure/opengl.py | 2 +- xpra/gtk/dialogs/base_gui_window.py | 2 ++ 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/xpra/gtk/configure/common.py b/xpra/gtk/configure/common.py index 7d87d76fa8..9a5c67e9a7 100644 --- a/xpra/gtk/configure/common.py +++ b/xpra/gtk/configure/common.py @@ -4,11 +4,21 @@ # later version. See the file COPYING for details. import os.path +from datetime import datetime from subprocess import check_call +from collections.abc import Callable -from xpra.os_util import POSIX +from xpra.os_util import POSIX, gi_import from xpra.util.env import osexpand from xpra.util.parsing import parse_simple_dict +from xpra.util.thread import start_thread +from xpra.scripts.config import make_defaults_struct +from xpra.log import Logger + +log = Logger("util") + +GLib = gi_import("GLib") + DISCLAIMER = """ IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, @@ -28,7 +38,7 @@ def sync() -> None: def get_user_config_file() -> str: from xpra.platform.paths import get_user_conf_dirs - return osexpand(os.path.join(get_user_conf_dirs()[0], "99_configure_tool.conf")) + return osexpand(os.path.join(get_user_conf_dirs()[0], "conf.d", "99_configure_tool.conf")) def parse_user_config_file() -> dict: @@ -42,6 +52,27 @@ def parse_user_config_file() -> dict: def save_user_config_file(options: dict) -> None: filename = get_user_config_file() + conf_dir = os.path.dirname(filename) + if not os.path.exists(conf_dir): + os.mkdir(conf_dir, mode=0o755) with open(filename, "w", encoding="utf8") as f: + f.write("# generated on " + datetime.now().strftime("%c")+"\n\n") for k, v in options.items(): f.write(f"{k} = {v}\n") + + +def update_config_attribute(attribute, value): + log(f"update config: {attribute}={value}") + config = parse_user_config_file() + config[attribute] = str(value) + save_user_config_file(config) + + +def with_config(cb: Callable): + # load config in a thread as this involves IO, + # then run the callback in the UI thread + def load_config(): + defaults = make_defaults_struct() + GLib.idle_add(cb, defaults) + + start_thread(load_config, "load-config", daemon=True) diff --git a/xpra/gtk/configure/features.py b/xpra/gtk/configure/features.py index 9dac211590..e07878582e 100644 --- a/xpra/gtk/configure/features.py +++ b/xpra/gtk/configure/features.py @@ -1,12 +1,11 @@ # This file is part of Xpra. -# Copyright (C) 2018-2023 Antoine Martin +# Copyright (C) 2023 Antoine Martin # 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.gtk.dialogs.base_gui_window import BaseGUIWindow -from xpra.scripts.config import make_defaults_struct, parse_bool -from xpra.gtk.configure.common import parse_user_config_file, save_user_config_file -from xpra.util.thread import start_thread +from xpra.scripts.config import parse_bool +from xpra.gtk.configure.common import update_config_attribute, with_config from xpra.gtk.widget import label from xpra.os_util import gi_import from xpra.log import Logger @@ -68,17 +67,11 @@ def populate(self): grid.attach(lbl, 0, i, 1, 1) switch = Gtk.Switch() switch.set_sensitive(False) - switch.set_state(i % 2 == 0) switch.connect("state-set", self.toggle_subsystem, sub) grid.attach(switch, 1, i, 1, 1) self.subsystem_switch[sub] = switch self.show_all() - # load config in a thread as this involves IO: - start_thread(self.load_config, "load-config", daemon=True) - - def load_config(self): - defaults = make_defaults_struct() - GLib.idle_add(self.configure_switches, defaults) + with_config(self.configure_switches) def configure_switches(self, defaults): for subsystem, switch in self.subsystem_switch.items(): @@ -91,17 +84,15 @@ def configure_switches(self, defaults): return False @staticmethod - def toggle_subsystem(switch, state, subsystem): - config = parse_user_config_file() - config[subsystem] = str(state).lower() - log(f"state_set({(switch, state, subsystem)} saving {config}") - save_user_config_file(config) + def toggle_subsystem(widget, state, subsystem): + update_config_attribute(subsystem, state) def main(_args) -> int: from xpra.gtk.configure.main import run_gui return run_gui(ConfigureGUI) + if __name__ == "__main__": import sys sys.exit(main(sys.argv[1:])) diff --git a/xpra/gtk/configure/opengl.py b/xpra/gtk/configure/opengl.py index 879a029b04..9fb2572f81 100644 --- a/xpra/gtk/configure/opengl.py +++ b/xpra/gtk/configure/opengl.py @@ -1,5 +1,5 @@ # This file is part of Xpra. -# Copyright (C) 2018-2023 Antoine Martin +# Copyright (C) 2023 Antoine Martin # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. diff --git a/xpra/gtk/dialogs/base_gui_window.py b/xpra/gtk/dialogs/base_gui_window.py index 48e2091ac3..3f86930f26 100644 --- a/xpra/gtk/dialogs/base_gui_window.py +++ b/xpra/gtk/dialogs/base_gui_window.py @@ -82,6 +82,8 @@ def __init__(self, with IgnoreWarningsContext(): self.set_wmclass(*wm_class) self.vbox = Gtk.VBox(homogeneous=False, spacing=10) + self.vbox.set_margin_start(40) + self.vbox.set_margin_end(40) self.add(self.vbox) self.populate() self.vbox.show_all()