So in the 2ish weeks since my last update I have been on and off again playing with the Google assistant. I have also started coding the Python code and gui. I was hoping to find an IDE for Python that mimics the drag and drop creation of the GUI elements like the older versions of Visual Basic. Unfortunately, the ones that I liked wouldn't compile properly on the PI ( https://github.com/dddomodossola/remi ). I ended up through many clicks and searches finding the following Python library which seemed somewhat close to what I wanted to do: https://lawsie.github.io/guizero/ . It also seemed fairly easy to use even if it wasn't drag and drop. I also found a way to control the alsa mixer volume via this link: https://www.raspberrypi.org/forums/viewtopic.php?t=191916 .
So, off I went like a herd of turtles laying out the buttons and textboxes. The following is what the GUI code looked like:
GUI Code |
---|
from guizero import App,Box,Text, PushButton import os def SetupSpiceOfPi(): debugBox.clear() debugBox.append("Setup Spice Of Pi\n") def LoadSpices(): debugBox.clear() debugBox.append("Load Spice") def PickASpice(): debugBox.clear() debugBox.append("Pick a Spice\n") def PlayMusic(): debugBox.clear() debugBox.append("Play Music") def MuteSpeaker(): if muteSpeaker.text == "Mute Speaker": os.system('amixer set Master 1%') debugBox.clear() debugBox.append("Set sound to 1%\n") muteSpeaker.text ="Unmute Speaker" else: os.system('amixer set Master 90%') debugBox.clear() debugBox.append("Set sound to 90%\n") muteSpeaker.text ="Mute Speaker" def Restart(): print("Restart") debugBox.clear() debugBox.append ("Reset in less than 10 seconds\n") os.system('sleep 10') #os.system('sudo shutdown -r now') app = App(title="Spice Of Pi", height=480, width=800, layout ="grid") box1 = Box(app,grid=[0,0],layout= "grid") box2 = Box(app,grid=[0,1],layout="grid") box3 = Box(app,grid=[0,2],layout= "grid") box4 = Box(app,grid=[0,3],layout="grid") box5 = Box(app,grid=[0,4],layout= "grid") box6 = Box(app,grid=[0,5],layout="grid") box7 = Box(app,grid=[0,6],layout= "grid") box8 = Box(app,grid=[0,7],layout="grid") debugBox = Text(box8,"Stuff to read will be here\n",grid=[0,5]) setupPi = PushButton(box1, command=SetupSpiceOfPi, text="Setup Spice of Pi", grid=[0,0]) setupPi.width = 20 loadPi = PushButton(box1, command=LoadSpices, text="Load Spices",grid=[1,0]) loadPi.width =20 pickSpice = PushButton(box1, command=PickASpice, text="Pick a Spice", grid=[2,0]) pickSpice.width =20 playMusic = PushButton(box1, command=PlayMusic, text="Play Music", grid=[3,0]) playMusic.width=20 muteSpeaker = PushButton(box2, command=MuteSpeaker, text="Mute Speaker", grid=[2,0]) muteSpeaker.width=20 restartPi = PushButton(box2, command=Restart, text="Restart Spice of Pi", grid=[3,0]) restartPi.width=20 app.display() |
And this is what it actually looked like on my Pi:
Nice, but not what I had envisioned. For the life of me, I could not get the text box to be displayed at the bottom of the window. You will notice, that the 'box' I had placed the text display into was supposed to be the 8th row, with empty space between it and the rest of the buttons, because the grid= section is supposedly x and y coordinates. So, I thought that I would move the text box to the top of the window and go from there:
More code |
---|
from guizero import App,Box,Text, PushButton import os import time def SetupSpiceOfPi(): debugBox.clear() debugBox.append("Setup Spice Of Pi\n") setup = App(title="Spice of Pi - Setup", height =300, width = 200) setup.display() def LoadSpices(): debugBox.clear() debugBox.append("Load Spice") def PickASpice(): debugBox.clear() debugBox.append("Pick a Spice\n") def PlayMusic(): debugBox.clear() debugBox.append("Play Music") def MuteSpeaker(): if muteSpeaker.text == "Mute Speaker": os.system('amixer set Master 1%') debugBox.clear() debugBox.append("Set sound to 1%\n") muteSpeaker.text ="Unmute Speaker" else: os.system('amixer set Master 90%') debugBox.clear() debugBox.append("Set sound to 90%\n") muteSpeaker.text ="Mute Speaker" def Restart(): debugBox.clear() debugBox.append ("Reset in less than 10 seconds\n") #time.sleep(1) #os.system('sleep 10') #debugBox.append ("Reseting now...") #os.system('sudo shutdown -r now') Reboot def Reboot(): os.system('sleep 10') debugBox.append ("Reseting now...") #os.system('sudo shutdown -r now') app = App(title="Spice Of Pi", height=480, width=800, layout ="grid") box1 = Box(app,grid=[0,0],layout= "grid") box2 = Box(app,grid=[0,1],layout="grid") box3 = Box(app,grid=[0,2],layout= "grid") box4 = Box(app,grid=[0,3],layout="grid") box5 = Box(app,grid=[0,4],layout= "grid") box6 = Box(app,grid=[0,5],layout="grid") box7 = Box(app,grid=[0,6],layout= "grid") box8 = Box(app,grid=[0,7],layout="grid") debugBox = Text(box1, "Stuff to read will be here\n",grid=[0,5]) setupPi = PushButton(box2, command=SetupSpiceOfPi, text="Setup Spice of Pi", grid=[0,0]) setupPi.width = 20 loadPi = PushButton(box2, command=LoadSpices, text="Load Spices",grid=[1,0]) loadPi.width =20 pickSpice = PushButton(box2, command=PickASpice, text="Pick a Spice", grid=[2,0]) pickSpice.width =20 playMusic = PushButton(box2, command=PlayMusic, text="Play Music", grid=[3,0]) playMusic.width=20 muteSpeaker = PushButton(box3, command=MuteSpeaker, text="Mute Speaker", grid=[2,0]) muteSpeaker.width=20 restartPi = PushButton(box3, command=Restart, text="Restart Spice of Pi", grid=[3,0]) restartPi.width=20 app.display()from guizero import App,Box,Text, MenuBar import os import time def SetupSpiceOfPi(): debugBox.clear() debugBox.append("Setup Spice Of Pi\n") def LoadSpices(): debugBox.clear() debugBox.append("Load Spice") def PickASpice(): debugBox.clear() debugBox.append("Pick a Spice\n") def PlayMusic(): debugBox.clear() debugBox.append("Play Music") def MuteSpeaker(): if muteSpeaker.text == "Mute Speaker": os.system('amixer set Master 1%') debugBox.clear() debugBox.append("Set sound to 1%\n") muteSpeaker.text ="Unmute Speaker" else: os.system('amixer set Master 90%') debugBox.clear() debugBox.append("Set sound to 90%\n") muteSpeaker.text ="Mute Speaker" def Restart(): debugBox.clear() debugBox.append ("Reset in less than 10 seconds\n") #time.sleep(1) #os.system('sleep 10') #debugBox.append ("Reseting now...") #os.system('sudo shutdown -r now') Reboot def Reboot(): os.system('sleep 10') debugBox.append ("Reseting now...") #os.system('sudo shutdown -r now') app = App(title="Spice Of Pi", height=480, width=800, layout ="grid") box1 = Box(app,grid=[0,0],layout= "grid") debugBox = Text(box1, "Stuff to read will be here\n",grid=[0,5]) app.display() |
Ah, much better. Or so I thought....
My next order of business was to be able to hide the buttons so that the user would talk to the Pi instead of using the screen buttons. No problem, because the library had a way to hide and show the boxes and by hiding the boxes, the elements in those boxes would be hidden as well. Perfect...
Sigh, apparently turning on and off the boxes changes the layout quite significantly and this is definitely not quite the layout I was hoping for...
Even more code |
---|
from guizero import App,Box,Text, MenuBar, PushButton import os import time import logging import sys def SetupSpiceOfPi(): debugBox.clear() debugBox.append("Setup Spice Of Pi\n") box2.show() def LoadSpices(): debugBox.clear() debugBox.append("Load Spice") def PickASpice(): debugBox.clear() debugBox.append("Pick a Spice\n") def PlayMusic(): debugBox.clear() debugBox.append("Play Music") def MuteSpeaker(): if muteSpeaker.text == "Mute Speaker": os.system('amixer set Master 1%') debugBox.clear() debugBox.append("Set sound to 1%\n") muteSpeaker.text ="Unmute Speaker" else: os.system('amixer set Master 90%') debugBox.clear() debugBox.append("Set sound to 90%\n") muteSpeaker.text ="Mute Speaker" def Restart(): debugBox.clear() debugBox.append ("Reset in less than 10 seconds\n") Reboot def Reboot(): os.system('sleep 10') debugBox.append ("Reseting now...") #os.system('sudo shutdown -r now') def BoxesOn(): box2.show() def BoxesOff(): box2.hide() def UpdatePi(): os.system('sleep 10') debugBox.clear() debugBox.append("This will take some time... I will speak when it is done...") os.system('sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade && sudo apt-get -y autoremove') def UpdateVoice(): debugBox.clear() debugBox.append("Not yet...") app = App(title="Spice Of Pi", height=480, width=400, layout ="grid") box1 = Box(app,grid=[0,0],layout= "grid") box2 = Box(app,grid=[0,1], layout = "grid") box3 = Box(app,grid=[0,2],layout= "grid") menubar = MenuBar(app, toplevel=["Setup", "Update"], options=[ [ ["Turn on Buttons", BoxesOn], ["Turn off Buttons", BoxesOff], ["Restart",Restart] ], [ ["Update Raspberry", UpdatePi], ["Update Google Voice", UpdateVoice] ] ]) debugBox = Text(box1, "Stuff to read will be here\n",grid=[0,5]) muteSpeaker = PushButton(box3, command=MuteSpeaker, text="Mute Speaker", grid=[2,0]) muteSpeaker.width=20 setupPi = PushButton(box2, command=SetupSpiceOfPi, text="Setup Spice of Pi", grid=[0,0]) setupPi.width = 20 loadPi = PushButton(box2, command=LoadSpices, text="Load Spices",grid=[1,0]) loadPi.width =20 BoxesOff() app.display() |
My first thought was that this was a stupid wonderful feature, and I should be rejoicing greatly because everyone loves hunting on the screen for the button that they want to press. But I was not. I was not indeed. So back to the Google searching I went to see if I could really find a IDE with a GUI designer. Again, I could not find anything that seemed to do what I wanted it to do, so I turned off the Pi, opened a bottle of red wine and stopped thinking about the whole project.
Now, don't think that I had given up on this, for I did find a completely different way to interact with the voice kit without using a handcrafted GUI which will be documented in my next post...
Design Challenge Links:
Project Links:
Blog Glenn 1 - AIY Voice Kit Unboxing
Blog Doug 2 - The Block Diagram and Bill of Materials
Blog Doug 3 - Spice Jar Lift Mechanism
Top Comments