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

DisplayOTron

Fri May 25, 2018 4:54 pm

i need help im trying to create a menu using the Display O Tron HAT,
i want to crontol the output of a few gpio pins via the touch buttons.
afterwards i will try to extend the options avaliabe once i can control an led or something
is there anyone who can possible help me.. :?:
much appreciacted in advance

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

Re: DisplayOTron

Fri May 25, 2018 4:59 pm

so far i've edited this example but i get errors..

#!/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




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.
""")

menu = Menu(
structure={
'Relay Control':relay.py,
},
lcd=lcd,
idle_handler=my_invader,
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)

DirkS
Posts: 8856
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: DisplayOTron

Fri May 25, 2018 6:19 pm

1. if you post code, you should use 'code' tags. Indentation is essential in
2. Post full error messages
3. do you use modules created by Pimoroni If so then you should ask them in their forum: https://forums.pimoroni.com/

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

Re: DisplayOTron

Fri May 25, 2018 6:33 pm

i have no idea as im still a newbie when it comes to anything pi related hence why i joined here,
i used the github examples found here: https://github.com/pimoroni/displayotron
is there anyone who is willing to give me a hand with some form of basic code to accomplish my goal?

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

Re: DisplayOTron

Fri May 25, 2018 8:55 pm

Following the link to the GitHub page you posted, there are several pages of examples tutorials and documentation listed along with the support forum for this display.

Documentation & Support

Getting started with Display-o-Tron 3000 - https://learn.pimoroni.com/tutorial/dis ... lay-o-tron
Tutorials - https://learn.pimoroni.com/?tag=display-o-tron
Display-o-Tron 3000 Pinout - https://pinout.xyz/pinout/display_o_tron_3000
Display-o-Tron HAT Pinout - https://pinout.xyz/pinout/display_o_tron_hat
Get help - http://forums.pimoroni.com/c/support

I would suggest you start by working through the first one, Getting started with Display-o-Tron 3000

By using code tags when posting your code

Add [code] at the top

code goes here

and [/code] at the bottom.

your code will retain its indenting.

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




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.
""")

menu = Menu(
    structure={
       'Relay Control':relay.py,
    },
    lcd=lcd,
    idle_handler=my_invader,
    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)
but you still need to post your error messages.
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

Fri May 25, 2018 9:41 pm

okay thank you for the help,
error came up as :

Code: Select all

Traceback (most recent call last):
  File "/home/pi/11.py", line 22, in <module>
    'Relay Control':relay.py,
