Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI #22

Open
dobrosketchkun opened this issue Oct 14, 2020 · 19 comments
Open

GUI #22

dobrosketchkun opened this issue Oct 14, 2020 · 19 comments
Labels
enhancement New feature or request

Comments

@dobrosketchkun
Copy link
Contributor

Okay, folks, I manage to make a very rudimentary GUI for this #21 version of fvid

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.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()

    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 password:
            pwd = '-p ' + password
        else:
            pwd = ''
            
        part1 = 'python -m fvid -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()
@Theelx
Copy link
Collaborator

Theelx commented Oct 14, 2020

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?

@dobrosketchkun
Copy link
Contributor Author

and use 100% CPU

I don't have any issues:

@Theelx
Copy link
Collaborator

Theelx commented Oct 14, 2020

@dobrosketchkun Ok, then I guess window.Read is blocking. Can you add an option for framerate to the GUI?

@dobrosketchkun
Copy link
Contributor Author

dobrosketchkun commented Oct 15, 2020

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()

@Theelx
Copy link
Collaborator

Theelx commented Oct 15, 2020

Looks good to me! Thoughts @AlfredoSequeida?

@AlfredoSequeida
Copy link
Owner

@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?

@Theelx
Copy link
Collaborator

Theelx commented Oct 25, 2020

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.

@dobrosketchkun
Copy link
Contributor Author

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.

@Theelx
Copy link
Collaborator

Theelx commented Oct 25, 2020

@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

@Theelx Theelx added the enhancement New feature or request label Oct 25, 2020
@dobrosketchkun
Copy link
Contributor Author

Yeah, I will sooner or later.

Little upgrade about #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()

@dobrosketchkun
Copy link
Contributor Author

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()

@Theelx
Copy link
Collaborator

Theelx commented Oct 28, 2020

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.

@dobrosketchkun
Copy link
Contributor Author

I will soon, yeah.

@Theelx
Copy link
Collaborator

Theelx commented Jan 17, 2021

@dobrosketchkun Do you have time to make this into a PR soon?

@QWERTIOX
Copy link

QWERTIOX commented Mar 7, 2021

can you upload easy to open for no programmer application file?

@AlfredoSequeida
Copy link
Owner

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.

@Theelx
Copy link
Collaborator

Theelx commented Mar 9, 2021

@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?

@AlfredoSequeida
Copy link
Owner

AlfredoSequeida commented Mar 9, 2021

@Theelgirl That's ok with me.

@dobrosketchkun
Copy link
Contributor Author

Sounds nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants