Initial hack to get things started with gui_handler

The main window now doesn’t use Tk. It uses gui_handler now which has an initial implementation for Qt.
master
BodgeMaster 2022-03-19 11:50:15 +01:00
parent ae6fe2896c
commit 507747d5be
2 changed files with 49 additions and 14 deletions

View File

@ -1,13 +1,40 @@
class window:
def __init__(self):
pass
from PySide6 import QtWidgets
import util
gui_handler_communication = util.Communication()
app = QtWidgets.QApplication([])
class Window:
def __init__(self, title="Concorde", size_x=640, size_y=480):
self.window = QtWidgets.QWidget()
self.window.setWindowTitle(title)
self.window.resize(size_x, size_y)
self.window.show()
def __del__(self):
#TODO: whatever needs to be done here
pass
def set_title(self, title):
pass
def get_geometry(self):
self.window.setWindowTitle(title)
def get_size(self):
#TODO: implement
util.warn("Not implemented!")
return None
def set_geometry(self, geometry):
pass
def set_size(self, size_x, size_y):
self.window.resize(size_x, size_y)
def update_menus(self, menu_dict):
pass
#TODO: implement
util.warn("Not implemented!")
#TODO: This needs to run in a thread but Qt really doesn't want it to. There are two ways around this:
# - create the QtWidgets.QApplication inside a thread and run all QT stuff inside that thread
# - make a generic wrapper for window mainloop that will always run in the main thread while the actual main control flow of the program gets moved to another thread
# There are some issues with these workarounds though; mainly that QT isn't thread safe.
# I really want to keep QT running in its own thread because I want to retain the ability to arbitrarily spawn and manipulate windows while other windows are running.
# Another issue that is probably easily worked around / fixed is that app.exec() will return once all running windows are closed.
def fixme_window_mainloop_workaround_to_just_get_a_window_started_really_should_not_be_implemented_this_way_for_reasons_stated_in_the_comment_above_the_definition_of_this_function():
app.exec()

20
main.py
View File

@ -1,7 +1,6 @@
#!/usr/bin/python3
import os
import gui_helper
import gui_handler
import gui_helper, gui_handler
from config import Config
################################################################################
@ -9,9 +8,13 @@ from config import Config
################################################################################
default_configuration = {
"window geometry": "640x480"
"window size": {
"x": 800,
"y": 600
}
}
configuration_file_path = os.path.join(os.path.expanduser("~"), "some_ide_config.json")
#TODO: make this a hidden file once development is far enough along that it doesnt need to be recreated constantly
configuration_file_path = os.path.join(os.path.expanduser("~"), "concorde.json")
################################################################################
# PROGRAM STARTUP
@ -23,8 +26,13 @@ configuration = Config(configuration_file_path, default_configuration)
# PROGRAM MAIN WINDOW
################################################################################
main_window = gui_handler.window()
main_window = gui_handler.Window()
main_window.set_title("Concorde IDE")
main_window.set_geometry(configuration.get_configuration_value("window geometry"))
main_window.set_size(configuration.get_configuration_value("window size")["x"], configuration.get_configuration_value("window size")["y"])
main_window.update_menus(gui_helper.menu_structure)
#TODO: get resolution of main window on exit and save it back to the configuration
#TODO: check if the GUI encountered an error in a toolkit agnostic way
gui_handler.fixme_window_mainloop_workaround_to_just_get_a_window_started_really_should_not_be_implemented_this_way_for_reasons_stated_in_the_comment_above_the_definition_of_this_function()