Blob Blame History Raw
From f942c1a00724a87ef0d115cc237bf48f8c837a70 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Tue, 15 Jan 2013 21:22:56 +0100
Subject: [PATCH 1/4] Tell the user, there was an error while connecting

Before, when there was an error while connecting, user didn't know, when
Pronterface wasn't launched from the terminal.

So you could just hit Connect button several times and all you've get was:
Connecting...
Connecting...
Connecting...

Now, when there is an exception during the connection, the user will notice:
Connecting...
Error: You are trying to connect to a non-exisiting port.

Or:
Connecting...
Error: You don't have permission to open /dev/ttyUSB0.
You might need to add yourself to the dialout group.

Unfortunately pyserial's SerialException doesn't provide errno yet, so the
message isn't so user friendly:
Connecting...
could not open port None: [Errno 2] No such file or directory: 'None'

I've filled a bug report with patch to pyserial.

Together with this I've realised, there is unnecessary UTF8 decoding of the
output. When user has UTF-8 locale, there was an exception when printing the
exception to the output (almost an exception inception). So I have dropped it,
but feel free to add it back, if I broke anything else.
---
 pronterface.py |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/pronterface.py b/pronterface.py
index 476ffb9..c13b8f7 100755
--- a/pronterface.py
+++ b/pronterface.py
@@ -28,6 +28,7 @@
 import sys, glob, time, datetime, threading, traceback, cStringIO, subprocess
 
 from printrun.pronterface_widgets import *
+from serial import SerialException
 
 StringIO = cStringIO
 
@@ -72,7 +73,7 @@ def write(self, data):
             self.target(data)
         except:
             pass
-        self.stdout.write(data.encode("utf-8"))
+        self.stdout.write(data)
     def flush(self):
         self.stdout.flush()
 
@@ -1420,7 +1421,19 @@ def connect(self, event):
             self.paused = 0
             if self.sdprinting:
                 self.p.send_now("M26 S0")
-        self.p.connect(port, baud)
+        try:
+            self.p.connect(port, baud)
+        except SerialException as e:
+            # Currently, there is no errno, but it should be there in the future
+            if e.errno == 2:
+                print _("Error: You are trying to connect to a non-exisiting port.")
+            elif e.errno == 8:
+                print _("Error: You don't have permission to open %s.") % port
+                print _("You might need to add yourself to the dialout group.")
+            else:
+                print e
+            # Kill the thread anyway
+            raise
         self.statuscheck = True
         if port != self.settings.port:
             self.set("port", port)
-- 
1.7.10


From ee386e00919210991775550ff2f0a23887f042f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Wed, 23 Jan 2013 16:55:38 +0100
Subject: [PATCH 2/4] Adding UTF-8 decoding back

---
 pronterface.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pronterface.py b/pronterface.py
index c13b8f7..87a18a3 100755
--- a/pronterface.py
+++ b/pronterface.py
@@ -73,7 +73,7 @@ def write(self, data):
             self.target(data)
         except:
             pass
-        self.stdout.write(data)
+        self.stdout.write(data.encode("utf-8"))
     def flush(self):
         self.stdout.flush()
 
-- 
1.7.10


From 064974b7336f02856fd5929eff63a6781892071b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Wed, 23 Jan 2013 17:11:08 +0100
Subject: [PATCH 3/4] Handle UTF encoding better

---
 pronterface.py |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/pronterface.py b/pronterface.py
index 87a18a3..add45e1 100755
--- a/pronterface.py
+++ b/pronterface.py
@@ -73,7 +73,11 @@ def write(self, data):
             self.target(data)
         except:
             pass
-        self.stdout.write(data.encode("utf-8"))
+        try:
+            data = data.encode("utf-8")
+        except:
+            pass
+        self.stdout.write(data)
     def flush(self):
         self.stdout.flush()
 
-- 
1.7.10


From 354bfb090fefa9577c36cf8fbb1127e0aaf6f3a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Wed, 23 Jan 2013 17:12:01 +0100
Subject: [PATCH 4/4] Do not rise, but end the scope

---
 pronterface.py |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pronterface.py b/pronterface.py
index add45e1..89536eb 100755
--- a/pronterface.py
+++ b/pronterface.py
@@ -1436,8 +1436,8 @@ def connect(self, event):
                 print _("You might need to add yourself to the dialout group.")
             else:
                 print e
-            # Kill the thread anyway
-            raise
+            # Kill the scope anyway
+            return
         self.statuscheck = True
         if port != self.settings.port:
             self.set("port", port)
-- 
1.7.10