Made the main directory the working directory, some refactoring, added open folder function to the dir widget

master
Jaka Perovšek 2024-09-28 00:28:45 +02:00
parent 66cda77233
commit 73ae09c438
3 changed files with 24 additions and 18 deletions

View File

@ -113,13 +113,13 @@ class OptionsWidget(QWidget):
# TODO: implement random local mod name
class EditorWidget(QWidget):
class CodeEditorWidget(QWidget):
def __init__(self, parent: QWidget):
super().__init__()
self.parent = parent
self.tapes_yaml = Path("../source/tapes.yaml")
self.tapes_yaml = Path("./source/tapes.yaml")
self.filename_string = f"<tt style=\"font-family: consolas;\"><b>{self.tapes_yaml.name}</b></tt>"
self.tapes_file_watcher = QFileSystemWatcher()
@ -127,19 +127,19 @@ class EditorWidget(QWidget):
self.tapes_file_watcher.fileChanged.connect(self.external_file_changed)
self.external_editor_pushbutton = QPushButton()
self.external_editor_pushbutton.setIcon(QIcon("./icons/ic_open_in_new_24px.svg"))
self.external_editor_pushbutton.setIcon(QIcon("./gui/icons/ic_open_in_new_24px.svg"))
self.external_editor_pushbutton.setToolTip("Edit in external editor")
self.external_editor_pushbutton.clicked.connect(self.open_file)
self.reload_code_pushbutton = QPushButton()
self.reload_code_pushbutton.setIcon(QIcon("./icons/ic_refresh_24px.svg"))
self.reload_code_pushbutton.setIcon(QIcon("./gui/icons/ic_refresh_24px.svg"))
self.reload_code_pushbutton.setToolTip("Reload the external file")
self.reload_code_pushbutton.clicked.connect(self.load_file)
self.save_code_pushbutton = QPushButton()
self.save_code_pushbutton.setIcon(QIcon("./icons/ic_save_24px.svg"))
self.save_code_pushbutton.setIcon(QIcon("./gui/icons/ic_save_24px.svg"))
self.save_code_pushbutton.setToolTip("Save setup")
self.save_code_pushbutton.clicked.connect(self.save_file)
self.transfer_to_validator_pushbutton = QPushButton()
self.transfer_to_validator_pushbutton.setIcon(QIcon("./icons/ic_keyboard_double_arrow_right_24px.svg"))
self.transfer_to_validator_pushbutton.setIcon(QIcon("./gui/icons/ic_keyboard_double_arrow_right_24px.svg"))
self.transfer_to_validator_pushbutton.setToolTip("Apply the code.")
self.transfer_to_validator_pushbutton.clicked.connect(self.apply_code)
@ -281,7 +281,7 @@ class ValidationWidget(QWidget):
self.tapes = self.load_tapes()
self.transfer_to_code_pushbutton = QPushButton()
self.transfer_to_code_pushbutton.setIcon(QIcon("./icons/ic_keyboard_double_arrow_left_24px.svg"))
self.transfer_to_code_pushbutton.setIcon(QIcon("./gui/icons/ic_keyboard_double_arrow_left_24px.svg"))
self.transfer_to_code_pushbutton.setToolTip("Update the code")
self.transfer_to_code_pushbutton.clicked.connect(self.save_tapes)
self.jump_spinbox = QSpinBox()
@ -324,7 +324,7 @@ class ValidationWidget(QWidget):
import tempfile
def load_tapes(self):
with open("../source/tapes.yaml", encoding="utf-8") as fp:
with open("./source/tapes.yaml", encoding="utf-8") as fp:
tapes = yaml.safe_load(fp)
return tapes
@ -430,7 +430,6 @@ class InstallWidget(QWidget):
self.does_ffmpeg_exists()
def does_ffmpeg_exists(self):
os.chdir("..")
if Path("./utils/ffmpeg-" + get_ffmpeg_version() + "-full_build/bin/ffmpeg.exe").exists():
self.install_grid.addWidget(self.ffmpeg_info_label, 3, 0, 1, 3)
self.ffmpeg_info_label.show()
@ -443,13 +442,11 @@ class InstallWidget(QWidget):
self.ffmpeg_pushbutton.setEnabled(not exists)
self.ffmpeg_checkbox.setChecked(exists)
self.songs_download_pushbutton.setEnabled(exists)
os.chdir("./gui")
return exists
def download_ffmpeg_action(self):
os.chdir("..")
download_ffmpeg()
os.chdir("./gui")
self.does_ffmpeg_exists()
class MainWidget(QWidget):
@ -459,7 +456,7 @@ class MainWidget(QWidget):
layout = QHBoxLayout()
self.options_widget = OptionsWidget(self)
self.editor_widget = EditorWidget(self)
self.editor_widget = CodeEditorWidget(self)
self.validation_widget = ValidationWidget(self)
# install = InstallWidget()
layout.addWidget(self.options_widget)
@ -483,6 +480,7 @@ class MainWindow(QMainWindow):
def main():
os.chdir("..")
app = QApplication(sys.argv)
window = MainWindow()
window.show()

