Skip to content

Commit

Permalink
#3978 cythonized versions can't be executed as files
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Oct 3, 2023
1 parent a66e058 commit 487f0a8
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions xpra/gtk/dialogs/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pylint: disable=wrong-import-position

import sys
import glob
import os.path
import subprocess
import gi
Expand All @@ -18,7 +19,7 @@
from xpra.gtk.gtk_util import add_close_accel
from xpra.gtk.widget import imagebutton, label
from xpra.gtk.pixbuf import get_icon_pixbuf
from xpra.platform.paths import get_python_execfile_command
from xpra.platform.paths import get_python_execfile_command, get_python_exec_command
from xpra.os_util import WIN32, OSX, is_X11
from xpra.log import Logger

Expand Down Expand Up @@ -80,8 +81,8 @@ def __init__(self, title=TITLE):
self.vbox = Gtk.VBox(homogeneous=False, spacing=10)
self.add(self.vbox)

epath = "../examples/"
cpath = "../../client/"
epath = "xpra.gtk.examples."
cpath = "xpra.client."

def addhbox(blabel, buttons):
self.vbox.add(self.label(blabel))
Expand All @@ -95,45 +96,45 @@ def addhbox(blabel, buttons):
wox11 = WIN32 or OSX or (os.environ.get("GDK_BACKEND", "")=="x11" or is_X11())

addhbox("Colors:", (
("Squares", "Shows RGB+Grey squares in a window", epath+"colors_plain.py"),
("Animated", "Shows RGB+Grey squares animated", epath+"colors.py"),
("Bit Depth", "Shows color gradients and visualize bit depth clipping", epath+"colors_gradient.py"),
("Squares", "Shows RGB+Grey squares in a window", epath+"colors_plain"),
("Animated", "Shows RGB+Grey squares animated", epath+"colors"),
("Bit Depth", "Shows color gradients and visualize bit depth clipping", epath+"colors_gradient"),
))
addhbox("Transparency and Rendering", (
("Circle", "Shows a semi-opaque circle in a transparent window", epath+"transparent_window.py"),
("RGB Squares", "RGB+Black shaded squares in a transparent window", epath+"transparent_colors.py"),
("OpenGL", "OpenGL window - transparent on some platforms", cpath+"gl/window.py", wox11),
("Circle", "Shows a semi-opaque circle in a transparent window", epath+"transparent_window"),
("RGB Squares", "RGB+Black shaded squares in a transparent window", epath+"transparent_colors"),
("OpenGL", "OpenGL window - transparent on some platforms", cpath+"gl.window", wox11),
))
addhbox("Widgets:", (
("Text Entry", "Simple text entry widget", epath+"text_entry.py"),
("File Selector", "Open the file selector widget", epath+"file_chooser.py"),
("Header Bar", "Window with a custom header bar", epath+"header_bar.py"),
("Text Entry", "Simple text entry widget", epath+"text_entry"),
("File Selector", "Open the file selector widget", epath+"file_chooser"),
("Header Bar", "Window with a custom header bar", epath+"header_bar"),
))
addhbox("Events:", (
("Grabs", "Test keyboard and pointer grabs", epath+"grabs.py"),
("Clicks", "Double and triple click events", epath+"clicks.py"),
("Focus", "Shows window focus events", epath+"window_focus.py"),
("Grabs", "Test keyboard and pointer grabs", epath+"grabs"),
("Clicks", "Double and triple click events", epath+"clicks"),
("Focus", "Shows window focus events", epath+"window_focus"),
))
addhbox("Windows:", (
("States", "Toggle various window attributes", epath+"window_states.py"),
("Title", "Update the window title", epath+"window_title.py"),
("Opacity", "Change window opacity", epath+"window_opacity.py"),
("Transient", "Show transient windows", epath+"window_transient.py"),
("Override Redirect", "Shows an override redirect window", epath+"window_overrideredirect.py"),
("States", "Toggle various window attributes", epath+"window_states"),
("Title", "Update the window title", epath+"window_title"),
("Opacity", "Change window opacity", epath+"window_opacity"),
("Transient", "Show transient windows", epath+"window_transient"),
("Override Redirect", "Shows an override redirect window", epath+"window_overrideredirect"),
))
addhbox("Geometry:", (
("Size constraints", "Specify window geometry size constraints", epath+"window_geometry_hints.py"),
("Move-Resize", "Initiate move resize from application", epath+"initiate_moveresize.py", wox11),
("Size constraints", "Specify window geometry size constraints", epath+"window_geometry_hints"),
("Move-Resize", "Initiate move resize from application", epath+"initiate_moveresize", wox11),
))
addhbox("Keyboard and Clipboard:", (
("Keyboard", "Keyboard event viewer", "view_keyboard.py"),
("Clipboard", "Clipboard event viewer", "view_clipboard.py"),
("Keyboard", "Keyboard event viewer", "xpra.gtk.dialogs.view_keyboard"),
("Clipboard", "Clipboard event viewer", "xpra.gtk.dialogs.view_clipboard"),
))
addhbox("Misc:", (
("Tray", "Show a system tray icon", epath+"tray.py"),
("Font Rendering", "Render characters with and without anti-aliasing", epath+"fontrendering.py"),
("Bell", "Test system bell", epath+"bell.py"),
("Cursors", "Show named cursors", epath+"cursors.py"),
("Tray", "Show a system tray icon", epath+"tray"),
("Font Rendering", "Render characters with and without anti-aliasing", epath+"fontrendering"),
("Bell", "Test system bell", epath+"bell"),
("Cursors", "Show named cursors", epath+"cursors"),
))
self.vbox.show_all()

Expand All @@ -142,20 +143,31 @@ def label(text):
return label(text, font="sans 14")

@staticmethod
def button(label_str, tooltip, relpath, enabled=True):
def button(label_str, tooltip, modpath, enabled=True):
cp = os.path.dirname(__file__)
script = os.path.join(cp, relpath)
script_path = os.path.join(cp, "../../../"+modpath.replace(".", "/"))
if WIN32 and os.path.sep == "/":
script = script.replace("/", "\\")
script = os.path.abspath(script)
if not os.path.exists(script):
if os.path.exists(script + "c"):
script += "c"
else:
enabled = False
log.warn("Warning: cannot find '%s'", script)
def cb(_btn):
script_path = script_path.replace("/", "\\")
script_path = os.path.abspath(script_path)
script = script_path+".py"
cmd = []
if os.path.exists(script):
cmd = get_python_execfile_command()+[script]
else:
for compiled_ext in (".pyc", ".*.pyd", ".*.so"):
script = script_path + compiled_ext
matches = glob.glob(script)
log(f"glob.glob({script})={matches}")
if matches and os.path.exists(matches[0]):
script = matches[0]
cmd = get_python_exec_command()+[f"from {modpath} import main;main()"]
break
if not cmd:
enabled = False
log.warn(f"Warning: cannot find '{modpath}'")
else:
log(f"{label_str} : {cmd}")
def cb(_btn):
proc = exec_command(cmd)
getChildReaper().add_process(proc, label_str, cmd, ignore=True, forget=True)
ib = imagebutton(label_str, None,
Expand Down

0 comments on commit 487f0a8

Please sign in to comment.