Compare commits
No commits in common. "f805295620d53de80d5fce32430e358f34a20291" and "603acb60f6fcfd89b06147f45b33f334bc2bac67" have entirely different histories.
f805295620
...
603acb60f6
|
@ -26,31 +26,32 @@ class Window(QtWidgets.QMainWindow):
|
||||||
def set_size(self, size_x, size_y):
|
def set_size(self, size_x, size_y):
|
||||||
self.resize(size_x, size_y)
|
self.resize(size_x, size_y)
|
||||||
|
|
||||||
def update_menus(self, menu_dict, menu=None):
|
def update_menus(self, menu_dict):
|
||||||
# if not a sub menu
|
menu = self.menuBar()
|
||||||
if menu == None:
|
|
||||||
menu = self.menuBar()
|
|
||||||
menu.clear()
|
|
||||||
|
|
||||||
#Looping through entire menu_dict
|
#Looping through entire menu_dict
|
||||||
for entry in menu_dict:
|
for topmenu, submenu in menu_dict.items():
|
||||||
# inactive or separator
|
#making top level menu
|
||||||
if menu_dict[entry] == None:
|
menu_item = menu.addMenu(topmenu)
|
||||||
# determine if entry is a separator or an inactive menu item
|
|
||||||
if type(entry) == int:
|
#adding menu items (populating menu)
|
||||||
menu.addSeparator()
|
for inner, data in submenu.items():
|
||||||
|
#Adding submenu and populating it
|
||||||
|
if type(data) == dict:
|
||||||
|
sub = menu_item.addMenu(inner)
|
||||||
|
for label, func in data.items():
|
||||||
|
sub.addAction(label)
|
||||||
|
|
||||||
|
if func == None:
|
||||||
|
sub.triggered.connect(lambda x: None)
|
||||||
|
else:
|
||||||
|
sub.triggered.connect(func)
|
||||||
|
#Adding separators
|
||||||
|
elif inner == None:
|
||||||
|
menu_item.addSeparator()
|
||||||
else:
|
else:
|
||||||
menu_item = menu.addAction(entry)
|
item = menu_item.addAction(inner)
|
||||||
menu_item.setEnabled(False)
|
item.triggered.connect(data)
|
||||||
# sub menus
|
|
||||||
if type(menu_dict[entry]) == dict:
|
|
||||||
submenu = menu.addMenu(entry)
|
|
||||||
# recurse because sub menus may have sub menus
|
|
||||||
self.update_menus(menu_dict[entry], menu=submenu)
|
|
||||||
# ordinary menu entries
|
|
||||||
if callable(menu_dict[entry]):
|
|
||||||
menu_item = menu.addAction(entry)
|
|
||||||
menu_item.triggered.connect(menu_dict[entry])
|
|
||||||
|
|
||||||
#TODO: This needs to run in a thread but Qt really doesn't want it to. There are two ways around this:
|
#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
|
# - create the QtWidgets.QApplication inside a thread and run all QT stuff inside that thread
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import tkinter as tk
|
||||||
import util
|
import util
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,13 +9,13 @@ def not_implemented():
|
||||||
# "":{} -> menu or submenu
|
# "":{} -> menu or submenu
|
||||||
# "":function -> menu entry
|
# "":function -> menu entry
|
||||||
# "":None -> disabled menu entry
|
# "":None -> disabled menu entry
|
||||||
# int:None -> separator
|
# None:None -> separator
|
||||||
#
|
#
|
||||||
# Entries with ... at the end are supposed to open dialogs whereas entries without dots are supposed to take effect immediately
|
# Entries with ... at the end are supposed to open dialogs whereas entries without dots are supposed to take effect immediately
|
||||||
menu_structure = {
|
menu_structure = {
|
||||||
"IDE": {
|
"IDE": {
|
||||||
"Preferences...": not_implemented,
|
"Preferences...": not_implemented,
|
||||||
0: None,
|
None: None,
|
||||||
"Quit": not_implemented
|
"Quit": not_implemented
|
||||||
},
|
},
|
||||||
"Project": {
|
"Project": {
|
||||||
|
@ -25,7 +26,7 @@ menu_structure = {
|
||||||
"Close": {
|
"Close": {
|
||||||
"No open projects": None
|
"No open projects": None
|
||||||
},
|
},
|
||||||
0: None,
|
None: None,
|
||||||
"Preferences...": not_implemented,
|
"Preferences...": not_implemented,
|
||||||
"Search...": not_implemented,
|
"Search...": not_implemented,
|
||||||
"Build": not_implemented
|
"Build": not_implemented
|
||||||
|
@ -35,7 +36,7 @@ menu_structure = {
|
||||||
"Open...": not_implemented,
|
"Open...": not_implemented,
|
||||||
"Save": not_implemented,
|
"Save": not_implemented,
|
||||||
"Close": not_implemented,
|
"Close": not_implemented,
|
||||||
0: None,
|
None: None,
|
||||||
"Rename...": not_implemented,
|
"Rename...": not_implemented,
|
||||||
"Move...": not_implemented,
|
"Move...": not_implemented,
|
||||||
"View in File Explorer...": not_implemented
|
"View in File Explorer...": not_implemented
|
||||||
|
@ -45,9 +46,9 @@ menu_structure = {
|
||||||
"Copy": not_implemented,
|
"Copy": not_implemented,
|
||||||
"Paste": not_implemented,
|
"Paste": not_implemented,
|
||||||
"Move code...": not_implemented,
|
"Move code...": not_implemented,
|
||||||
0: None,
|
None: None,
|
||||||
"Search and Replace...": not_implemented,
|
"Search and Replace...": not_implemented,
|
||||||
1: None,
|
None: None,
|
||||||
"Format": not_implemented,
|
"Format": not_implemented,
|
||||||
"Indent": not_implemented,
|
"Indent": not_implemented,
|
||||||
"Unindent": not_implemented,
|
"Unindent": not_implemented,
|
||||||
|
@ -63,3 +64,21 @@ menu_structure = {
|
||||||
"About IDE...": not_implemented,
|
"About IDE...": not_implemented,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#FIXME: come up with a way to uniquely declare separators so they don't become the same element of a dict
|
||||||
|
|
||||||
|
def build_menu(structure_dict, menu):
|
||||||
|
for entry in structure_dict:
|
||||||
|
if structure_dict[entry]==None:
|
||||||
|
if entry==None:
|
||||||
|
menu.add_separator()
|
||||||
|
else:
|
||||||
|
menu.add_command(label=entry)
|
||||||
|
menu.entryconfig(entry, state="disabled")
|
||||||
|
if isinstance(structure_dict[entry], dict):
|
||||||
|
submenu = tk.Menu(menu, tearoff=False)
|
||||||
|
build_menu(structure_dict[entry], submenu)
|
||||||
|
menu.add_cascade(label=entry, menu=submenu)
|
||||||
|
if callable(structure_dict[entry]):
|
||||||
|
menu.add_command(label=entry, command=structure_dict[entry])
|
||||||
|
|
||||||
|
|
4
main.py
4
main.py
|
@ -29,10 +29,14 @@ configuration = Config(configuration_file_path, default_configuration)
|
||||||
# It seems like opening multiple instances already works as intended
|
# It seems like opening multiple instances already works as intended
|
||||||
|
|
||||||
main_window = gui_handler.Window()
|
main_window = gui_handler.Window()
|
||||||
|
main_window2 = gui_handler.Window()
|
||||||
main_window.set_title("Concorde IDE")
|
main_window.set_title("Concorde IDE")
|
||||||
|
main_window2.set_title("Another window")
|
||||||
main_window.set_size(configuration.get_configuration_value("window size")["x"], configuration.get_configuration_value("window size")["y"])
|
main_window.set_size(configuration.get_configuration_value("window size")["x"], configuration.get_configuration_value("window size")["y"])
|
||||||
|
main_window2.set_size(400, 500)
|
||||||
|
|
||||||
main_window.update_menus(gui_helper.menu_structure)
|
main_window.update_menus(gui_helper.menu_structure)
|
||||||
|
main_window2.update_menus(gui_helper.menu_structure)
|
||||||
|
|
||||||
|
|
||||||
#TODO: get resolution of main window on exit and save it back to the configuration
|
#TODO: get resolution of main window on exit and save it back to the configuration
|
||||||
|
|
Reference in New Issue