Skip to content

Commit

Permalink
adds languages and adds default value for model
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed May 10, 2023
1 parent 683d65d commit 0b201fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/video_subtitles/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def open_folder(path):
subprocess.Popen(["xdg-open", path]) # pylint: disable=consider-using-with


class MainWidget(QMainWindow):
class MainWidget(QMainWindow): # pylint: disable=too-many-instance-attributes
"""Main widget."""

def __init__(self, on_drop_callback):
Expand Down Expand Up @@ -80,13 +80,24 @@ def __init__(self, on_drop_callback):
self.model_label.setText("Model:")
self.model_select = QComboBox(self)
self.model_select.addItems(MODELS.keys())
self.model_select.setCurrentText(settings.model())
model_layout.addWidget(self.model_label)
model_layout.addWidget(self.model_select)
model_layout.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)

header_layout.addLayout(deepl_layout)
header_layout.addLayout(model_layout)

# Add translation output label and text field
output_layout = QHBoxLayout()
self.output_label = QLabel(self)
self.output_label.setText("Translation Outputs:")
self.output_text = QLineEdit(self)
output_layout.addWidget(self.output_label)
output_layout.addWidget(self.output_text)
output_layout.setAlignment(QtCore.Qt.AlignmentFlag.AlignLeft)
header_layout.addLayout(output_layout)

# Add a label to the window on top of everything else
self.label = QLabel(self)
self.label.setText("Drag and Drop Video File Here")
Expand All @@ -111,9 +122,10 @@ def dragEnterEvent(self, event):
def save_settings(self) -> None:
"""Save the settings."""
deepl_api_key = self.deepl_input.text().strip() # get api key from input field
if deepl_api_key != settings.deepl_key():
settings.set_deepl_key(deepl_api_key) # write api key to settings
settings.save() # save settings to file
settings.set_deepl_key(deepl_api_key) # write api key to settings
model = self.model_select.currentText().strip()
settings.set_model(model)
settings.save() # save settings to file

def dropEvent(self, event):
"""Drag and drop handler."""
Expand Down
8 changes: 8 additions & 0 deletions src/video_subtitles/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def set_deepl_key(self, key: str) -> None:
"""Set the DeepL API key."""
self.data["deepl_key"] = key

def model(self) -> str:
"""Return the model."""
return self.data.get("model", "large") # type: ignore

def set_model(self, model: str) -> None:
"""Set the model."""
self.data["model"] = model

def save(self) -> None:
"""Save the settings."""
# dump json to file
Expand Down

0 comments on commit 0b201fe

Please sign in to comment.