From e030b0b3eaa30a5246b6bb748d60fc972fbe731e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 21 Aug 2019 13:19:54 +1000 Subject: [PATCH] base: add an argument to peek at the first drawing only Use --peek to download the first (oldest) drawing on the device but do not delete it. This is primarily intended as a debugging option, so we can debug the tablet handling without having to draw new drawings (which cause the protocol messages to change slightly). Since the tablet only has a "download oldest file" command this isn't very useful to end users. If there are two or more files on the tablet, we can only ever retrieve the oldest one. Signed-off-by: Peter Hutterer --- tuhi/base.py | 5 +++++ tuhi/config.py | 1 + tuhi/gui/application.py | 6 ++++++ tuhi/wacom.py | 10 +++++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tuhi/base.py b/tuhi/base.py index 2f59fc1..22eb914 100644 --- a/tuhi/base.py +++ b/tuhi/base.py @@ -450,9 +450,14 @@ def main(args=sys.argv): help='Base directory for configuration', type=str, default=DEFAULT_CONFIG_PATH) + parser.add_argument('--peek', + help='Download first drawing only but do not remove it from the device', + action='store_true', + default=False) ns = parser.parse_args(args[1:]) TuhiConfig.set_base_path(ns.config_dir) + TuhiConfig().peek_at_drawing = ns.peek setup_logging(ns.config_dir) if ns.verbose: diff --git a/tuhi/config.py b/tuhi/config.py index a093d82..0a7ff61 100644 --- a/tuhi/config.py +++ b/tuhi/config.py @@ -41,6 +41,7 @@ class TuhiConfig(GObject.Object): self._devices = {} self._scan_config_dir() + self.peek_at_drawing = False return cls._instance @GObject.Property diff --git a/tuhi/gui/application.py b/tuhi/gui/application.py index 1c4e563..5e0a0ac 100644 --- a/tuhi/gui/application.py +++ b/tuhi/gui/application.py @@ -46,6 +46,12 @@ class Application(Gtk.Application): GLib.OptionFlags.NONE, GLib.OptionArg.NONE, 'enable verbose output') + # unused, just here to have option compatibility with the tuhi + # server but we could add some GUI feedback here + self.add_main_option('peek', 0, + GLib.OptionFlags.NONE, + GLib.OptionArg.NONE, + 'download first drawing only but do not remove it from the device') self._tuhi = None def do_startup(self): diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 8dada7b..4be9cd2 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -26,6 +26,7 @@ from .uhid import UHIDDevice import tuhi.protocol from tuhi.protocol import NordicData, Interactions, Mode, ProtocolVersion, StrokeFile from .util import list2hex, flatten +from tuhi.config import TuhiConfig logger = logging.getLogger('tuhi.wacom') @@ -745,7 +746,8 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): def read_offline_data(self): self.set_paper_mode() transaction_count = 0 - while self.count_available_files(): + file_count = self.count_available_files() + while file_count > 0: count, timestamp = self.get_stroke_data() logger.info(f'receiving {count} bytes drawn on UTC {time.strftime("%y%m%d%H%M%S", time.gmtime(timestamp))}') self.start_downloading_oldest_file() @@ -755,6 +757,12 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): drawing = self.parse_pen_data(pen_data, timestamp) if drawing: self.emit('drawing', drawing) + file_count -= 1 + if TuhiConfig().peek_at_drawing: + logger.info(f'Not deleting drawing from device') + if file_count > 0: + logger.info(f'{file_count} more files on device but I can only download the oldest one') + break self.delete_oldest_file() transaction_count += 1 return transaction_count