Advertisement
Guest User

randomizerInterface.py

a guest
Oct 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.83 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. # randomizerInterface.py
  4.  
  5. #Run on Python 3.5.4 on windows
  6.  
  7. import tkinter as tk
  8. from tkinter.filedialog import askopenfilename
  9. from tkinter.messagebox import showerror
  10.  
  11. import threading
  12.  
  13. from randomizer import videoRandom
  14.  
  15. class RandomizerInterface():
  16.    
  17.     def __init__(self):
  18.        
  19.         #init of randomizer
  20.         self.player = videoRandom()
  21.         self.videos = 0
  22.         self.stop = False
  23.         self.thread = None
  24.        
  25.         self.isPlaying = False
  26.        
  27.         self.window = tk.Tk(className = "Randomizer")
  28.         self.window.geometry("500x500")
  29.        
  30.         #simple select button
  31.         selectButton = tk.Button(self.window, text = "Select file", command = self.choose_file)
  32.        
  33.         #simple start button
  34.         startButton = tk.Button(self.window, text = "Start", command = self.start_sequence)
  35.        
  36.         #clear videos loaded button
  37.         clearButton = tk.Button(self.window, text = "Reset Videos", command = self.reset_videos)
  38.        
  39.         #gives the current status
  40.         self.fileLabel = tk.Label(self.window, text = "No file")
  41.        
  42.         #simple quit button
  43.         quitButton = tk.Button(self.window, text = "Quit", command = self.quit_window)
  44.        
  45.         self.minRate = tk.IntVar()
  46.         minRateScale = tk.Scale(self.window, variable = self.minRate, from_ = 50, to = 150, orient = 'horizontal', command = self.setMinRateIT)
  47.         minRateScale.set(100)
  48.         minRatelab = tk.Label(self.window, text = "minRate")
  49.        
  50.         self.maxRate = tk.IntVar()
  51.         maxRateScale = tk.Scale(self.window, variable = self.maxRate, from_ = 50, to = 150, orient = 'horizontal', command = self.setMaxRateIT)
  52.         maxRateScale.set(100)
  53.         maxRatelab = tk.Label(self.window, text = "maxRate")        
  54.        
  55.         self.minTime = tk.IntVar()
  56.         minTimeScale = tk.Scale(self.window, variable = self.minTime, from_ = 3, to = 30, orient = 'horizontal', command = self.setMinTimeIT)
  57.         minTimeScale.set(5)
  58.         minTimelab = tk.Label(self.window, text = "minTime")
  59.        
  60.         self.maxTime = tk.IntVar()
  61.         maxTimeScale = tk.Scale(self.window, variable = self.maxTime, from_ = 10, to = 120, orient = 'horizontal', command = self.setMaxTimeIT)
  62.         maxTimeScale.set(30)
  63.         maxTimelab = tk.Label(self.window, text = "maxTime")
  64.        
  65.         self.delayTime = tk.IntVar()
  66.         delayTimeScale = tk.Scale(self.window, variable = self.delayTime, from_ = 0, to = 120, orient = 'horizontal', command = self.setDelayIT)
  67.         delayTimeScale.set(0)
  68.         delayTimeLab = tk.Label(self.window, text = "delay before starting")
  69.        
  70.        
  71.         selectButton.pack()
  72.         self.fileLabel.pack()
  73.         clearButton.pack()
  74.         startButton.pack()
  75.         quitButton.pack()
  76.        
  77.         minRateScale.pack()
  78.         minRatelab.pack()
  79.         maxRateScale.pack()
  80.         maxRatelab.pack()
  81.        
  82.         minTimeScale.pack()
  83.         minTimelab.pack()
  84.         maxTimeScale.pack()
  85.         maxTimelab.pack()
  86.        
  87.         delayTimeScale.pack()
  88.         delayTimeLab.pack()
  89.        
  90.         self.window.mainloop()
  91.        
  92.     def quit_window(self):
  93.         #closing the player
  94.         self.stop = True
  95.         if self.thread is not None:
  96.             self.thread.join()
  97.            
  98.         self.isPlaying = False
  99.        
  100.         self.window.destroy()
  101.        
  102.     def start_sequence(self):
  103.         if self.videos == 0:
  104.             showerror("No video", "No video to play, please select a file")
  105.         else:
  106.             if not self.isPlaying:
  107.                 self.thread = threading.Thread(target = self.player.playLoop, args = ((lambda: self.stop),)).start()
  108.                 self.isPlaying = True
  109.             else:
  110.                 showerror("Already playing", "A video is already playing")    
  111.    
  112.     def choose_file(self):
  113.         filename = askopenfilename(title="Open file",filetypes=[('txt files','.txt'),('all files','.*')])
  114.         #load videos onto the player
  115.         self.videos = self.player.loadFromFile(filename)
  116.        
  117.         self.fileLabel['text'] = str(self.videos) + " Videos Loaded"
  118.        
  119.     def setMinRateIT(self, event):
  120.         self.player.setMinRate(self.minRate.get())
  121.    
  122.     def setMaxRateIT(self, event):
  123.         self.player.setMaxRate(self.maxRate.get())
  124.        
  125.     def setMinTimeIT(self, event):
  126.         self.player.setMinTime(self.minTime.get())
  127.    
  128.     def setMaxTimeIT(self, event):
  129.         self.player.setMaxTime(self.maxTime.get())
  130.        
  131.     def reset_videos(self):
  132.         self.player.reset()
  133.         self.videos = 0
  134.         self.fileLabel['text'] = "No file"
  135.        
  136.     def setDelayIT(self, event):
  137.         self.player.setDelay(self.delayTime.get())
  138.    
  139. if __name__ == '__main__':
  140.     rd = RandomizerInterface()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement