Skip to content

Commit

Permalink
Dynamic form controls visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MachWheel committed Jun 1, 2022
1 parent 9f6f904 commit 7de889b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 28 deletions.
20 changes: 18 additions & 2 deletions controller/_form.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
import os

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._controls: sg.Column = view['-CONTROLS_ROW-']
self._controls.hide_row()

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._set_duration = assets.cfg.MAX_DURATION
self._duration_slider: sg.Slider = view["-DURATION_SLIDER-"]
self._duration_display: sg.Text = view["-DURATION_TXT-"]

self._set_speed = assets.cfg.DFT_SPEED
self._speed_slider: sg.Slider = view["-SPEED_SLIDER-"]
self._speed_display: sg.Text = view['-SPEED_TEXT-']


def controls_state(self, values):
file = values['-VIDEO_IN-']
if file and os.path.isfile(file):
self._controls.unhide_row()
else:
self._controls.hide_row()

@property
def data(self):
hh: str = self._s_hour.get()
Expand Down
5 changes: 4 additions & 1 deletion controller/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@

class Application:
def __init__(self, window):
self.view = window
self.view: sg.Window = window
self.form = Form(window)

def read_events(self):
event, values = self.view.read(timeout=10)

if event == "-VIDEO_IN-":
self.form.controls_state(values)

if event == "-START_BTN-":
options = self.read_form()
if not options:
Expand Down
3 changes: 1 addition & 2 deletions views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def MAIN_WINDOW():
[
[_ui.HEADING()],
[*_ui.VIDEO_BROWSER()],
[_ui.TRIM_FRAME()],
[_ui.SPEED_FRAME(), _ui.INFO()]
[_ui.CONTROLS_ROW()]
], finalize=True, icon=assets.icons.LOGO()
)

Expand Down
36 changes: 24 additions & 12 deletions views/_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from . import controls
import assets
from .controls import INFO_BTN


def HEADING() -> sg.Text:
Expand All @@ -20,14 +21,29 @@ def VIDEO_BROWSER() -> tuple:
controls.START_BTN()
)

##################################################################################

def CONTROLS_ROW():
layout = [
[TRIM_FRAME()],
[SPEED_FRAME(), INFO_BTN()]
]
return sg.Column(
layout=layout,
key='-CONTROLS_ROW-',
size=(450, None),
element_justification='center',
vertical_alignment='center'
)


def TRIM_FRAME() -> sg.Frame:
sep = sg.HSep(pad=(5, 15), color=assets.style.BG_COLOR())
layout = [
[sg.VPush()],
[*controls.TRIM_START_AT(), sg.Push()],
[*controls.START_TIME_INPUTS(), sg.Push()],
[sep],
[*controls.TRIM_DURATION_SLIDER()],
[*controls.DURATION_SLIDER()],
[sg.VPush()],
]
return sg.Frame(
Expand All @@ -37,7 +53,8 @@ def TRIM_FRAME() -> sg.Frame:
relief=sg.RELIEF_RAISED,
expand_x=True,
element_justification='left',
font=assets.style.F_11_B
font=assets.style.F_11_B,
size=(430, 130)
)


Expand All @@ -49,18 +66,13 @@ def SPEED_FRAME() -> sg.Frame:
expand_y=True,
font=assets.style.F_11_B,
relief=sg.RELIEF_RAISED,
vertical_alignment='top'
vertical_alignment='top',
size=(375, 65),
p=(5, 5)
)


def INFO() -> sg.Button:
return sg.Button(
image_data=assets.icons.INFO(),
button_color=assets.style.BTN_COLOR(),
border_width=0,
key="-INFO_BTN-",
enable_events=True
)
##################################################################################

def PROGRESS_BAR(bar_end: int):
return [
Expand Down
35 changes: 24 additions & 11 deletions views/_ui/controls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import PySimpleGUI as sg

import assets
from assets import txt, style, icons


def VIDEO_INPUT() -> sg.Input:
return sg.Input(
k='-VIDEO_IN-',
size=(30, 4),
expand_x=True,
font=style.F_14,
enable_events=True
)


def BROWSE_BTN() -> sg.Button:
return sg.Button(
button_type=sg.BUTTON_TYPE_BROWSE_FILE,
Expand All @@ -14,15 +25,6 @@ def BROWSE_BTN() -> sg.Button:
)


def VIDEO_INPUT() -> sg.Input:
return sg.Input(
k='-VIDEO_IN-',
size=(30, 4),
expand_x=True,
font=style.F_14
)


def START_BTN() -> sg.Button:
return sg.Button(
button_type=sg.BUTTON_TYPE_READ_FORM,
Expand All @@ -34,6 +36,17 @@ def START_BTN() -> sg.Button:
)


def INFO_BTN() -> sg.Button:
return sg.Button(
image_data=assets.icons.INFO(),
button_color=assets.style.BTN_COLOR(),
border_width=0,
key="-INFO_BTN-",
enable_events=True,
p=(5, 5)
)


def _time_input(mode: str) -> tuple:
time_input = sg.Input(
k=f'-{mode.upper()}_IN-',
Expand All @@ -48,7 +61,7 @@ def _time_input(mode: str) -> tuple:
return time_input, input_display


def TRIM_START_AT() -> tuple:
def START_TIME_INPUTS() -> tuple:
check = sg.Checkbox(
text=txt.START_AT,
font=style.F_11_B,
Expand All @@ -62,7 +75,7 @@ def TRIM_START_AT() -> tuple:
return check, sg.P(), *hour, sg.P(), *minute, sg.P(), *second


def TRIM_DURATION_SLIDER():
def DURATION_SLIDER():
return (
sg.T(txt.DURATION, font=style.F_11_B),
sg.Slider(
Expand Down

0 comments on commit 7de889b

Please sign in to comment.