From 1855b21ccb1147808b57ad216e26ddb2e1841827 Mon Sep 17 00:00:00 2001 From: e-sollier Date: Wed, 13 Mar 2024 12:21:47 +0100 Subject: [PATCH] GUI: use filedialpy --- docs/content/usage.rst | 11 ++++------- figeno/cli/gui.py | 13 +++---------- figeno/gui/gui_browser.py | 24 +++++++++++++++++------- pyproject.toml | 4 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/content/usage.rst b/docs/content/usage.rst index 054ad43..6385106 100644 --- a/docs/content/usage.rst +++ b/docs/content/usage.rst @@ -63,19 +63,16 @@ Start the graphical user interface. .. code:: bash - figeno gui [-m MODE] [-p PORT] [--debug] + figeno gui [--webview] [-p PORT] [--debug] Parameters: -* ``-m``, ``--mode``. Can be "auto" (default), "browser" or "webview". Browser will start a local server which can be viewed in a web browser (at localhost:5000 by default) while webview will open the gui in a separate window using pywebview. If "auto", will use browser for linux and webview for windows and mac. +* ``-w``, ``--webview``. If set, will use pywebview to render the GUI. Otherwise, the GUI can be viewed in the browser (at localhost:5000 by default). * ``-p``, ``--port``. Port for the local server, in case the browser mode is used (default: 5000). -* ``--debug``: if set, will print more information to the terminal. +* ``--debug``: If set, will print more information to the terminal. -.. warning:: - The browser mode for is currently only supported for linux. - .. warning:: The webview mode works for linux, windows and mac, but for linux you will need to install additional dependencies (see https://pywebview.flowrl.com/guide/installation.html#linux). @@ -96,7 +93,7 @@ You can also import figeno as a python module, and give ``figeno_make`` the conf import figeno_make from figeno config={"general":{"reference":"hg19","layout":"horizontal"}} - config["output"] = {"file":"figure.svg"),"dpi":200,"width":180} + config["output"] = {"file":"figure.svg","dpi":200,"width":180} config["regions"] = [{"chr":"17","start":7000000,"end":7500000}] config["tracks"] = [{"type":"genes"}, {"type":"chr_axis"}] figeno_make(config) diff --git a/figeno/cli/gui.py b/figeno/cli/gui.py index 9ebab04..ae8de50 100644 --- a/figeno/cli/gui.py +++ b/figeno/cli/gui.py @@ -1,13 +1,7 @@ from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter -import platform def main(args): - mode = args.mode - if mode=="auto": - if platform.system()=="Linux": mode="browser" - else: mode="webview" - - if mode=="browser": + if not args.webview: from figeno.gui import gui_browser gui_browser.main(args) else: @@ -16,10 +10,9 @@ def main(args): def argparser(): parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter,add_help=False) - parser.add_argument("-m","--mode",type=str,default="auto", - help="The GUI can either be viewed in a browser tab (--mode browser) or in a separate webview window (--mode webview).\ - By default (--mode auto), will select browser for linux and webview for windows and mac.") + parser.add_argument('-w','--webview', dest="webview",action='store_true',help="If set, start the GUI in webview (using pywebview) instead of in the browser..") parser.add_argument("-p","--port",type=int,default=5000, help="Port, only used in browser mode.") parser.add_argument('--debug', action='store_true',help="If set, will provide more debugging information.") parser.set_defaults(debug=False) + parser.set_defaults(webview=False) return parser \ No newline at end of file diff --git a/figeno/gui/gui_browser.py b/figeno/gui/gui_browser.py index 33b4891..35efcca 100644 --- a/figeno/gui/gui_browser.py +++ b/figeno/gui/gui_browser.py @@ -4,13 +4,14 @@ import logging from flask import Flask, jsonify, request import json -import crossfiledialog +import filedialpy from figeno import figeno_make app = Flask(__name__, static_folder='./build', static_url_path='/') last_dir=os.getcwd() config_dir=last_dir +config_file="config.json" @@ -21,15 +22,15 @@ def browse(): data=request.get_json() start_dir = last_dir if len(data["path"])>0 and os.path.exists(os.path.dirname(data["path"])): - start_dir = os.path.dirname(data["path"]) - t=crossfiledialog.open_file(start_dir=start_dir) + start_dir = os.path.dirname(data["path"], title="Select file") + t=filedialpy.openFile(initial_dir=start_dir) if len(t)>0: last_dir= os.path.dirname(t) return jsonify({"path":t}) @app.route('/open_files') def open_files(): global last_dir - t=crossfiledialog.open_multiple(start_dir=last_dir) + t=filedialpy.openFiles(initial_dir=last_dir,title="Select files") if len(t)>0 and len(t[0])>0: last_dir= os.path.dirname(t[0]) return jsonify({"files":t}) @@ -40,18 +41,25 @@ def save(): start_dir = last_dir if len(data["path"])>0 and os.path.exists(os.path.dirname(data["path"])): start_dir=os.path.dirname(data["path"]) - t=crossfiledialog.save_file(start_dir=start_dir) + save_filename="figure.svg" + if len(data["path"])>0: + filename = os.path.basename(data["path"]) + if len(filename)>0 and (filename.endswith(".svg") or filename.endswith(".pdf") or filename.endswith(".ps") or filename.endswith(".eps") or filename.endswith(".png")): + save_filename=filename + t=filedialpy.saveFile(initial_dir=start_dir,initial_file=save_filename,title="Select output path for the figure", filter="*.svg *.pdf *.png *.eps *.ps") if len(t)>0:last_dir= os.path.dirname(t) return jsonify({"path":t}) @app.route('/save_config', methods = ['POST']) def save_config(): global config_dir + global config_file if request.is_json: data = request.get_json() - filename=crossfiledialog.save_file(start_dir=config_dir) + filename=filedialpy.saveFile(initial_dir=config_dir,initial_file=config_file,title="Select path to save the config file",filter="*.json") if len(filename)>0: config_dir=os.path.dirname(filename) + config_file=os.path.basename(filename) with open(filename,"w") as fp: json.dump(data,fp,indent= "\t") return jsonify({"path":filename}) @@ -60,9 +68,11 @@ def save_config(): @app.route('/load_config') def load_config(): global config_dir - filename=crossfiledialog.open_file(filter="*.json",start_dir=config_dir) + global config_file + filename=filedialpy.openFile(initial_dir=config_dir,filter="*.json",title="Select config file to load") if len(filename)>0: config_dir=os.path.dirname(filename) + config_file=os.path.basename(filename) with open(filename,"r") as fp: config = json.load(fp) return jsonify(config) diff --git a/pyproject.toml b/pyproject.toml index 587b581..fdafa17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ packages = ["figeno", "figeno.data", "figeno.cli", "figeno.gui"] [project] name = 'figeno' -version = "0.0.2" +version = "0.3.0" description = 'Package for generating genomics figures.' readme = 'README.md' authors = [ @@ -30,7 +30,7 @@ dependencies = [ "vcfpy>=0.13.5", "cooler>=0.9.1", "Flask>=2.2.5", - "crossfiledialog>=0.2.0", + "filedialpy>=1.0.0", "pywebview>=4.4.1" ]