first parts of GUI migrated

This commit is contained in:
2023-03-14 18:04:49 +01:00
parent 5d4202e1a9
commit 2e73026a8d
4 changed files with 55 additions and 188 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,13 +1,13 @@
########################################################### """
# * FSRImageVideoUpscalerFrontend - fsrimagevideoupscaler.py
# FSRImageVideoUpscalerFrontend written in GTK+ *
# * Created by Janis Hutz 03/14/2023, Licensed under the GPL V3 License
# This code is licensed under the GPL V3 License! * https://janishutz.com, development@janishutz.com
# Developed 2022 by Janis Hutz *
# *
########################################################### """
import sys import sys
import gi
import bin.handler import bin.handler
import multiprocessing import multiprocessing
import bin.checks import bin.checks
@@ -17,141 +17,33 @@ arg = bin.arg_assembly.ArgAssembly()
checks = bin.checks.Checks() checks = bin.checks.Checks()
handler = bin.handler.Handler() handler = bin.handler.Handler()
gi.require_version("Gtk", "3.0") from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QDialog, QFileDialog, QComboBox, QHBoxLayout, QVBoxLayout, QWidget
from gi.repository import Gtk
class ErrorDialogFileMissing(Gtk.Dialog):
def __init__(self, parent):
super().__init__(title="Error", transient_for=parent, flags=0)
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
self.set_default_size(150, 100)
self.label = Gtk.Label(label=" No file specified. Please select an input AND output file! ")
self.box = self.get_content_area()
self.box.pack_start(self.label, True, True, 20)
self.show_all()
class ErrorDialogRunning(Gtk.Dialog): class HomeWindow(QMainWindow):
def __init__(self, parent): def __init__( self, parent=None ):
super().__init__(title="Error", transient_for=parent, flags=0) super( HomeWindow, self ).__init__( parent )
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
self.set_default_size(150, 100)
self.label = Gtk.Label(label=" You are already upscaling. Please wait for the current job to finish! ")
self.box = self.get_content_area()
self.box.pack_start(self.label, True, True, 20)
self.show_all()
class ErrorDialogCheckFail(Gtk.Dialog):
def __init__(self, parent):
super().__init__(title="Error", transient_for=parent, flags=0)
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
self.set_default_size(150, 100)
self.label = Gtk.Label(label=" File and settings check failed. \n Make sure to specify the same file extension in the output like in the input \n make sure that the entries you made as settings are valid! (4 >= scale >= 1) ")
self.box = self.get_content_area()
self.box.pack_start(self.label, True, True, 20)
self.show_all()
class HomeWindow(Gtk.Window):
def __init__(self):
super().__init__(title="Test")
self.os_type = sys.platform self.os_type = sys.platform
self.save_file = "" self.save_file = ""
self.open_file = "" self.open_file = ""
# Spawn box
self.main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.sub_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.orient_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.top_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.quality_select_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.custom_quality_selector_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
# Headerbar box = QHBoxLayout();
self.hb = Gtk.HeaderBar() widget = QWidget();
self.hb.set_show_close_button(True)
self.hb.props.title = "FSR Image & Video Upscaler"
self.set_titlebar(self.hb)
# Create filechooser button self.button = QPushButton( 'Input file' );
self.filechoosebutton = Gtk.Button(label="Choose Input File") self.button.clicked.connect( self.filechooser_clicked );
self.filechoosebutton.connect("clicked", self.filechooser_clicked)
self.box.pack_start(self.filechoosebutton, True, True, 0)
# Create output filechooser button self.qualitySelector = QComboBox();
self.opfchooserbutton = Gtk.Button(label="Choose Output File") self.qualitySelector.addItems( ['2x', '1.7x', '1.5x', '1.3x', 'Custom (will respect value below)' ] );
self.opfchooserbutton.connect("clicked", self.opfilechooser_clicked)
self.box.pack_start(self.opfchooserbutton, True, True, 0)
# Create start button
self.start_button = Gtk.Button(label="Start upscaling")
self.start_button.connect("clicked", self.start_clicked)
self.box.pack_start(self.start_button, True, True, 0)
# Create Input File label
self.ip_file_label = Gtk.Label(label="Choose input file")
# Create Output File label
self.op_file_label = Gtk.Label(label="Choose output file")
# Pack File labels
self.filebox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.filebox.pack_start(self.ip_file_label, True, True, 10)
self.filebox.pack_start(self.op_file_label, True, True, 10)
# QualitySelect
self.title = Gtk.Label(label="Upscaling Multiplier Presets")
self.qualities = Gtk.ListStore(str)
self.qualities.append(["2x"])
self.qualities.append(["1.7x"])
self.qualities.append(["1.5x"])
self.qualities.append(["1.3x"])
self.qualities.append(["Custom (will respect value below)"])
self.quality_select = Gtk.ComboBox.new_with_model(self.qualities)
self.text_renderer = Gtk.CellRendererText()
self.quality_select.pack_start(self.text_renderer, True)
self.quality_select.add_attribute(self.text_renderer, "text", 0)
self.quality_select.connect("changed", self.on_quality_change)
self.quality_select_shrink = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.quality_select_shrink.pack_start(self.quality_select, True, False, 10)
self.quality_select_box.pack_start(self.title, True, True, 0)
self.quality_select_box.pack_start(self.quality_select_shrink, True, True, 20)
# Custom Quality Selector
self.custom_quality_selector_title = Gtk.Label(label="Custom Upscaling Multiplier\nNOTE that factors greater than 2 are not recommended!\nFactors greater than 4 will not run!")
self.custom_quality_selector_shrink = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.custom_quality_selector = Gtk.Entry()
self.custom_quality_selector_shrink.pack_start(self.custom_quality_selector, True, False, 10)
self.custom_quality_selector_box.pack_start(self.custom_quality_selector_title, True, True, 0)
self.custom_quality_selector_box.pack_start(self.custom_quality_selector_shrink, True, True, 20)
# Info
self.infos = Gtk.Label(label="Settings")
# Details
self.details = Gtk.Label(label="Ready")
# Separator
self.separator = Gtk.Separator().new(Gtk.Orientation.HORIZONTAL)
# Packing boxes
self.top_box.pack_start(self.infos, True, True, 0)
self.top_box.pack_start(self.quality_select_box, True, True, 0)
self.top_box.pack_start(self.custom_quality_selector_box, True, True, 0)
self.top_box.pack_start(self.details, True, True, 0)
self.top_box.pack_start(self.separator, True, False, 0)
self.orient_box.pack_start(self.filebox, True, True, 0) box.addWidget( self.button )
self.orient_box.pack_start(self.box, True, True, 0) box.addWidget( self.qualitySelector );
self.sub_box.pack_start(self.orient_box, True, True, 30) widget.setLayout( box );
self.main_box.pack_start(self.top_box, True, True, 0)
self.main_box.pack_end(self.sub_box, True, True, 5)
self.add(self.main_box)
self.setCentralWidget( widget );
self.setWindowTitle( 'FSRImageVideoUpscalerFrontend' );
def on_quality_change(self, quality): def on_quality_change(self, quality):
@@ -162,55 +54,31 @@ class HomeWindow(Gtk.Window):
self.output = self.model[self.tree_iter][0] self.output = self.model[self.tree_iter][0]
def filechooser_clicked(self, widget): def filechooser_clicked(self, widget):
self.filechooserdialog = Gtk.FileChooserDialog(title="Choose input file", action=Gtk.FileChooserAction.OPEN) self.open_file = QFileDialog.getOpenFileName( self, 'Open input file', '', 'Image & Video files (*.jpg *.png *.mp4 *.mkv *.jpeg)' );
self.filechooserdialog.add_buttons(
Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN,
Gtk.ResponseType.OK,
)
self.response = self.filechooserdialog.run()
if self.response == Gtk.ResponseType.OK:
self.ip_file_label.set_text(self.filechooserdialog.get_filename())
self.open_file = self.filechooserdialog.get_filename()
elif self.response == Gtk.ResponseType.CANCEL:
pass
self.filechooserdialog.destroy()
def opfilechooser_clicked(self, widget): def opfilechooser_clicked(self, widget):
self.filechooserdialog_save = Gtk.FileChooserDialog(title="Choose output file", action=Gtk.FileChooserAction.SAVE) self.path = '';
Gtk.FileChooser.set_do_overwrite_confirmation(self.filechooserdialog_save, True)
if self.os_type == "linux": if str(self.open_file)[len(self.open_file) - 4:] == '.mp4':
Gtk.FileChooser.set_current_folder(self.filechooserdialog_save, "/home") self.path = 'video.mp4';
elif self.os_type == "win32": elif str(self.open_file)[len(self.open_file) - 4:] == '.mkv':
Gtk.FileChooser.set_current_folder(self.filechooserdialog_save, "%HOMEPATH%") self.path = 'video.mkv';
elif str(self.open_file)[len(self.open_file) - 4:] == '.png':
self.path = 'image.png';
elif str(self.open_file)[len(self.open_file) - 4:] == '.jpg':
self.path = 'image.jpg';
elif str(self.open_file)[len(self.open_file) - 4:] == '.jpeg':
self.path = 'image.jpeg';
self.open_file_out = QFileDialog( self, 'Select output file', '', 'Image & Video files (*.jpg *.png *.mp4 *.mkv *.jpeg)' );
self.open_file_out.setAcceptMode( 'AcceptSave' );
if self.os_type == 'linux':
self.open_file_out.setDirectoryUrl( '/home' );
elif self.os_type == 'win32':
self.open_file_out.setDirectoryUrl( '%HOMEPATH%' );
else: else:
pass pass;
if str(self.open_file)[len(self.open_file) - 4:] == ".mp4":
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "video.mp4")
elif str(self.open_file)[len(self.open_file) - 4:] == ".mkv":
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "video.mkv")
elif str(self.open_file)[len(self.open_file) - 4:] == ".png":
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "image.png")
elif str(self.open_file)[len(self.open_file) - 4:] == ".jpg":
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "image.jpg")
elif str(self.open_file)[len(self.open_file) - 4:] == ".jpeg":
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "image.jpeg")
else:
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "")
self.filechooserdialog_save.add_buttons(
Gtk.STOCK_CANCEL,
Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE,
Gtk.ResponseType.OK,
)
self.response = self.filechooserdialog_save.run()
if self.response == Gtk.ResponseType.OK:
self.op_file_label.set_text(self.filechooserdialog_save.get_filename())
self.save_file = self.filechooserdialog_save.get_filename()
elif self.response == Gtk.ResponseType.CANCEL:
pass
self.filechooserdialog_save.destroy()
def info_button(self): def info_button(self):
self.info_dialog = Gtk.Dialog() self.info_dialog = Gtk.Dialog()
@@ -286,9 +154,9 @@ class HomeWindow(Gtk.Window):
self.runningerrordialog.destroy() self.runningerrordialog.destroy()
def fileerror(self): def fileerror(self):
self.fileerrordialog = ErrorDialogFileMissing(self) self.fileMissingErrorDialog = QDialog( self );
self.fileerrordialog.run() self.fileMissingErrorDialog.setWindowTitle( 'Missing file selection! Please ensure you have selected both an input and output file!' );
self.fileerrordialog.destroy() self.fileMissingErrorDialog.exec();
def checkerror(self): def checkerror(self):
self.checkerrordialog = ErrorDialogCheckFail(self) self.checkerrordialog = ErrorDialogCheckFail(self)
@@ -296,8 +164,7 @@ class HomeWindow(Gtk.Window):
self.checkerrordialog.destroy() self.checkerrordialog.destroy()
win = HomeWindow() app = QApplication( sys.argv );
win.set_default_size(800, 600) ex = HomeWindow();
win.connect("destroy", Gtk.main_quit) ex.show();
win.show_all() sys.exit( app.exec_() );
Gtk.main()