NameError: name 'relay' is not defined
my script is still the same

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




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.
""")

menu = Menu(
    structure={
       'Relay Control':relay.py,
    },
    lcd=lcd,
    idle_handler=my_invader,
    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)
{/code]
hope this is what everyone meant lol
i have done a few of the basics and now struggling with path diretories etc.

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

Re: DisplayOTron

Fri May 25, 2018 10:06 pm

Looking at their example of a menu

Code: Select all

menu = Menu({
        'Clock': Clock(),
        'IP': IPAddress(),
        'CPU': GraphCPU(),
        'Temp': GraphTemp()
},
they are calling functions from within the running program, which have been imported.

you appear to be try to call a python program directly

Code: Select all

menu = Menu(
    structure={
       'Relay Control':relay.py,
    },
    
I could not find an example that did this, so it may not be possible.

you may be better asking here http://forums.pimoroni.com/c/support
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

Fri May 25, 2018 10:13 pm

i have already posted there also,
if that is the case what script would be capable of displaying an option on the HAT
to change the output of a couple of GPIO pins,
theres gotta be a way of doing something along those lines

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

Re: DisplayOTron

Fri May 25, 2018 10:36 pm

this project is stressing out me to the point of giving up on the pi all together

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

Re: DisplayOTron

Fri May 25, 2018 10:39 pm

i just want a simple menu to turn a signal high or low so i control an led or relay etc.
everything ive tried doesnt seem to work, i thought the pi would be great as it has a huge community but i cant seem to find anything relating to what i require

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

Re: DisplayOTron

Sat May 26, 2018 2:32 am

Update:
I decided to start a fresh and did a clean install of raspbian
then downloaded the libaries for the Display-O-TronHAT
now i can get the example code working

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

# 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
from plugins.wlan import Wlan


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 SpaceInvader(MenuOption):
    """
    A silly example "plug-in" showing an
    animated space invader.
    """

    def __init__(self):
        self.start = self.millis()
        self.invader = [
            [14, 31, 21, 31, 9, 18, 9, 18],
            [14, 31, 21, 31, 18, 9, 18, 9]
        ]
        MenuOption.__init__(self)

    def redraw(self, menu):
        now = self.millis()

        x = int((self.start - now) / 200 % 16)
        menu.lcd.create_char(0, self.invader[int((self.start - now) / 400 % 2)])

        menu.write_row(0, 'Space Invader!')
        menu.write_row(1, (' ' * x) + chr(0))
        menu.clear_row(2)


"""
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.
"""
my_invader = SpaceInvader()

menu = Menu(
    structure={
        'WiFi': Wlan(),
        'Space Invader': my_invader,
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_handler=my_invader,
    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 im trying to add a menu option for power control,

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

# 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 DoShutdown():
    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 shutdown -h now")
            quit()
        sleep(0.25)

def DoReboot():
    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)

class Relays(MenuOption):
    """
    Relay Control Option
    """

    def __init__(self):
        self.
        MenuOption.__init__(self)

    def redraw(self, menu):
        now = self.millis()

        x = int((self.start - now) / 200 % 16)
        menu.lcd.create_char(0, self.invader[int((self.start - now) / 400 % 2)])

        menu.write_row(0, 'Space Invader!')
        menu.write_row(1, (' ' * x) + chr(0))
        menu.clear_row(2)


"""
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.
"""
my_invader = SpaceInvader()

menu = Menu(
    structure={
        'WiFi': Wlan(),
        'Space Invader': my_invader,
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_handler=my_invader,
    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)
i get these errors

Code: Select all

Traceback (most recent call last) :
   File "/home/pi/Pimoroni/displayotron/examples/dothat/advance/menu.py", line 93, in <module>
     menu.redraw()
  File"/usr/local/lib/python3.5/dist-packages/dot3k/menu.py", line 476, in redraw
     self.current_value().redraw(self)  File "/home/pi/Pimoroni/displayotron/examples/plugins/wlan.py", line 213, in redraw
     if self.current_network is not None:
 File "/home/pi/Pimoroni/displayotron/examples/plugins/wlan.py", line 85, in current_network
 if self.selected_item < len(self.items):
 typeError:  object of type 'map' has no len()
 
i have chopped this from other examples so dont understand half of it but think im getting my head around it slowly

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

Re: DisplayOTron

Sat May 26, 2018 11:00 am

It looks like in your line 89 were you call Wlan() , in the function your are calling there is an error with the map object which is returning no value for len() which would normally return the number of characters in the variable , in this case map.

I an only guessing here as I don't have a copy of"/home/pi/Pimoroni/displayotron/examples/plugins/wlan.py" or a DisplayOTron to do any testing with.
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 11:42 am

okay forget the preivouse, im now trying to change the space invader section of this part of code to say power options then once selected have options: Shutdown and Reboot options
if i can get that working i was then hoping to creat another class called Relays to control 2 GPIO pins.
hoping this sounds simple enough for someone.
the plugins folder is seen in the github for displayotron
https://github.com/pimoroni/displayotro ... es/plugins

Code: Select all

#!/usr/bin/env python

import sys
import time

import dot3k.backlight as backlight
import dot3k.joystick as nav
import dot3k.lcd as lcd
from dot3k.menu import Menu, MenuOption

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

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


print("""
This advanced example uses the menu framework.
It gives you an example of a menu created with a specific order.
Press CTRL+C to exit.
""")

class SpaceInvader(MenuOption):
    """
    A silly example "plug-in" showing an
    animated space invader.
    """

    def __init__(self):
        self.start = self.millis()
        self.invader = [
            [14, 31, 21, 31, 9, 18, 9, 18],
            [14, 31, 21, 31, 18, 9, 18, 9]
        ]
        MenuOption.__init__(self)

    def redraw(self, menu):
        now = self.millis()

        x = int((self.start - now) / 200 % 16)
        menu.lcd.create_char(0, self.invader[int((self.start - now) / 400 % 2)])

        menu.write_row(0, 'Space Invader!')
        menu.write_row(1, (' ' * x) + chr(0))
        menu.clear_row(2)


my_invader = SpaceInvader()

menu = Menu(
    None,
    lcd,
    my_invader,
    5)

"""
If you want menu items to appear in a defined order, you must
add them one at a time using 'add_item'. This method accepts
a plugin instance, plus the path where you want it to appear.
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.add_item('Space Invader', my_invader)
menu.add_item('Clock', Clock())
menu.add_item('Status/IP', IPAddress())
menu.add_item('Status/Test', '')
menu.add_item('Status/CPU', GraphCPU())
menu.add_item('Status/Arrr', 'Blah blah')
menu.add_item('Status/Temp', GraphTemp())
menu.add_item('Settings/Display/Contrast', Contrast(lcd)),
menu.add_item('Settings/Display/Backlight', Backlight(backlight))

"""
You can use anything to control dot3k.menu,
but you'll probably want to use dot3k.joystick
"""
REPEAT_DELAY = 0.5


@nav.on(nav.UP)
def handle_up(pin):
    menu.up()
    nav.repeat(nav.UP, menu.up, REPEAT_DELAY, 0.9)


@nav.on(nav.DOWN)
def handle_down(pin):
    menu.down()
    nav.repeat(nav.DOWN, menu.down, REPEAT_DELAY, 0.9)


@nav.on(nav.LEFT)
def handle_left(pin):
    menu.left()
    nav.repeat(nav.LEFT, menu.left, REPEAT_DELAY, 0.9)


