move resize event handling to the generic Window class

master
BodgeMaster 2022-03-28 15:45:17 +02:00
parent 964668467c
commit 72d30b4688
1 changed files with 11 additions and 3 deletions

View File

@ -6,10 +6,11 @@ app = QtWidgets.QApplication([])
#TODO: Implement separate editor, terminal and main_window classes using Window as a parent
class Window(QtWidgets.QMainWindow):
def __init__(self, size=(640, 480), title="Concorde"):
def __init__(self, size=(640, 480), title="Concorde", on_resize=lambda event: None):
super().__init__()
self.setWindowTitle(title)
self.resize(size[0], size[1])
self.__on_resize = on_resize
def __del__(self):
#TODO: whatever needs to be done here
@ -26,6 +27,9 @@ class Window(QtWidgets.QMainWindow):
def set_size(self, size_x, size_y):
self.resize(size_x, size_y)
def on_resize(self, function):
self.__on_resize = function
def update_menus(self, menu_dict, menu=None):
# if not a sub menu
if menu == None:
@ -52,6 +56,11 @@ class Window(QtWidgets.QMainWindow):
menu_item = menu.addAction(entry)
menu_item.triggered.connect(menu_dict[entry])
# Toolkit specific! Do not use outside gui_handler.
def resizeEvent(self, event):
self.__on_resize(event)
class Editor(Window):
def __init__(self, size=(640, 480)):
super().__init__(size, "Editor")
@ -72,8 +81,7 @@ class Editor(Window):
self.setLayout(layout)
def resizeEvent(self, event):
self.set_size(event.size().width(), event.size().height())
super().on_resize(lambda event: self.set_size(event.size().width(), event.size().height()))
#FIXME: This function is inherently flawed because it doesn't take the
# actual height of the usable area inside the window into account.