Created
July 16, 2018 01:31
-
-
Save terabyte128/db1860270a37033bd3d2d382759f1453 to your computer and use it in GitHub Desktop.
quick n dirty way to play with lifx light colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter | |
import lifxlan | |
class Application(tkinter.Frame): | |
def sendCommand(self, type, val): | |
try: | |
light = self.lights[int(self.selectedLight.get())] | |
except ValueError: | |
return | |
if light is None: | |
return | |
if type not in ['hue', 'brightness', 'saturation', 'colortemp']: | |
print("invalid type: %s" % type) | |
func = getattr(light, 'set_' + type) | |
func(val) | |
def sendWithType(self, type): | |
def f(val): | |
return self.sendCommand(type, val) | |
return f | |
def createWidgets(self): | |
self.lan = lifxlan.LifxLAN() | |
self.lights = self.lan.get_color_lights() | |
labelText = "\n".join([ "%d: %s" % (i, self.lights[i].get_label()) for i in range(len(self.lights)) ]) | |
label = tkinter.Label(self, text=labelText) | |
label.pack() | |
self.selectedLight = tkinter.StringVar(self) | |
self.selectedLight.set("Select an option") | |
self.lightSelector = apply(tkinter.OptionMenu, (self, self.selectedLight) + tuple(range(len(self.lights)))) | |
self.lightSelector.pack() | |
for type in ['hue', 'saturation', 'brightness', 'colortemp']: | |
min = 2500 if type == 'colortemp' else 0 | |
max = 9000 if type == 'colortemp' else 2**16 - 1 | |
scale = tkinter.Scale(self, from_=min, to=max, | |
orient=tkinter.HORIZONTAL, | |
label=type, | |
command=self.sendWithType(type), | |
length=200) | |
scale.pack() | |
def __init__(self, master=None): | |
tkinter.Frame.__init__(self, master) | |
self.pack() | |
self.createWidgets() | |
root = tkinter.Tk() | |
app = Application(master=root) | |
app.mainloop() | |
root.destroy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
before using:
requires python3, probably