Skip to content

Commit

Permalink
Removed all unsafe references to lifxlan.Light.get_label(). Added
Browse files Browse the repository at this point in the history
full stack traceback to uncaught exceptions. 1.4.2
  • Loading branch information
samclane committed Jun 26, 2018
1 parent daa79be commit 56dd346
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions _constants.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions color_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<LABEL-ERR>"
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.')
Expand Down
2 changes: 1 addition & 1 deletion debug.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion demo.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions dummy_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
31 changes: 13 additions & 18 deletions gui.pyw
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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('<Button-1>', self.on_canvas_click)
Expand Down Expand Up @@ -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('<Unmap>', lambda *_: self.master.withdraw()) # reregister callback

def on_canvas_click(self, event):
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 56dd346

Please sign in to comment.