[Testing] Miniscreen Buttons

So I thought to try out the Miniscreen buttons and here is what i got

And this is the code

from pitop.miniscreen import Miniscreen
from time import sleep
from PIL import Image, ImageDraw, ImageFont


ms = Miniscreen()
image = Image.new(ms.mode, ms.size,)
canvas = ImageDraw.Draw(image)
up = ms.up_button
down = ms.down_button
page = 1

def display_page():
    global page
    canvas.rectangle(ms.bounding_box, fill=0)
    if page == 1:
        canvas.text((23, 23),f"Page : {page}",font=ImageFont.load_default(),fill=1)
    elif page == 2:
        canvas.text((60, 43),f"Page : {page}",font=ImageFont.load_default(),fill=1)
    elif page == 3:
        canvas.text((13, 36),f"Page : {page}",font=ImageFont.load_default(),fill=1)
    ms.display_image(image)

def do_up_thing():
    global page
    if page == 3:
        page = 1
    else: 
        page += 1

def do_down_thing():
    global page
    if page == 1:
        page = 3
    else: 
        page -= 1

up.when_pressed = do_up_thing
down.when_pressed = do_down_thing

while True:
    display_page()
1 Like

Going a step forward adding a selection preference (does nothing significant, just text display) to the different “pages”

And here is the code

from pitop.miniscreen import Miniscreen
from time import sleep
from PIL import Image, ImageDraw, ImageFont


ms = Miniscreen()
image = Image.new(ms.mode, ms.size,)
canvas = ImageDraw.Draw(image)
up = ms.up_button
down = ms.down_button
select = ms.select_button
cancel = ms.cancel_button

selection = {'1' : False, '2' : False, '3' : False}
page = 1

def display_page():
    global page, selection
    canvas.rectangle(ms.bounding_box, fill=0)
    if page == 1:
        canvas.text((23, 23),f"Page : {page}",font=ImageFont.load_default(),fill=1)
        canvas.text((0, 0),f"Selection : {selection[str(page)]}",font=ImageFont.load_default(),fill=1)
    elif page == 2:
        canvas.text((60, 43),f"Page : {page}",font=ImageFont.load_default(),fill=1)
        canvas.text((0, 0),f"Selection : {selection[str(page)]}",font=ImageFont.load_default(),fill=1)
    elif page == 3:
        canvas.text((13, 36),f"Page : {page}",font=ImageFont.load_default(),fill=1)
        canvas.text((0, 0),f"Selection : {selection[str(page)]}",font=ImageFont.load_default(),fill=1)
    ms.display_image(image)

def do_up_thing():
    global page
    if page == 3:
        page = 1
    else: 
        page += 1

def do_down_thing():
    global page
    if page == 1:
        page = 3
    else: 
        page -= 1

def do_delect_thing():
    global page, selection
    if page == 1:
        selection['1'] = True if selection['1'] == False else False
    elif page == 2:
        selection['2'] = True if selection['2'] == False else False
    elif page == 3:
        selection['3'] = True if selection['3'] == False else False

up.when_pressed = do_up_thing
down.when_pressed = do_down_thing
select.when_pressed = do_delect_thing
while True:
    display_page()
2 Likes

No we just need to get everything talking to the system menu so we can launch these scripts from it and then close them when were done.