From 1feb3982b8e9d5c03d84ab8e77cfb3d2bcfc1890 Mon Sep 17 00:00:00 2001 From: Emanuele Date: Tue, 22 Dec 2020 00:43:55 +0100 Subject: [PATCH] Better handling of setting files --- README.md | 8 +++++++- src/rmview/rmview.py | 34 +++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ea18883..7774f17 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,13 @@ Tested with Python 3.8.2, PyQt 5.14.2, MacOs 10.15.4, reMarkable firmware 2.1.1. ## Usage and configuration -You can invoke the program with +**Suggested first use:** +after installing run `rmview`, insert when prompted the IP of your tablet and the password, +as found in the Menu / Settings / Help / Copyright and Licences menu of the tablet. +Then, optionally, select "Settings..." from the context menu (or the error dialog) to open +the default configuration file which you can edit according to the documentation below. + +More generally, you can invoke the program with rmview [config] diff --git a/src/rmview/rmview.py b/src/rmview/rmview.py index 65b0f23..92147e7 100644 --- a/src/rmview/rmview.py +++ b/src/rmview/rmview.py @@ -37,8 +37,12 @@ class rMViewApp(QApplication): def __init__(self, args): super(rMViewApp, self).__init__(args) + + self.DEFAULT_CONFIG = QStandardPaths.standardLocations(QStandardPaths.ConfigLocation)[0] + self.DEFAULT_CONFIG = os.path.join(self.DEFAULT_CONFIG, 'rmview.json') + config_files = [] if len(args) < 2 else [args[1]] - config_files += ['rmview.json'] + config_files += ['rmview.json', self.DEFAULT_CONFIG] rmview_conf = os.environ.get("RMVIEW_CONF") if rmview_conf is not None: config_files += [rmview_conf] @@ -72,11 +76,11 @@ class rMViewApp(QApplication): act.triggered.connect(self.cloneViewer) # self.viewer.menu.addSeparator() self.viewer.menu.addAction(act) - if self.config_file: - act = QAction('Settings...', self) - act.triggered.connect(self.openSettings) - self.viewer.menu.addSeparator() - self.viewer.menu.addAction(act) + + act = QAction('Settings...', self) + act.triggered.connect(self.openSettings) + self.viewer.menu.addSeparator() + self.viewer.menu.addAction(act) self.viewer.setWindowTitle("rMview") self.viewer.show() @@ -218,8 +222,7 @@ class rMViewApp(QApplication): "If you are unsure, please consult the documentation.") mbox.addButton(QMessageBox.Cancel) mbox.addButton(QMessageBox.Help) - if self.config_file: - mbox.addButton("Settings...", QMessageBox.YesRole) + mbox.addButton("Settings...", QMessageBox.ResetRole) mbox.addButton("Auto Install", QMessageBox.AcceptRole) mbox.setDefaultButton(0) answer = mbox.exec() @@ -332,7 +335,17 @@ class rMViewApp(QApplication): if ans == QMessageBox.Cancel: return - QDesktopServices.openUrl(QUrl("file://" + os.path.abspath(self.config_file))) + confpath = os.path.abspath(self.config_file or self.DEFAULT_CONFIG) + if not os.path.isfile(confpath): + with open(confpath, "w") as f: + json.dump({ + "ssh": {"address": [self.config['ssh'].get('address', "10.11.99.1")]}, + "orientation": "auto", + "pen_size": 15, + "pen_color": "red", + "pen_trail": 200 + }, f, indent=4) + QDesktopServices.openUrl(QUrl("file://" + confpath)) self.quit() @pyqtSlot(Exception) @@ -377,8 +390,7 @@ class rMViewApp(QApplication): else: mbox.setInformativeText("I could not connect to the reMarkable at %s:\n%s." % (self.config.get('ssh').get('address'), e)) mbox.addButton(QMessageBox.Cancel) - if self.config_file: - mbox.addButton("Settings...", QMessageBox.ResetRole) + mbox.addButton("Settings...", QMessageBox.ResetRole) mbox.addButton(QMessageBox.Retry) mbox.setDefaultButton(QMessageBox.Retry) answer = mbox.exec()