diff --git a/mia_layout b/mia_layout index 101be585e8d128145708a4e4143db2a12c90bc8d..389240da584aad71d3c3d98738e2e62a8b958cb1 100644 --- a/mia_layout +++ b/mia_layout @@ -1 +1 @@ -[{"Bus": [687.0, 298.0], "uPC": [1175.0, 371.0], "SuPC": [1034.0, 373.0], "PC": [862.0, 452.0], "AR": [476.0, 408.0], "ASR": [483.0, 460.0], "HR": [862.0, 497.0], "uM": [985.0, 695.0], "ALU": [451.0, 292.0], "GRx": [186.0, 628.0], "IR": [757.0, 293.0], "Z-Flag": [186.0, 579.0], "N-Flag": [186.0, 532.0], "C-Flag": [186.0, 484.0], "O-Flag": [186.0, 435.0], "L-Flag": [186.0, 387.0], "LC": [209.0, 341.0], "PM": [427.0, 504.0], "K1": [955.0, 457.0], "K2": [1137.0, 457.0]}, {"0": [0.0, 180.0, 1, true], "1": [10.0, 0.0, 3, true], "2": [10.0, 80.0, 3, true], "3": [0.0, 231.0, 1, true], "4": [0.0, 255.0, 1, true], "5": [10.0, 160.0, 3, true], "6": [10.0, 180.0, 3, true], "7": [0.0, 38.0, 1, true], "8": [0.0, 146.0, 1, true], "9": [10.0, 210.0, 3, true], "10": [10.0, 233.0, 3, true], "11": [0.0, 415.0, 1, true], "12": [0.0, 435.0, 1, true], "13": [17.0, 0.0, 0, true], "14": [61.0, 15.0, 3, true], "15": [0.0, 7.0, 1, true], "16": [0.0, 34.0, 1, true], "17": [69.0, 32.0, 3, true], "18": [69.0, 5.0, 3, true], "19": [0.0, 6.0, 1, true], "20": [0.0, 26.0, 1, true], "21": [69.0, 36.0, 3, true], "22": [0.0, 11.0, 1, true], "23": [34.5, 0.0, 0, true], "24": [61.0, 18.0, 3, true], "25": [0.0, 24.0, 1, true], "26": [0.0, 11.0, 1, true], "27": [0.0, 34.0, 1, true], "28": [0.0, 25.0, 1, true], "29": [0.0, 26.0, 1, true], "30": [120.0, 44.0, 3, true], "31": [59.0, 60.0, 2, true], "32": [187.0, 85.0, 3, true], "33": [187.0, 105.0, 3, true], "34": [150.0, 25.0, 3, true], "35": [150.0, 49.0, 3, true], "36": [0.0, 18.0, 1, true], "37": [123.0, 0.0, 0, true], "38": [17.0, 0.0, 0, true], "39": [37.5, 200.0, 2, true], "40": [38.0, 0.0, 0, true], "41": [132.0, 0.0, 0, true], "42": [37.5, 200.0, 2, true]}, {"0": [[[679.0, 478.0], [640.0, 478.0], [640.0, 478.0], [552.0, 478.0]], true], "1": [[[679.0, 529.0], [632.0, 529.0], [632.0, 529.0], [585.0, 529.0]], true], "2": [[[679.0, 553.0], [616.0, 553.0], [616.0, 553.0], [585.0, 553.0]], true], "3": [[[705.0, 458.0], [782.0, 458.0], [782.0, 458.0], [854.0, 458.0]], true], "4": [[[705.0, 478.0], [842.0, 478.0], [842.0, 478.0], [854.0, 478.0]], true], "5": [[[679.0, 336.0], [623.0, 336.0], [623.0, 336.0], [579.0, 336.0]], true], "6": [[[679.0, 444.0], [671.0, 444.0], [671.0, 444.0], [553.0, 444.0]], true], "7": [[[705.0, 508.0], [842.0, 508.0], [842.0, 508.0], [854.0, 508.0]], true], "8": [[[705.0, 531.0], [854.0, 531.0], [854.0, 531.0], [854.0, 531.0]], true], "9": [[[679.0, 713.0], [643.5, 713.0], [643.5, 713.0], [381.0, 713.0]], true], "10": [[[679.0, 733.0], [643.5, 733.0], [643.5, 733.0], [381.0, 733.0]], true], "11": [[[1192.0, 363.0], [1192.0, 363.0], [1192.0, 338.0], [972.0, 338.0], [972.0, 449.0], [972.0, 449.0]], true], "12": [[[1244.0, 386.0], [1268.0, 386.0], [1268.0, 449.0], [1269.0, 449.0]], true], "13": [[[1167.0, 378.0], [1121.0, 378.0], [1121.0, 378.0], [1111.0, 378.0]], true], "14": [[[1167.0, 405.0], [1112.0, 405.0], [1112.0, 405.0], [1111.0, 405.0]], true], "15": [[[468.0, 419.0], [407.0, 419.0], [407.0, 318.0], [443.0, 318.0]], true], "16": [[[510.5, 400.0], [510.0, 400.0], [510.0, 360.0], [510.0, 360.0]], true], "17": [[[475.0, 484.0], [419.0, 484.0], [419.0, 522.0], [419.0, 522.0]], true], "18": [[[1078.0, 449.0], [1137.0, 449.0], [1137.0, 449.0], [1175.0, 449.0]], true]}] +[{"Bus": [815.0, 332.0], "uPC": [999.0, 243.0], "SuPC": [1132.0, 242.0], "PC": [885.0, 491.0], "AR": [561.0, 494.0], "ASR": [596.0, 271.0], "HR": [563.0, 564.0], "uM": [355.0, 621.0], "ALU": [543.0, 380.0], "GRx": [407.0, 727.0], "IR": [651.0, 159.0], "Z-Flag": [853.0, 780.0], "N-Flag": [933.0, 780.0], "C-Flag": [1012.0, 780.0], "O-Flag": [1092.0, 780.0], "L-Flag": [1173.0, 780.0], "LC": [1197.0, 737.0], "PM": [354.0, 308.0], "K1": [979.0, 321.0], "K2": [978.0, 538.0]}, {"0": [0.0, 23.0, 1, true], "1": [10.0, 0.0, 3, true], "2": [3.0, 0.0, 0, true], "3": [0.0, 80.0, 1, true], "4": [0.0, 100.0, 1, true], "5": [10.0, 168.0, 3, true], "6": [10.0, 191.0, 3, true], "7": [0.0, 287.0, 1, true], "8": [0.0, 210.0, 1, true], "9": [0.0, 242.0, 1, true], "10": [0.0, 264.0, 1, true], "11": [0.0, 480.0, 1, true], "12": [0.0, 500.0, 1, true], "13": [0.0, 6.0, 1, true], "14": [23.0, 0.0, 0, true], "15": [61.0, 35.0, 3, true], "16": [61.0, 6.0, 3, true], "17": [0.0, 7.0, 1, true], "18": [0.0, 36.0, 1, true], "19": [0.0, 9.0, 1, true], "20": [0.0, 32.0, 1, true], "21": [25.0, 40.0, 2, true], "22": [69.0, 35.0, 3, true], "23": [41.0, 0.0, 0, true], "24": [61.0, 28.0, 3, true], "25": [0.0, 29.0, 1, true], "26": [69.0, 10.0, 3, true], "27": [69.0, 32.0, 3, true], "28": [0.0, 25.0, 1, true], "29": [90.0, 0.0, 0, true], "30": [30.0, 0.0, 0, true], "31": [60.0, 60.0, 2, true], "32": [187.0, 85.0, 3, true], "33": [187.0, 105.0, 3, true], "34": [0.0, 23.0, 1, true], "35": [0.0, 60.0, 1, true], "36": [180.0, 23.0, 3, true], "37": [23.0, 0.0, 0, true], "38": [180.0, 50.0, 3, true], "39": [150.0, 15.0, 3, true], "40": [150.0, 33.0, 3, true], "41": [99.0, 0.0, 0, true], "42": [150.0, 25.0, 3, true], "43": [7.0, 0.0, 0, true], "44": [37.5, 200.0, 2, true], "45": [150.0, 25.0, 3, true], "46": [0.0, 22.0, 1, true], "47": [37.5, 200.0, 2, true]}, {"0": [[[807.0, 355.0], [758.0, 355.0], [758.0, 299.0], [665.0, 299.0]], true], "1": [[[833.0, 332.0], [1087.0, 332.0], [1087.0, 201.0], [737.0, 201.0]], false], "2": [[[818.0, 324.0], [703.0, 324.0], [703.0, 235.0], [721.0, 235.0]], false], "3": [[[807.0, 412.0], [719.0, 412.0], [719.0, 323.0], [512.0, 323.0]], true], "4": [[[807.0, 432.0], [710.0, 432.0], [710.0, 341.0], [512.0, 341.0]], true], "5": [[[833.0, 500.0], [862.0, 500.0], [862.0, 500.0], [877.0, 500.0]], true], "6": [[[833.0, 523.0], [853.0, 523.0], [853.0, 523.0], [877.0, 523.0]], true], "7": [[[807.0, 619.0], [531.0, 619.0], [531.0, 372.0], [573.0, 372.0]], true], "8": [[[807.0, 542.0], [743.0, 542.0], [743.0, 542.0], [586.0, 542.0]], true], "9": [[[807.0, 574.0], [701.0, 574.0], [701.0, 574.0], [640.0, 574.0]], true], "10": [[[807.0, 596.0], [726.0, 596.0], [726.0, 596.0], [640.0, 596.0]], true], "11": [[[807.0, 812.0], [643.5, 812.0], [643.5, 812.0], [602.0, 812.0]], true], "12": [[[807.0, 832.0], [643.5, 832.0], [643.5, 832.0], [602.0, 832.0]], true], "13": [[[991.0, 249.0], [986.0, 249.0], [986.0, 313.0], [986.0, 313.0]], true], "14": [[[1022.0, 235.0], [965.0, 235.0], [965.0, 560.0], [970.0, 560.0]], true], "15": [[[1068.0, 278.0], [1082.0, 278.0], [1082.0, 278.0], [1124.0, 278.0]], true], "16": [[[1068.0, 249.0], [1085.0, 249.0], [1085.0, 249.0], [1124.0, 249.0]], true], "17": [[[638.0, 529.0], [685.0, 529.0], [685.0, 372.0], [633.0, 372.0]], true], "18": [[[602.0, 486.0], [644.0, 486.0], [644.0, 448.0], [603.0, 448.0]], true], "19": [[[588.0, 300.0], [549.0, 300.0], [549.0, 300.0], [453.0, 300.0]], true], "20": [[[630.0, 159.0], [1612.75, 159.0], [1612.75, 529.0], [1016.5, 529.0]], false], "21": [[[630.0, 186.0], [1662.75, 186.0], [1662.75, 746.0], [1015.5, 746.0]], false], "22": [[[1137.0, 346.0], [1175.0, 346.0], [1175.0, 563.0], [1136.0, 563.0]], true]}] diff --git a/mia_layout_backup b/mia_layout_backup new file mode 100644 index 0000000000000000000000000000000000000000..389240da584aad71d3c3d98738e2e62a8b958cb1 --- /dev/null +++ b/mia_layout_backup @@ -0,0 +1 @@ +[{"Bus": [815.0, 332.0], "uPC": [999.0, 243.0], "SuPC": [1132.0, 242.0], "PC": [885.0, 491.0], "AR": [561.0, 494.0], "ASR": [596.0, 271.0], "HR": [563.0, 564.0], "uM": [355.0, 621.0], "ALU": [543.0, 380.0], "GRx": [407.0, 727.0], "IR": [651.0, 159.0], "Z-Flag": [853.0, 780.0], "N-Flag": [933.0, 780.0], "C-Flag": [1012.0, 780.0], "O-Flag": [1092.0, 780.0], "L-Flag": [1173.0, 780.0], "LC": [1197.0, 737.0], "PM": [354.0, 308.0], "K1": [979.0, 321.0], "K2": [978.0, 538.0]}, {"0": [0.0, 23.0, 1, true], "1": [10.0, 0.0, 3, true], "2": [3.0, 0.0, 0, true], "3": [0.0, 80.0, 1, true], "4": [0.0, 100.0, 1, true], "5": [10.0, 168.0, 3, true], "6": [10.0, 191.0, 3, true], "7": [0.0, 287.0, 1, true], "8": [0.0, 210.0, 1, true], "9": [0.0, 242.0, 1, true], "10": [0.0, 264.0, 1, true], "11": [0.0, 480.0, 1, true], "12": [0.0, 500.0, 1, true], "13": [0.0, 6.0, 1, true], "14": [23.0, 0.0, 0, true], "15": [61.0, 35.0, 3, true], "16": [61.0, 6.0, 3, true], "17": [0.0, 7.0, 1, true], "18": [0.0, 36.0, 1, true], "19": [0.0, 9.0, 1, true], "20": [0.0, 32.0, 1, true], "21": [25.0, 40.0, 2, true], "22": [69.0, 35.0, 3, true], "23": [41.0, 0.0, 0, true], "24": [61.0, 28.0, 3, true], "25": [0.0, 29.0, 1, true], "26": [69.0, 10.0, 3, true], "27": [69.0, 32.0, 3, true], "28": [0.0, 25.0, 1, true], "29": [90.0, 0.0, 0, true], "30": [30.0, 0.0, 0, true], "31": [60.0, 60.0, 2, true], "32": [187.0, 85.0, 3, true], "33": [187.0, 105.0, 3, true], "34": [0.0, 23.0, 1, true], "35": [0.0, 60.0, 1, true], "36": [180.0, 23.0, 3, true], "37": [23.0, 0.0, 0, true], "38": [180.0, 50.0, 3, true], "39": [150.0, 15.0, 3, true], "40": [150.0, 33.0, 3, true], "41": [99.0, 0.0, 0, true], "42": [150.0, 25.0, 3, true], "43": [7.0, 0.0, 0, true], "44": [37.5, 200.0, 2, true], "45": [150.0, 25.0, 3, true], "46": [0.0, 22.0, 1, true], "47": [37.5, 200.0, 2, true]}, {"0": [[[807.0, 355.0], [758.0, 355.0], [758.0, 299.0], [665.0, 299.0]], true], "1": [[[833.0, 332.0], [1087.0, 332.0], [1087.0, 201.0], [737.0, 201.0]], false], "2": [[[818.0, 324.0], [703.0, 324.0], [703.0, 235.0], [721.0, 235.0]], false], "3": [[[807.0, 412.0], [719.0, 412.0], [719.0, 323.0], [512.0, 323.0]], true], "4": [[[807.0, 432.0], [710.0, 432.0], [710.0, 341.0], [512.0, 341.0]], true], "5": [[[833.0, 500.0], [862.0, 500.0], [862.0, 500.0], [877.0, 500.0]], true], "6": [[[833.0, 523.0], [853.0, 523.0], [853.0, 523.0], [877.0, 523.0]], true], "7": [[[807.0, 619.0], [531.0, 619.0], [531.0, 372.0], [573.0, 372.0]], true], "8": [[[807.0, 542.0], [743.0, 542.0], [743.0, 542.0], [586.0, 542.0]], true], "9": [[[807.0, 574.0], [701.0, 574.0], [701.0, 574.0], [640.0, 574.0]], true], "10": [[[807.0, 596.0], [726.0, 596.0], [726.0, 596.0], [640.0, 596.0]], true], "11": [[[807.0, 812.0], [643.5, 812.0], [643.5, 812.0], [602.0, 812.0]], true], "12": [[[807.0, 832.0], [643.5, 832.0], [643.5, 832.0], [602.0, 832.0]], true], "13": [[[991.0, 249.0], [986.0, 249.0], [986.0, 313.0], [986.0, 313.0]], true], "14": [[[1022.0, 235.0], [965.0, 235.0], [965.0, 560.0], [970.0, 560.0]], true], "15": [[[1068.0, 278.0], [1082.0, 278.0], [1082.0, 278.0], [1124.0, 278.0]], true], "16": [[[1068.0, 249.0], [1085.0, 249.0], [1085.0, 249.0], [1124.0, 249.0]], true], "17": [[[638.0, 529.0], [685.0, 529.0], [685.0, 372.0], [633.0, 372.0]], true], "18": [[[602.0, 486.0], [644.0, 486.0], [644.0, 448.0], [603.0, 448.0]], true], "19": [[[588.0, 300.0], [549.0, 300.0], [549.0, 300.0], [453.0, 300.0]], true], "20": [[[630.0, 159.0], [1612.75, 159.0], [1612.75, 529.0], [1016.5, 529.0]], false], "21": [[[630.0, 186.0], [1662.75, 186.0], [1662.75, 746.0], [1015.5, 746.0]], false], "22": [[[1137.0, 346.0], [1175.0, 346.0], [1175.0, 563.0], [1136.0, 563.0]], true]}] diff --git a/src/simudator/core/processor.py b/src/simudator/core/processor.py index 709195328f73a4890ef6992ffb456442adcec2ea..b5269963bf81cb413f066bbb946b9344be6ba106 100644 --- a/src/simudator/core/processor.py +++ b/src/simudator/core/processor.py @@ -36,6 +36,10 @@ class Processor: self.max_line_len = 170 self.line_seperator = "-" self.is_stopped = False + # TODO: keeping track of what pieces of info not to show + # show not be done at the processor level. + # Maybe implemenet a 'get_pretty_print_state' at module + # level? self.ignore_keys = [ "bit_length", "mask", "increment", "read_from_bus", "read_from_uADR", "decrement_by_one", "bus_id" @@ -69,12 +73,15 @@ class Processor: def run_continuously(self): + """ + Runs the processor until it halts. + """ while not self.should_halt() and not self.is_stopped: self.do_tick() # Print all reached breakpoints then exit the loop self.breakpoint_reached = False - for bp_id, bp in self.breakpoints.items(): + for _, bp in self.breakpoints.items(): #TODO: Can make this more efficient by only checking enabled breakpoints if bp.is_break() and bp.is_enabled: self.breakpoint_reached = True @@ -470,8 +477,8 @@ class Processor: if not self.breakpoints: print("There are no breakpoints.") else: - for id, bp in self.breakpoints.items(): - print(f"BP {id}: {bp}") + for bp_id, bp in self.breakpoints.items(): + print(f"BP {bp_id}: {bp}") def add_memory_breakpoint(self, module_name:str, adress: int, value: Any) -> None: diff --git a/src/simudator/gui/breakpoint_window.py b/src/simudator/gui/breakpoint_window.py index bf713be52d56593502b42f2706a231868a7b6737..82530cf9cf06fb9584aed20272876ab39b616e6f 100644 --- a/src/simudator/gui/breakpoint_window.py +++ b/src/simudator/gui/breakpoint_window.py @@ -69,7 +69,7 @@ class BreakpointWindow(QWidget): """ Removes all list items from the breakpoint list. """ - for row in range(self.breakpoint_list.count()): + for _ in range(self.breakpoint_list.count()): self.breakpoint_list.takeItem(0) def toggleEnabledClicked(self) -> None: diff --git a/src/simudator/gui/color_scheme.py b/src/simudator/gui/color_scheme.py new file mode 100644 index 0000000000000000000000000000000000000000..ea428aee0355f603636bbcdcc6b55b0cd7dbb552 --- /dev/null +++ b/src/simudator/gui/color_scheme.py @@ -0,0 +1,18 @@ +from PyQt5.QtGui import QColor + + +""" +A class used for storing colors used by the gui in a central place that is easy +to edit. +""" +class ColorScheme(): + Window = QColor(125, 174, 163) + ModuleBackground = QColor(212, 190, 152) + ModuleOutline = QColor(0, 0, 0) + ModuleText = QColor(0, 0, 0) + ModuleShadow = QColor(60, 56, 54, 127) + Signal = QColor(255, 0, 0) + SignalHighlighted = QColor(255, 0, 0) + Port = QColor(0, 0, 0) + PortLabel = QColor(0, 0, 0) + PortHighlighted = QColor(0, 0, 0) diff --git a/src/simudator/gui/cpu_graphics_scene.py b/src/simudator/gui/cpu_graphics_scene.py index 748870b4b8a9b060bdb02d9046f53d68b9147759..e00332fe5dc84700c68ba92cc590df4e36fb549c 100644 --- a/src/simudator/gui/cpu_graphics_scene.py +++ b/src/simudator/gui/cpu_graphics_scene.py @@ -1,6 +1,7 @@ from PyQt5.QtWidgets import QGraphicsItem, QGraphicsScene from simudator.core.processor import Processor +from simudator.gui.color_scheme import ColorScheme from simudator.gui.module_graphics_item.module_graphics_item import ModuleGraphicsItem from simudator.gui.signal_graphics_item import SignalGraphicsItem @@ -19,6 +20,7 @@ class CpuGraphicsScene(QGraphicsScene): self.cpu = cpu self.module_graphics_items = dict() self.signal_graphics_items = [] + self.setBackgroundBrush(ColorScheme.Window) def resetSignals(self) -> None: """ @@ -37,6 +39,11 @@ class CpuGraphicsScene(QGraphicsScene): self.placeModuleGraphicsItemDefault(graphics_item) def placeModuleGraphicsItemDefault(self, graphics_item: ModuleGraphicsItem) -> None: + """ + Places a module graphics items at a position where the x value + is equal to the y value. Used to place all graphics items in a + diagonal. + """ placement = len(self.module_graphics_items)*self.MODULE_SPACEING graphics_item.setPos(placement, placement) self.addItem(graphics_item) @@ -46,6 +53,9 @@ class CpuGraphicsScene(QGraphicsScene): pos_x: int, pos_y: int ) -> None: + """ + Changes the postions of an existing modules graphics item. + """ graphics_item.setPos(pos_x*self.MODULE_SPACEING, pos_y*self.MODULE_SPACEING) @@ -87,6 +97,7 @@ class CpuGraphicsScene(QGraphicsScene): port_1.toggled.connect(signal_w.toggleVisibility) port_2.toggled.connect(signal_w.toggleVisibility) + def getModulesGraphicsItems(self) -> list[ModuleGraphicsItem]: return list(self.module_graphics_items.values()) @@ -100,6 +111,9 @@ class CpuGraphicsScene(QGraphicsScene): super().mousePressEvent(event) def load_layout_from_file(self, file_path: str) -> None: + """ + Loads a layout for a processor from a saved filed. + """ file = open(file_path) graphics_item_name = None diff --git a/src/simudator/gui/gui.py b/src/simudator/gui/gui.py index b274814095e739e96771a8b716a4d3f51c3a28e2..bb165ca84e013d0459054cbbdf410ea9877bd7eb 100644 --- a/src/simudator/gui/gui.py +++ b/src/simudator/gui/gui.py @@ -3,7 +3,7 @@ import json import sys from json import JSONDecodeError -from PyQt5 import QtCore +from PyQt5 import QtCore, QtWidgets from PyQt5.QtCore import QPointF, pyqtSignal, pyqtSlot from PyQt5.QtWidgets import ( QAction, @@ -32,6 +32,56 @@ from simudator.gui.run_continuously_thread import RunThread from simudator.gui.signal_graphics_item import SignalGraphicsItem +class View(QGraphicsView): + """ + This class views all QGraphicsItems for the user. It takes the + QGraphicsScene as input and inherits all funcitonality from the + QGraphicsView and overrides the wheelEvent function. + This allows the users to navigate the view with their trackpads + and zoom in/out with their trackpads + ctrl. + """ + def __init__(self, QGraphicsScene): + super().__init__(QGraphicsScene) + self.scene = QGraphicsScene + + def wheelEvent(self, event): + """ + Default behaviour if ctrl is not pressed, otherwise zoom in/out. + """ + modifiers = QtWidgets.QApplication.keyboardModifiers() + if modifiers == QtCore.Qt.ControlModifier: + + # Factor above 1 zooms in, below zooms out + factor = 1.03 + if event.angleDelta().y() < 0: + factor = 0.97 + + # If event got triggered due to the x axis, do nothing + if event.pixelDelta().x() != 0: + return + + view_pos = event.globalPosition() + scene_pos = self.mapToScene( + int(view_pos.x()), + int(view_pos.y()) + ) + + self.centerOn(scene_pos) + self.scale(factor, factor) + + old_mapToScene = self.mapToScene(int(view_pos.x()), int(view_pos.y())) + new_mapToScene = self.mapToScene(self.viewport().rect().center()) + + delta = old_mapToScene - new_mapToScene + + self.centerOn(scene_pos - delta) + + else: + + # Default behaviour + super().wheelEvent(event) + + class GUI(QMainWindow): """ This is the main class for the GUI. It handles creating the widnow for @@ -51,7 +101,8 @@ class GUI(QMainWindow): self.setWindowTitle("SimuDator") self.cpu_graphics_scene = CpuGraphicsScene(cpu) - self.graphics_view = QGraphicsView(self.cpu_graphics_scene) + self.graphics_view = View(self.cpu_graphics_scene) + #self.graphics_view.setDragMode(True) self.moduleActions: dict[str, QAction] = {} self.setCentralWidget(self.graphics_view) @@ -253,6 +304,10 @@ class GUI(QMainWindow): """ @pyqtSlot(str, str, str) def editModuleState(self, module_name, state, value) -> None: + """ + Tries to change the value of module to value given by user + through the dialog opened by editModuleStateDialog. + """ try: parsed_value = ast.literal_eval(value) except SyntaxError as e: @@ -266,6 +321,10 @@ class GUI(QMainWindow): @pyqtSlot(str, str, str) def editMemoryContent(self, module_name: str, adress: str, value: str) -> None: + """ + Tries to change the value at adress to value given by user + through the dialog opened by editModuleStateDialog. + """ try: parsed_adress = int(adress, 16) parsed_value = ast.literal_eval(value) @@ -285,6 +344,10 @@ class GUI(QMainWindow): @pyqtSlot(str, str, str) def addStateBreakpoint(self, module_name: str, state: str, value: str) -> None: + """ + Tries to add a breakpoint to the module through the dialog + opened by stateBreakpointDialog. + """ try: parsed_value = ast.literal_eval(value) self.cpu.add_state_breakpoint(module_name, state, parsed_value) @@ -294,6 +357,10 @@ class GUI(QMainWindow): @pyqtSlot(str, str) def addLambdaBreakpoint(self, lambda_name, kwargs_str) -> None: + """ + Tries to add a breakpoint to the module through the dialog + opened by lambdaBreakpointDialog. + """ try: lambda_kwargs = {} for kwarg in kwargs_str.split(' '): @@ -306,6 +373,10 @@ class GUI(QMainWindow): @pyqtSlot(str, str, str) def addMemoryBreakpoint(self, module_name: str, adress: str, value: str) -> None: + """ + Tries to add a breakpoint to the module through the dialog + opened by memoryBreakpointDialog. + """ try: parsed_adress = int(adress) parsed_value = int(value) @@ -480,8 +551,8 @@ class GUI(QMainWindow): def saveLayoutToolBarButtonClick(self) -> None: """ - Saves the layout of all the modules in a human readable - (and editable) format. + Saves the layout of all the modules in a (somewhat) + human readable format. Erases the previous content of the file before saving the data. """ 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 1eb208e5ae67afbfbbccf97b07504be19e9e6cd2..5eab4dac748c1629f010a1b8a1f947667df7ddce 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 @@ -10,6 +10,7 @@ from PyQt5.QtWidgets import ( ) from simudator.core.modules import Memory +from simudator.gui.color_scheme import ColorScheme as CS from simudator.gui.module_graphics_item.memory_graphic import MemoryGraphicsItem from simudator.gui.module_graphics_item.mia.mia_memory_content_dialog import ( MiaMemoryContentDialog, @@ -68,6 +69,8 @@ class MiaMemoryGraphicsItem(MemoryGraphicsItem): # Create base backgrond rect self.baserect = QGraphicsRectItem(0, 0, self.RECT_WIDTH, self.RECT_HEIGHT, self) + self.baserect.setPen(CS.ModuleOutline) + self.baserect.setBrush(CS.ModuleBackground) # Make ports self.input = PortGraphicsItem(self.module.get_input_signal(), 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 aea45a4e389928bfd61360194f81a06d190b53b7..a63c9301cc88b1f16e0308c4e203a1943894a5b3 100644 --- a/src/simudator/gui/module_graphics_item/module_graphics_item.py +++ b/src/simudator/gui/module_graphics_item/module_graphics_item.py @@ -15,6 +15,7 @@ from PyQt5.QtWidgets import ( ) from simudator.core.module import Module +from simudator.gui.color_scheme import ColorScheme as CS from simudator.gui.dialogs.module_state_dialog import ModuleStateDialog from simudator.gui.orientation import Orientation from simudator.gui.port_graphics_item import PortGraphicsItem @@ -101,10 +102,17 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): height = max(inputs_height, outputs_height, members_height) - width = longest_line_len * self.CHAR_LEN * 2 + 2 * self.WIDTH_MARGIN + width = longest_line_len * self.CHAR_LEN * 2 + 2 * self.WIDTH_MARGIN + + # Shadow + self.shadow = QGraphicsRectItem(0, 0, width, height, self) + self.shadow.setBrush(CS.ModuleShadow) + self.shadow.setPen(CS.ModuleShadow) + self.shadow.setPos(self.pos() + QtCore.QPointF(5, 10)) # Create base background rectangle self.baserect = QGraphicsRectItem(0, 0, width, height, self) + self.baserect.setBrush(CS.ModuleBackground) # Add ports for input signals self.draw_ports() @@ -112,6 +120,7 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): # Create name lable name_text = QGraphicsSimpleTextItem(self.state["name"], self) name_text.setPos(width/2-len(self.state["name"])*self.CHAR_LEN, 0) + name_text.setBrush(CS.ModuleText) # Create state lables self.state_lables = {} @@ -122,6 +131,7 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): state_text = QGraphicsSimpleTextItem(text, self) state_text.setPos(width/20, state_tuple[0]*self.CHAR_HEIGHT) + state_text.setBrush(CS.ModuleText) self.state_lables[state_tuple[1]] = state_text def draw_ports(self) -> None: @@ -297,15 +307,6 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): name = self.name return f"{name}:\nx: {x_pos} y: {y_pos}\n" - def get_pos(self): - return self.pos() - - def get_scene_pos(self): - return self.scenePos() - - def get_ports(self) -> None: - return self.listeners - def getName(self) -> str: return self.name diff --git a/src/simudator/gui/port_graphics_item.py b/src/simudator/gui/port_graphics_item.py index 43856d2ab12c32587fb7d16934aeb29f3bdbe786..2dfd45c0930b1b4a513dc3596008c227427b11b2 100644 --- a/src/simudator/gui/port_graphics_item.py +++ b/src/simudator/gui/port_graphics_item.py @@ -12,6 +12,7 @@ from PyQt5.QtWidgets import ( ) from simudator.core.signal import Signal +from simudator.gui.color_scheme import ColorScheme from simudator.gui.orientation import Orientation @@ -93,6 +94,11 @@ class PortGraphicsItem(QGraphicsItemGroup): font.setPointSize(self.FONT_SIZE) self.name_label.setFont(font) + # Set colors + self.vertical_line.setPen(ColorScheme.Port) + self.horizontal_line.setPen(ColorScheme.Port) + self.name_label.setBrush(ColorScheme.PortLabel) + self.addToGroup(self.vertical_line) self.addToGroup(self.horizontal_line) self.addToGroup(self.name_label) diff --git a/src/simudator/gui/signal_graphics_item.py b/src/simudator/gui/signal_graphics_item.py index 22bde5b312f33cd2acf6f47d0ffeec06604b3824..e9ddc3922662ad66ecb42193ebc5ae8c24c1df4f 100644 --- a/src/simudator/gui/signal_graphics_item.py +++ b/src/simudator/gui/signal_graphics_item.py @@ -6,6 +6,7 @@ from PyQt5.QtCore import QPointF, Qt from PyQt5.QtGui import QCursor from PyQt5.QtWidgets import QGraphicsItem, QGraphicsLineItem, QGraphicsSceneMouseEvent +from simudator.gui.color_scheme import ColorScheme from simudator.gui.port_graphics_item import PortGraphicsItem SHORTEST_LINE_LEN = 400 @@ -117,6 +118,7 @@ class SignalGraphicsItem(QGraphicsItem): x2 = point.x() y2 = point.y() line = QGraphicsLineItem(x1, y1, x2, y2, self) + line.setPen(ColorScheme.Signal) self.lines.append(line) prev_point = point diff --git a/src/simudator/processor/mia/alu.py b/src/simudator/processor/mia/alu.py index 4c99aaf03568b80251ffbe1aebb383e0e68b078d..15e090010d61c70c77ca7a30de21d64966749939 100644 --- a/src/simudator/processor/mia/alu.py +++ b/src/simudator/processor/mia/alu.py @@ -323,7 +323,6 @@ class ALU(Module): # Convert shifted to int value = self.bin_to_int(new_binary_number) - print(carry) self.update_flags(None, None, new_binary_number, carry) return value