-
Notifications
You must be signed in to change notification settings - Fork 0
/
guiController.py
executable file
·179 lines (139 loc) · 5.95 KB
/
guiController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import tkinter.filedialog as fileDialog
from tkinter import Tk, N, S, W, E, StringVar, BooleanVar
from tkinter.ttk import Frame, Button, Style
from subprocess import *
from menuBar import MenuBar
from filesTree import FilesTree
from langManager import _
from data.defaultOpt import *
class OmxGui(Frame):
def __init__(self, parent, argv):
Frame.__init__(self, parent, padding=(3,6,3,12), style="TFrame")
self.parent = parent
self.initData()
self.initUI()
if len(argv) > 1:
try:
self.updateAndPlayVideo(argv[1])
except FileNotFoundError:
self.logDebug('File Not Found')
def initData(self):
self.browseInitialDir = def_initialDir
self.recentFile = def_recentFile
self.menuOutputAudio = StringVar()
self.menuOutputAudio.set(def_menuOutputAudio)
self.menuVideoRefresh = BooleanVar()
self.menuVideoRefresh.set(def_menuVideoRefresh)
self.menuBgBlack = BooleanVar()
self.menuBgBlack.set(def_menuBgBlack)
self.maxRecentVideos = def_maxRecentVideos
self.moreOptions = def_moreOptions
self.playProcess = None
def initUI(self):
self.parent.title('OMX GUI')
self.parent.bind("<Key>", self.keyEvt)
# ---- STYLE ----
Style().theme_use('default')
Style().configure("TFrame", background="white")
Style().configure("TButton", font="12", padding=(5,1,5,1), background="#4285F4", foreground="white")
Style().configure("TEntry", font="12", padding=(5,3,5,2))
Style().configure("TLabel", background="white")
Style().map('TButton',
foreground=[('pressed', 'white'), ('active', 'white')],
background=[('pressed', '!disabled', '#3367d6'), ('active', '#3b78e7')],
highlightcolor=[('focus','#4285F4')],
relief=[('pressed', '!disabled', 'flat')])
Style().configure('Treeview', foreground='#333', background="white", highlightthickness='0')
Style().map('Treeview',
foreground=[('focus', '#000')],
background=[('focus', '#F5F5F5')])
# ---- MENU ----
self.menubar = menubar = MenuBar(self, self.parent)
# ---- TREE ----
self.filesTree = filesTree = FilesTree(self)
self.filesTree.loadRecentFile()
# ---- BUTTONS ----
bBrowse = Button(self, text=_("browse"), width="6", command=self.openVideo)
bPlay = Button(self, text=_("play"), width="6", command=self.playVideo)
# ---- GRID ----
self.grid(column=0, row=0, sticky=(N, E, W, S))
filesTree.grid(column=0, row=0, columnspan=2, rowspan=2, sticky=(N,W,E))
bBrowse.grid(column=0, row=2, sticky=(N,W))
bPlay.grid(column=0, row=2, sticky=(N,W), padx=70)
self.parent.columnconfigure(0, weight=1)
self.parent.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
self.rowconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.centerWindow()
def centerWindow(self):
self.parent.update_idletasks()
w = self.parent.winfo_reqwidth() + 20
h = self.parent.winfo_reqheight() + 20
sw = self.parent.winfo_screenwidth()
sh = self.parent.winfo_screenheight()
x = (sw - w)/4
y = (sh - h)/4
self.parent.geometry("%dx%d+%d+%d" % (w, h, x, y))
self.parent.resizable(False,False)
self.parent.focus_force()
self.parent.lift()
def quitProgram(self):
self.parent.quit()
def clearRecentVideos(self):
self.filesTree.clearRecentVideos()
def updateRecentVideos(self, fullpath):
return self.filesTree.updateRecentVideos(fullpath)
def updateAndPlayVideo(self, fullpath):
if self.updateRecentVideos(fullpath):
self.playVideo()
def openVideo(self):
fullpath = fileDialog.askopenfilename(
title=_('open.file')
,initialdir=self.browseInitialDir)
self.updateAndPlayVideo(fullpath)
def playVideo(self):
lastFile = self.filesTree.getLastFile()
if lastFile is not None and lastFile['fullpath'] is not '':
outputAudio = '-o ' + self.menuOutputAudio.get() + ' '
adjustVideo = '-r ' if self.menuVideoRefresh.get() else ''
bgBlack = '-b ' if self.menuBgBlack.get() else ''
moreOptions = self.moreOptions
fPath = lastFile['fullpath'].replace(' ', '\ ')
cmdStr = 'omxplayer ' + outputAudio + adjustVideo + bgBlack + moreOptions + fPath
self.logDebug(cmdStr)
self.playProcess = Popen(['bash', '-c', cmdStr], stdin=PIPE, bufsize = 1)
self.parent.focus_force()
def keyEvt(self, event):
self.logDebug('char: ' + event.char + ' --- key simbol: ' + event.keysym + ' --- key code: ' + str(event.keycode))
if self.playProcess is not None:
# right
if event.keysym == 'Right':
self.playProcess.stdin.write(bytes('^[[C', 'UTF-8'))
# left
elif event.keysym == 'Left':
self.playProcess.stdin.write(bytes('^[[D', 'UTF-8'))
# up
elif event.keysym == 'Up':
self.playProcess.stdin.write(bytes('^[[A', 'UTF-8'))
# down
elif event.keysym == 'Down':
self.playProcess.stdin.write(bytes('^[[B', 'UTF-8'))
elif event.char == 'x':
self.playProcess.kill()
self.playProcess = None
else:
self.playProcess.stdin.write(bytes(event.char, 'UTF-8'))
try:
self.playProcess.stdin.flush()
except IOError:
try:
self.playProcess.stdin.close()
self.playProcess = None
except IOError:
self.playProcess = None
self.parent.focus_force()
def logDebug(self, msg):
if isDebug and msg is not None:
print(str(msg))