ich bin neu im Thema Raspberry Pi und habe für eine Umsetzung meiner Idee das Programm Pimenu gefunden. Meine Programmierkentnisse basieren noch auf dem C64 also schon etwas veraltet.
Ich habe das Problem, daß ich das Tool Pimenu nicht zum laufen bekomme.
Das Fenster öffnet sich wie gewünscht. Diverse Änderungen in der Yaml-Datei werden übernommen. Ich habe mich in der Py-Datei schon umgesehen, jedoch fehlen mir noch die Kenntnisse und langsam die Lust was zu suchen/finden.
Es scheint als ob die Sh-Datei nicht gestartet oder falsch ausgeführt wird. Denn:
Nach dem drücken auf einen Button erscheint der Schriftzug "Executing..." und nicht passiert. Alles bleibt so, bis ich das Py-Programm mit "kill" beende.
Kann mir jemand dabei helfen?
Hier die Pimenu.py:
Code: Alles auswählen
#!/usr/bin/python2
# -*- coding: utf-8 -*-
from math import sqrt, floor, ceil
import os
import subprocess
import yaml
import Tkconstants as TkC
from Tkinter import Tk, Frame, Button, Label, PhotoImage
import sys
class FlatButton(Button):
def __init__(self, master=None, cnf={}, **kw):
Button.__init__(self, master, cnf, **kw)
# self.pack()
self.config(
compound=TkC.TOP,
relief=TkC.FLAT,
bd=0,
bg="#b91d47", # dark-red
fg="white",
activebackground="#b91d47", # dark-red
activeforeground="white",
# height=118,
#width=104,
highlightthickness=0
)
def set_color(self, color):
self.configure(
bg=color,
fg="white",
activebackground=color,
activeforeground="white"
)
class PiMenu(Frame):
doc = None
framestack = []
icons = {}
path = ''
def __init__(self, parent):
Frame.__init__(self, parent, background="white")
self.parent = parent
self.pack(fill=TkC.BOTH, expand=1)
self.path= os.path.dirname(os.path.realpath(sys.argv[0]))
with open(self.path + '/pimenu.yaml', 'r') as f:
self.doc = yaml.load(f)
self.show_items(self.doc)
def show_items(self, items, upper=[]):
"""
Creates a new page on the stack, automatically adds a back button when there are
pages on the stack already
:param items: list the items to display
:param upper: list previous levels' ids
:return: None
"""
num = 0
# create a new frame
wrap = Frame(self, bg="black")
# when there were previous frames, hide the top one and add a back button for the new one
if len(self.framestack):
self.hide_top()
back = FlatButton(
wrap,
text='Zurück',
image=self.get_icon("arrow.left"),
command=self.go_back,
)
back.set_color("#00a300") # green
back.grid(row=0, column=0, padx=1, pady=1, sticky=TkC.W + TkC.E + TkC.N + TkC.S)
num += 1
# add the new frame to the stack and display it
self.framestack.append(wrap)
self.show_top()
# calculate tile distribution
all = len(items) + num
rows = floor(sqrt(all))
cols = ceil(all / rows)
# make cells autoscale
for x in range(int(cols)):
wrap.columnconfigure(x, weight=1)
for y in range(int(rows)):
wrap.rowconfigure(y, weight=1)
# display all given buttons
for item in items:
act = upper + [item['name']]
if 'icon' in item:
image = self.get_icon(item['icon'])
else:
image = self.get_icon('scrabble.'+item['label'][0:1].lower())
btn = FlatButton(
wrap,
text=item['label'],
image=image
)
if 'items' in item:
# this is a deeper level
btn.configure(command=lambda act=act, item=item: self.show_items(item['items'], act), text=item['label']+'…')
btn.set_color("#2b5797") # dark-blue
else:
# this is an action
btn.configure(command=lambda act=act: self.go_action(act), )
if 'color' in item:
btn.set_color(item['color'])
# add buton to the grid
btn.grid(
row=int(floor(num / cols)),
column=int(num % cols),
padx=1,
pady=1,
sticky=TkC.W + TkC.E + TkC.N + TkC.S
)
num += 1
def get_icon(self, name):
"""
Loads the given icon and keeps a reference
:param name: string
:return:
"""
if name in self.icons:
return self.icons[name]
ico = self.path + '/ico/' + name + '.gif'
if not os.path.isfile(ico):
ico = self.path + '/ico/cancel.gif'
self.icons[name] = PhotoImage(file=ico)
return self.icons[name]
def hide_top(self):
"""
hide the top page
:return:
"""
self.framestack[len(self.framestack) - 1].pack_forget()
def show_top(self):
"""
show the top page
:return:
"""
self.framestack[len(self.framestack) - 1].pack(fill=TkC.BOTH, expand=1)
def destroy_top(self):
"""
destroy the top page
:return:
"""
self.framestack[len(self.framestack) - 1].destroy()
self.framestack.pop()
def destroy_all(self):
"""
destroy all pages except the first aka. go back to start
:return:
"""
while len(self.framestack) > 1:
self.destroy_top()
def go_action(self, actions):
"""
execute the action script
:param actions:
:return:
"""
# hide the menu and show a delay screen
self.hide_top()
delay = Frame(self, bg="#2d89ef")
delay.pack(fill=TkC.BOTH, expand=1)
label = Label(delay, text="Ich mach ja schon...", fg="white", bg="#2d89ef", font="Sans 20")
label.pack(fill=TkC.BOTH, expand=1)
self.parent.update()
# excute shell script
subprocess.call([self.path + '/pimenu.sh' , actions])
# remove delay screen and show menu again
delay.destroy()
self.destroy_all()
self.show_top()
def go_back(self):
"""
destroy the current frame and reshow the one below
:return:
"""
self.destroy_top()
self.show_top()
def main():
root = Tk()
root.geometry("320x240")
root.wm_title('PiMenu')
if len(sys.argv) > 1 and sys.argv[1] == 'fs':
root.wm_attributes('-fullscreen', True)
app = PiMenu(root)
root.mainloop()
if __name__ == '__main__':
main()
Code: Alles auswählen
# Menu configuration
---
-
name: "Menu"
label: "Rocrail "
color: "#0000FF"
icon: "RocMen"
items:
-
name: "rocan"
label: "Rocrail Server AN"
color: "#0E0EEE"
icon: "RocAN"
-
name: "rocaus"
label: "Rocrail Server AUS"
color: "#EE0E0E"
icon: "RocAUS"
-
name: "down"
label: "Herunterfahren"
color: "#FF0000"
icon: "radioactive"
-
name: "sicher"
label: "Sichern"
color: "#770707"
icon: "disk1"
-
name: "konfi"
label: "Einstellungen"
color: "#707707"
icon: "cogs1"
Code: Alles auswählen
#!/bin/bash
key=$(echo "$*" | awk 'NF>1{print $NF}')
case $key in
rocan)
echo -e "\a"
sleep 10
;;
rocaus)
echo -e "\a"
sleep 12
;;
sicher)
echo -e "\a"
sleep 15
;;
down)
echo -e "\a"
sudo reboot
;;
'')
sleep 20
;;
esac
sleep 1
Gruß
Harald