here it is - it is based on a Pimorni library. The imported modules datapi and temp_rgb are simple scripts I wrote to provide data (temp and weather). The only change that has affected the running was the USB mount
my crontab entry is: @reboot sudo python /home/pi/scripts/menu.py
#!/usr/bin/env python
import sys
import signal
import subprocess
sys.path.append("/home/pi/Pimoroni/displayotron/")
import dothat.touch as touch
import dothat.lcd as lcd
import dothat.backlight as backlight
import psutil as ps
from dot3k.menu import Menu, MenuOption
from plugins.utils import Backlight, Contrast
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed
from plugins.clock import Clock
from plugins.wlan import Wlan
from plugins.text import Text
import time
import RPi.GPIO as GPIO
import datapi as dp
import urllib2
import temp_rgb as tm
#helper functions
def reset():
backlight.off()
lcd.clear()
backlight.graph_off()
def signal_term_handler():
global running
running=0
#set signal to catch kill process command
signal.signal(signal.SIGTERM, signal_term_handler)
lcd.set_contrast(50)
#
class Trains(MenuOption):
def __init__(self):
reset()
self.trains=dp.rail_times()
self.select()
MenuOption.__init__(self)
def begin(self):
reset()
backlight.rgb(100,100,100)
def select(self):
# print ("updating")
try:
self.trains=dp.rail_times()
except:
self.trains=["offline ", "offline ","offline "]
def redraw(self, menu):
menu.write_option(
row=0,
text=self.trains[0],
scroll=False
)
menu.write_option(
row=1,
text=self.trains[1],
scroll=False)
menu.write_option(
row=2,
text=self.trains[2],
scroll=False)
class Idle(MenuOption):
def begin(self):
self.timenow=self.millis()
self.started=True
backlight.rgb(0,0,0)
self.cycle=5
self.mode=0
self.SWITCH=5
def cleanup(self):
backlight.rgb(0,0,0)
def redraw(self, menu):
if (self.millis()-self.timenow>5000) or self.started==True:
cpu=(tm.get_temp())
cpu=int(float(cpu))
r,g,b=tm.temp_rgb(cpu, 25,70)
# print r,g,b
backlight.rgb(r,g,b)
self.started=False
self.timenow=self.millis()
#check cycle through modes
if self.cycle==0:
self.mode+=1
self.cycle=self.SWITCH
if self.mode>2:
self.mode=0
self.cycle=self.SWITCH
#system monitoring mode
if self.mode==0:
try:
signal=subprocess.check_output(['iwconfig wlan0 | grep -i quality'], shell=True)
except:
signal=" Offline"
menu.write_option(
row=0,
text="wifi:"+signal[22:30],
scroll=False)
menu.write_option(
row=1,
text="Temp "+tm.get_temp()+"C",
scroll=False)
menu.write_option(
row=2,
text="CPU "+str(ps.cpu_percent()),
scroll=False)
self.cycle-=1
#clock mode
elif self.mode==1:
lcd.clear()
menu.write_option(
row=0,
text=time.ctime(),
scroll=False)
self.cycle-=1
elif self.mode==2:
lcd.clear()
self.cycle-=1
#weather widget uses datapi.py
class Weather(MenuOption):
def __init__(self):
self.mode=0
self.active=False
MenuOption.__init__(self)
def begin(self):
reset()
self.timenow=self.millis()
self.started=True
self.day=0
self.days=["Today", "Tomorrow"]
backlight.rgb(0,0,0)
def right(self):
self.day=1
def left(self):
self.day=0
return True
def cleanup(self):
backlight.rgb(0,0,0)
def select(self):
return False
def redraw(self, menu):
if (self.millis()-self.timenow>5000) or self.started==True:
self.started=False
try:
self.temp=int(dp.weather_forecast(self.day)[2])
r,g,b=tm.temp_rgb(self.temp, 0,30)
except:
r,g,b=(100,100,100)
backlight.rgb(r,g,b)
menu.write_option(
row=1,
text=dp.weather_forecast(self.day)[0],
scroll=False
)
menu.write_option(
row=0,
text=self.days[self.day]+" "+dp.weather_forecast(self.day)[2]+" C",
scroll=False
)
menu.write_option(
row=2,
text=dp.weather_forecast(self.day)[1]+" chance rain",
scroll=False
)
self.timenow=self.millis()
"""
If you're not going to use a row, you should clear it!
"""
#menu structure
menu = Menu(
structure={
'Weather': Weather(),
'System': Idle(),
'Trains': Trains(),
},
lcd=lcd,
idle_handler=Idle(),
idle_timeout=30,
input_handler=Text(),
backlight=backlight.rgb(50,50,75)
)
touch.bind_defaults(menu)
#main loop
def main():
print ("running")
global running
running=1
while running==1:
menu.redraw()
time.sleep(0.05)
#error handling and system interrupt
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
except:
print ("exiting")
finally:
reset()
GPIO.cleanup()
sys.exit()