Skip to content

Commit

Permalink
Get theme names from the file system
Browse files Browse the repository at this point in the history
  • Loading branch information
machinewrapped committed May 14, 2023
1 parent 4420328 commit f73bf8e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion GUI/FirstRunOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from PySide6.QtGui import QTextOption

from PySubtitleGPT.Helpers import GetResourcePath
from GUI.GuiHelpers import GetResourcePath


class FirstRunOptions(QDialog):
Expand Down
20 changes: 20 additions & 0 deletions GUI/GuiHelpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import sys

def GetResourcePath(relative_path):
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)

def GetThemeNames():
themes = []
theme_path = GetResourcePath("theme")
for file in os.listdir(theme_path):
if file.endswith(".qss"):
theme_name = os.path.splitext(file)[0]
themes.append(theme_name)

themes.sort()
return themes


2 changes: 1 addition & 1 deletion GUI/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
from GUI.CommandQueue import CommandQueue
from GUI.FileCommands import LoadSubtitleFile
from GUI.FirstRunOptions import FirstRunOptions
from GUI.GuiHelpers import GetResourcePath
from GUI.MainToolbar import MainToolbar
from GUI.SettingsDialog import SettingsDialog
from GUI.ProjectActions import NoApiKeyError, ProjectActions
from GUI.ProjectCommands import BatchSubtitlesCommand
from GUI.ProjectDataModel import ProjectDataModel
from GUI.Widgets.LogWindow import LogWindow
from GUI.Widgets.ModelView import ModelView
from PySubtitleGPT.Helpers import GetResourcePath
from PySubtitleGPT.Options import Options
from PySubtitleGPT.SubtitleProject import SubtitleProject
from PySubtitleGPT.VersionCheck import CheckIfUpdateAvailable, CheckIfUpdateCheckIsRequired
Expand Down
5 changes: 4 additions & 1 deletion GUI/SettingsDialog.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from PySide6.QtWidgets import (QDialog, QVBoxLayout, QTabWidget, QDialogButtonBox, QWidget, QFormLayout, QFrame)
from GUI.GuiHelpers import GetThemeNames

from GUI.Widgets.OptionsWidgets import CreateOptionWidget

class SettingsDialog(QDialog):
SECTIONS = {
'General': {
'theme': ['subtrans', 'subtrans-dark'],
'theme': [],
'autosave': bool,
'write_backup': bool,
'stop_on_error': bool,
Expand Down Expand Up @@ -44,6 +45,8 @@ def __init__(self, options, parent=None):

self.options = options

self.SECTIONS['General']['theme'] = ['default'] + GetThemeNames()

self.layout = QVBoxLayout(self)

self.sections = QTabWidget(self)
Expand Down
5 changes: 0 additions & 5 deletions PySubtitleGPT/Helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ def GetOutputPath(filepath):
basename = basename + "-ChatGPT"
return os.path.join(os.path.dirname(filepath), f"{basename}.srt")

def GetResourcePath(relative_path):
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)

def GenerateBatchPrompt(prompt, lines, tag_lines=None):
"""
Create the user prompt for translating a set of lines
Expand Down

0 comments on commit f73bf8e

Please sign in to comment.