Compare commits

..

No commits in common. "5eda9f1de450188cd371afe2a84ef89e56e4c931" and "0ea29235cb8b91f397ccc3ec2ea46d187da39e89" have entirely different histories.

2 changed files with 178 additions and 102 deletions

View File

@ -361,58 +361,40 @@ class PicomcVersionSelector(QWidget):
def showError(self, title, message): def showError(self, title, message):
QMessageBox.critical(self, title, message) QMessageBox.critical(self, title, message)
def manage_accounts(self): def manage_accounts(self):
# Main account management dialog
dialog = QDialog(self) dialog = QDialog(self)
self.open_dialogs.append(dialog) self.open_dialogs.append(dialog)
dialog.setWindowTitle('Manage Accounts') dialog.setWindowTitle('Manage Accounts')
dialog.setFixedSize(400, 250) dialog.setFixedSize(400, 250)
# Title
title_label = QLabel('Manage Accounts') title_label = QLabel('Manage Accounts')
title_label.setFont(QFont("Arial", 14)) title_label.setFont(QFont("Arial", 14))
# Dropdown for selecting accounts
account_combo = QComboBox()
self.populate_accounts(account_combo)
# Buttons
create_account_button = QPushButton('Create Account') create_account_button = QPushButton('Create Account')
create_account_button.clicked.connect(self.open_create_account_dialog) create_account_button.clicked.connect(self.open_create_account_dialog)
authenticate_button = QPushButton('Authenticate Account') select_account_button = QPushButton('Select Account')
authenticate_button.clicked.connect(lambda: self.authenticate_account(dialog, account_combo.currentText())) select_account_button.clicked.connect(self.open_select_account_dialog)
authenticate_account_button = QPushButton('Authenticate Account')
authenticate_account_button.clicked.connect(self.open_authenticate_account_dialog)
remove_account_button = QPushButton('Remove Account') remove_account_button = QPushButton('Remove Account')
remove_account_button.clicked.connect(lambda: self.remove_account(dialog, account_combo.currentText())) remove_account_button.clicked.connect(self.open_remove_account_dialog)
# New button to set the account idk
set_default_button = QPushButton('Select')
set_default_button.setFixedWidth(100) # Set button width to a quarter
set_default_button.clicked.connect(lambda: self.set_default_account(account_combo.currentText(), dialog))
# Layout for account selection (dropdown and set default button)
account_layout = QHBoxLayout()
account_layout.addWidget(account_combo)
account_layout.addWidget(set_default_button)
button_layout = QHBoxLayout()
button_layout.addWidget(create_account_button)
button_layout.addWidget(authenticate_button)
button_layout.addWidget(remove_account_button)
# Main layout
layout = QVBoxLayout() layout = QVBoxLayout()
layout.addWidget(title_label) layout.addWidget(title_label)
layout.addLayout(account_layout) layout.addWidget(create_account_button)
layout.addLayout(button_layout) layout.addWidget(select_account_button)
layout.addWidget(authenticate_account_button)
layout.addWidget(remove_account_button)
dialog.setLayout(layout) dialog.setLayout(layout)
dialog.exec_() dialog.exec_()
self.open_dialogs.remove(dialog) self.open_dialogs.remove(dialog)
def open_create_account_dialog(self): def open_create_account_dialog(self):
# Dialog for creating a new account
dialog = QDialog(self) dialog = QDialog(self)
self.open_dialogs.append(dialog) self.open_dialogs.append(dialog)
dialog.setWindowTitle('Create Account') dialog.setWindowTitle('Create Account')
@ -435,13 +417,68 @@ class PicomcVersionSelector(QWidget):
dialog.exec_() dialog.exec_()
self.open_dialogs.remove(dialog) self.open_dialogs.remove(dialog)
def authenticate_account(self, dialog, account_name): def open_select_account_dialog(self):
# Authenticate a selected account dialog = QDialog(self)
account_name = account_name.strip().lstrip(" * ") self.open_dialogs.append(dialog)
if not account_name: dialog.setWindowTitle('Select Account')
QMessageBox.warning(dialog, "Warning", "Please select an account to authenticate.") dialog.setFixedSize(300, 150)
return
account_combo = QComboBox()
self.populate_accounts(account_combo)
select_button = QPushButton('Select')
select_button.clicked.connect(lambda: self.set_default_account(dialog, account_combo.currentText()))
layout = QVBoxLayout()
layout.addWidget(account_combo)
layout.addWidget(select_button)
dialog.setLayout(layout)
dialog.exec_()
self.open_dialogs.remove(dialog)
def open_authenticate_account_dialog(self):
dialog = QDialog(self)
self.open_dialogs.append(dialog)
dialog.setWindowTitle('Authenticate Account')
dialog.setFixedSize(300, 150)
account_combo = QComboBox()
self.populate_accounts(account_combo)
authenticate_button = QPushButton('Authenticate')
authenticate_button.clicked.connect(lambda: self.authenticate_account(dialog, account_combo.currentText()))
layout = QVBoxLayout()
layout.addWidget(account_combo)
layout.addWidget(authenticate_button)
dialog.setLayout(layout)
dialog.exec_()
self.open_dialogs.remove(dialog)
def open_remove_account_dialog(self):
dialog = QDialog(self)
self.open_dialogs.append(dialog)
dialog.setWindowTitle('Remove Account')
dialog.setFixedSize(300, 150)
account_combo = QComboBox()
self.populate_accounts(account_combo)
remove_button = QPushButton('Remove')
remove_button.clicked.connect(lambda: self.remove_account(dialog, account_combo.currentText()))
layout = QVBoxLayout()
layout.addWidget(account_combo)
layout.addWidget(remove_button)
dialog.setLayout(layout)
dialog.exec_()
self.open_dialogs.remove(dialog)
def authenticate_account(self, dialog, account_name):
account_name = account_name.strip().lstrip(" * ")
try: try:
subprocess.run(['picomc', 'account', 'authenticate', account_name], check=True) subprocess.run(['picomc', 'account', 'authenticate', account_name], check=True)
QMessageBox.information(self, "Success", f"Account '{account_name}' authenticated successfully!") QMessageBox.information(self, "Success", f"Account '{account_name}' authenticated successfully!")
@ -450,28 +487,27 @@ class PicomcVersionSelector(QWidget):
logging.error(error_message) logging.error(error_message)
QMessageBox.critical(self, "Error", error_message) QMessageBox.critical(self, "Error", error_message)
def remove_account(self, dialog, username): def populate_accounts(self, account_combo):
# Remove a selected account try:
username = username.strip().lstrip(" * ") process = subprocess.Popen(['picomc', 'account', 'list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if not username: output, error = process.communicate()
QMessageBox.warning(dialog, "Warning", "Please select an account to remove.") if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, process.args, error)
except FileNotFoundError:
logging.error("'picomc' command not found. Please make sure it's installed and in your PATH.")
return
except subprocess.CalledProcessError as e:
logging.error("Error: %s", e.stderr)
return return
confirm_message = f"Are you sure you want to remove the account '{username}'?\nThis action cannot be undone." accounts = output.splitlines()
confirm_dialog = QMessageBox.question(dialog, "Confirm Removal", confirm_message, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) accounts = [account.replace(' *', '').strip() for account in accounts]
if confirm_dialog == QMessageBox.Yes:
try: account_combo.clear()
subprocess.run(['picomc', 'account', 'remove', username], check=True) account_combo.addItems(accounts)
QMessageBox.information(dialog, "Success", f"Account '{username}' removed successfully!")
self.populate_accounts_for_all_dialogs()
except subprocess.CalledProcessError as e:
error_message = f"Error removing account: {e.stderr.decode()}"
logging.error(error_message)
QMessageBox.critical(dialog, "Error", error_message)
def create_account(self, dialog, username, is_microsoft): def create_account(self, dialog, username, is_microsoft):
# Create a new account if username.strip() == '':
if not username.strip():
QMessageBox.warning(dialog, "Warning", "Username cannot be blank.") QMessageBox.warning(dialog, "Warning", "Username cannot be blank.")
return return
@ -480,73 +516,112 @@ class PicomcVersionSelector(QWidget):
if is_microsoft: if is_microsoft:
command.append('--ms') command.append('--ms')
subprocess.run(command, check=True) result = subprocess.run(command, check=True, capture_output=True, text=True)
QMessageBox.information(dialog, "Success", f"Account '{username}' created successfully!") QMessageBox.information(self, "Success", f"Account {username} created successfully!")
self.populate_accounts_for_all_dialogs() self.populate_accounts_for_all_dialogs()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
error_message = f"Error creating account: {e.stderr.decode()}" error_message = f"Error creating account: {e.stderr.decode()}"
logging.error(error_message) logging.error(error_message)
QMessageBox.critical(dialog, "Error", error_message) QMessageBox.critical(self, "Error", error_message)
def populate_accounts(self, account_combo):
# Populate the account dropdown
try:
process = subprocess.Popen(['picomc', 'account', 'list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
output, error = process.communicate()
if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, process.args, error)
# Process accounts, keeping the one with "*" at the top
accounts = output.splitlines()
starred_account = None
normal_accounts = []
for account in accounts:
account = account.strip()
if account.startswith('*'):
starred_account = account.lstrip(' *').strip()
else:
normal_accounts.append(account)
# Clear the combo box and add accounts
account_combo.clear()
# Add the starred account first, if exists
if starred_account:
account_combo.addItem(f"* {starred_account}")
# Add the normal accounts
for account in normal_accounts:
account_combo.addItem(account)
except FileNotFoundError:
logging.error("'picomc' command not found. Please make sure it's installed and in your PATH.")
except subprocess.CalledProcessError as e:
logging.error(f"Error: {e.stderr}")
def populate_accounts_for_all_dialogs(self): def populate_accounts_for_all_dialogs(self):
# Update account dropdowns in all open dialogs
for dialog in self.open_dialogs: for dialog in self.open_dialogs:
combo_box = dialog.findChild(QComboBox) combo_box = dialog.findChild(QComboBox)
if combo_box: if combo_box:
self.populate_accounts(combo_box) self.populate_accounts(combo_box)
def set_default_account(self, account_name, dialog): def set_default_account(self, dialog, account):
# Set the selected account as the default dialog.close()
account_name = account_name.strip().lstrip(" * ") try:
if not account_name: subprocess.run(['picomc', 'account', 'setdefault', account], check=True)
QMessageBox.warning(dialog, "Warning", "Please select an account to set as default.") QMessageBox.information(self, "Success", f"Default account set to {account}!")
except subprocess.CalledProcessError as e:
error_message = f"Error setting default account: {e.stderr.decode()}"
logging.error(error_message)
QMessageBox.critical(self, "Error", error_message)
def remove_account(self, dialog, username):
if username.strip() == '':
QMessageBox.warning(dialog, "Warning", "Please select an account to remove.")
return
username = username.strip().lstrip(" * ")
confirm_message = f"Are you sure you want to remove the account '{username}'?\nThis action cannot be undone."
confirm_dialog = QMessageBox.question(self, "Confirm Removal", confirm_message, QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if confirm_dialog == QMessageBox.Yes:
confirm_message_again = "This action is irreversible. Are you absolutely sure?"
confirm_dialog_again = QMessageBox.question(self, "Confirm Removal", confirm_message_again, QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if confirm_dialog_again == QMessageBox.Yes:
try:
subprocess.run(['picomc', 'account', 'remove', username], check=True)
QMessageBox.information(self, "Success", f"Account '{username}' removed successfully!")
self.populate_accounts_for_all_dialogs()
except subprocess.CalledProcessError as e:
error_message = f"Error removing account: {e.stderr.decode()}"
logging.error(error_message)
QMessageBox.critical(self, "Error", error_message)
def create_account(self, dialog, username, is_microsoft):
if username.strip() == '':
QMessageBox.warning(dialog, "Warning", "Username cannot be blank.")
return return
try: try:
subprocess.run(['picomc', 'account', 'setdefault', account_name], check=True) command = ['picomc', 'account', 'create', username]
QMessageBox.information(self, "Success", f"Account '{account_name}' set as default!") if is_microsoft:
command.append('--ms')
result = subprocess.run(command, check=True, capture_output=True, text=True)
QMessageBox.information(self, "Success", f"Account {username} created successfully!")
self.populate_accounts_for_all_dialogs() self.populate_accounts_for_all_dialogs()
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
error_message = f"Error setting default account '{account_name}': {e.stderr.decode()}" error_message = f"Error creating account: {e.stderr.decode()}"
logging.error(error_message) logging.error(error_message)
QMessageBox.critical(self, "Error", error_message) QMessageBox.critical(self, "Error", error_message)
def populate_accounts_for_all_dialogs(self):
for dialog in self.open_dialogs:
combo_box = dialog.findChild(QComboBox)
if combo_box:
self.populate_accounts(combo_box)
def set_default_account(self, dialog, account):
dialog.close()
try:
subprocess.run(['picomc', 'account', 'setdefault', account], check=True)
QMessageBox.information(self, "Success", f"Default account set to {account}!")
except subprocess.CalledProcessError as e:
error_message = f"Error setting default account: {e.stderr.decode()}"
logging.error(error_message)
QMessageBox.critical(self, "Error", error_message)
def remove_account(self, dialog, username):
if username.strip() == '':
QMessageBox.warning(dialog, "Warning", "Please select an account to remove.")
return
username = username.strip().lstrip(" * ")
confirm_message = f"Are you sure you want to remove the account '{username}'?\nThis action cannot be undone."
confirm_dialog = QMessageBox.question(self, "Confirm Removal", confirm_message, QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if confirm_dialog == QMessageBox.Yes:
confirm_message_again = "This action is irreversible. Are you absolutely sure?"
confirm_dialog_again = QMessageBox.question(self, "Confirm Removal", confirm_message_again, QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if confirm_dialog_again == QMessageBox.Yes:
try:
subprocess.run(['picomc', 'account', 'remove', username], check=True)
QMessageBox.information(self, "Success", f"Account '{username}' removed successfully!")
self.populate_accounts_for_all_dialogs()
except subprocess.CalledProcessError as e:
error_message = f"Error removing account: {e.stderr.decode()}"
logging.error(error_message)
QMessageBox.critical(self, "Error", error_message)
def show_about_dialog(self): def show_about_dialog(self):
# Load the version number from version.json # Load the version number from version.json
try: try:
@ -1031,6 +1106,7 @@ class ModLoaderAndVersionMenu(QDialog):
logging.error(error_message) logging.error(error_message)
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(sys.argv) app = QApplication(sys.argv)
current_date = datetime.now() current_date = datetime.now()

View File

@ -1,5 +1,5 @@
{ {
"version": "0.9.9.7", "version": "0.9.9.3",
"links": [ "links": [
"https://raw.githubusercontent.com/nixietab/picodulce/main/version.json", "https://raw.githubusercontent.com/nixietab/picodulce/main/version.json",
"https://raw.githubusercontent.com/nixietab/picodulce/main/picodulce.py", "https://raw.githubusercontent.com/nixietab/picodulce/main/picodulce.py",