Skip to content

Commit

Permalink
#4064 move more code to common
Browse files Browse the repository at this point in the history
make encodings gui usable
  • Loading branch information
totaam committed Dec 7, 2023
1 parent e2d2565 commit a46ccca
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
35 changes: 33 additions & 2 deletions xpra/gtk/configure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand All @@ -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)
23 changes: 7 additions & 16 deletions xpra/gtk/configure/features.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# This file is part of Xpra.
# Copyright (C) 2018-2023 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2023 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.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
Expand Down Expand Up @@ -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():
Expand All @@ -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:]))
2 changes: 1 addition & 1 deletion xpra/gtk/configure/opengl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of Xpra.
# Copyright (C) 2018-2023 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2023 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.

Expand Down
2 changes: 2 additions & 0 deletions xpra/gtk/dialogs/base_gui_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a46ccca

Please sign in to comment.