Skip to content

Commit

Permalink
GUI: use filedialpy
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sollier committed Mar 13, 2024
1 parent c6b6f3b commit 1855b21
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
11 changes: 4 additions & 7 deletions docs/content/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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)
Expand Down
13 changes: 3 additions & 10 deletions figeno/cli/gui.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
24 changes: 17 additions & 7 deletions figeno/gui/gui_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"



Expand All @@ -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})

Expand All @@ -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})
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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"
]

Expand Down

0 comments on commit 1855b21

Please sign in to comment.