Skip to content

Commit

Permalink
WORKING GUI
Browse files Browse the repository at this point in the history
The GUI works!!!! Run 'gui.py' to try it!

This is probably the last update, unless I decide to add teres support.
  • Loading branch information
gem-storm committed Mar 29, 2024
1 parent 80f1a5a commit ab2b22d
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 32 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ In the future, [teres](https://github.com/animafps/teres) *may* be supported.
download the [latest release](https://github.com/gem-storm/configtool/releases/latest) and unzip it.

## usage
run `main.py` to start the program and paste the path to your config/recipe when prompted. the rest should be self-explanatory.
2 ways of running configtool:
1. gui: you can run `gui.py` to use the (new) gui version of configtool! (only supports converting rn)
2. cli: run `main.py` to get the (old) cli version of configtool. (has all the other features + cli args)

## cli args (v0.3+)

## cli args
(for `main.py`)
`--help`
shows basic help message and exits.

Expand Down
Binary file added assets/logo.ico
Binary file not shown.
14 changes: 8 additions & 6 deletions src/blur_18.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def make_recipe(config):
model: rife-v4.6"""


def calculate_vegas(config):
def calculate_vegas(config, fps=0):
match config["interpolate"]:
case "true":
blurframes = int(
Expand All @@ -199,11 +199,13 @@ def calculate_vegas(config):
* float(config["blur amount"])
)
case "false":
blurframes = int(
int(input("Interpolation is disabled, what's the input video's fps?: "))
/ int(config["blur output fps"])
* int(config["blur amount"])
)
if fps == 0:
blurframes = 1
# so it returns equal
else:
blurframes = (
fps / int(config["blur output fps"]) * int(config["blur amount"])
)
if blurframes % 2 == 0:
weighting = "[1," + "2," * (blurframes - 1) + "1]"
else:
Expand Down
22 changes: 12 additions & 10 deletions src/blur_192.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
def weighting(config):
weighting = config["blur weighting"]
std_dev = config["blur weighting gaussian std dev"]
bound = config["blur weighting bound"]
if config["interpolate"] == "true" and "x" not in config["interpolated fps"]:
blurframes = int(
int(config["interpolated fps"]) / int(config["blur output fps"])
Expand All @@ -7,9 +10,6 @@ def weighting(config):
vegas = "[1," + "2," * (blurframes - 1) + "1]"
if weighting == vegas:
return "vegas"
weighting = config["blur weighting"]
std_dev = {config["blur weighting gaussian std dev"]}
bound = {config["blur weighting bound"]}
match weighting:
case "equal":
return "equal"
Expand Down Expand Up @@ -138,7 +138,7 @@ def make_recipe(config):
[output]
process: ffmpeg
enc args: {config["custom ffmpeg filters"]}
file format: %FILENAME%
file format: %FILENAME% ~ %FRUIT%
container: .{config["video container"]}
[preview window]
Expand Down Expand Up @@ -192,7 +192,7 @@ def make_recipe(config):
model: rife-v4.6"""


def calculate_vegas(config):
def calculate_vegas(config, fps=0):
match config["interpolate"]:
case "true":
blurframes = int(
Expand All @@ -201,11 +201,13 @@ def calculate_vegas(config):
* float(config["blur amount"])
)
case "false":
blurframes = int(
int(input("Interpolation is disabled, what's the input video's fps?: "))
/ int(config["blur output fps"])
* int(config["blur amount"])
)
if fps == 0:
blurframes = 1
# so it returns equal
else:
blurframes = (
fps / int(config["blur output fps"]) * int(config["blur amount"])
)
if blurframes % 2 == 0:
weighting = "[1," + "2," * (blurframes - 1) + "1]"
else:
Expand Down
2 changes: 2 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@
"""

YES = ["on", "True", "true", "yes", "y", "1", "yeah", "yea", "yep", "sure", "positive"]

VERSION = 1.0
181 changes: 167 additions & 14 deletions src/gui.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,182 @@
from tkinter import *
from constants import VERSION
import main

version = 0.3
from tkinter import *


window = Tk()
window.title(f"configtool v{version}")
window.minsize(width=500, height=800)
window.title(f"configtool v{VERSION}")
window.minsize(width=530, height=750)
window.iconbitmap("../assets/logo.ico")


input_box_label = Label(text="Paste input config contents here:")
output_box_label = Label(text="Output appears here:")

input_box_label.grid(column=0, row=0, pady=10)
output_box_label.grid(column=1, row=0, pady=10)


input_box = Text(height=30, width=30)
output_box = Text(height=30, width=30)
input_box.grid(column=0, row=1, padx=10)
output_box.grid(column=1, row=1, padx=10)


def output_format():
match output.get():
case 0:
return "smoothie"
case 1:
return "blur_1.8"
case 2:
return "blur_1.92"


label = Label(
text="THIS DOES NOT YET WORK;\nTHE CONVERTING, SHORTENING, VEGAS WEIGHTS,\nETC HAVE NOT BEEN IMPLEMENTED",
format_label = Label(text="Output format:")
format_label.grid(column=1, row=3, sticky=W, padx=50)

output = IntVar()

smoothie_button = Radiobutton(text="Smoothie (Latest)", value=0, variable=output)
blur_18_button = Radiobutton(text="Blur (1.8)", value=1, variable=output)
blur_192_button = Radiobutton(text="Blur (1.92)", value=2, variable=output)

smoothie_button.grid(column=1, row=4, sticky=W, padx=50)
blur_18_button.grid(column=1, row=5, sticky=W, padx=50)
blur_192_button.grid(column=1, row=6, sticky=W, padx=50)


input_fps_label = Label(text="Input FPS (if needed):")
input_fps_text = Entry(width=5)


def input_fps():
if vegas_var.get() == 1:
input_fps_label.grid(column=0, row=8, sticky=W, padx=10)
input_fps_text.grid(column=0, row=9, sticky=W, padx=15)
else:
input_fps_label.grid_forget()
input_fps_text.grid_forget()


vegas_var = IntVar()
vegas_check = Checkbutton(
text="Calculate VEGAS weights", variable=vegas_var, command=input_fps
)
label.config(font=("Arial", 20))
label.pack()
vegas_check.grid(column=0, row=7, stick=W, padx=10)


shorten_var = IntVar()
shorten_check = Checkbutton(text="Shorten", variable=shorten_var)
shorten_check.grid(column=0, row=4, stick=W, padx=10)


path_text = Entry(width=40)


def path():
if path_var.get() == 1:
path_text.grid(column=0, row=6, sticky=W, padx=10)
else:
path_text.grid_forget()


path_var = IntVar()
path_check = Checkbutton(text="Use path instead", variable=path_var, command=path)
path_check.grid(column=0, row=5, sticky=W, padx=10)


def config_type(config):
if "interpolation program (svp/rife/rife-ncnn)" in config:
return "blur_1.8"
elif "interpolation block size" in config:
return "blur_1.92"
return "smoothie"


def parse_config():
if path_var.get() == 1:
with open(path_text.get()) as file:
config = file.read()
else:
config = input_box.get("1.0", END)
config_lines = config.split("\n")

if config_type(config) in ["blur_1.8", "blur_1.92"]:
dict_config = {}
for line in config_lines:
if ": " in line:
split_line = line.split(": ", 1)
dict_config[split_line[0]] = split_line[1]
return dict_config
else:
cfgparse = main.configparser.RawConfigParser()
cfgparse.read_string(config)
dict = {}
for section in cfgparse.sections():
dict[section] = {}
for item in cfgparse.items(section):
dict[section][item[0]] = item[1]
return dict


def convert_config():
config = parse_config()
output = output_format()
input_type = config_type(input_box.get("1.0", END))

if input_type == output:
return input_box.get("1.0", END)

match input_type:
case "blur_1.8":
converted_config = main.blur_18.convert(config, output)
case "blur_1.92":
converted_config = main.blur_192.convert(config, output)
case "smoothie":
converted_config = main.smoothie.convert(config, output)

if vegas_var.get() == 1:
match input_type:
case "blur_1.8":
converted_config = main.blur_18.calculate_vegas(
config, input_fps_text.get()
)
case "blur_1.92":
converted_config = main.blur_192.calculate_vegas(
config, input_fps_text.get()
)
case "smoothie":
converted_config = main.smoothie.calculate_vegas(config)
if shorten_var.get() == 1:
match input_type:
case "blur_1.8":
converted_config = main.blur_18.shorten(config)
case "blur_1.92":
converted_config = main.blur_192.shorten(config)
case "smoothie":
converted_config = main.smoothie.shorten(config)
return converted_config


def paste_config():
converted_config = convert_config()
output_box.delete("1.0", END)
output_box.insert(1.0, converted_config)


text = Text(height=30, width=30)
text.pack()
def copy_config():
main.pyperclip.copy(output_box.get("1.0", END))


def get_text():
print(text.get("1.0", END))
convert_button = Button(text="Convert", command=paste_config)
convert_button.config(width=10, height=1)

copy_button = Button(text="Copy", command=copy_config)
copy_button.config(width=10, height=1)

button = Button(text="convert", command=get_text)
button.pack()
convert_button.grid(column=0, row=2, pady=10)
copy_button.grid(column=1, row=2, pady=10)

window.mainloop()

0 comments on commit ab2b22d

Please sign in to comment.