Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter GUI #41

Open
kaitoxakimoto opened this issue Sep 19, 2017 · 3 comments
Open

Tkinter GUI #41

kaitoxakimoto opened this issue Sep 19, 2017 · 3 comments

Comments

@kaitoxakimoto
Copy link

kaitoxakimoto commented Sep 19, 2017

it's a very very simple prototype (in fact, i declare the use of my bulb's mac in the first declaration) but i think the use of Tkinter could be very useful to implement!

from tkinter import *
from magicblue import MagicBlue

#CHANGE THE BULB MAC HERE
bulb_mac_address = 'F8:1D:78:60:8E:0F'
bulb = MagicBlue(bulb_mac_address, 10) # Replace 9 by whatever your version is (default: 7)
bulb.connect()

def switch():
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
		inf=bulb.get_device_info()
	if inf["on"]:
		bulb.turn_off()
	else:
		bulb.turn_on()
	
def change_red(re):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)

def change_green(gr):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)

def change_blue(bl):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)
	
def change_bright(br):
	global first
	if first:
		first = False
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	bulb.set_warm_light(bright.get()/255.0)	
	
	
	
w = Tk()	
	
#Models

r=IntVar()
g=IntVar()
b=IntVar()
bright=IntVar()

#First Check
inf=bulb.get_device_info()
r.set(inf["r"])
g.set(inf["g"])
b.set(inf["b"])
bright.set(inf["brightness"])
first=True

#Power Button

switch=Button(w,text="On / Off",command=switch)
switch.pack()

#First Frame

color_frame=Frame(w)
color_frame.pack()

#RGB

rgb_frame=Frame(color_frame,bd=10)
rgb_frame.grid(row=0,column=0)

red=Scale(rgb_frame, variable = r,orient=HORIZONTAL,to = 255, command = change_red, resolution = 5)
Label(rgb_frame,text="Red").pack()
red.pack()

green=Scale(rgb_frame, variable = g,orient=HORIZONTAL,to = 255, command = change_green, resolution = 5)
Label(rgb_frame,text="Green").pack()
green.pack()

blue=Scale(rgb_frame, variable = b , orient = HORIZONTAL , to = 255, command = change_blue, resolution = 5)
Label(rgb_frame,text="Blue").pack()
blue.pack()

#Bright

bright_frame=Frame(color_frame,bd=10)
bright_frame.grid(row=0,column=1)

bright=Scale(bright_frame, variable = bright , orient = VERTICAL ,from_ = 255, to = 0	, command = change_bright, resolution = -5)
Label(bright_frame,text="Brightness").pack()
bright.pack()



w.mainloop()

bulb.disconnect()

it looks like this for now:
image

@Betree
Copy link
Owner

Betree commented Sep 20, 2017

This is cool! We have to think about how relevant it is to integrate it in this project as this is mainly used on Raspberry Pi or shell scripts at the moment, but I like the idea of a simple GUI that could be useful for "non-technical" users willing to use their bulbs from their PC.

Any arguments or ideas are welcome

@styfle
Copy link

styfle commented Sep 21, 2017

My python skills are not great, but I would imagine you can distribute a separate magicblue-gui package that depends on the magicblue package via pip, correct?

...After looking at the docker-compose package, it looks like these dependencies are called "Requires Distributions"

@Betree
Copy link
Owner

Betree commented Sep 21, 2017

@styfle Yes, I prefer this approach rather than integrating a GUI directly on this project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants