-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
337 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import cfg, icons, msgs, style, txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
NO_TIME = '00' | ||
|
||
DFT_SPEED = 1.0 | ||
|
||
MAX_DURATION = 0 | ||
DFT_DURATION = 5.0 | ||
LIMIT_DURATION = 59.0 | ||
|
||
MAX_DURATION_TXT = "WHOLE VIDEO" | ||
DFT_DURATION_TXT = "5 Seconds" | ||
|
||
DONATE_LINK = "https://www.paypal.com/donate/?hosted_button_id=RNDCMNV4YWHX4" | ||
|
||
DISABLED_DURATION = { | ||
'duration': MAX_DURATION, | ||
'slider': LIMIT_DURATION, | ||
'display': MAX_DURATION_TXT | ||
} | ||
|
||
ENABLED_DURATION = { | ||
'duration': DFT_DURATION, | ||
'slider': DFT_DURATION, | ||
'display': DFT_DURATION_TXT | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1 @@ | ||
import webbrowser | ||
from os import startfile | ||
from os.path import realpath | ||
|
||
from PySimpleGUI import read_all_windows, WIN_CLOSED | ||
|
||
from views import DONE_POPUP, INFO_POPUP | ||
from ._config import DONATE_LINK | ||
from .gifer import Gifer | ||
from .options_form import OptionsForm | ||
|
||
|
||
class Controller: | ||
def __init__(self, window): | ||
self.view = window | ||
self.options = OptionsForm(window) | ||
|
||
|
||
def read_events(self): | ||
window, event, values = read_all_windows() | ||
|
||
if event == "-START_BTN-": | ||
if not self.options.validate(): | ||
return | ||
window.hide() | ||
output = Gifer.run(self.options) | ||
if DONE_POPUP(): | ||
startfile(realpath(output)) | ||
window.un_hide() | ||
return | ||
|
||
if event == '-TRIM_CHECK-': | ||
self.options.update_trim_state() | ||
|
||
if event == '-DURATION_SLIDER-': | ||
self.options.update_duration(values) | ||
|
||
if event == '-SPEED_SLIDER-': | ||
self.options.update_speed(values) | ||
|
||
if event == "-INFO_BTN-": | ||
self.show_donate() | ||
|
||
if event == WIN_CLOSED: | ||
return 'done' | ||
|
||
|
||
def show_donate(self): | ||
self.view.hide() | ||
if INFO_POPUP() == 'Yes': | ||
webbrowser.open(DONATE_LINK, new=0) | ||
self.view.un_hide() | ||
from .application import Application |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import webbrowser | ||
import os | ||
|
||
import PySimpleGUI as sg | ||
|
||
import model | ||
import views | ||
import assets | ||
from .gifer import Gifer | ||
from .form import Form | ||
|
||
|
||
class Application: | ||
def __init__(self, window): | ||
self.view = window | ||
self.form = Form(window) | ||
|
||
|
||
def read_events(self): | ||
event, values = self.view.read(timeout=10) | ||
|
||
if event == "-START_BTN-": | ||
options = self.read_form() | ||
if not options: | ||
return | ||
self.run_gifer(options) | ||
|
||
if event == '-TRIM_CHECK-': | ||
self.form.update_trim_state() | ||
|
||
if event == '-DURATION_SLIDER-': | ||
self.form.update_duration(values) | ||
|
||
if event == '-SPEED_SLIDER-': | ||
self.form.update_speed(values) | ||
|
||
if event == "-INFO_BTN-": | ||
self.show_donate() | ||
|
||
if event == sg.WIN_CLOSED: | ||
return 'done' | ||
|
||
def read_form(self) -> model.Options | None: | ||
try: | ||
options = model.Options(self.form.data) | ||
except ValueError as err: | ||
views.ERROR_POPUP(str(err)) | ||
return None | ||
return options | ||
|
||
def run_gifer(self, options): | ||
self.view.hide() | ||
output = Gifer.run(options) | ||
if views.DONE_POPUP(): | ||
os.startfile(os.path.realpath(output)) | ||
self.view.un_hide() | ||
|
||
def show_donate(self): | ||
self.view.hide() | ||
if views.INFO_POPUP() == 'Yes': | ||
webbrowser.open(assets.cfg.DONATE_LINK, new=0) | ||
self.view.un_hide() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import PySimpleGUI as sg | ||
|
||
import assets | ||
|
||
|
||
class Form: | ||
def __init__(self, view): | ||
self._set_duration = assets.cfg.MAX_DURATION | ||
self._set_speed = assets.cfg.DFT_SPEED | ||
self._video_input: sg.Input = view["-VIDEO_IN-"] | ||
self._trim_check: sg.Checkbox = view["-TRIM_CHECK-"] | ||
self._s_hour: sg.Input = view["-HOUR_IN-"] | ||
self._s_minute: sg.Input = view["-MINUTE_IN-"] | ||
self._s_second: sg.Input = view["-SECOND_IN-"] | ||
self._duration_slider: sg.Slider = view["-DURATION_SLIDER-"] | ||
self._duration_display: sg.Text = view["-DURATION_TXT-"] | ||
self._speed_slider: sg.Slider = view["-SPEED_SLIDER-"] | ||
self._speed_display: sg.Text = view['-SPEED_TEXT-'] | ||
|
||
@property | ||
def data(self): | ||
hour: str = self._s_hour.get() | ||
minute: str = self._s_minute.get() | ||
sec: str = self._s_second.get() | ||
return { | ||
'input_path': self._video_input.get(), | ||
'start': (hour, minute, sec), | ||
'duration': self._set_duration, | ||
'gif_speed': self._set_speed | ||
} | ||
|
||
def update_speed(self, values) -> None: | ||
value = values['-SPEED_SLIDER-'] | ||
speed_txt = f"{value}x" | ||
self._set_speed = value | ||
self._speed_display.update(speed_txt) | ||
|
||
def update_duration(self, values) -> None: | ||
secs = int(values['-DURATION_SLIDER-']) | ||
txt = f"{secs:02d} Second" | ||
txt += 's' if secs != 1 else ' ' | ||
self._set_duration = secs | ||
self._duration_display.update(txt) | ||
|
||
def update_trim_state(self) -> None: | ||
checked = self._trim_check.get() | ||
disable = not checked | ||
self._start_inputs(disable) | ||
self._duration_inputs(disable) | ||
|
||
def _start_inputs(self, disable: bool) -> None: | ||
color = assets.style.STATE_COLOR(disable) | ||
inputs = [self._s_hour, self._s_minute, self._s_second] | ||
if disable: | ||
[i.update(assets.cfg.NO_TIME) for i in inputs] | ||
[i.update(disabled=disable, text_color=color) for i in inputs] | ||
|
||
def _duration_inputs(self, disable: bool) -> None: | ||
color = assets.style.STATE_COLOR(disable) | ||
if disable: | ||
values = assets.cfg.DISABLED_DURATION | ||
else: | ||
values = assets.cfg.ENABLED_DURATION | ||
self._set_duration = values['duration'] | ||
self._duration_slider.update(values['slider'], disabled=disable) | ||
self._duration_display(values['display'], text_color=color) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from controller import Controller | ||
from controller import Application | ||
from views import MAIN_WINDOW | ||
|
||
|
||
def main(app: Controller): | ||
def main(app: Application): | ||
while True: | ||
status = app.read_events() | ||
if status == 'done': | ||
break | ||
|
||
if __name__ == "__main__": | ||
main(Controller(MAIN_WINDOW())) | ||
main(Application(MAIN_WINDOW())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .options import Options |
Oops, something went wrong.