trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 3:07 pm

pcmanbob wrote:
Sat May 26, 2018 3:03 pm
if adding the "( )" does not fix it then it must be something to do with how you are defining the shutdown function,

try removing the indentation so your code looks like this

Code: Select all

#!/usr/bin/env python

import sys
import time

import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
from dot3k.menu import Menu, MenuOption
from time import sleep

# Add the root examples dir so Python can find the plugins
sys.path.append('/home/pi/Pimoroni/displayotron/examples')

from plugins.clock import Clock
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed
from plugins.text import Text
from plugins.utils import Backlight, Contrast

print("""
This advanced example uses the menu framework.
It gives you a basic menu setup with plugins. You should be able to view system info and adjust settings!

Press CTRL+C to exit.
""")

class Power(MenuOption):
    """
    Power Options
    """
def Shutdown():
    lcd.clear()
    lcd.write('Are you sure?\nPress Sel for Y')
    if nav.on(nav.LEFT):
        def handle_left(ch, evt):
         menu.left()
    if nav.on(nav.BUTTON):
        def handle_button(ch, evt):
         menu.select()
         lcd.clear()
         lcd.backlight(lcd.OFF)
         commands.getoutput("sudo shutdown -h now")
         quit()
    sleep(0.25)

def Reboot():
    lcd.clear()
    lcd.message('Are you sure?\nPress Sel for Y')
    while 1:
        if lcd.buttonPressed(lcd.LEFT):
            break
        if lcd.buttonPressed(lcd.SELECT):
            lcd.clear()
            lcd.backlight(lcd.OFF)
            commands.getoutput("sudo reboot")
            quit()
sleep(0.25)

    

"""
Using a set of nested lists you can describe
the menu you want to display on dot3k.

Instances of classes derived from MenuOption can
be used as menu items to show information or change settings.

See GraphTemp, GraphCPU, Contrast and Backlight for examples.
"""

