From 593a4566ebfb0d38b31369616599ad60b9b9d87e Mon Sep 17 00:00:00 2001 From: Nix <75538775+nixietab@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:20:11 -0300 Subject: [PATCH] fixed the last version not saving on config file by dumb issue --- picodulce.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/picodulce.py b/picodulce.py index ec83737..fe28ad2 100644 --- a/picodulce.py +++ b/picodulce.py @@ -10,7 +10,7 @@ import os import time from PyQt5.QtWidgets import QApplication, QComboBox, QWidget, QVBoxLayout, QListWidget, QPushButton, QMessageBox, QDialog, QHBoxLayout, QLabel, QLineEdit, QCheckBox, QTabWidget, QFrame, QSpacerItem, QSizePolicy, QMainWindow, QGridLayout from PyQt5.QtGui import QFont, QIcon, QColor, QPalette, QMovie, QPixmap, QDesktopServices -from PyQt5.QtCore import Qt, QObject, pyqtSignal, QThread, QUrl +from PyQt5.QtCore import Qt, QObject, pyqtSignal, QThread, QUrl, QMetaObject, Q_ARG logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') @@ -301,7 +301,6 @@ class PicomcVersionSelector(QWidget): logging.error("'marroc.py' not found.") QMessageBox.critical(self, "Error", "'marroc.py' not found.") - def play_instance(self): if self.installed_version_combo.count() == 0: QMessageBox.warning(self, "No Version Available", "Please download a version first.") @@ -319,7 +318,7 @@ class PicomcVersionSelector(QWidget): QMessageBox.warning(self, "No Account Selected", "Please select an account.") return except subprocess.CalledProcessError as e: - error_message = f"Error fetching accounts: {e.stderr.decode()}" + error_message = f"Error fetching accounts: {str(e)}" logging.error(error_message) QMessageBox.critical(self, "Error", error_message) return @@ -333,13 +332,15 @@ class PicomcVersionSelector(QWidget): def run_game(self, selected_instance): try: subprocess.run(['picomc', 'play', selected_instance], check=True) - # Update lastplayed field in config.json - self.update_last_played(selected_instance) + # Update lastplayed field in config.json on a separate thread + update_thread = threading.Thread(target=self.update_last_played, args=(selected_instance,)) + update_thread.start() except subprocess.CalledProcessError as e: - error_message = f"Error playing {selected_instance}: {e.stderr.decode()}" + error_message = f"Error playing {selected_instance}: {e}" logging.error(error_message) - QMessageBox.critical(self, "Error", error_message) - + # Use QMetaObject.invokeMethod to call showError safely + QMetaObject.invokeMethod(self, "showError", Qt.QueuedConnection, + Q_ARG(str, "Error"), Q_ARG(str, error_message)) def update_last_played(self, selected_instance): config_path = "config.json" @@ -347,6 +348,11 @@ class PicomcVersionSelector(QWidget): with open(config_path, "w") as config_file: json.dump(self.config, config_file, indent=4) + + def showError(self, title, message): + QMessageBox.critical(self, title, message) + + def manage_accounts(self): dialog = QDialog(self) self.open_dialogs.append(dialog)