Skip to content

Commit

Permalink
Added logo, icon and About dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
machinewrapped committed Aug 15, 2023
1 parent f6e844e commit f74623f
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 6 deletions.
98 changes: 98 additions & 0 deletions GUI/AboutDialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import os
import pkg_resources
from PySide6.QtWidgets import (QDialog, QVBoxLayout, QDialogButtonBox, QLabel, QHBoxLayout)
from PySide6.QtGui import QPixmap
from PySide6.QtCore import Qt
from GUI.GuiHelpers import GetResourcePath

from PySubtitleGPT.version import __version__

class AboutDialog(QDialog):
"""
Show application information etc.
"""
def __init__(self, parent=None):
super(AboutDialog, self).__init__(parent)
self.setWindowTitle("About GUI-Subtrans")
self.setMinimumWidth(512)
self.setMaximumWidth(768)

# Main Horizontal Layout
main_layout = QHBoxLayout(self)

# Image on the left
image_layout = QVBoxLayout()
image_label = QLabel(self)
filepath = GetResourcePath(os.path.join("theme", "subtransmd.png"))
pixmap = QPixmap(filepath)
image_label.setPixmap(pixmap)

# Label for image attribution
image_attribution_label = QLabel('Logo generated with <a href="https://stability.ai/stablediffusion">Stable Diffusion XL</a>')
image_attribution_label.setOpenExternalLinks(True) # This ensures the link opens in a default web browser
image_attribution_label.setWordWrap(True)
image_attribution_label.setAlignment(Qt.AlignmentFlag.AlignCenter)

image_layout.addWidget(image_label)
image_layout.addWidget(image_attribution_label)
main_layout.addLayout(image_layout)

# Right side vertical layout
layout = QVBoxLayout()

# Title
title_label = QLabel(f"GUI-Subtrans Version {__version__}")
font = title_label.font()
font.setPointSize(24)
title_label.setFont(font)

# Description
description_label = QLabel("GUI-Subtrans uses OpenAI's GPT AI to translate SRT subtitles into other languages, or to improve the quality of an existing translation.")
description_label.setWordWrap(True)

# Author Information and GitHub link
author_label = QLabel("Developed by: MachineWrapped<br>"
"Contact: [email protected]<br>"
'<a href="https://github.com/machinewrapped/gpt-subtrans">GitHub Repository</a>')
author_label.setOpenExternalLinks(True)
author_label.setTextInteractionFlags(Qt.TextInteractionFlag.TextBrowserInteraction)

# License information
license_text = QLabel("GUI-Subtrans is released under the MIT License.\n\n"
"Permission is hereby granted, free of charge, to any person obtaining a copy "
"of this software and associated documentation files, to deal in the software "
"without restriction, including without limitation the rights to use, copy, "
"modify, merge, publish, distribute, sublicense, and/or sell copies of the software.")
license_text.setWordWrap(True)

# Libraries and their versions
libraries = ["openai", "srt", "pyside6", "regex", "events", "darkdetect", "appdirs", "python-dotenv"]
library_strings = []

for lib in libraries:
try:
version = pkg_resources.get_distribution(lib).version
library_strings.append(f"{lib} ({version})")
except pkg_resources.DistributionNotFound:
library_strings.append(lib)

libraries_list = QLabel("GUI-Subtrans would not work without these libraries:\n" + ", ".join(library_strings))
libraries_list.setWordWrap(True)

# OK Button
button_box = QDialogButtonBox(QDialogButtonBox.Ok)
button_box.accepted.connect(self.accept)

# Add widgets to layout
layout.addWidget(title_label)
layout.addWidget(description_label)
layout.addWidget(author_label)
layout.addWidget(license_text)
layout.addWidget(libraries_list)
layout.addWidget(button_box)

# Add right side layout to the main layout
main_layout.addLayout(layout)

# Set the main layout for the dialog
self.setLayout(main_layout)
2 changes: 1 addition & 1 deletion GUI/MainToolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class MainToolbar(QToolBar):
# _action_groups = [ ["Load Subtitles", "Save Project"], ["Start Translating", "Stop Translating"], ["Quit"] ]
_action_groups = [ ["Load Subtitles", "Save Project"], ["Start Translating", "Start Translating Fast", "Stop Translating"], ['Settings'], ["Quit"] ]
_action_groups = [ ["Load Subtitles", "Save Project"], ["Start Translating", "Start Translating Fast", "Stop Translating"], ["Settings"], ["About", "Quit"] ]

def __init__(self, handler : ProjectActions):
super().__init__("Main Toolbar")
Expand Down
12 changes: 12 additions & 0 deletions GUI/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import darkdetect

