Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # randomizerInterface.py
- #Run on Python 3.5.4 on windows
- import tkinter as tk
- from tkinter.filedialog import askopenfilename
- from tkinter.messagebox import showerror
- import threading
- from randomizer import videoRandom
- class RandomizerInterface():
- def __init__(self):
- #init of randomizer
- self.player = videoRandom()
- self.videos = 0
- self.stop = False
- self.thread = None
- self.isPlaying = False
- self.window = tk.Tk(className = "Randomizer")
- self.window.geometry("500x500")
- #simple select button
- selectButton = tk.Button(self.window, text = "Select file", command = self.choose_file)
- #simple start button
- startButton = tk.Button(self.window, text = "Start", command = self.start_sequence)
- #clear videos loaded button
- clearButton = tk.Button(self.window, text = "Reset Videos", command = self.reset_videos)
- #gives the current status
- self.fileLabel = tk.Label(self.window, text = "No file")
- #simple quit button
- quitButton = tk.Button(self.window, text = "Quit", command = self.quit_window)
- self.minRate = tk.IntVar()
- minRateScale = tk.Scale(self.window, variable = self.minRate, from_ = 50, to = 150, orient = 'horizontal', command = self.setMinRateIT)
- minRateScale.set(100)
- minRatelab = tk.Label(self.window, text = "minRate")
- self.maxRate = tk.IntVar()
- maxRateScale = tk.Scale(self.window, variable = self.maxRate, from_ = 50, to = 150, orient = 'horizontal', command = self.setMaxRateIT)
- maxRateScale.set(100)
- maxRatelab = tk.Label(self.window, text = "maxRate")
- self.minTime = tk.IntVar()
- minTimeScale = tk.Scale(self.window, variable = self.minTime, from_ = 3, to = 30, orient = 'horizontal', command = self.setMinTimeIT)
- minTimeScale.set(5)
- minTimelab = tk.Label(self.window, text = "minTime")
- self.maxTime = tk.IntVar()
- maxTimeScale = tk.Scale(self.window, variable = self.maxTime, from_ = 10, to = 120, orient = 'horizontal', command = self.setMaxTimeIT)
- maxTimeScale.set(30)
- maxTimelab = tk.Label(self.window, text = "maxTime")
- self.delayTime = tk.IntVar()
- delayTimeScale = tk.Scale(self.window, variable = self.delayTime, from_ = 0, to = 120, orient = 'horizontal', command = self.setDelayIT)
- delayTimeScale.set(0)
- delayTimeLab = tk.Label(self.window, text = "delay before starting")
- selectButton.pack()
- self.fileLabel.pack()
- clearButton.pack()
- startButton.pack()
- quitButton.pack()
- minRateScale.pack()
- minRatelab.pack()
- maxRateScale.pack()
- maxRatelab.pack()
- minTimeScale.pack()
- minTimelab.pack()
- maxTimeScale.pack()
- maxTimelab.pack()
- delayTimeScale.pack()
- delayTimeLab.pack()
- self.window.mainloop()
- def quit_window(self):
- #closing the player
- self.stop = True
- if self.thread is not None:
- self.thread.join()
- self.isPlaying = False
- self.window.destroy()
- def start_sequence(self):
- if self.videos == 0:
- showerror("No video", "No video to play, please select a file")
- else:
- if not self.isPlaying:
- self.thread = threading.Thread(target = self.player.playLoop, args = ((lambda: self.stop),)).start()
- self.isPlaying = True
- else:
- showerror("Already playing", "A video is already playing")
- def choose_file(self):
- filename = askopenfilename(title="Open file",filetypes=[('txt files','.txt'),('all files','.*')])
- #load videos onto the player
- self.videos = self.player.loadFromFile(filename)
- self.fileLabel['text'] = str(self.videos) + " Videos Loaded"
- def setMinRateIT(self, event):
- self.player.setMinRate(self.minRate.get())
- def setMaxRateIT(self, event):
- self.player.setMaxRate(self.maxRate.get())
- def setMinTimeIT(self, event):
- self.player.setMinTime(self.minTime.get())
- def setMaxTimeIT(self, event):
- self.player.setMaxTime(self.maxTime.get())
- def reset_videos(self):
- self.player.reset()
- self.videos = 0
- self.fileLabel['text'] = "No file"
- def setDelayIT(self, event):
- self.player.setDelay(self.delayTime.get())
- if __name__ == '__main__':
- rd = RandomizerInterface()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement