Skip to content

Commit

Permalink
updated qats link app and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
eneelo committed Dec 5, 2023
1 parent ab78eff commit f44d5a9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 83 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ python -m pip install --upgrade qats
You may now import qats in your own scripts:

```python
from qats import TsDB, TimeSeries
>>> from qats import TsDB, TimeSeries
```

... or use the GUI to inspect time series.
Expand Down Expand Up @@ -133,8 +133,8 @@ This will
You should now be able to import the package in the Python console,

```python
import qats
help(qats)
>>> import qats
>>> help(qats)
```

... and use the command line interface (CLI).
Expand Down
50 changes: 23 additions & 27 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ QATS is installed from PyPI by using `pip`:

.. code-block:: console
python -m pip install qats
$ python -m pip install qats
Now you should be able to import the package in the Python console

Expand Down Expand Up @@ -53,7 +53,7 @@ and run the command line interface (CLI).
.. code-block:: console
qats -h
$ qats -h
usage: qats [-h] [--version] {app,config} ...
Expand All @@ -70,47 +70,43 @@ and run the command line interface (CLI).
.. note::
As of version 5.0.0, qats installs the [Qt](https://www.qt.io) binding [PySide6](https://pypi.org/project/PySide6/).
Although not recommended you can choose a different qt binding yourself by installing the package and setting the
environmental variable `QT_API`. Accepted values include `pyqt6` (to use PyQt6) and `pyside6` (PySide6). For more details,
see [README file for qtpy](https://github.com/spyder-ide/qtpy/blob/master/README.md).
As of version 5.0.0, qats installs the `Qt <https://www.qt.io>`_ binding `PySide6 <https://pypi.org/project/PySide6/>`_.
Although not recommended, you can choose a different qt binding yourself by installing the package and setting the
environmental variable :code:`QT_API`. Accepted values include :code:`pyqt6` (to use PyQt6) and :code:`pyside6` (PySide6). For more details,
see `README file for qtpy <https://github.com/spyder-ide/qtpy/blob/master/README.md>`_.
.. note::
As of version 4.11.0, the CLI is also available through the ``python -m`` switch, for example:
Launching the GUI
*****************
The GUI is launched via the CLI:
.. code-block::
.. code-block::
$ python -m qats -h
$ python -m qats app
qats app
.. $ python -m qats config --link-app
Or, you may add a shortcut for launching the QATS GUI to your Windows Start menu and on the Desktop by running the command:
.. code-block::
.. :code:`python -m qats config --link-app-no-exe`.
qats config --link-app
.. note::
As of version 4.11.0, the CLI is also available through the ``python -m`` switch, for example:
.. :code:`python -m qats -h` or :code:`python -m qats app`.
.. code-block::
python -m qats -h
python -m qats app
To add a Windows Start menu shortcut that utilizes this to launch the GUI without invoking the qats executable
(i.e., does not call ``qats.exe``), use
Launching the GUI
*****************
.. code-block::
The GUI is launched via the CLI:
python -m qats config --link-app-no-exe
.. code-block::
$ qats app
.. :code:`python -m qats config --link-app-no-exe`.
If using qats on **Windows**, you may add a shortcut for launching the qats GUI to your Windows Start menu and on the Desktop by running the command:
.. code-block::
.. :code:`python -m qats -h` or :code:`python -m qats app`.
C:\> qats config --link-app
Your first script
Expand All @@ -123,5 +119,5 @@ Import the time series database, load data to it from file and plot it all.
:linenos:
:lines: 1-17
Take a look at :ref:`examples` and the :ref:`api` to learn how to use QATS and build it into your code.
Take a look at :ref:`examples` and the :ref:`api` to learn how to use :code:`qats` and build it into your code.
2 changes: 1 addition & 1 deletion docs/source/gui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Create link to GUI in start menu and desktop
:figclass: align-center
:target: _images/link_app.gif

In the terminal, run ``qats config --link-app`` to create start menu and desktop links to QATS. Pin the start menu
In the terminal, run :code:`qats config --link-app` to create start menu and desktop links to qats. Pin the start menu
link to the taskbar to further ease accessibility.


Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ myst-parser = ">=2.0.0"

[tool.poetry.scripts]
qats = "qats.cli:main"
qats-app = "qats.cli:launch_app"
# I expected the below solution to work but it does not. I will find a solution to
# launch the application without a console window.
#qats-app = {source = "qats.cli:launch_app", type = "gui"}
#qats = {source = "qats.cli:main", type = "console"}


[tool.poetry.urls]
Expand Down
56 changes: 9 additions & 47 deletions qats/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,9 @@

def link_app():
"""
Create start menu item and desktop shortcut to QATS desktop app.
"""
if not sys.platform == "win32":
print(f"Unable to create links to app on {sys.platform} OS.")
sys.exit()

from win32com.client import Dispatch

pkg_name = "qats"
scripts_dir = sysconfig.get_path("scripts")
ico_path = resource_filename("qats.app", "qats.ico")
target = os.path.join(scripts_dir, f"{pkg_name}-app.exe")
lnk_name = pkg_name.upper() + ".lnk"

# open shell
shell = Dispatch("WScript.Shell")

# create shortcuts to gui in desktop folder and start-menu programs
for loc in ("Desktop", "Programs"):
location = shell.SpecialFolders(loc)
path_link = os.path.join(location, lnk_name)
shortcut = shell.CreateShortCut(path_link)
shortcut.Description = f"{pkg_name.upper()} v{__version__}"
shortcut.TargetPath = target
shortcut.WorkingDirectory = os.getenv("USERPROFILE")
shortcut.IconLocation = ico_path
shortcut.Save()


def link_app_no_exe():
"""
Create start menu item and desktop shortcut to QATS desktop app
(by invoking pythonw.exe with the necessary arguments, not qats.app.exe)
Create start menu item and desktop shortcut to `qats` desktop app
(by invoking pythonw.exe with the necessary arguments, not the
previous entry point qats-app.exe (or .cmd)).
"""
if not sys.platform == "win32":
print(f"Unable to create links to app on {sys.platform} OS.")
Expand All @@ -72,12 +42,9 @@ def link_app_no_exe():
target = python_exec_path

# define arguments to target
# alternative 1: does not rely on entry point scripts
# (relies on invoking qats.__main__, not the entry point executable)
arguments = f"-m {pkg_name} app"
# # alternative 2: relies on the pyw script generated for the entry point 'qats-app.exe'
# scripts_dir = sysconfig.get_path("scripts")
# arguments = os.path.join(scripts_dir, f"{pkg_name}-app-script.pyw")


# open shell
shell = Dispatch("WScript.Shell")

Expand All @@ -96,7 +63,7 @@ def link_app_no_exe():

def unlink_app():
"""
Remove start menu item and desktop shortcut to QATS desktop application.
Remove start menu item and desktop shortcut to `qats` desktop application.
"""
if not sys.platform == "win32":
print(f"Unable to remove links to app on {sys.platform} OS.")
Expand Down Expand Up @@ -148,8 +115,8 @@ def main():
"""
# top-level parser
parser = argparse.ArgumentParser(prog="qats",
description="QATS is a library and desktop application for time series analysis")
parser.add_argument("--version", action="version", version=f"QATS {__version__}", help="Package version")
description="qats is a library and desktop application for time series analysis")
parser.add_argument("--version", action="version", version=f"qats {__version__}", help="Package version")
subparsers = parser.add_subparsers(title="Commands", dest="command")

# app parser
Expand All @@ -164,10 +131,7 @@ def main():
config_parser = subparsers.add_parser("config", help="Configure the package")
applink_group = config_parser.add_mutually_exclusive_group()
applink_group.add_argument("--link-app", action="store_true",
help="Create start menu and destop links to the app.")
applink_group.add_argument("--link-app-no-exe", action="store_true",
help="Create start menu and destop links to the app. The desktop link generated by this "
"option does not rely on invoking any other executables but 'pythonw.exe'.")
help="Create start menu and destop links to the app (GUI).")
applink_group.add_argument("--unlink-app", action="store_true",
help="Remove start menu and destop links to the app.")

Expand All @@ -181,8 +145,6 @@ def main():
elif args.command == "config":
if args.link_app:
link_app()
elif args.link_app_no_exe:
link_app_no_exe()
elif args.unlink_app:
unlink_app()
else:
Expand Down

0 comments on commit f44d5a9

Please sign in to comment.