From d1d71f03ade1371d64c7bd21b145aa87c8d96727 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Wed, 14 Aug 2024 14:07:41 +0200 Subject: [PATCH] add cross-platform function to open file browser --- common/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/common/utils.py b/common/utils.py index 17b5ae4..975842b 100644 --- a/common/utils.py +++ b/common/utils.py @@ -35,6 +35,22 @@ def deprecated(func): return func(*args, **kwargs) return new_func +def open_file_browser(directory): + if sys.platform=='win32': + os.startfile(directory) + + elif sys.platform=='darwin': + subprocess.Popen(['open', directory]) + + else: + try: + subprocess.Popen(['xdg-open', directory]) + except OSError: + pass + # er, think of something else to try + # xdg-open *should* be supported by recent Gnome, KDE, Xfce + + # # Evaluate a bezier curve for the parameter 0<=t<=1 along its length # def evaluateBezierPoint(p1, h1, h2, p2, t): # return ((1 - t)**3) * p1 + (3 * t * (1 - t)**2) * h1 + (3 * (t**2) * (1 - t)) * h2 + (t**3) * p2