from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
Expand All @@ -12,6 +13,7 @@
QSplitter,
QDialog
)
from GUI.AboutDialog import AboutDialog
from GUI.Command import Command
from GUI.CommandQueue import CommandQueue
from GUI.FileCommands import LoadSubtitleFile
Expand Down Expand Up @@ -53,6 +55,7 @@ def __init__(self, parent=None, options : Options = None, filepath : str = None)

self.setWindowTitle("GUI-Subtrans")
self.setGeometry(100, 100, 1600, 900)
self._load_icon("gui-subtrans")

if not options:
options = Options()
Expand Down Expand Up @@ -138,6 +141,9 @@ def ShowSettingsDialog(self):
LoadStylesheet(options.get('theme'))
logging.info("Settings updated")

def ShowAboutDialog(self):
result = AboutDialog(self).exec()

def PrepareForSave(self):
self.model_viewer.CloseProjectOptions()

Expand All @@ -150,6 +156,12 @@ def closeEvent(self, e):

super().closeEvent(e)

def _load_icon(self, name):
if not name or name == "default":
name = "subtrans64"
filepath = GetResourcePath(f"{name}.ico")
self.setWindowIcon(QIcon(filepath))

def _on_action_requested(self, action_name, params):
if not self.datamodel:
raise Exception(f"Cannot perform {action_name} without a data model")
Expand Down
4 changes: 4 additions & 0 deletions GUI/ProjectActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, mainwindow : QMainWindow = None):
self.AddAction('Start Translating', self._start_translating, QStyle.StandardPixmap.SP_MediaPlay, 'Ctrl+T', 'Start/Resume Translating')
self.AddAction('Start Translating Fast', self._start_translating_fast, QStyle.StandardPixmap.SP_MediaSeekForward, 'Ctrl+Shift+T', 'Start translating on multiple threads (fast but unsafe)')
self.AddAction('Stop Translating', self._stop_translating, QStyle.StandardPixmap.SP_MediaStop, 'Esc', 'Stop translation')
self.AddAction('About', self._show_about_dialog, QStyle.StandardPixmap.SP_MessageBoxInformation, tooltip='About this program')

#TODO: Mixing different concepts of "action" here, is there a better separation?
# self.AddAction('Translate Selection', self._translate_selection, shortcut='Ctrl+T')
Expand Down Expand Up @@ -144,6 +145,9 @@ def _toggle_project_options(self):
def _show_settings_dialog(self):
self._mainwindow.ShowSettingsDialog()

def _show_about_dialog(self):
self._mainwindow.ShowAboutDialog()

def _validate_datamodel(self, datamodel : ProjectDataModel):
"""
Validate that there is a datamodel with subtitles that have been batched
Expand Down
2 changes: 1 addition & 1 deletion PySubtitleGPT/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "v0.3.3"
__version__ = "v0.4.0"
Binary file added gui-subtrans.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion gui-subtrans.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ a = Analysis(
['gui-subtrans.py'],
pathex=[],
binaries=[],
datas=[('theme/*', 'theme/'), ('instructions*', '.'), ('LICENSE', '.')],
datas=[('theme/*', 'theme/'), ('instructions*', '.'), ('LICENSE', '.'), ('gui-subtrans.ico', '.')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
Expand Down
2 changes: 1 addition & 1 deletion makedistro-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
source envsubtrans/bin/activate
pip install --platform=universal2 --no-deps --upgrade --target ./envsubtrans/lib pyinstaller
pip install --platform=universal2 --no-deps --upgrade --force-reinstall --target ./envsubtrans/lib -r requirements.txt
pyinstaller --paths="./envsubtrans/lib" --add-data "theme/*:theme/" --add-data "instructions*:." --add-data "LICENSE:." --target-arch universal2 --noconfirm gui-subtrans.py
pyinstaller --paths="./envsubtrans/lib" --add-data "theme/*:theme/" --add-data "instructions*:." --add-data "LICENSE:." --add-data "gui-subtrans.ico:." --target-arch universal2 --noconfirm gui-subtrans.py
2 changes: 1 addition & 1 deletion makedistro.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
call envsubtrans/scripts/activate
pip install -r requirements.txt
pyinstaller --add-data "theme/*;theme/" --add-data "instructions*;." --add-data "LICENSE;." gui-subtrans.py
pyinstaller --add-data "theme/*;theme/" --add-data "instructions*;." --add-data "LICENSE;." --add-data "gui-subtrans.ico;." gui-subtrans.py
2 changes: 1 addition & 1 deletion makedistro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

source envsubtrans/bin/activate
pip install -r requirements.txt
pyinstaller --add-data "theme/*:theme/" --add-data "instructions*:." --add-data "LICENSE:." gui-subtrans.py
pyinstaller --add-data "theme/*:theme/" --add-data "instructions*:." --add-data "LICENSE:." --add-data "gui-subtrans.ico:." gui-subtrans.py
Binary file added theme/subtranslg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added theme/subtransmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f74623f

Please sign in to comment.