Skip to content

Commit 1855b21

Browse files
committed
GUI: use filedialpy
1 parent c6b6f3b commit 1855b21

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

docs/content/usage.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,16 @@ Start the graphical user interface.
6363

6464
.. code:: bash
6565
66-
figeno gui [-m MODE] [-p PORT] [--debug]
66+
figeno gui [--webview] [-p PORT] [--debug]
6767
6868
Parameters:
6969

70-
* ``-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.
70+
* ``-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).
7171

7272
* ``-p``, ``--port``. Port for the local server, in case the browser mode is used (default: 5000).
7373

74-
* ``--debug``: if set, will print more information to the terminal.
74+
* ``--debug``: If set, will print more information to the terminal.
7575

76-
.. warning::
77-
The browser mode for is currently only supported for linux.
78-
7976
.. warning::
8077
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).
8178

@@ -96,7 +93,7 @@ You can also import figeno as a python module, and give ``figeno_make`` the conf
9693
import figeno_make from figeno
9794
9895
config={"general":{"reference":"hg19","layout":"horizontal"}}
99-
config["output"] = {"file":"figure.svg"),"dpi":200,"width":180}
96+
config["output"] = {"file":"figure.svg","dpi":200,"width":180}
10097
config["regions"] = [{"chr":"17","start":7000000,"end":7500000}]
10198
config["tracks"] = [{"type":"genes"}, {"type":"chr_axis"}]
10299
figeno_make(config)

figeno/cli/gui.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
2-
import platform
32

43
def main(args):
5-
mode = args.mode
6-
if mode=="auto":
7-
if platform.system()=="Linux": mode="browser"
8-
else: mode="webview"
9-
10-
if mode=="browser":
4+
if not args.webview:
115
from figeno.gui import gui_browser
126
gui_browser.main(args)
137
else:
@@ -16,10 +10,9 @@ def main(args):
1610

1711
def argparser():
1812
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter,add_help=False)
19-
parser.add_argument("-m","--mode",type=str,default="auto",
20-
help="The GUI can either be viewed in a browser tab (--mode browser) or in a separate webview window (--mode webview).\
21-
By default (--mode auto), will select browser for linux and webview for windows and mac.")
13+
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..")
2214
parser.add_argument("-p","--port",type=int,default=5000, help="Port, only used in browser mode.")
2315
parser.add_argument('--debug', action='store_true',help="If set, will provide more debugging information.")
2416
parser.set_defaults(debug=False)
17+
parser.set_defaults(webview=False)
2518
return parser

figeno/gui/gui_browser.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
import logging
55
from flask import Flask, jsonify, request
66
import json
7-
import crossfiledialog
7+
import filedialpy
88
from figeno import figeno_make
99

1010
app = Flask(__name__, static_folder='./build', static_url_path='/')
1111

1212
last_dir=os.getcwd()
1313
config_dir=last_dir
14+
config_file="config.json"
1415

1516

1617

@@ -21,15 +22,15 @@ def browse():
2122
data=request.get_json()
2223
start_dir = last_dir
2324
if len(data["path"])>0 and os.path.exists(os.path.dirname(data["path"])):
24-
start_dir = os.path.dirname(data["path"])
25-
t=crossfiledialog.open_file(start_dir=start_dir)
25+
start_dir = os.path.dirname(data["path"], title="Select file")
26+
t=filedialpy.openFile(initial_dir=start_dir)
2627
if len(t)>0: last_dir= os.path.dirname(t)
2728
return jsonify({"path":t})
2829

2930
@app.route('/open_files')
3031
def open_files():
3132
global last_dir
32-
t=crossfiledialog.open_multiple(start_dir=last_dir)
33+
t=filedialpy.openFiles(initial_dir=last_dir,title="Select files")
3334
if len(t)>0 and len(t[0])>0: last_dir= os.path.dirname(t[0])
3435
return jsonify({"files":t})
3536

@@ -40,18 +41,25 @@ def save():
4041
start_dir = last_dir
4142
if len(data["path"])>0 and os.path.exists(os.path.dirname(data["path"])):
4243
start_dir=os.path.dirname(data["path"])
43-
t=crossfiledialog.save_file(start_dir=start_dir)
44+
save_filename="figure.svg"
45+
if len(data["path"])>0:
46+
filename = os.path.basename(data["path"])
47+
if len(filename)>0 and (filename.endswith(".svg") or filename.endswith(".pdf") or filename.endswith(".ps") or filename.endswith(".eps") or filename.endswith(".png")):
48+
save_filename=filename
49+
t=filedialpy.saveFile(initial_dir=start_dir,initial_file=save_filename,title="Select output path for the figure", filter="*.svg *.pdf *.png *.eps *.ps")
4450
if len(t)>0:last_dir= os.path.dirname(t)
4551
return jsonify({"path":t})
4652

4753
@app.route('/save_config', methods = ['POST'])
4854
def save_config():
4955
global config_dir
56+
global config_file
5057
if request.is_json:
5158
data = request.get_json()
52-
filename=crossfiledialog.save_file(start_dir=config_dir)
59+
filename=filedialpy.saveFile(initial_dir=config_dir,initial_file=config_file,title="Select path to save the config file",filter="*.json")
5360
if len(filename)>0:
5461
config_dir=os.path.dirname(filename)
62+
config_file=os.path.basename(filename)
5563
with open(filename,"w") as fp:
5664
json.dump(data,fp,indent= "\t")
5765
return jsonify({"path":filename})
@@ -60,9 +68,11 @@ def save_config():
6068
@app.route('/load_config')
6169
def load_config():
6270
global config_dir
63-
filename=crossfiledialog.open_file(filter="*.json",start_dir=config_dir)
71+
global config_file
72+
filename=filedialpy.openFile(initial_dir=config_dir,filter="*.json",title="Select config file to load")
6473
if len(filename)>0:
6574
config_dir=os.path.dirname(filename)
75+
config_file=os.path.basename(filename)
6676
with open(filename,"r") as fp:
6777
config = json.load(fp)
6878
return jsonify(config)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ packages = ["figeno", "figeno.data", "figeno.cli", "figeno.gui"]
99

1010
[project]
1111
name = 'figeno'
12-
version = "0.0.2"
12+
version = "0.3.0"
1313
description = 'Package for generating genomics figures.'
1414
readme = 'README.md'
1515
authors = [
@@ -30,7 +30,7 @@ dependencies = [
3030
"vcfpy>=0.13.5",
3131
"cooler>=0.9.1",
3232
"Flask>=2.2.5",
33-
"crossfiledialog>=0.2.0",
33+
"filedialpy>=1.0.0",
3434
"pywebview>=4.4.1"
3535
]
3636

0 commit comments

Comments
 (0)