diff --git a/src/simudator/gui/gui.py b/src/simudator/gui/gui.py index bb165ca84e013d0459054cbbdf410ea9877bd7eb..8d649c05c74f7f33eefc50ed222349d564abd1b0 100644 --- a/src/simudator/gui/gui.py +++ b/src/simudator/gui/gui.py @@ -259,6 +259,19 @@ class GUI(QMainWindow): toolbar.addWidget(self.clock_label) def connectModuleActions(self, action_signals: []) -> None: + """ + This function takes a list of tuples with an + action id (which is a predefined string) and a signal. + It then connects the signal to a function depending on the action id. + We do this so graphics items actions can access functionalty + that is contolled by the gui and cpu. Mainly creating breakpoints. + + We do this instead of sending the graphics items the cpu or + creating actions in the gpu. Sending the cpu directly to the + graphics items could become problematic when many sources + affect the cpu in unexpected ways, and creating these + actions in the gpu would make the graphics items much less modular. + """ for action_id, signal in action_signals: match action_id: case "BP": diff --git a/src/simudator/gui/module_graphics_item/memory_graphic.py b/src/simudator/gui/module_graphics_item/memory_graphic.py index 31c5f64ecc79410be706c3bba308783b67fb900a..e1d2e995b6f4005a9c6fd4ef976edde757c7243b 100644 --- a/src/simudator/gui/module_graphics_item/memory_graphic.py +++ b/src/simudator/gui/module_graphics_item/memory_graphic.py @@ -135,6 +135,7 @@ class MemoryGraphicsItem(ModuleGraphicsItem): return super().shouldIgnoreAction(action) def generateActions(self) -> []: + # Make parent actions and then add memory specific actions super().generateActions() memory_br_action = QAction('Add memory breakpoint', self) @@ -167,6 +168,9 @@ class MemoryGraphicsItem(ModuleGraphicsItem): def memoryBreakpointAccepted(self, module_name: str, adress: str, value: str) -> None: + """ + Takes the info from a breakpoint dialog and sends it to the gui + """ try: self.new_memory_breakpoint_signal.emit(module_name, adress, value) except SyntaxError as e: @@ -174,6 +178,11 @@ class MemoryGraphicsItem(ModuleGraphicsItem): @pyqtSlot(str, str, str) def editMemoryAccepted(self, module_name: str, adress: str, value: str) -> None: + """ + Takes the info from a edit memory dialog + and updates the memory content accordingly. + Also asks the gui to update. + """ try: parsed_adress = int(adress) except SyntaxError as e: @@ -185,6 +194,7 @@ class MemoryGraphicsItem(ModuleGraphicsItem): self.update_graphics_signal.emit() def getActionSignals(self) -> []: + # Do parent signals and then add memory specific signals signals = super().getActionSignals() signals.append(("MEM_BP", self.new_memory_breakpoint_signal)) return signals diff --git a/src/simudator/gui/module_graphics_item/mia/mia_memory_graphic.py b/src/simudator/gui/module_graphics_item/mia/mia_memory_graphic.py index 5eab4dac748c1629f010a1b8a1f947667df7ddce..07f408d184ea5fc5f48294816d6ecb4e7c5545be 100644 --- a/src/simudator/gui/module_graphics_item/mia/mia_memory_graphic.py +++ b/src/simudator/gui/module_graphics_item/mia/mia_memory_graphic.py @@ -116,6 +116,9 @@ class MiaMemoryGraphicsItem(MemoryGraphicsItem): def memoryBreakpointAccepted(self, module_name: str, adress: str, value: str) -> None: + """ + Same as prent function but also prases data so it is hexadecimal. + """ try: parsed_adress = int(adress, 16) parsed_value = ast.literal_eval(value) @@ -131,6 +134,9 @@ class MiaMemoryGraphicsItem(MemoryGraphicsItem): @pyqtSlot(str, str, str) def editMemoryAccepted(self, module_name: str, adress: str, value: str) -> None: + """ + Same as prent function but also prases data so it is hexadecimal. + """ try: parsed_adress = int(adress, 16) parsed_value = ast.literal_eval(value) diff --git a/src/simudator/gui/module_graphics_item/module_graphics_item.py b/src/simudator/gui/module_graphics_item/module_graphics_item.py index a63c9301cc88b1f16e0308c4e203a1943894a5b3..66a8af697255f2c1b60c350dd49623ea4e6d482f 100644 --- a/src/simudator/gui/module_graphics_item/module_graphics_item.py +++ b/src/simudator/gui/module_graphics_item/module_graphics_item.py @@ -179,6 +179,11 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): @pyqtSlot(str, str, str) def editModuleState(self, module_name, state, value) -> None: + """ + This function will be run when the edit module actions + dialog is okey'd by the user. + It will take the info from the dialog and edit the module accordinly. + """ try: parsed_value = ast.literal_eval(value) except SyntaxError as e: @@ -187,6 +192,7 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): module_state = self.module.get_state() module_state[state] = parsed_value self.module.set_state(module_state) + # Since we have changed a value we send a signal to the gui to update self.update_graphics_signal.emit() def update(self): @@ -247,16 +253,23 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): return menu def generateActions(self) -> None: + """ + Generates the default actions avalible in the context menu ofthe item. + All other modules will also have these but may also add more actions. + """ + # Create action to make all ports visible self.show_ports_action = QAction("Show all ports") self.show_ports_action.triggered.connect(self.showPorts) self.show_ports_action.setEnabled(not self.isLocked) self.actions.append(self.show_ports_action) + # Create action to add breakpoint i items module state_br_action = QAction('Add breakpoint', self) state_br_action.triggered.connect(self.stateBreakpointDialog) self.actions.append(state_br_action) + # Create action to edit items module edit_state_action = QAction('Edit module state', self) edit_state_action.triggered.connect(self.editModuleStateDialog) self.actions.append(edit_state_action) @@ -318,6 +331,14 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): return self.actions def getActionSignals(self) -> []: + """ + This function returns a list of tuples with action ids and signals. + The gui will connect these signals to functions depending on the id. + This is mostly used so items can ask the gui to create breakpoints + or ask it to updat functions depending on the id. + This is mostly used so items can ask the gui to create breakpoints + or ask it to update. + """ signals = [] signals.append(("BP", self.new_state_breakpoint_signal)) signals.append(("UPDATE", self.update_graphics_signal)) @@ -325,6 +346,10 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): @pyqtSlot(str, str, str) def stateBreakpointAccepted(self, module_name: str, state: str, value: str) -> None: + """ + This function takes the info from a breakpoint dialog and sends it to the gui. + Other items might replace this function to parse the data. + """ try: self.new_state_breakpoint_signal.emit(module_name, state, value) except (ValueError, SyntaxError) as e: