Skip to content

Commit c0495d9

Browse files
committed
#4064 opengl configure dialog
1 parent a0d660c commit c0495d9

File tree

8 files changed

+349
-126
lines changed

8 files changed

+349
-126
lines changed

xpra/client/gui/fake_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self):
2121
self.mmap = None
2222
self.readonly = False
2323
self.encoding_defaults = {}
24+
self.modal_windows = []
2425
self._focused = None
2526
self._remote_server_mode = "seamless"
2627
self.wheel_smooth = False

xpra/gtk/configure/common.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
44
# later version. See the file COPYING for details.
55

6+
import os.path
67
from subprocess import check_call
78

89
from xpra.os_util import POSIX
10+
from xpra.util.env import osexpand
11+
from xpra.util.parsing import parse_simple_dict
912

1013
DISCLAIMER = """
1114
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
@@ -21,3 +24,23 @@
2124
def sync() -> None:
2225
if POSIX:
2326
check_call("sync")
27+
28+
29+
def get_user_config_file() -> str:
30+
from xpra.platform.paths import get_user_conf_dirs
31+
return osexpand(os.path.join(get_user_conf_dirs()[0], "99_configure_tool.conf"))
32+
33+
34+
def parse_user_config_file() -> dict:
35+
filename = get_user_config_file()
36+
if not os.path.exists(filename):
37+
return {}
38+
with open(filename, "r", encoding="utf8") as f:
39+
return parse_simple_dict(f.read())
40+
41+
42+
def save_user_config_file(options: dict) -> None:
43+
filename = get_user_config_file()
44+
with open(filename, "w", encoding="utf8") as f:
45+
for k, v in options.items():
46+
f.write(f"{k} = {v}\n")

xpra/gtk/configure/gstreamer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def __init__(self, parent: Gtk.Window | None = None):
4141
self.set_resizable(False)
4242

4343
def populate(self):
44-
for x in self.vbox.get_children():
45-
self.vbox.remove(x)
44+
self.clear_vbox()
4645
if not self.warning_shown:
4746
self.populate_with_warning()
4847
else:

xpra/gtk/configure/main.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import os.path
77
from importlib import import_module
88

9+
from xpra.gtk.configure.common import get_user_config_file
910
from xpra.scripts.config import InitExit
1011
from xpra.exit_codes import ExitCode
1112
from xpra.os_util import gi_import
12-
from xpra.util.parsing import parse_simple_dict
1313
from xpra.gtk.dialogs.base_gui_window import BaseGUIWindow
1414
from xpra.gtk.widget import label
1515
from xpra.log import Logger
@@ -29,18 +29,19 @@ def __init__(self):
2929
default_size=(480, 300),
3030
header_bar=(True, False),
3131
)
32-
self.dialogs : dict[str,BaseGUIWindow] = {}
32+
self.dialogs : dict[str, BaseGUIWindow] = {}
3333

3434
def populate(self):
3535
self.vbox.add(label("Configure Xpra", font="sans 20"))
3636
self.vbox.add(label("Tune your xpra configuration:", font="sans 14"))
37-
self.sub("Features", "features.png","Enable or disable feature groups", "features")
38-
self.sub("Picture compression", "encoding.png","Encodings, speed and quality", "encodings")
39-
self.sub("GStreamer", "gstreamer.png","Configure the GStreamer codecs", "gstreamer")
40-
self.sub("OpenGL acceleration", "opengl.png","Test and validate OpenGL renderer", "opengl")
37+
self.sub("Features", "features.png", "Enable or disable feature groups", "features")
38+
self.sub("Picture compression", "encoding.png", "Encodings, speed and quality", "encodings")
39+
self.sub("GStreamer", "gstreamer.png", "Configure the GStreamer codecs", "gstreamer")
40+
self.sub("OpenGL acceleration", "opengl.png", "Test and validate OpenGL renderer", "opengl")
4141

42-
def sub(self, title="", icon_name="browse.png", tooltip="", configure:str="") -> None:
43-
def callback(btn):
42+
def sub(self, title="", icon_name="browse.png", tooltip="", configure: str = "") -> None:
43+
44+
def callback(_btn):
4445
dialog = self.dialogs.get(configure)
4546
if dialog is None:
4647
mod = import_module(f"xpra.gtk.configure.{configure}")
@@ -68,29 +69,11 @@ def run_gui(gui_class=ConfigureGUI) -> int:
6869
return 0
6970

7071

71-
def get_user_config_file() -> str:
72-
from xpra.platform.paths import get_user_conf_dirs
73-
return os.path.join(get_user_conf_dirs()[0], "99_configure_tool.conf")
74-
75-
def parse_user_config_file() -> dict:
76-
filename = get_user_config_file()
77-
if not os.path.exists(filename):
78-
return {}
79-
with open(filename, "r", encoding="utf8") as f:
80-
return parse_simple_dict(f.read())
81-
82-
def save_user_config_file(options:dict) -> None:
83-
filename = get_user_config_file()
84-
with open(filename, "w", encoding="utf8") as f:
85-
for k,v in options.items():
86-
f.write(f"{k} = {v}")
87-
88-
8972
def main(args) -> ExitCode:
9073
if args:
9174
conf = get_user_config_file()
9275
subcommand = args[0]
93-
if subcommand=="reset":
76+
if subcommand == "reset":
9477
import datetime
9578
now = datetime.datetime.now()
9679
with open(conf, "w", encoding="utf8") as f:
@@ -105,15 +88,21 @@ def main(args) -> ExitCode:
10588
with open(bak, "w", encoding="utf8") as write:
10689
write.write(read.read())
10790
return ExitCode.OK
108-
elif subcommand=="show":
91+
elif subcommand == "show":
10992
if not os.path.exists(conf):
11093
print(f"# {conf!r} does not exist yet")
11194
else:
11295
with open(conf, "r", encoding="utf8") as f:
11396
print(f.read())
11497
return ExitCode.OK
11598
else:
116-
raise InitExit(ExitCode.FILE_NOT_FOUND, f"unknown configure subcommand {subcommand!r}")
99+
if any(not str.isalnum(x) for x in subcommand):
100+
raise ValueError("invalid characters found in subcommand")
101+
from importlib import import_module
102+
mod = import_module(f"xpra.gtk.configure.{subcommand}")
103+
if not mod:
104+
raise InitExit(ExitCode.FILE_NOT_FOUND, f"unknown configure subcommand {subcommand!r}")
105+
return mod.main(args[1:])
117106
return run_gui(ConfigureGUI)
118107

119108

0 commit comments

Comments
 (0)