Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from subprocess import Popen
- from time import sleep
- from sys import exit
- import commands # TODO: Austauschen, da nur unter Python2 verfuegbar!
- import pitouch
- import datum_einstellen
- def main(p):
- p.gen_grid(3, 3)
- p.locate(0, 0)
- p.set_text("Benutzerdefinierte\nAnwendungen")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(user_apps)
- p.locate(2, 0)
- p.set_text("System-\nEinstellungen\nändern")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(systemsettings)
- p.locate(2, 2)
- p.set_text("Raspberry Pi\nherunterfahren")
- p.set_bgcolor("#ff8888")
- p.set_nextcommand(rpi_shutdown)
- def user_apps(p):
- p.gen_grid(3, 3)
- p.locate(2, 0)
- p.set_text("<-----\nZurück")
- p.set_bgcolor("#88ffff")
- p.set_nextcommand(main)
- p.locate(0, 0)
- if Popen("pgrep motion", shell=True).wait() == 0:
- p.set_text("Aufnahme\nstoppen")
- p.set_bgcolor("#ff8888")
- p.set_nextcommand(stop_capture)
- else:
- p.set_text("Aufnahme\nstarten")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(start_capture)
- p.locate(0, 1)
- p.set_text("Screenshot\nanzeigen")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(do_screenshot)
- p.locate(1, 1)
- p.set_text("Video\nzeigen")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(show_video)
- p.locate(0, 2)
- p.set_text("Bildschirm\nausschalten")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(blank_screen)
- def show_video(p):
- p.gen_grid(1, 1)
- cmd = Popen("mplayer tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0:input=1 -fps 20 -fs -nosound -noconsolecontrols", shell=True)
- sleep(5)
- Popen("v4l2-ctl -c brightness=-5", shell=True).wait()
- Popen("v4l2-ctl -c contrast=16", shell=True).wait()
- Popen("v4l2-ctl -c saturation=12", shell=True).wait()
- Popen("v4l2-ctl -c hue=0", shell=True).wait()
- cmd.wait()
- user_apps(p)
- def blank_screen(p):
- p.msgbox_showinfo(None, "Das Touch-Display einfach\nberühren, um es wieder\neinzuschalten.")
- p.gen_grid(1, 1)
- sleep(1)
- Popen("xset dpms force off", shell=True).wait()
- p.locate(0, 0)
- p.set_text("<-----\nZurück")
- p.set_bgcolor("#88ffff")
- p.set_nextcommand(user_apps)
- def ask_dhcp(p):
- p.gen_grid(1, 1)
- Popen("systemctl restart dhcpcd", shell=True).wait()
- tmp = commands.getoutput("ifconfig -a | grep inet | grep -v 127. | awk '{ print $2 }'")
- p.msgbox_showinfo(None, "IP wird angefordert...\n" + tmp)
- systemsettings(p)
- def stop_smb(p):
- p.gen_grid(1, 1)
- Popen("systemctl stop smbd", shell=True).wait()
- systemsettings(p)
- def start_smb(p):
- p.gen_grid(1, 1)
- Popen("systemctl start smbd", shell=True).wait()
- systemsettings(p)
- def do_screenshot(p):
- p.gen_grid(1, 1)
- Popen("fswebcam -r 320x240 --skip 5 --save /public/screenshot.jpeg", shell=True).wait()
- p.set_image("/public/screenshot.jpeg")
- p.set_nextcommand(user_apps)
- def stop_capture(p):
- p.gen_grid(1, 1)
- Popen("pkill motion", shell=True).wait()
- while Popen("pgrep motion", shell=True).wait() == 0:
- sleep(2)
- Popen("systemctl stop smbd", shell=True).wait()
- Popen("sync", shell=True).wait()
- Popen("umount /dev/sda", shell=True).wait()
- Popen("sync", shell=True).wait()
- Popen("systemctl start smbd", shell=True).wait()
- user_apps(p)
- def start_capture(p):
- p.gen_grid(1, 1)
- Popen("mount /dev/sda /public -o sync", shell=True).wait()
- Popen("motion &", shell=True)
- user_apps(p)
- def rpi_shutdown(p):
- if p.get_msgbox_askyesno(None, "Den Raspberry Pi wirklich\nherunterfahren?"):
- p.window.destroy()
- Popen("systemctl poweroff", shell=True)
- exit()
- def systemsettings(p):
- p.gen_grid(3, 3)
- p.locate(0, 0)
- p.set_text("Datum\neinstellen")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(datum_einstellen.datum_einstellen)
- p.locate(2, 0)
- p.set_text("<-----\nZurück")
- p.set_bgcolor("#88ffff")
- p.set_nextcommand(main)
- p.locate(0, 1)
- if Popen("pgrep smbd", shell=True).wait() == 0:
- p.set_text("Freigabe\nbeenden")
- p.set_bgcolor("#ff8888")
- p.set_nextcommand(stop_smb)
- else:
- p.set_text("Freigabe\nstarten")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(start_smb)
- p.locate(2, 2)
- p.set_text("USB-Stick\nformatieren")
- p.set_bgcolor("#ff8888")
- p.set_nextcommand(del_usb)
- p.locate(0, 2)
- p.set_text("DHCP-Anfrage\nsenden")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(ask_dhcp)
- p.locate(1, 0)
- p.set_text("Mit WLAN\nverbinden")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(wlan_connect)
- p.locate(1, 2)
- p.set_text("/public\nlöschen")
- p.set_bgcolor("#ff8888")
- p.set_nextcommand(del_public)
- p.locate(1, 1)
- p.set_bgcolor("#88ff88")
- if Popen('grep "/dev/sda " /proc/mounts', shell=True).wait() != 0:
- p.set_text("USB-Stick\neinhängen")
- p.set_nextcommand(usb_mount)
- else:
- p.set_text("USB-Stick\naushängen")
- p.set_nextcommand(usb_umount)
- def usb_mount(p):
- p.gen_grid(1, 1)
- Popen("mount /dev/sda /public", shell=True).wait()
- systemsettings(p)
- def usb_umount(p):
- p.gen_grid(1, 1)
- Popen("umount /public", shell=True).wait()
- systemsettings(p)
- def wlan_connect(p):
- Popen("pkill wpa_supplicant", shell=True).wait()
- p.gen_grid(1, 3)
- p.locate(2, 0)
- p.set_text("<-----\nZurück")
- p.set_bgcolor("#88ffff")
- p.set_nextcommand(systemsettings)
- p.locate(0, 0)
- p.set_text("Verbinde mit:\n3er-WG")
- p.set_bgcolor("#88ff88")
- p.set_nextcommand(connect_3erwg)
- def connect_3erwg(p):
- Popen("wpa_supplicant -iwlan0 -Dwext -c /etc/wpa_supplicant/3erwg.conf -B", shell=True)
- systemsettings(p)
- def del_usb(p):
- if p.get_msgbox_askyesno(None, "ACHTUNG: Alle Daten\nauf dem Stick\nwerden gelöscht!\nFortfahren?"):
- p.gen_grid(1, 1)
- Popen("systemctl stop smbd", shell=True).wait()
- Popen("umount /dev/sda", shell=True).wait()
- Popen("dd if=/dev/zero of=/dev/sda bs=5000 count=1", shell=True).wait()
- Popen("mkfs.vfat -I -F 32 /dev/sda", shell=True).wait()
- systemsettings(p)
- def del_public(p):
- if p.get_msgbox_askyesno(None, "/public wirklich\nlöschen?"):
- p.gen_grid(1, 1)
- Popen("rm -rf /public/*", shell=True).wait()
- systemsettings(p)
- if __name__ == "__main__":
- p = pitouch.pitouch()
- Popen("xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 0 1", shell=True).wait()
- Popen("xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axes Swap' 1", shell=True).wait()
- Popen("xset -dpms", shell=True).wait()
- main(p)
- p.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement