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.
master
Miro Hrončok 2013-01-15 21:22:56 +01:00
parent 629a53ac5c
commit f942c1a007
1 changed files with 15 additions and 2 deletions

View File

@ -28,6 +28,7 @@ except:
import sys, glob, time, datetime, threading, traceback, cStringIO, subprocess
from printrun.pronterface_widgets import *
from serial import SerialException
StringIO = cStringIO
@ -72,7 +73,7 @@ class Tee(object):
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 @@ class PronterWindow(MainWindow, pronsole.pronsole):
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)