From 48a073ac505f97ffa1a2c3fe3476e0b97d70eff3 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sun, 1 Dec 2013 14:23:11 +0100 Subject: fix some error cases --- ptgui.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ptgui.py b/ptgui.py index 45046e2..4478493 100644 --- a/ptgui.py +++ b/ptgui.py @@ -7,6 +7,7 @@ ml = GLib.MainLoop() import pttarget, ptlayout from ptlayout import PTLText import time +import usb.core class MainWindow(object): def __init__(self): @@ -84,18 +85,25 @@ class MainWindow(object): def dev_select(self): itr = self.devbox.get_active_iter() + if itr is None: + return dev = self.devlist[itr][1] dev.setup() self.status_update() def status_update(self): itr = self.devbox.get_active_iter() + if itr is None: + return dev = self.devlist[itr][1] - if dev.last_status is None or time.time() - dev.last_status >= 1: - dev.refresh_status() - else: - dev.check_status() + try: + if dev.last_status is None or time.time() - dev.last_status >= 1: + dev.refresh_status() + else: + dev.check_status() + except usb.core.USBError, e: + print 'problem while status refresh:', str(e) if dev.err1 == 0 and dev.err2 == 0: self.printbtn.set_sensitive(True) @@ -181,6 +189,9 @@ class MainWindow(object): ctx.fill() def layout_update(self): + if self.label_surface is None: + return + w, h = self.layout.prep_size(self.label_surface.get_height()) if w < 32: w = 32 -- cgit v1.2.1