Open dobrosketchkun opened 4 years ago
For the while True loop, I'd suggest adding a time.sleep(0.1) at the bottom, or some other blocking call, so it doesn't run over and over and use 100% CPU while it's at it. Does window.Read() block until something happens to the screen?
and use 100% CPU
I don't have any issues:
@dobrosketchkun Ok, then I guess window.Read is blocking. Can you add an option for framerate to the GUI?
Yeah, right, I forgot about it since I never use it.
import PySimpleGUI as sg
import os
import sys
class MissingArgument(Exception):
pass
layout = [
[sg.Button('Password', key='popup_pass', size=(20, 1))],
[sg.Button('File to de/encode', key='popup_file', size=(20, 1))],
[sg.Radio('Encoding', 1, enable_events=True, default=True, key='R1'), sg.Radio('Decoding',1, enable_events=True, key='R2')],
[sg.Text('Framerate: '), sg.InputText(default_text='1/5', key='framerate', size=(9, 1))],
[sg.Button('Start', key='start', size=(20, 1))],
]
window = sg.Window('Simple fvid GUI', layout, font='a 16')
password = None
line = None
while True: # Event Loop
event, values = window.Read()
print('event', event, 'values', values)
if event in [None ,'Exit']:
break
if event == 'popup_pass':
password = sg.popup_get_text('Password', password_char='*')
if event == 'popup_file':
fname = sg.popup_get_file('File to open')
try:
fname2 = os.path.basename(fname)
except:
pass
if event == 'start':
try:
fname = fname + ' '
except:
raise MissingArgument('You need a file to en/decrypt.')
if framerate != '1/5':
framerate = values['framerate']
if password:
pwd = '-p ' + password
else:
pwd = ''
part1 = 'python -m fvid -f ' + framerate + ' -i ' + fname
if values['R1'] == True:
part2 = '-e ' + pwd + ' -o ' + fname2 + '_encoded.mp4'
else:
part2 = '-d ' + pwd
line = part1 + part2
break
if line:
# if sys.platform == 'win32':
# os.system('cls')
# else:
# os.system('clear')
print('Command:', line)
os.system(line)
window.Close()
Looks good to me! Thoughts @AlfredoSequeida?
@dobrosketchkun At a quick glance that looks awesome! I am curious if you guys think this should be added to a new repo for people interested that are not interested in a GUI. I am personally primarily a Linux user and don't use GUI's very often with the exception of browsers (or places where I really need to). Maybe we can add something to the setup file to let a user select the option of having a GUI or something similar?
As far as I can tell, the user would have to select whether they want the GUI after the entire package has already been downloaded, because I don't think pip install
allows a package to accept custom args (like --no-gui
). It could be best to place this GUI code within its own file that's only called if a user runs something like fvid gui.py
from the command line/prompt and just leave it be when a user doesn't want to actively use it.
Yeah, I thought about approach like @Theelgirl just mentioned. For instance, if you want a GUI, you just use py -m fvid
without any args and if you don't, just use CLI as intented.
@dobrosketchkun If you have time, you can make a PR with that py -m fvid
GUI approach you mentioned, and I think Alfredo and/or I would be happy to test it
Yeah, I will sooner or later.
Little upgrade about https://github.com/AlfredoSequeida/fvid/pull/26
import PySimpleGUI as sg
import os
import sys
from fvid import FRAMERATE
class MissingArgument(Exception):
pass
layout = [
[sg.Button('Password', key='popup_pass', size=(20, 1))],
[sg.Button('File to de/encode', key='popup_file', size=(20, 1))],
[sg.Radio('Encoding', 1, enable_events=True, default=True, key='R1'), sg.Radio('Decoding',1, enable_events=True, key='R2')],
[sg.Text('Framerate: '), sg.InputText(default_text=FRAMERATE, key='framerate', size=(9, 1))],
[sg.Text('If you don\'t know what you are doing, use a default value', size=(40, 1), font=("Arial", 7))],
[sg.Button('Start', key='start', size=(20, 1))],
]
window = sg.Window('Simple fvid GUI', layout, font='a 16')
password = None
line = None
while True: # Event Loop
event, values = window.Read()
print('event', event, 'values', values)
if event in [None ,'Exit']:
break
if event == 'popup_pass':
password = sg.popup_get_text('Password', password_char='*')
if event == 'popup_file':
fname = sg.popup_get_file('File to open')
try:
fname2 = os.path.basename(fname)
except:
pass
if event == 'start':
try:
fname = fname + ' '
except:
raise MissingArgument('You need a file to en/decrypt.')
if framerate != '1/5':
framerate = values['framerate']
if password:
pwd = '-p ' + password
else:
pwd = ''
part1 = 'python -m fvid -f ' + framerate + ' -i ' + fname
if values['R1'] == True:
part2 = '-e ' + pwd + ' -o ' + fname2 + '_encoded.mp4'
else:
part2 = '-d ' + pwd
line = part1 + part2
break
if line:
# if sys.platform == 'win32':
# os.system('cls')
# else:
# os.system('clear')
# print('Command:', line)
os.system(line)
window.Close()
Another addition - use of youtube-dl if it's in your system:
import PySimpleGUI as sg
import os
import sys
from fvid import FRAMERATE
class MissingArgument(Exception):
pass
layout = [
[sg.Button('Password', key='popup_pass', size=(20, 1))],
[sg.Button('File to de/encode', key='popup_file', size=(20, 1))],
[sg.Radio('Encoding', 1, enable_events=True, default=True, key='R1'), sg.Radio('Decoding',1, enable_events=True, key='R2')],
[sg.Text('Framerate: '), sg.InputText(default_text=FRAMERATE, key='framerate', size=(9, 1))],
[sg.Text('If you don\'t know what you are doing, use a default value', size=(40, 1), font=("Arial", 7))],
[sg.Text('Youtube link'), sg.InputText(key='y_dl', size=(9, 1))],
[sg.Text('Use only if you have youtube-dl in your system', size=(40, 1), font=("Arial", 7))],
[sg.Button('Start', key='start', size=(20, 1))],
]
window = sg.Window('Simple fvid GUI', layout, font='a 16')
password = None
line = None
while True: # Event Loop
event, values = window.Read()
y_dl = values['y_dl']
framerate = values['framerate']
#print('event', event, 'values', values)
if event in [None ,'Exit']:
break
if event == 'popup_pass':
password = sg.popup_get_text('Password', password_char='*')
if event == 'popup_file':
fname = sg.popup_get_file('File to open')
try:
fname2 = os.path.basename(fname)
except:
pass
if event == 'start':
try:
fname = fname + ''
except:
if y_dl:
pass
else:
raise MissingArgument('You need a file to en/decrypt.')
if framerate != '1/5':
framerate = values['framerate']
if password:
pwd = '-p ' + password
else:
pwd = ''
if y_dl:
fname = 'youtube_video.mp4'
os.system('youtube-dl -o ' + fname + ' -f "bestvideo[height=1080]" ' + y_dl)
part1 = 'python -m fvid -f ' + framerate + ' -i ' + fname
#print('PART ONE', part1)
if values['R1'] == True:
part2 = ' -e ' + pwd + ' -o ' + fname2 + '_encoded.mp4'
else:
part2 = ' -d ' + pwd
#print('PART TWO', part2)
line = part1 + part2
#print(line)
break
if line:
# if sys.platform == 'win32':
# os.system('cls')
# else:
# os.system('clear')
# print('Command:', line)
os.system(line)
window.Close()
Looks good! Would you like to submit that for a PR? If so, make sure to either put it in its own file, or make it run only if fvid is run without args.
I will soon, yeah.
@dobrosketchkun Do you have time to make this into a PR soon?
can you upload easy to open for no programmer application file?
can you upload easy to open for no programmer application file?
That might be made easier to accomplish once we implement a GUI for the program. I have honestly been pretty busy lately, but I would recommend you keep a lookout on the repo to see if we implement that.
@AlfredoSequeida @dobrosketchkun I'd like to build on this PySimpleGUI for 1.1.0, and we can change to a different GUI library if needed for 1.2.0 or 2.0.0, is that okay?
@Theelgirl That's ok with me.
Sounds nice
Okay, folks, I manage to make a very rudimentary GUI for this https://github.com/AlfredoSequeida/fvid/pull/21 version of fvid