@nav.on(nav.RIGHT)
def handle_right(pin):
    menu.right()
    nav.repeat(nav.RIGHT, menu.right, REPEAT_DELAY, 0.9)


@nav.on(nav.BUTTON)
def handle_button(pin):
    menu.select()


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 11:50 am

so far i have 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

# 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 DoShutdown():
    lcd.clear()
    lcd.write'Are you sure?\nPress Sel for Y')
    while 1:
        if @nav.on(nav.LEFT)
        def handle_left(ch, evt):
        menu.left()
            break
        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 DoReboot():
    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)

class Relays(MenuOption):
    """
    Relay Control Option
    """

    def __init__(self):
        self.
        MenuOption.__init__(self)

    def redraw(self, menu):
        now = self.millis()

        x = int((self.start - now) / 200 % 16)
        menu.lcd.create_char(0, self.invader[int((self.start - now) / 400 % 2)])

        menu.write_row(0, 'Space Invader!')
        menu.write_row(1, (' ' * x) + chr(0))
        menu.clear_row(2)


"""
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.
"""
my_invader = SpaceInvader()

menu = Menu(
    structure={
        'WiFi': Wlan(),
        'Space Invader': my_invader,
        'Clock': Clock(backlight),
        'Status': {
            'IP': IPAddress(),
            'CPU': GraphCPU(backlight),
            'Temp': GraphTemp()
        },
        'Settings': {
            'Display': {
                'Contrast': Contrast(lcd),
                'Backlight': Backlight(backlight)
            }
        }
    },
    lcd=lcd,
    idle_handler=my_invader,
    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)
expected an indented block

Code: Select all

def DoShutdown():
lcd.clear()
it highlights lcd in red

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

Re: DisplayOTron

Sat May 26, 2018 12:27 pm

Update:
ive now gotten past that error but now gettting one

Code: Select all


class Power(MenuOption):
    """
    Power Options
    """
    def DoShutdown():
        lcd.clear()
        lcd.write'Are you sure?\nPress Sel for Y')
    while 1:
        if nav.on(nav.LEFT):
        def handle_left(ch, evt):
        menu.left()
            break
        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)
now im getting the expected error inbetween def and handle_button(ch, evt):

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

Re: DisplayOTron

Sat May 26, 2018 1:21 pm

i cant get past this indendation error

Code: Select all

class Power(MenuOption):
    """
    Power Options
    """
    def DoShutdown():
        lcd.clear()
        lcd.write'Are you sure?\nPress Sel for Y')
    while 1:
        if nav.on(nav.LEFT):
        def handle_left(ch, evt):
        menu.left()                      ^^^^^^^^
            break                           "error with red highlight"
        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)

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

Re: DisplayOTron

Sat May 26, 2018 1:41 pm

Sorry but your code does not make sense

you have an if statement and then you are trying to create a function ( def ) inside the if statement indented code.

Code: Select all

    while 1:
        if nav.on(nav.LEFT):        this is you if statement
        def handle_left(ch, evt):         but here you are trying to define a function.
        menu.left()                      ^^^^^^^^
            break      
            
   


code would normally work like this

Code: Select all

def some function():
    we do some thing here in the function
    
while true:
    if some thing is true:
        some function()     then we call the function
        
you would define the function in the body of the code and then call it from within the if statement part of the code.
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 2:03 pm

i have gotten past that issue and now on line 74 in <module> i am faced with 'Shutdown': Shutdown(),
NameError: name 'Shutdown' is not defined

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 DoShutdown():
        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 DoReboot():
    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': DoShutdown(),
            'Reboot': DoReboot()
            },
        '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: 4266
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: DisplayOTron

Sat May 26, 2018 2:23 pm

Probably because you defined it as "def DoShutdown():" and not "Shutdown" Image
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 2:30 pm

as mentioned before im still a beginner at this,
i tried changing all the DoShutDown to just ShutDown and still getting the same error
for some reason i cant copy the code at the moment,
could you please show me the correction?

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

Re: DisplayOTron

Sat May 26, 2018 2:34 pm

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)

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

Re: DisplayOTron

Sat May 26, 2018 2:41 pm

Going to make you work this out for yourself ....................

Some clues

you are missing some thing from the end of "'Shutdown': Shutdown,"

clue " 'IP': IPAddress(),"

look closely :shock: young grass hopper :lol:
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 2:51 pm

pcmanbob wrote:
Sat May 26, 2018 2:41 pm
Going to make you work this out for yourself ....................

Some clues

you are missing some thing from the end of "'Shutdown': Shutdown,"

clue " 'IP': IPAddress(),"

look closely :shock: young grass hopper :lol:
i still dont understand ive tried serval things,
still getting the same error with or without ()

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

Re: DisplayOTron

Sat May 26, 2018 2:56 pm

Code: Select all

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())
    
line 74, in <module>
'Shutdown': Shutdown(),
NameError: name 'Shutdown' is not defined

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

Re: DisplayOTron

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)
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

Return to “Python”

Who is online

Users browsing this forum: No registered users and 6 guests