Compare commits

...

5 Commits

Author SHA1 Message Date
BodgeMaster 72d30b4688 move resize event handling to the generic Window class 2022-03-28 15:45:17 +02:00
BodgeMaster 964668467c added FIXMES for two problems 2022-03-28 15:43:58 +02:00
Milan Suman 0f3e9b0689 fixed resize event 2022-03-28 00:30:44 +05:30
Milan Suman b7018e1a73 began work on code editor 2022-03-27 15:57:58 +05:30
Milan Suman 33e42e411c Started work on editor class 2022-03-26 14:13:00 +05:30
2 changed files with 47 additions and 6 deletions

View File

@ -1,14 +1,16 @@
from PySide6 import QtWidgets
from PySide6 import QtWidgets, QtCore, QtGui
import util
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.show()
self.__on_resize = on_resize
def __del__(self):
#TODO: whatever needs to be done here
@ -25,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:
@ -51,6 +56,40 @@ 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")
#TODO: Figure out a way to do the fucking line numbers
#Text Editor
self.text_edit = QtWidgets.QPlainTextEdit(self)
self.text_edit.setFrameStyle(QtWidgets.QFrame.NoFrame)
self.set_size(size[0], size[1])
#layout
#FIXME: Somehow this places the editor behind the menu bar so that the
# first couple lines are cut off
layout = QtWidgets.QHBoxLayout()
layout.addChildWidget(self.text_edit)
self.setLayout(layout)
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.
# On a side note: This should be taken care of by the toolkit (Qt).
def set_size(self, size_x, size_y):
self.text_edit.resize(size_x, size_y)
self.resize(size_x, size_y)
class Message(QtWidgets.QMessageBox):
def __init__(self, title, text):

View File

@ -26,11 +26,13 @@ configuration = Config(configuration_file_path, default_configuration)
# PROGRAM MAIN WINDOW
################################################################################
main_window = gui_handler.Window()
main_window.set_title("Concorde IDE")
main_window.set_size(configuration.get_configuration_value("window size")["x"], configuration.get_configuration_value("window size")["y"])
#Commented out so that I can work on the dockable windows
main_window = gui_handler.Editor((configuration.get_configuration_value("window size")["x"], configuration.get_configuration_value("window size")["y"]))
main_window.set_title("Concorde IDE")
main_window.update_menus(gui_helper.menu_structure)
main_window.show()
#TODO: get resolution of main window on exit and save it back to the configuration