95 lines
3.9 KiB
Python
95 lines
3.9 KiB
Python
|
import os
|
||
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||
|
import configparser
|
||
|
|
||
|
# Load configuration from file
|
||
|
config = configparser.ConfigParser()
|
||
|
config.read('dbgr.conf')
|
||
|
|
||
|
class ConfigEditor(QtWidgets.QMainWindow):
|
||
|
def __init__(self, parent=None):
|
||
|
super().__init__(parent)
|
||
|
self.setGeometry(100, 100, 600, 150) # Set window size to 600x150 pixels
|
||
|
self.create_widgets()
|
||
|
|
||
|
def create_widgets(self):
|
||
|
central_widget = QtWidgets.QWidget(self)
|
||
|
self.setCentralWidget(central_widget)
|
||
|
|
||
|
# Create labels and entry fields for each config variable
|
||
|
dosbox_path_label = QtWidgets.QLabel('DOSBox Path', central_widget)
|
||
|
self.dosbox_path_entry = QtWidgets.QLineEdit(central_widget)
|
||
|
self.dosbox_path_entry.setText(config['DEFAULT']['dosbox_path'])
|
||
|
|
||
|
game_path_label = QtWidgets.QLabel('Game Path', central_widget)
|
||
|
self.game_path_entry = QtWidgets.QLineEdit(central_widget)
|
||
|
self.game_path_entry.setText(config['DEFAULT']['game_path'])
|
||
|
self.browse_button = QtWidgets.QPushButton('Browse', central_widget)
|
||
|
self.browse_button.clicked.connect(self.browse_game_path)
|
||
|
|
||
|
working_directory_label = QtWidgets.QLabel('Working Directory', central_widget)
|
||
|
self.working_directory_entry = QtWidgets.QLineEdit(central_widget)
|
||
|
self.working_directory_entry.setText(config['DEFAULT']['working_directory'])
|
||
|
|
||
|
cycles_label = QtWidgets.QLabel('Cycles', central_widget)
|
||
|
self.cycles_entry = QtWidgets.QLineEdit(central_widget)
|
||
|
self.cycles_entry.setText(config['DEFAULT']['-cycles'])
|
||
|
|
||
|
memsize_label = QtWidgets.QLabel('Memsize', central_widget)
|
||
|
self.memsize_entry = QtWidgets.QLineEdit(central_widget)
|
||
|
self.memsize_entry.setText(config['DEFAULT']['-memsize'])
|
||
|
|
||
|
# Create save button
|
||
|
save_button = QtWidgets.QPushButton('Save', central_widget)
|
||
|
save_button.clicked.connect(self.save_config)
|
||
|
|
||
|
# Set layout
|
||
|
layout = QtWidgets.QGridLayout(central_widget)
|
||
|
layout.addWidget(dosbox_path_label, 0, 0)
|
||
|
layout.addWidget(self.dosbox_path_entry, 0, 1)
|
||
|
layout.addWidget(game_path_label, 1, 0)
|
||
|
layout.addWidget(self.game_path_entry, 1, 1)
|
||
|
layout.addWidget(self.browse_button, 1, 2)
|
||
|
layout.addWidget(working_directory_label, 2, 0)
|
||
|
layout.addWidget(self.working_directory_entry, 2, 1)
|
||
|
layout.addWidget(cycles_label, 3, 0)
|
||
|
layout.addWidget(self.cycles_entry, 3, 1)
|
||
|
layout.addWidget(memsize_label, 4, 0)
|
||
|
layout.addWidget(self.memsize_entry, 4, 1)
|
||
|
layout.addWidget(save_button, 5, 0, 1, 2)
|
||
|
|
||
|
def browse_game_path(self):
|
||
|
# Set initial directory to script directory
|
||
|
initial_dir = os.path.dirname(__file__)
|
||
|
|
||
|
# Open file dialog to select game file
|
||
|
filetypes = [('All files', '*.*')]
|
||
|
game_file, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Select game file', initial_dir, ';;'.join(['{} (*.{})'.format(ft.upper(), ft) for ft in ['exe', 'com', 'bat']]))
|
||
|
if game_file:
|
||
|
self.game_path_entry.setText(game_file)
|
||
|
self.working_directory_entry.setText(os.path.dirname(game_file))
|
||
|
|
||
|
def save_config(self):
|
||
|
# Update configuration with values from entry fields
|
||
|
config['DEFAULT']['dosbox_path'] = self.dosbox_path_entry.text()
|
||
|
config['DEFAULT']['game_path'] = self.game_path_entry.text()
|
||
|
config['DEFAULT']['working_directory'] = self.working_directory_entry.text()
|
||
|
config['DEFAULT']['-cycles'] = self.cycles_entry.text()
|
||
|
config['DEFAULT']['-memsize'] = self.memsize_entry.text()
|
||
|
|
||
|
# Write updated configuration to file
|
||
|
with open('dbgr.conf', 'w') as configfile:
|
||
|
config.write(configfile)
|
||
|
|
||
|
# Close GUI window
|
||
|
self.close()
|
||
|
|
||
|
# Create and run GUI application
|
||
|
if __name__ == '__main__':
|
||
|
import sys
|
||
|
app = QtWidgets.QApplication(sys.argv)
|
||
|
editor = ConfigEditor()
|
||
|
editor.show()
|
||
|
sys.exit(app.exec_())
|
||
|
|