• Benvenuti su RaspberryItaly!
Benvenuto ospite! Login Login con Facebook Registrati Login with Facebook


Valutazione discussione:
  • 0 voto(i) - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5

[-]
Tags
come tft menu 4 fare? 2 per

Menu per TFT 2.4 - come fare?
#1
Salve atutti!
Volevo fare un semplice menu (sei tasti mi batono) che come funzione principare serebbe quella di far partire al click un programma python, piu precisamente un programma per scattare foto. Esempio; se clico nel menu "Foto color 200 asa", lui fara partire il programa piton preconfigurato con il color 200 asa, e cosi via 400 asa, 800 ecc.
ho trvato questo script python (pitftmenu) che in origine era per un TFT 2.8 e quindi ho cercato di adattarlo al mio piccolo 2.4.
Vi inserisco lo script e se qualcuno mi sa dire che comando devo inserire per far si che mi apra il programma nel mio caso di test si chiama "camera.matrix.py" si apra, sarei grato.

come devo scrivere il comando?

if number == 6:
# Camera Matrix
pygame.quit()
##startx only works when we don't use subprocess here, don't know why
os.execvp("python", ["python", home/pi/camera-matrix/camera-matrix.py])
sys.exit()

AIUTO!!! Huh Huh Huh



#----------------------------------------------------------------------------------------

#!/usr/bin/env python
import sys, os, time, subprocess, commands, pygame
from pygame.locals import *
from subprocess import *
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
os.environ["SDL_MOUSEDRV"] = "TSLIB"

# Initialize pygame modules individually (to avoid ALSA errors) and hide mouse
pygame.font.init()
pygame.display.init()

pygame.mouse.set_visible(0)

# define function for printing text in a specific place with a specific width and height with a specific colour and border
def make_button(text, xpo, ypo, height, width, colour):
pygame.draw.rect(screen, tron_regular, (xpo-7,ypo-7,width,height),3)
pygame.draw.rect(screen, tron_light, (xpo-7,ypo-7,width-1,height-1),1)
pygame.draw.rect(screen, tron_regular, (xpo-7,ypo-7,width-2,height-2),1)
font=pygame.font.Font(None,21)
label=font.render(str(text), 1, (colour))
screen.blit(label,(xpo,ypo))


# define function for printing text in a specific place with a specific colour
def make_label(text, xpo, ypo, fontsize, colour):
font=pygame.font.Font(None,fontsize)
label=font.render(str(text), 1, (colour))
screen.blit(label,(xpo,ypo))

# define function that checks for touch location
def on_touch():
# get the position that was touched
touch_pos = (pygame.mouse.get_pos() [0], pygame.mouse.get_pos() [1])
# x_min x_max y_min y_max
# button 1 event
if 30 <= touch_pos[0] <= 170 and 70 <= touch_pos[1] <=130:
button(1)
# button 2 event
if 175 <= touch_pos[0] <= 315 and 70 <= touch_pos[1] <=130:
button(2)
# button 3 event
if 30 <= touch_pos[0] <= 170 and 130 <= touch_pos[1] <=165:
button(3)
# button 4 event
if 175 <= touch_pos[0] <= 315 and 130 <= touch_pos[1] <=165:
button(4)
# button 5 event
if 30 <= touch_pos[0] <= 170 and 180 <= touch_pos[1] <=200:
button(5)
# button 6 event
if 175 <= touch_pos[0] <= 315 and 180 <= touch_pos[1] <=200:
button(6)

def run_cmd(cmd):
process = Popen(cmd.split(), stdout=PIPE)
output = process.communicate()[0]
return output


# Define each button press action
def button(number):
if number == 1:
# X TFT
pygame.quit()
## Requires "Anybody" in dpkg-reconfigure x11-common if we have scrolled pages previously
run_cmd("/usr/bin/sudo -u pi FRAMEBUFFER=/dev/fb1 startx")
os.execv(__file__, sys.argv)

if number == 2:
# X HDMI
pygame.quit()
## Requires "Anybody" in dpkg-reconfigure x11-common if we have scrolled pages previously
run_cmd("/usr/bin/sudo -u pi FRAMEBUFFER=/dev/fb0 startx")
os.execv(__file__, sys.argv)


if number == 3:
# exit
pygame.quit()
sys.exit()

if number == 4:
# htop
pygame.quit()
process = subprocess.call("/usr/bin/htop", shell=True)
os.execv(__file__, sys.argv)

if number == 5:
# next page
pygame.quit()
##startx only works when we don't use subprocess here, don't know why
page=os.environ["MENUDIR"] + "menu_screenoff.py"
os.execvp("python", ["python", page])
sys.exit()

if number == 6:
# next page
pygame.quit()
##startx only works when we don't use subprocess here, don't know why
page=os.environ["MENUDIR"] + "menu_kali-2.py"
os.execvp("python", ["python", page])
sys.exit()



# colors R G B
white = (255, 255, 255)
tron_whi = (189, 254, 255)
red = (255, 0, 0)
green = ( 0, 255, 0)
blue = ( 0, 0, 255)
tron_blu = ( 0, 219, 232)
black = ( 0, 0, 0)
cyan = ( 50, 255, 255)
magenta = (255, 0, 255)
yellow = (255, 255, 0)
tron_yel = (255, 218, 10)
orange = (255, 127, 0)
tron_ora = (255, 202, 0)

# Tron theme orange
tron_regular = tron_ora
tron_light = tron_yel
tron_inverse = tron_whi

# Tron theme blue
##tron_regular = tron_blu
##tron_light = tron_whi
##tron_inverse = tron_yel

# Set up the base menu you can customize your menu with the colors above

#set size of the screen
size = width, height = 320, 240
screen = pygame.display.set_mode(size)

# Background Color
screen.fill(black)

# Outer Border
pygame.draw.rect(screen, tron_regular, (0,0,319,239),8)
pygame.draw.rect(screen, tron_light, (2,2,319-4,239-4),2)

pi_hostname = run_cmd("hostname")
pi_hostname = " " + pi_hostname[:-1]
# Buttons and labels
# First Row Label
make_label(pi_hostname, 15, 15, 24, tron_inverse)
# Second Row buttons 3 and 4
make_button(" X on TFT", 30, 70, 30, 140, tron_light)
make_button(" X on HDMI", 175, 70, 30, 140, tron_light)
# Third Row buttons 5 and 6
make_button(" Terminal", 30, 130, 30, 140, tron_light)
make_button(" hTop", 175, 140, 30, 140, tron_light)
# Fourth Row Buttons
make_button(" Screen Off", 30, 180, 30, 140, tron_light)
make_button(" >>>", 175, 180, 30, 140, tron_light)


#While loop to manage touch screen inputs
while 1:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
pos = (pygame.mouse.get_pos() [0], pygame.mouse.get_pos() [1])
on_touch()

#ensure there is always a safe way to end the program if the touch screen fails
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
pygame.display.update()
## Reduce CPU utilisation
time.sleep(0.1)
#----------------------------------------------------------------------------------------
Risposta
  


Vai al forum:


Navigazione:
Forum con nuovi Post
Forum senza nuovi post
Forum bloccato
Forum Redirect