Hi all,
mostly new to python, certainly new to tkinter and mpv!
wrote a little python/tkinter script to select recorded mkv's (from motion) which then play via mpv. All works OK, but:
whether I select one or multiple video's, one of two things are a problem:
1- if I pause any video before end and try to close the player window, it freezes until I close the app from idle
2- if I select one mor multiple mkv's, then either play to end or go through selection process again (via Browse button), the app closes.
Here is the complete code:
mostly new to python, certainly new to tkinter and mpv!
wrote a little python/tkinter script to select recorded mkv's (from motion) which then play via mpv. All works OK, but:
whether I select one or multiple video's, one of two things are a problem:
1- if I pause any video before end and try to close the player window, it freezes until I close the app from idle
2- if I select one mor multiple mkv's, then either play to end or go through selection process again (via Browse button), the app closes.
Here is the complete code:
#!/usr/bin/python3 import os import shutil import tkinter as tk from tkinter import * from tkinter import ttk from tkinter import filedialog from tkinter import messagebox import webbrowser if os.environ.get('DISPLAY','') == "": print('no display found.Using :0.0') os.environ.__setitem__('DISPLAY',':0.0') ##### MPV.py HAS TO BE copied into the directory which imports mpv ###### import mpv player = mpv.MPV(ytdl=True,input_default_bindings=True,input_vo_keyboard=True,osc=True) root = tk.Tk() root.title("Motion GUI") root.minsize(width=1000, height=700) root.maxsize(width=1400, height = 900) mainframe = ttk.Frame(root, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(N,W,E,S)) root.columnconfigure(0, weight=1) root.rowconfigure(0,weight=1) WidgetFrame = ttk.Frame(mainframe, borderwidth=2,relief='ridge',height = 60) WidgetFrame.grid(column=0,row=0, sticky="E,W") DisplayFrame = ttk.Frame(mainframe, borderwidth=1) DisplayFrame.grid(column=0, row=1, sticky="E,W", rowspan=10) StatusFrame = ttk.Frame(mainframe, borderwidth=1) StatusFrame.grid(column=0,row=11, sticky="E,W") root.geometry("830x420") root.title("View/Copy/Move mkv's") root.config(background = "gray") def CreateWidgets(): WidgetFrame.link_Label = Label(WidgetFrame, text ="Select File(s): ", bg = "#E8D579") WidgetFrame.link_Label.grid(row = 1, column = 0, pady = 5, padx = 5) #widget_frame.source_message = Entry(widgetFrame, text= " ") #widget_frame.source_message.grid(row = 1, column = 4,columnspan = 2) WidgetFrame.sourceText = Entry(WidgetFrame, width = 50, textvariable = sourceLocation) WidgetFrame.sourceText.grid(row = 1, column = 1, pady = 5, padx = 5, columnspan = 2) WidgetFrame.source_browseButton = Button(WidgetFrame, text ="Browse", command = SourceBrowse, width = 15) WidgetFrame.source_browseButton.grid(row = 1, column = 3, pady = 5, padx = 5) WidgetFrame.destinationLabel = Label(WidgetFrame, text ="Select The Destination : ", bg ="#E8D579") WidgetFrame.destinationLabel.grid(row = 2, column = 0, pady = 5, padx = 5) WidgetFrame.destinationText = Entry(WidgetFrame, width = 50, textvariable = destinationLocation) WidgetFrame.destinationText.grid(row = 2, column = 1, pady = 5, padx = 5, columnspan = 2) WidgetFrame.dest_browseButton = Button(WidgetFrame, text ="Browse", command = DestinationBrowse, width = 15) WidgetFrame.dest_browseButton.grid(row = 2, column = 3, pady = 5, padx = 5) WidgetFrame.viewButton = Button(WidgetFrame, text ="View File(s)", command = ViewFile, width = 15) WidgetFrame.viewButton.grid(row = 3, column = 0, pady = 5, padx = 5) WidgetFrame.copyButton = Button(WidgetFrame, text ="Copy File", command = CopyFile, width = 15) WidgetFrame.copyButton.grid(row = 3, column = 1, pady = 5, padx = 5) WidgetFrame.moveButton = Button(WidgetFrame, text ="Move File", command = MoveFile, width = 15) WidgetFrame.moveButton.grid(row = 3, column = 2, pady = 5, padx = 5) WidgetFrame.moveButton = Button(WidgetFrame, text ="Delete File(s)", command = DeleteFile, width = 15) WidgetFrame.moveButton.grid(row = 3, column = 3, pady = 5, padx = 5) WidgetFrame.MotionButton = Button(WidgetFrame, text="IP Streams",command=MotionHTTP, font="LUCIDA 12") WidgetFrame.MotionButton.grid(row=3,column=5,pady=5,padx=5) WidgetFrame.exitButton = Button(WidgetFrame, text="Quit", command=root.destroy, font="LUCIDA 12 bold") WidgetFrame.exitButton.grid(row = 3, column = 6,pady = 5, padx = 5) #destinationdirectory = '/home/rainer/Vids' def MotionHTTP(): webbrowser.open("http://<IP>:<port>") def SourceBrowse(): WidgetFrame.files_list = list(filedialog.askopenfilenames(initialdir ="/mnt/data/Motion_Data/Motion_Clips",title="Press shift key plus Left mouse click to select multiple files")) WidgetFrame.sourceText.insert() WidgetFrame.sourceText.insert('1', WidgetFrame.files_list) def DestinationBrowse(): destinationdirectory = filedialog.askdirectory(initialdir ="/mnt/data/Motion_Data/Motion_Clips") WidgetFrame.destinationText.insert('1', destinationdirectory) def ViewFile_trial(): files_list = WidgetFrame.files_list player.play(files_list) player.wait_for_pplayback() # messagebox.showinfo("Done") def ViewFile(): # plays all selected files one by one, keeps speed selected in 1st clip unless changed.. files_list = WidgetFrame.files_list for f in files_list: player.playlist_append(f) player.playlist_pos = 0 player.wait_for_playback #messagebox.showinfo("Done", "All files have been viewed") ## - ? for some reason, messagbox exits the program ? def CopyFile(): files_list = WidgetFrame.files_list destination_location = destinationLocation.get() for f in files_list: shutil.copy(f, destination_location) #messagebox.showinfo("SUCCESSFULL") def MoveFile(): files_list = WidgetFrame.files_list destination_location = destinationLocation.get() for f in files_list: shutil.move(f, destination_location) def DeleteFile(): files_list = WidgetFrame.files_list for f in files_list: os.remove(f) #messagebox.showinfo("SUCCESSFULL") # Creating tkinter variable sourceLocation = StringVar() destinationLocation = StringVar() CreateWidgets() root.mainloop() #if __name__ == "__main__": # app.run('0.0.0.0' , port=7080, debug = True)
Larz60+ write Feb-14-2021, 12:40 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.