12-07-2021 03:50 - edited 12-07-2021 04:08
12-07-2021 03:50 - edited 12-07-2021 04:08
from tkinter import *
from tkinter.ttk import *
from tkinter.filedialog import *
from pygame import mixer
from os import system
from tkinter.messagebox import *
from pynput.keyboard import Key,Controller
from subprocess import run, PIPE
import screen_brightness_control as sbc
keyboard = Controller()
def audioEngine():
if mixer.get_init():
mixer.quit()
audioButton.config(text='Start Audio Engine')
fileButton.config(state=DISABLED)
playButton.config(state=DISABLED)
pauseButton.config(state=DISABLED)
stopButton.config(state=DISABLED)
midifileButton.config(state=DISABLED)
midiplayButton.config(state=DISABLED)
midipauseButton.config(state=DISABLED)
midistopButton.config(state=DISABLED)
else:
mixer.init()
root.channel=mixer.find_channel()
audioButton.config(text='Stop Audio Engine')
fileButton.config(state=NORMAL)
playButton.config(state=NORMAL)
pauseButton.config(state=NORMAL)
stopButton.config(state=NORMAL)
midifileButton.config(state=NORMAL)
midiplayButton.config(state=NORMAL)
midipauseButton.config(state=NORMAL)
midistopButton.config(state=NORMAL)
def volume(v):
if v==2:
keyboard.press(Key.media_volume_up)
keyboard.release(Key.media_volume_up)
elif v==1:
keyboard.press(Key.media_volume_down)
keyboard.release(Key.media_volume_down)
else:
keyboard.press(Key.media_volume_mute)
keyboard.release(Key.media_volume_mute)
def media(m):
if m==2:
keyboard.press(Key.media_next)
keyboard.release(Key.media_next)
elif m==1:
keyboard.press(Key.media_play_pause)
keyboard.release(Key.media_play_pause)
else:
keyboard.press(Key.media_previous)
keyboard.release(Key.media_previous)
def shutdown(arg):
system('shutdown -'+arg+' -t 0')
def play():
try:
if root.audiopaused:
root.channel.unpause()
else:
root.channel.play(mixer.Sound(root.file))
root.audioplaying=True
root.audiopaused=False
except:
showerror('Error', "The file can't be played or there is no file loaded.")
def midiplay():
try:
if root.midipaused:
mixer.music.unpause()
else:
mixer.music.play()
root.midiplaying=True
root.midipaused=False
except:
showerror('Error', "The file can't be played or there is no file loaded.")
def pause():
if root.audioplaying:
root.channel.pause()
root.audiopaused=True
root.audioplaying=False
def midipause():
if root.midiplaying:
mixer.music.pause()
root.midipaused=True
root.midiplaying=False
def stop():
root.channel.stop()
root.audioplaying=False
root.audiopaused=False
def midistop():
mixer.music.stop()
root.midiplaying=False
root.midipaused=False
def file():
f=askopenfilename(filetypes=[('WAV Files', '*.wav'),('MP3 Files', '*.mp3'),('M4A Files', '*.m4a'),('WMA Files','*.wma'),])
if f=='':
root.file=None
else:
root.file=f
stop()
def midifile():
f=askopenfilename(filetypes=[('MIDI Files', '*.mid')])
midistop()
if not f=='':
mixer.music.load(f)
else:
mixer.music.unload()
def brightness(b):
if b==1 and sbc.get_brightness()<100:
sbc.set_brightness(sbc.get_brightness()+1)
elif sbc.get_brightness()>0:
sbc.set_brightness(sbc.get_brightness()-1)
bright.config(text=str(sbc.get_brightness()))
def runprocess():
try:
run(cmd.get())
except OSError as e:
showerror("Can't Run Process", e)
def detect():
bright.config(text=str(sbc.get_brightness()))
root.after(100, detect)
root=Tk()
root.file=''
root.iconbitmap('control.ico')
root.audioplaying=False
root.audiopaused=False
root.midiplaying=False
root.midipaused=False
menu=Menu(root, tearoff=0)
optionmenu=Menu(menu, tearoff=0)
menu.add_cascade(label="Options", menu=optionmenu)
root.resizable(False, False)
root.title('Windows Control Center v1.0')
optionmenu.add_command(label='Connect Smartphone/Smartwatch...', command=lambda: showinfo('Coming Soon', 'Connecting a smartphone/smartwatch will be supported probably in the next update.'))
frame1=LabelFrame(root, text='Power Controls')
frame1.grid()
Button(frame1, text='Suspend', command=lambda: system('rundll32.exe powrprof.dll,SetSuspendState 0,1,0')).grid(column=0, row=0)
Button(frame1, text='Power Off', command=lambda: shutdown('s')).grid(column=1, row=0)
Button(frame1, text='Restart', command=lambda: shutdown('r')).grid(column=2, row=0)
root.config(menu=menu)
frame4=LabelFrame(root, text='User Controls')
frame4.grid()
Button(frame4, text='Lock', command=lambda: system('Rundll32.exe user32.dll,LockWorkStation')).grid(column=0, row=0)
Button(frame4, text='Sign out', command=lambda: shutdown('l')).grid(column=1, row=0)
frame2=LabelFrame(root, text='Audio Controls')
frame2.grid()
Button(frame2, text='+', command=lambda: volume(2))grid(column=2, row=0)
Button(frame2, text='-', command=lambda: volume(1)).grid(column=1, row=0)
Button(frame2, text='X', command=lambda: volume(0)).grid(column=0, row=0)
Button(frame2, text='|<<', command=lambda: media(0)).grid(column=3, row=0)
Button(frame2, text='>||', command=lambda: media(1)).grid(column=4, row=0)
Button(frame2, text='>>|', command=lambda: media(2)).grid(column=5, row=0)
frame3=LabelFrame(root, text='Audio Player')
frame3.grid()
audioButton=Button(frame3, text='Start Audio Engine', command=audioEngine)
audioButton.grid(column=0, row=0)
fileButton=Button(frame3, text='File', command=file, state=DISABLED)
fileButton.grid(column=4, row=0)
playButton=Button(frame3, text='|>', command=play, state=DISABLED)
playButton.grid(column=1, row=0)
pauseButton=Button(frame3, text='||', command=pause, state=DISABLED)
pauseButton.grid(column=2, row=0)
stopButton=Button(frame3, text='X', command=stop, state=DISABLED)
stopButton.grid(column=3, row=0)
frame6=LabelFrame(root, text='MIDI Player')
frame6.grid()
midifileButton=Button(frame6, text='File', command=midifile, state=DISABLED)
midifileButton.grid(column=4, row=0)
midiplayButton=Button(frame6, text='|>', command=midiplay, state=DISABLED)
midiplayButton.grid(column=1, row=0)
midipauseButton=Button(frame6, text='||', command=midipause, state=DISABLED)
midipauseButton.grid(column=2, row=0)
midistopButton=Button(frame6, text='X', command=midistop, state=DISABLED)
midistopButton.grid(column=3, row=0)
frame5=LabelFrame(root, text='Display Controls')
frame5.grid()
ok=True
try:
bright=Label(frame5, text=sbc.get_brightness())
except:
ok=False
bright=Label(frame5, text='Not Available')
bright.grid(column=1, row=0)
if ok:
Button(frame5, text='-', command=lambda: brightness(0)).grid(column=0, row=0)
Button(frame5, text='+', command=lambda: brightness(1)).grid(column=2, row=0)
else:
Button(frame5, text='-', command=lambda: brightness(0), state=DISABLED).grid(column=0, row=0)
Button(frame5, text='+', command=lambda: brightness(1), state=DISABLED).grid(column=2, row=0)
frame7=LabelFrame(root, text='Command Prompt')
frame7.grid()
frame8=LabelFrame(root, text='Remote Control')
frame8.grid()
cmd=Entry(frame7)
cmd.grid(column=0, row=0)
Button(frame7, text='Run', command=runprocess).grid(column=0, row=1)
allowremote=Checkbutton(frame8, text='Allow Remote Control')
allowremote.grid(column=0, row=0)
allowremote.config(state=DISABLED)
allowremote.state([('!alternate')])
if ok:
detect()
root.mainloop()This Python program is a central control center for Windows which allows changing of brightness, volume, play/pause media, and even suspending, shutting down, and restarting your computer. How can I allow this to be remote controlled by a Fitbit smartwatch?
Best Answer12-07-2021 11:42
Gold Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
12-07-2021 11:42
Write a clockface or app that runs on the watch.
It would be possible to integrate the server component into your python app, but that would mean you'd need a non-self-signed SSL certificate on your windows box.
Best Answer12-07-2021 13:03 - edited 12-07-2021 13:03
12-07-2021 13:03 - edited 12-07-2021 13:03
I need to ping the main program with the command when the corresponding button is pressed in the watch app. Then the main Windows app decides what to do (e.g. shutdown, restart, change volume/brightness, etc.) What I need is the code to listen for those commands in my Windows app and the code to send the commands in the watch app.