Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
severinsimmler committed May 12, 2018
1 parent 783f0a8 commit 28edba3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
5 changes: 3 additions & 2 deletions application/config.py
Expand Up @@ -5,8 +5,9 @@

def create_app(**kwargs):
"""
Creates a Flask app. If the scripts were frozen with PyInstaller,
the paths to the template and static folder are adjusted accordingly.
Creates a Flask app and temporary folders. If the scripts were frozen with
PyInstaller, the paths to the template and static folder are adjusted
accordingly.
"""
tempdir = tempfile.gettempdir()
dumpdir = pathlib.Path(tempdir, 'topicsexplorerdump')
Expand Down
13 changes: 13 additions & 0 deletions application/gui.py
Expand Up @@ -26,6 +26,9 @@ def __init__(self, root_url):
self.root_url = root_url

def home(self):
"""
Loads the root URL.
"""
self.load(PyQt5.QtCore.QUrl(self.root_url))

def acceptNavigationRequest(self, url, kind, is_main_frame):
Expand All @@ -42,6 +45,10 @@ def acceptNavigationRequest(self, url, kind, is_main_frame):


def init_gui(application, port=5000, argv=None):
"""
Initializes the Qt web engine, starts the web application, and loads the
main page.
"""
if argv is None:
argv = sys.argv

Expand Down Expand Up @@ -72,6 +79,9 @@ def init_gui(application, port=5000, argv=None):
webview.setPage(page)

def download_requested(item):
"""
Opens a file dialog to save the ZIP archive.
"""
path = PyQt5.QtWidgets.QFileDialog.getSaveFileName(None,
'Select destination folder and file name',
'',
Expand All @@ -86,4 +96,7 @@ def download_requested(item):


def run():
"""
Calls the main function.
"""
sys.exit(init_gui(application.web.app))
13 changes: 8 additions & 5 deletions application/web.py
Expand Up @@ -11,8 +11,8 @@
@app.route('/')
def index():
"""
Renders the main page. A warning pops up, if the machine is not
connected to the internet.
Renders the main page, and unlinks the content (if any) in the temporary
folders. A warning pops up, if the machine is not connected to the internet.
"""
application.utils.unlink_content(dumpdir)
application.utils.unlink_content(archivedir)
Expand Down Expand Up @@ -41,8 +41,7 @@ def stream_template(template_name, **context):
app.update_template_context(context)
t = app.jinja_env.get_template(template_name)
return t.stream(context)
stream = flask.stream_with_context(application.modeling.workflow(dumpdir,
archivedir))
stream = flask.stream_with_context(application.modeling.workflow(dumpdir, archivedir))
return flask.Response(stream_template('modeling.html', info=stream))


Expand All @@ -53,9 +52,13 @@ def model():
"""
data = application.utils.load_data(dumpdir)
return flask.render_template('model.html', **data)



@app.route('/download')
def download():
"""
Sends the ZIP archive.
"""
return flask.send_file(str(pathlib.Path(archivedir, 'topicmodeling.zip')))


Expand Down
9 changes: 5 additions & 4 deletions topicsexplorer.py
Expand Up @@ -4,10 +4,11 @@
import argparse


DESCRIPTION = "Run DARIAH Topics Explorer either as a standalone desktop "\
"application with its own window, or as a web application in a "\
"browser. If you do not specify any parameters, the desktop "\
"application is started."
DESCRIPTION = """
Run DARIAH Topics Explorer either as a desktop application with
its own window, or as a web application in a browser. If you do
not specify any parameters, the desktop application is started.
"""

parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('--browser', action='store_true',
Expand Down

0 comments on commit 28edba3

Please sign in to comment.