menu = Menu(
    structure={
        'Power Options': {
            'Shutdown': Shutdown(),
            'Reboot': Reboot(),
            },
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_timeout=30,
    input_handler=Text())

"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.touch
"""
nav.bind_defaults(menu)

while 1:
    menu.redraw()
    time.sleep(0.05)
okay so that worked...no errors, i can see my menu and select power options which then shows me the sub menu but i cant select shutdown just nothing happens

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 3:26 pm

Code: Select all

#!/usr/bin/env python

from subprocess import call
import sys
import time

import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
from dot3k.menu import Menu, MenuOption
from time import sleep

# Add the root examples dir so Python can find the plugins
sys.path.append('/home/pi/Pimoroni/displayotron/examples')

from plugins.clock import Clock
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed
from plugins.text import Text
from plugins.utils import Backlight, Contrast

print("""
This advanced example uses the menu framework.
It gives you a basic menu setup with plugins. You should be able to view system info and adjust settings!

Press CTRL+C to exit.
""")

class Power(MenuOption):
    """
    Power Options
    """
def Shutdown():
    lcd.clear()
    lcd.write('Are you sure?\nPress Sel for Y')
    if nav.on(nav.LEFT):
        def handle_left(ch, evt):
            menu.left()
        if nav.on(nav.BUTTON):
         def handle_button(ch, evt):
             menu.select()
             lcd.clear()
             lcd.backlight(lcd.OFF)
             commands.getoutput("sudo shutdown -h now")
             quit()
        sleep(0.25)

def Reboot():
    lcd.clear()
    lcd.write('Are you sure?\nPress Sel for Y')
    if nav.on(nav.LEFT):
           
        if nav.on(nav.BUTTON):
            def handle_button(ch, evt):
                menu.select()
                lcd.clear()
                lcd.backlight(lcd.OFF)
                commands.getoutput("sudo reboot")
                quit()
sleep(0.25)

    

"""
Using a set of nested lists you can describe
the menu you want to display on dot3k.

Instances of classes derived from MenuOption can
be used as menu items to show information or change settings.

See GraphTemp, GraphCPU, Contrast and Backlight for examples.
"""

menu = Menu(
    structure={
        'Power Options': {
            'Shutdown': Shutdown(),
            'Reboot': Reboot
            },
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_timeout=30,
    input_handler=Text())

"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.touch
"""
nav.bind_defaults(menu)

while 1:
    menu.redraw()
    time.sleep(0.05)
this is where i am at now, reboot button doesnt reboot just refresh whats on screen, and shut down doesnt do anything at all

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 3:50 pm

this is what i have for the shutdown button, but it wont do anything if i press select

Code: Select all

def Shutdown():
    lcd.clear()
    lcd.write('Are you sure?\nPress Sel for Y')
    if nav.on(nav.LEFT):
        def handle_left(ch, evt):
            menu.left()
        if nav.on(nav.BUTTON):
         def handle_button(ch, evt):
             menu.select()
             lcd.clear()
             lcd.backlight(lcd.OFF)
             os.system('sudo shutdown -r now')
             quit()
        sleep(0.25)

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 4:08 pm

i think the problem lies in the way im trying to detect the button select as i dont think its even attempting to run the command as i cannot see the confirmation warning screen which should be then next step before shutting down

pcmanbob
Posts: 4465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DisplayOTron

Sat May 26, 2018 5:22 pm

Again you appear to be defining functions with in the code called by the if statement, which is not how you do things.

I think you need to go learn about how you use a function in python, because as you are using it now when your if statement is true all you try and do is set up a function by using "def handle_left(ch, evt):"
As I explained before you setup functions in the main body of the code and then you call them, in your case via an if statement.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 5:33 pm

pcmanbob wrote:
Sat May 26, 2018 5:22 pm
Again you appear to be defining functions with in the code called by the if statement, which is not how you do things.

I think you need to go learn about how you use a function in python, because as you are using it now when your if statement is true all you try and do is set up a function by using "def handle_left(ch, evt):"
As I explained before you setup functions in the main body of the code and then you call them, in your case via an if statement.
i understand what your saying and i really do appreciate your help, but i have tried learning about functions, now im stuck...once i get over it ill learn from it and be able to understand more when re reading function tutorials.
so do i leave the def in and take out the if statements?

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 5:42 pm

i tried removing the if staement then correting the unexpected errors, the menu stil works up to when pressing select nothing happens for shutdown

Code: Select all

def Shutdown():
    lcd.clear()
    lcd.write('Are you sure?\nPress Sel for Y')
    nav.on(nav.LEFT)
    def handle_left(ch, evt):
            menu.left()
    nav.on(nav.BUTTON)
    def handle_button(ch, evt):
             menu.select()
             lcd.clear()
             lcd.backlight(lcd.OFF)
             os.system('sudo shutdown -r now')
             quit()
    sleep(0.25)

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 6:02 pm

trippyt wrote:
Sat May 26, 2018 5:42 pm
i tried removing the if staement then correting the unexpected errors, the menu stil works up to when pressing select nothing happens for shutdown

Code: Select all

def Shutdown():
    lcd.clear()
    lcd.write('Are you sure?\nPress Sel for Y')
    nav.on(nav.LEFT)
    def handle_left(ch, evt):
            menu.left()
    nav.on(nav.BUTTON)
    def handle_button(ch, evt):
             menu.select()
             lcd.clear()
             lcd.backlight(lcd.OFF)
             os.system('sudo shutdown -r now')
             quit()
    sleep(0.25)
think it may have something to do with the handle statement as when i press left it will go back a screen
just cant select the shutdown option

pcmanbob
Posts: 4465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DisplayOTron

Sat May 26, 2018 6:29 pm

its not the if statements that's the problem you are defining an function with the lines, were as I think you probably mean to call one.

Code: Select all

def handle_left(ch, evt):
            menu.left()
            
As I said you need to go learn how to use defined functions.

may be this will help

Code: Select all

import time

# here we define the function
def print_function():
    print ("")
    print ("we are now in the defined function")
    time.sleep (5)
    print ("after waiting for 5 seconds we are now leaving the function")
    print ("")
       
# this in the main loop which will run 4 times
a = 0
while a < 4:
    print ("this is the first line of the main loop pass :  ", a + 1)
    print ("")
    time.sleep (2)
    print ("after waiting 2 seconds well call the function")
    print ("")
    print_function()
    print ("")
    print ("we are now back in the main loop")
    time.sleep (1)
    print ("")
    a = a + 1
    
if you run the above code it will print the lines telling you were in the program it is printing from so may be then you will understand how you use a function and how you define one.
each loop of the main loop calls the function and then returns to the main loop so it can continue.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 6:34 pm

pcmanbob wrote:
Sat May 26, 2018 6:29 pm
its not the if statements that's the problem you are defining an function with the lines, were as I think you probably mean to call one.

Code: Select all

def handle_left(ch, evt):
            menu.left()
            
As I said you need to go learn how to use defined functions.

may be this will help

Code: Select all

import time

# here we define the function
def print_function():
    print ("")
    print ("we are now in the defined function")
    time.sleep (5)
    print ("after waiting for 5 seconds we are now leaving the function")
    print ("")
       
# this in the main loop which will run 4 times
a = 0
while a < 4:
    print ("this is the first line of the main loop pass :  ", a + 1)
    print ("")
    time.sleep (2)
    print ("after waiting 2 seconds well call the function")
    print ("")
    print_function()
    print ("")
    print ("we are now back in the main loop")
    time.sleep (1)
    print ("")
    a = a + 1
    
if you run the above code it will print the lines telling you were in the program it is printing from so may be then you will understand how you use a function and how you define one.
each loop of the main loop calls the function and then returns to the main loop so it can continue.
im afraid thats confused me even more as i cant work what i need out, im at breaking point :cry:

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 6:37 pm

surely someone can help me get this menu to shutdown or reboot when selected?
thought it would be a quick easy fix for somebody on here,
then i can learn by seeing what they did differently

pcmanbob
Posts: 4465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DisplayOTron

Sat May 26, 2018 6:41 pm

My posted example program is not how to fix your problems as such its just a demonstration of how you use a defined function.

if you cant understand how it works then it suggests you need to go and study python either via an online training site or via a python book, before you continue trying to write your program because you obviously don't have a basic understanding of python.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 6:44 pm

pcmanbob wrote:
Sat May 26, 2018 6:41 pm
My posted example program is not how to fix your problems as such its just a demonstration of how you use a defined function.

if you cant understand how it works then it suggests you need to go and study python either via an online training site or via a python book, before you continue trying to write your program because you obviously don't have a basic understanding of python.
i understand your point, i understand most of your example script i just cant apply it to my own, i already said this is my way of learning, all i am looking for is someone to help me not to keep telling me to go elsewhere :(
i dont want examples i just need a fix?

pcmanbob
Posts: 4465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DisplayOTron

Sat May 26, 2018 6:50 pm

So you want some one to write your code for you.

well in that case you need to find some one with the same hardware you are using, I don't have a DisplayOTron so cant help .

as no one else has contributed to this thread it may be that no one here that posts has one either or they may not have seen your post.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 6:55 pm

pcmanbob wrote:
Sat May 26, 2018 6:50 pm
So you want some one to write your code for you.

well in that case you need to find some one with the same hardware you are using, I don't have a DisplayOTron so cant help .

as no one else has contributed to this thread it may be that no one here that posts has one either or they may not have seen your post.
no im not asking someone to write my code completly only to fix the one section that im having an issue with,
i just thought someone here could spot the error without needing the hardware,
sorry if i seem annoyed, just getting frustrated wtih this project

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 7:14 pm

i have finally managed to get it to reboot :!:

Code: Select all

#!/usr/bin/env python

import sys
import time

import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
from dot3k.menu import Menu, MenuOption
from time import sleep 

# Add the root examples dir so Python can find the plugins
sys.path.append('/home/pi/Pimoroni/displayotron/examples')

from plugins.clock import Clock
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown
from plugins.text import Text
from plugins.utils import Backlight, Contrast

print("""
This advanced example uses the menu framework.
It gives you a basic menu setup with plugins. You should be able to view system info and adjust settings!

Press CTRL+C to exit.
""")

class Power(MenuOption):
    """
    Power Options
    """

    

"""
Using a set of nested lists you can describe
the menu you want to display on dot3k.

Instances of classes derived from MenuOption can
be used as menu items to show information or change settings.

See GraphTemp, GraphCPU, Contrast and Backlight for examples.
"""

menu = Menu(
    structure={
        'Power Options': {
           'Reboot':GraphSysReboot(),
        'Shutdown':GraphSysShutdown(),
            },
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_timeout=30,
    input_handler=Text())

"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.touch
"""
nav.bind_defaults(menu)

while 1:
    menu.redraw()
    time.sleep(0.05)

pcmanbob
Posts: 4465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DisplayOTron

Sat May 26, 2018 7:19 pm

So the functions your required were already provided by the software you had installed, this is why you would have probably been better asking on the pimoroni forum: https://forums.pimoroni.com/ as they would have known what was installed and supported by their software.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 7:26 pm

pcmanbob wrote:
Sat May 26, 2018 7:19 pm
So the functions your required were already provided by the software you had installed, this is why you would have probably been better asking on the pimoroni forum: https://forums.pimoroni.com/ as they would have known what was installed and supported by their software.
i told you that also i had posted in both forums, i still havent had a response on theirs, im now trying to create a function to control some GPIO Pins

pcmanbob
Posts: 4465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DisplayOTron

Sat May 26, 2018 7:34 pm

You may have to wait several days for support especially if its pimoroni staff answering the questions rather that peer to peer support which is what you are getting here.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 8:00 pm

so how would i create a funtion inside a menu class just to control a gpio pin? here is my attempt and im now back to trying to get my head around the function statements, think im getting there slowly

Code: Select all

#!/usr/bin/env python

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
import sys
import time

import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
from dot3k.menu import Menu, MenuOption
from time import sleep 

# Add the root examples dir so Python can find the plugins
sys.path.append('/home/pi/Pimoroni/displayotron/examples')

from plugins.clock import Clock
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown
from plugins.text import Text
from plugins.utils import Backlight, Contrast

print("""
This advanced example uses the menu framework.
It gives you a basic menu setup with plugins. You should be able to view system info and adjust settings!

Press CTRL+C to exit.
""")

class Lights(MenuOption):
    """
    lighting Options
    """
    def ON(MenuOption):
        GPIO.setup(5,GPIO.OUT)
        lcd.write ("ON")
        GPIO.output(5,GPIO.HIGH)
        time.sleep(3)
        lcd.write ("OFF")
        GPIO.output(5,GPIO.LOW)
        GPIO.cleanup()
        
        

    

"""
Using a set of nested lists you can describe
the menu you want to display on dot3k.

Instances of classes derived from MenuOption can
be used as menu items to show information or change settings.

See GraphTemp, GraphCPU, Contrast and Backlight for examples.
"""

menu = Menu(
    structure={
        'Power Options': {
           'Reboot':GraphSysReboot(),
        'Shutdown':GraphSysShutdown(),
            },
        'Aquarium': {
            'Lighting': {
                'ON': Lights(),
                }
            },
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_timeout=30,
    input_handler=Text())

"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.touch
"""
nav.bind_defaults(menu)

while 1:
    menu.redraw()
    time.sleep(0.05)

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 8:44 pm

now ive been trying to work my way throught this example to create a function to handle the gpio but yet again im stuck and cant find anything elsewhere...any help is much appreciated,
just need a sub menu to turn a led on or off via gpio

Code: Select all

#!/usr/bin/env python

"""
This example builds upon our hello_world plugin,
now we're going to add some options to cycle though.

Because interfaces can differ widely, there are no helpers
for displaying and cycling through options. You might choose
to lay out icons on a single screen/row or cycle through
multiple lines of text.

In this example, we're going to to the latter!
"""

from dot3k.menu import MenuOption


class HelloWorld(MenuOption):
    """
    First we introduce __init__, this is called when your plugin
    is first instantiated and is where you should create the variables
    you wish to use.

    You *must* also call MenuOption.__init__(self)
    """

    def __init__(self):
        """
        We need somewhere to track which option is selected
        """
        self.selected_option = 0

        """
        We should also keep track of what the options are
        """
        self.options = [
            'Pirate',
            'Monkey',
            'Robot',
            'Ninja',
            'Dolphin'
        ]

        """
        You *must* call the __init__ method on the parent class
        """
        MenuOption.__init__(self)

    """
    These functions let us move between options,
    wrapping around when we reach the lowest or highest

    The use of modulus ( % ) is an easy way to wrap around
    without any pesky, complex logic
    """

    def next_option(self):
        self.selected_option = (self.selected_option + 1) % len(self.options)

    def prev_option(self):
        self.selected_option = (self.selected_option - 1) % len(self.options)

    """
    We'll need to override the up/down control methods
    to call our next/prev methods
    """

    def up(self):
        self.prev_option()

    def down(self):
        self.next_option()

    """
    And these are some handy functions for getting the prev/next/current
    option text for display on the menu.
    """

    def get_current_option(self):
        return self.options[self.selected_option]

    def get_next_option(self):
        return self.options[(self.selected_option + 1) % len(self.options)]

    def get_prev_option(self):
        return self.options[(self.selected_option - 1) % len(self.options)]

    """
    When the menu is redrawn, it calls your plugins
    redraw method and passes an instance of itself.
    """

    def redraw(self, menu):
        menu.write_option(
            row=0,
            margin=1,
            text=self.get_prev_option()
        )

        menu.write_option(
            row=1,
            margin=1,
            icon='>',
            text=self.get_current_option()
        )

        menu.write_option(
            row=2,
            margin=1,
            text=self.get_next_option()
        )


from dot3k.menu import Menu
import dot3k.joystick
import dot3k.backlight
import dot3k.lcd
import time

"""
Let there be light!
"""
dot3k.backlight.rgb(255, 255, 255)

"""
The menu structure is defined as a nested dictionary,
to "install" your plugin, it should be added like so:

You will also need to pass Menu a reference to the LCD
you wish to draw to.
"""
menu = Menu(
    structure={
        'Hello World': HelloWorld()
    },
    lcd=dot3k.lcd
)

"""
We'll virtually press "right" to
enter your plugin:

"""
menu.right()

"""
We will also need to handle up/down
to let us select options
"""


@dot3k.joystick.on(dot3k.joystick.UP)
def handle_up(pin):
    menu.up()


@dot3k.joystick.on(dot3k.joystick.DOWN)
def handle_down(pin):
    menu.down()


"""
You can decide when the menu is redrawn, but
you'll usually want to do this:
"""
while 1:
    menu.redraw()
    time.sleep(0.01)

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 8:46 pm

Code: Select all

#!/usr/bin/env python

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
import sys
import time

import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
from dot3k.menu import Menu, MenuOption
from time import sleep 

# Add the root examples dir so Python can find the plugins
sys.path.append('/home/pi/Pimoroni/displayotron/examples')

from plugins.clock import Clock
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown
from plugins.text import Text
from plugins.utils import Backlight, Contrast

print("""
This advanced example uses the menu framework.
It gives you a basic menu setup with plugins. You should be able to view system info and adjust settings!

Press CTRL+C to exit.
""")

class Lights(MenuOption):
    """
    lighting Options
    """
    def __init__(self):
        self.on = 1
        Menuoption.__init__(self)
    def ON():
        GPIO.setup(5,GPIO.OUT)
        menu.write_row(2,'ON')
        GPIO.output(5,GPIO.HIGH)
        time.sleep(3)
        menu.cleanup()
        menu.write_row(2,'OFF')
        GPIO.output(5,GPIO.LOW)
        GPIO.cleanup()
        
        

    

"""
Using a set of nested lists you can describe
the menu you want to display on dot3k.

Instances of classes derived from MenuOption can
be used as menu items to show information or change settings.

See GraphTemp, GraphCPU, Contrast and Backlight for examples.
"""

menu = Menu(
    structure={
        'Power Options': {
           'Reboot':GraphSysReboot(),
        'Shutdown':GraphSysShutdown(),
            },
        'Aquarium': {
            'Lighting': {
                'ON': Lights(),
                }
            },
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_timeout=30,
    input_handler=Text())

"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.touch
"""
nav.bind_defaults(menu)

while 1:
    menu.redraw()
    time.sleep(0.05)
this is what i have so far but get the following error

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Scripts/myMenu.py", line 68, in <module>
    'ON': Lights(),
  File "/home/pi/Scripts/myMenu.py", line 35, in __init__
    Menuoption.__init__(self)
NameError: name 'Menuoption' is not defined

B.Goode
Posts: 6544
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: DisplayOTron

Sat May 26, 2018 9:08 pm

NameError: name 'Menuoption' is not defined

Look at the name of the base class that you specify in the class Lights() statement.

trippyt
Posts: 49
Joined: Sun Jun 08, 2014 12:40 am

Re: DisplayOTron

Sat May 26, 2018 9:18 pm

Update:

Code: Select all

#!/usr/bin/env python

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
import sys
import time

import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
from dot3k.menu import Menu, MenuOption
from time import sleep 

# Add the root examples dir so Python can find the plugins
sys.path.append('/home/pi/Pimoroni/displayotron/examples')

from plugins.clock import Clock
from plugins.graph import IPAddress, GraphTemp, GraphCPU, GraphNetSpeed, GraphSysReboot, GraphSysShutdown
from plugins.text import Text
from plugins.utils import Backlight, Contrast

print("""
Script now Running. You should be able to view system info and adjust settings!

Press CTRL+C to exit.
""")

class Lights(MenuOption):
    """
    lighting Options
    """
    def __init__(self):
        self.selected_option = 0

        self.options = [
            'On',
            'Off',
            'Day',
            'Night',
        ]
        self.actions = [
            self.handle_On,
            self.handle_Off,
            self.handle_Day,
            self.handle_Night,
        ]
        
        Menuoption.__init__(self)
 
        
        def handle_On(self):
            print('lihghts on')
            GPIO.setup(5,GPIO.OUT)
            GPIO.output(5,GPIO.HIGH)
            menu.write_row(3,'Turning Lights On')
            time.sleep(3)
            GPIO.cleanup()
            
    

"""
Using a set of nested lists you can describe
the menu you want to display on dot3k.

Instances of classes derived from MenuOption can
be used as menu items to show information or change settings.

See GraphTemp, GraphCPU, Contrast and Backlight for examples.
"""

menu = Menu(
    structure={
        'Power Options': {
           'Reboot':GraphSysReboot(),
        'Shutdown':GraphSysShutdown(),
            },
        'Aquarium': {
            'Lighting': {
                'ON': Lights(MenuOption),
                }
            },
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_timeout=30,
    input_handler=Text())

"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.touch
"""
nav.bind_defaults(menu)

while 1:
    menu.redraw()
    time.sleep(0.05)
now getting the error:

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Scripts/myMenu.py", line 79, in <module>
    'ON': Lights(MenuOption),
TypeError: __init__() takes 1 positional argument but 2 were given

B.Goode
Posts: 6544
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: DisplayOTron

Sat May 26, 2018 9:34 pm

Why do you need to pass the name of that Class to the Lights() function?

Also, you have defined a Lights class with its own methods, but you don't seem to create an instance of it?

For an example, see https://github.com/pimoroni/displayotro ... ed/menu.py

Return to “Python”