Progress!
This commit is contained in:
parent
546fdf8e6b
commit
8b0c6f5020
129
Pi-Recorder.py
129
Pi-Recorder.py
@ -1,11 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from ntpath import altsep
|
||||
import os
|
||||
import subprocess
|
||||
import tkinter as tk
|
||||
from tkinter import *
|
||||
from datetime import datetime
|
||||
|
||||
def checkUSB():
|
||||
def run_command(command):
|
||||
ret_code, output = subprocess.getstatusoutput(command)
|
||||
return output.splitlines()
|
||||
|
||||
def check_usb():
|
||||
stream = os.popen('lsusb | grep "Audio" | cut -d" " -f7')
|
||||
output = stream.read()
|
||||
if (output.find("PreSonus") != -1):
|
||||
@ -13,7 +17,7 @@ def checkUSB():
|
||||
else:
|
||||
return False
|
||||
|
||||
def checkRecordStatus():
|
||||
def check_record_status():
|
||||
stream = os.popen('screen -list | grep -c "Pi-ARecord" || true')
|
||||
output = stream.read()
|
||||
if (output.find("1")):
|
||||
@ -22,12 +26,12 @@ def checkRecordStatus():
|
||||
return False
|
||||
|
||||
def record():
|
||||
if checkRecordStatus():
|
||||
if check_record_status():
|
||||
os.system('screen -S record -X stuff "^C"')
|
||||
btn_record_var.set('Start Recording')
|
||||
else:
|
||||
if (checkUSB()):
|
||||
os.system('screen -S record -d -m arecord -D plughw:2,0 -f dat -vv /home/pi/test_input.wav')
|
||||
if (check_usb()):
|
||||
os.system('screen -S record -d -m arecord -D plughw:2,0 -f dat -vv /mnt/USB/test_input.wav')
|
||||
btn_record_var.set('Stop Recording')
|
||||
else:
|
||||
btn_record_var.set('PreSonus N/A')
|
||||
@ -35,6 +39,10 @@ def record():
|
||||
### tkinter variables
|
||||
run_tk = True
|
||||
light_mode = True
|
||||
is_mounted = False
|
||||
mount_directory = '/mnt/USB/'
|
||||
record_start_time = None
|
||||
record_current_time = None
|
||||
|
||||
### tkinter theme
|
||||
btn_light_color = '#BA09C6'
|
||||
@ -45,21 +53,89 @@ text_light_color = '#000000'
|
||||
text_dark_color = '#adadad'
|
||||
|
||||
### tkinter functions
|
||||
def onExit():
|
||||
def on_exit():
|
||||
global run_tk
|
||||
if checkRecordStatus():
|
||||
if check_record_status():
|
||||
record()
|
||||
run_tk = False
|
||||
main_window.destroy()
|
||||
exit()
|
||||
|
||||
def btnRecord():
|
||||
def restart_ar():
|
||||
global run_tk
|
||||
if check_record_status():
|
||||
record()
|
||||
run_tk = False
|
||||
main_window.destroy()
|
||||
exit()
|
||||
|
||||
def btn_record_func():
|
||||
record()
|
||||
|
||||
def btn_mount_func():
|
||||
drives = run_command("lsblk | grep 'sda1'")
|
||||
if is_mounted:
|
||||
run_command("sudo umount /dev/sda1")
|
||||
else:
|
||||
command = "sudo mount /dev/sda1 %s" % (mount_directory)
|
||||
run_command(command)
|
||||
|
||||
def calculate_timer():
|
||||
global record_start_time
|
||||
global record_current_time
|
||||
if check_record_status():
|
||||
record_current_time = datetime.now()
|
||||
record_elapsed = record_current_time - record_start_time
|
||||
label_record_timer_var.set("%02d:%02d:%02d" % (record_elapsed.seconds // 3600, record_elapsed.seconds // 60 % 60, record_elapsed.seconds % 60))
|
||||
|
||||
def check_mount_status():
|
||||
global is_mounted
|
||||
try:
|
||||
mounted_drives = run_command("lsblk | grep 'USB'")
|
||||
if mounted_drives[0].find("USB") != -1:
|
||||
is_mounted = True
|
||||
btn_mount_var.set("Unmount USB")
|
||||
except:
|
||||
is_mounted = False
|
||||
btn_mount_var.set("Mount USB")
|
||||
|
||||
def check_remaining_space():
|
||||
if is_mounted:
|
||||
try:
|
||||
drive = run_command("df -h %s | grep 'USB'" % (mount_directory))[0].split()
|
||||
space = ("Used: %s, Remaining: %s, Percentage: %s" % (drive[2], drive[3], drive[4]))
|
||||
label_mount_space_var.set(space)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
label_mount_space_var.set("Used: ???, Remaining: ???, Percentage: ???")
|
||||
|
||||
def toggle_gui_func():
|
||||
global light_mode
|
||||
if light_mode:
|
||||
main_window.configure(background=bg_dark_color)
|
||||
btn_record.configure(bg=btn_dark_color, foreground=text_dark_color)
|
||||
btn_mount.configure(bg=btn_dark_color, foreground=text_dark_color)
|
||||
#shutdown_btn.configure(bg=btn_dark_color, foreground=text_dark_color)
|
||||
btn_exit.configure(bg=btn_dark_color, foreground=text_dark_color)
|
||||
btn_restart.configure(bg=btn_dark_color, foreground=text_dark_color)
|
||||
btn_lightmode.configure(bg=btn_dark_color, foreground=text_dark_color)
|
||||
light_mode = False
|
||||
else:
|
||||
main_window.configure(background=bg_light_color)
|
||||
btn_record.configure(bg=btn_light_color, foreground=text_light_color)
|
||||
btn_mount.configure(bg=btn_light_color, foreground=text_light_color)
|
||||
#btn_shutdown.configure(bg=btn_light_color, foreground=text_light_color)
|
||||
btn_exit.configure(bg=btn_light_color, foreground=text_light_color)
|
||||
btn_restart.configure(bg=btn_light_color, foreground=text_light_color)
|
||||
btn_lightmode.configure(bg=btn_light_color, foreground=text_light_color)
|
||||
light_mode = True
|
||||
|
||||
|
||||
### tkinter main window setup
|
||||
main_window = Tk()
|
||||
main_window.attributes("-fullscreen", False)
|
||||
main_window.protocol("WM_DELETE_WINDOW", onExit)
|
||||
main_window.protocol("WM_DELETE_WINDOW", on_exit)
|
||||
main_window.configure(background=bg_light_color)
|
||||
main_window.title("Momo\'s Awesome Recorder")
|
||||
main_window.columnconfigure(0, weight=1)
|
||||
@ -68,9 +144,38 @@ main_window.columnconfigure(2, weight=1)
|
||||
### tkinter record button
|
||||
btn_record_var = tk.StringVar()
|
||||
btn_record_var.set('Start Recording')
|
||||
btn_record = Button(main_window, textvariable=btn_record_var, bg=btn_light_color, command=btnRecord)
|
||||
btn_record = Button(main_window, textvariable=btn_record_var, bg=btn_light_color, command=btn_record_func)
|
||||
btn_record.grid(column=0, row=0, sticky='NSEW', padx=5, pady=5)
|
||||
### tkinter record timer
|
||||
label_record_timer_var = tk.StringVar()
|
||||
label_record_timer_var.set("00:00:00")
|
||||
label_record_timer = Label(main_window, textvariable=label_record_timer_var, font=('arial', 18, 'bold'))
|
||||
label_record_timer.grid(column=0, row=2, sticky='NSEW', padx=5, pady=5)
|
||||
### tkinter mount button
|
||||
btn_mount_var = tk.StringVar()
|
||||
btn_mount_var.set('Mount USB')
|
||||
btn_mount = Button(main_window, textvariable=btn_mount_var, bg=btn_light_color, command=btn_mount_func)
|
||||
btn_mount.grid(column=1, row=0, sticky='NSEW', padx=5, pady=5)
|
||||
### tkinter usb remaining space
|
||||
label_mount_space_var = tk.StringVar()
|
||||
label_mount_space_var.set("Used: ???, Remaining: ???, Percentage: ???")
|
||||
label_mount_space = Label(main_window, textvariable=label_mount_space_var, font=('arial', 18, 'bold'))
|
||||
label_mount_space.grid(column=1, row=1, sticky='NSEW', padx=5, pady=5)
|
||||
### tkinter exit program
|
||||
btn_exit = Button(main_window, text='Exit Recorder', bg=btn_light_color, command=on_exit)
|
||||
btn_exit.grid(column=2, row=1, sticky='NSEW', padx=5, pady=5)
|
||||
### tkinter restart program
|
||||
btn_restart = Button(main_window, text='Restart Recorder', bg=btn_light_color, command=restart_ar)
|
||||
btn_restart.grid(column=2, row=2, sticky='NSEW', padx=5, pady=5)
|
||||
### tkinter lightmode button
|
||||
btn_lightmode_var = tk.StringVar()
|
||||
btn_lightmode_var.set("Go Dark")
|
||||
btn_lightmode = Button(main_window, textvariable=btn_lightmode_var, bg=btn_light_color, command=toggle_gui_func)
|
||||
btn_lightmode.grid(column=1, row=2, sticky='NSEW', padx=5, pady=5)
|
||||
|
||||
while run_tk:
|
||||
main_window.update_idletasks()
|
||||
main_window.update()
|
||||
calculate_timer()
|
||||
check_mount_status()
|
||||
check_remaining_space()
|
||||
|
Loading…
Reference in New Issue
Block a user