From 56dd34668b55078518c19cdc71c4bc42ac5251d1 Mon Sep 17 00:00:00 2001 From: Sawyer McLane Date: Tue, 26 Jun 2018 12:45:37 -0600 Subject: [PATCH] Removed all unsafe references to `lifxlan.Light.get_label()`. Added full stack traceback to uncaught exceptions. 1.4.2 --- _constants.py | 6 +++--- color_thread.py | 7 +++++-- debug.spec | 2 +- default.ini | 4 ++-- demo.spec | 2 +- dummy_devices.py | 12 +++++++----- gui.pyw | 31 +++++++++++++------------------ main.spec | 2 +- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/_constants.py b/_constants.py index b3c41f7..ddf6ed7 100644 --- a/_constants.py +++ b/_constants.py @@ -1,4 +1,4 @@ -VERSION = "1.4.1" -BUILD_DATE = "2018-06-22T16:14:36.320685" +VERSION = "1.4.2" +BUILD_DATE = "2018-06-26T12:41:59.782568" AUTHOR = "Sawyer McLane" -DEBUGGING = False +DEBUGGING = True diff --git a/color_thread.py b/color_thread.py index 12de621..128c325 100644 --- a/color_thread.py +++ b/color_thread.py @@ -54,9 +54,12 @@ def __init__(self, bulb, color_function, parent, continuous=True): self.prev_color = parent.get_color_values_hsbk() self.continuous = continuous self.t = ColorThread(target=self.match_color, args=(self.bulb,)) - # self.t.setDaemon(True) + try: + label = self.bulb.get_label() + except Exception: + label = "" self.logger.info( - 'Initialized Thread: Bulb: {} // Continuous: {}'.format(self.bulb.get_label(), self.continuous)) + 'Initialized Thread: Bulb: {} // Continuous: {}'.format(label, self.continuous)) def match_color(self, bulb): self.logger.debug('Starting color match.') diff --git a/debug.spec b/debug.spec index c495c84..8786f3f 100644 --- a/debug.spec +++ b/debug.spec @@ -3,7 +3,7 @@ import datetime bd = datetime.datetime.now().isoformat() auth = "Sawyer McLane" -vers = "1.4.1" +vers = "1.4.2" is_debug = True # Write version info into _constants.py resource file diff --git a/default.ini b/default.ini index 827cfb9..c5a9b88 100644 --- a/default.ini +++ b/default.ini @@ -8,6 +8,6 @@ defaultmonitor = get_primary_monitor() # Used for diagnostic purposes. Please do not change. [Info] -version = 1.4.1 +version = 1.4.2 author = Sawyer McLane -builddate = 2018-06-22T16:14:36.320685 +builddate = 2018-06-26T12:41:59.782568 diff --git a/demo.spec b/demo.spec index c9df83f..4407ef7 100644 --- a/demo.spec +++ b/demo.spec @@ -3,7 +3,7 @@ import datetime bd = datetime.datetime.now().isoformat() auth = "Sawyer McLane" -vers = "1.4.1" +vers = "1.4.2" is_debug = True # Write version info into _constants.py resource file diff --git a/dummy_devices.py b/dummy_devices.py index 0a15a20..bc6c537 100644 --- a/dummy_devices.py +++ b/dummy_devices.py @@ -4,13 +4,15 @@ from random import randint, sample, randrange, choice from tkinter import messagebox from tkinter import * - -from gui import Color as DummyColor -from lifxlan import product_map -from utils import resource_path +import traceback from threading import Timer import logging import os +from lifxlan import product_map + +from gui import Color as DummyColor +from utils import resource_path + LOGFILE = 'lifx-control-panel.log' @@ -500,6 +502,6 @@ def myHandler(type, value, tb): main() except Exception as e: messagebox.showerror("Unhandled Exception", "Unhandled runtime exception: {}\n\n" - "Please report this at: {}".format(e, + "Please report this at: {}".format(traceback.format_exc(), r"https://github.com/samclane/LIFX-Control-Panel/issues")) raise e diff --git a/gui.pyw b/gui.pyw index a05f108..6eda291 100644 --- a/gui.pyw +++ b/gui.pyw @@ -1,17 +1,15 @@ import logging import threading import tkinter.font as font -from collections import namedtuple +from collections import namedtuple, OrderedDict from tkinter import * -from tkinter import _setit -from tkinter import messagebox -from tkinter import ttk +from tkinter import _setit, messagebox, ttk from tkinter.colorchooser import * from win32gui import GetCursorPos - from PIL import Image as pImage from lifxlan import * from lifxlan import errors +import traceback import SysTrayIcon import audio @@ -68,18 +66,12 @@ class LifxFrame(ttk.Frame): # Initialize LIFX objects self.lightvar = StringVar(self) - self.lights = [] - self.lightsdict = {} # LifxLight objects + self.lightsdict = OrderedDict() # LifxLight objects self.framesdict = {} # corresponding LightFrame GUI self.current_lightframe = None # currently selected and visible LightFrame self.bulb_icons = BulbIconList(self) - self.lights = self.lifx.get_lights() - if len(self.lights) == 0: - messagebox.showerror("No lights found.", "No LIFX devices were found on your LAN. Exiting.") - self.on_closing() - - for x, light in enumerate(self.lights): + for x, light in enumerate(self.lifx.get_lights()): try: product = product_map[light.get_product()] label = light.get_label() @@ -91,8 +83,11 @@ class LifxFrame(ttk.Frame): self.logger.warning("Error when communicating with LIFX device: {}".format(e)) if len(self.lightsdict): # if any lights are found - self.lightvar.set(self.lights[0].get_label()) + self.lightvar.set(next(iter(self.lightsdict.keys()))) self.current_light = self.lightsdict[self.lightvar.get()] + else: + messagebox.showerror("No lights found.", "No LIFX devices were found on your LAN. Exiting.") + self.on_closing() self.bulb_icons.grid(row=1, column=1, sticky='w') self.bulb_icons.canvas.bind('', self.on_canvas_click) @@ -141,9 +136,9 @@ class LifxFrame(ttk.Frame): "Brought existing frame to front: {}".format(self.framesdict[new_light_label].get_label())) self.current_lightframe = self.framesdict[new_light_label] self.current_lightframe.restart() - if not self.current_light.get_label() == self.current_lightframe.get_label() == self.lightvar.get(): - self.logger.error("Mismatch between Current Light ({}), LightFrame ({}) and Dropdown ({})".format( - self.current_light.get_label(), self.current_lightframe.get_label(), self.lightvar.get())) + if not self.current_lightframe.get_label() == self.lightvar.get(): + self.logger.error("Mismatch between LightFrame ({}) and Dropdown ({})".format( + self.current_lightframe.get_label(), self.lightvar.get())) self.master.bind('', lambda *_: self.master.withdraw()) # reregister callback def on_canvas_click(self, event): @@ -587,6 +582,6 @@ if __name__ == "__main__": except Exception as e: root.logger.exception(e) messagebox.showerror("Unhandled Exception", "Unhandled runtime exception: {}\n\n" - "Please report this at: {}".format(e, + "Please report this at: {}".format(traceback.format_exc(), r"https://github.com/samclane/LIFX-Control-Panel/issues")) os._exit(1) diff --git a/main.spec b/main.spec index f28900c..95ce07e 100644 --- a/main.spec +++ b/main.spec @@ -3,7 +3,7 @@ import datetime bd = datetime.datetime.now().isoformat() auth = "Sawyer McLane" -vers = "1.4.1" +vers = "1.4.2" is_debug = False # Write version info into _constants.py resource file