View File

@ -35,7 +35,7 @@ class CoverEditWidget(QLabel):
super().__init__()
self.tape = tape
pix = QPixmap(f"../source/images/{self.tape['identifier']}.png")
pix = QPixmap(f"./source/images/{self.tape['identifier']}.png")
self.pixmap = pix.scaled(350, 350,
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation)

View File

@ -7,6 +7,7 @@ from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QWidget, Q
import webbrowser
import validators
import datetime
import os
from pathlib import Path
@ -133,23 +134,26 @@ class DirWidget(QWidget):
def __init__(self, default_dir: Path | str | None = None):
super().__init__()
self.directory = default_dir
layout = QHBoxLayout()
layout.setSpacing(2)
layout.setContentsMargins(0, 0, 0, 0)
self.dir_lineedit = QLineEdit()
self.dir_lineedit.setFont("Consolas")
self.dir_lineedit.setText(default_dir)
self.dir_lineedit.setText(self.directory)
self.dir_set_btn = QPushButton()
self.dir_set_btn.setIcon(QIcon("./icons/ic_folder_open_48px.svg"))
self.dir_set_btn.setIcon(QIcon("./gui/icons/ic_folder_open_48px.svg"))
self.dir_set_btn.setIconSize(QSize(16, 16))
self.dir_set_btn.setToolTip("Set directory with selection dialog")
self.dir_open_btn = QPushButton()
self.dir_open_btn.setIcon(QIcon("./icons/ic_open_in_new_24px.svg"))
self.dir_open_btn.setIcon(QIcon("./gui/icons/ic_open_in_new_24px.svg"))
self.dir_open_btn.setIconSize(QSize(16, 16))
self.dir_open_btn.setToolTip("Open directory")
self.dir_open_btn.clicked.connect(self.open_dir)
layout.addWidget(self.dir_set_btn)
layout.addWidget(self.dir_lineedit)
@ -157,6 +161,10 @@ class DirWidget(QWidget):
self.setLayout(layout)
def open_dir(self):
directory = Path(self.directory)
os.startfile(directory)
class UrlLineEdit(QLineEdit):
@ -194,7 +202,7 @@ class UrlWidget(QWidget):
self.url_lineedit.textChanged.connect(self.toggle_url_open_btn)
self.url_open_btn = QPushButton()
self.url_open_btn.setIcon(QIcon("./icons/ic_open_in_new_24px.svg"))
self.url_open_btn.setIcon(QIcon("./gui/icons/ic_open_in_new_24px.svg"))
self.url_open_btn.setIconSize(QSize(16, 16))
self.url_open_btn.setToolTip("Open in browser")
self.url_open_btn.clicked.connect(self.url_lineedit.open_url)