From 7108556bbdc57d1d6ea3c5002c6b475667cea4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20W=C3=BCst?= Date: Sun, 14 Jul 2013 19:44:08 +0200 Subject: changed how encoder passes errors (bzr r12417.1.5) --- share/extensions/hpgl_encoder.py | 2 +- share/extensions/hpgl_output.py | 15 ++++++++++----- share/extensions/plotter.py | 14 +++++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/share/extensions/hpgl_encoder.py b/share/extensions/hpgl_encoder.py index 58b1f79ea..e7308beff 100644 --- a/share/extensions/hpgl_encoder.py +++ b/share/extensions/hpgl_encoder.py @@ -81,7 +81,7 @@ class hpglEncoder: self.vData = [['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0]] self.process_group(self.doc) if self.divergenceX == 9999999999999.0 or self.divergenceY == 9999999999999.0 or self.sizeX == -9999999999999.0 or self.sizeY == -9999999999999.0: - return -1 + raise Exception('NO_PATHS') # live run self.dryRun = False if self.options.center: diff --git a/share/extensions/hpgl_output.py b/share/extensions/hpgl_output.py index 1a12b5a49..10d118a95 100755 --- a/share/extensions/hpgl_output.py +++ b/share/extensions/hpgl_output.py @@ -50,14 +50,19 @@ class MyEffect(inkex.Effect): def effect(self): # get hpgl data myHpglEncoder = hpgl_encoder.hpglEncoder(self.document.getroot(), self.options) - # TODO:2013-07-13:Sebastian Wüst:Find a better way to pass errors correctly. - self.hpgl = myHpglEncoder.getHpgl() - if self.hpgl == -1: - inkex.errormsg(_("No paths where found. Please convert all objects you want to save into paths.")) + try: + self.hpgl = myHpglEncoder.getHpgl() + except Exception as inst: + if inst.args[0] == 'NO_PATHS': + # issue error if no paths found + inkex.errormsg(_("No paths where found. Please convert all objects you want to save into paths.")) + self.hpgl = 1 + else: + raise Exception(inst) def output(self): # print to file - if self.hpgl != -1: + if self.hpgl != 1: print self.hpgl if __name__ == '__main__': diff --git a/share/extensions/plotter.py b/share/extensions/plotter.py index d54f9ed6c..ebb69e8a1 100644 --- a/share/extensions/plotter.py +++ b/share/extensions/plotter.py @@ -53,7 +53,6 @@ class MyEffect(inkex.Effect): try: import serial except ImportError, e: - # TODO:2013-07-13:Sebastian Wüst:Maybe add this text to extension window inkex.errormsg(_("pySerial is not installed." + "\n\n1. Download pySerial here: http://pypi.python.org/pypi/pyserial" + "\n2. Extract the \"serial\" subfolder from the zip to the following folder: \"C:\\Program Files (x86)\\inkscape\\python\\Lib\\\" (Or wherever your Inkscape is installed to)" @@ -61,10 +60,15 @@ class MyEffect(inkex.Effect): return # get hpgl data myHpglEncoder = hpgl_encoder.hpglEncoder(self.document.getroot(), self.options) - self.hpgl = myHpglEncoder.getHpgl() - if self.hpgl == -1: - inkex.errormsg(_("No paths where found. Please convert all objects you want to plot into paths.")) - return + try: + self.hpgl = myHpglEncoder.getHpgl() + except Exception as inst: + if inst.args[0] == 'NO_PATHS': + # issue error if no paths found + inkex.errormsg(_("No paths where found. Please convert all objects you want to plot into paths.")) + return 1 + else: + raise Exception(inst) # TODO:2013-07-13:Sebastian Wüst:Get preview to work. This requires some work on the C++ side to be able to determine if it is a preview or a final run. ''' # reparse data for preview -- cgit v1.2.3