Skip to content
Snippets Groups Projects
Commit c0f63030 authored by Martin Högstedt's avatar Martin Högstedt
Browse files

removed unnecessary buttons

parent 9a61582c
Branches 56-old-state
No related tags found
1 merge request!33Reworked how the memory is displayed and editet
Pipeline #132635 failed
...@@ -32,15 +32,10 @@ from simudator.gui.port_graphics_item import PortGraphicsItem ...@@ -32,15 +32,10 @@ from simudator.gui.port_graphics_item import PortGraphicsItem
class Base(Enum): class Base(Enum):
NONE = 0 NONE = 0
DECIMAL = 1 DECIMAL_SIGNED = 1
BINARY = 2 DECIMAL_UNSIGNED = 2
HEXADECIMAL = 3 BINARY = 3
HEXADECIMAL = 4
class Sign(Enum):
NONE = 0
SIGNED = 1
UNSIGNED = 2
class MemoryWindow(QWidget): class MemoryWindow(QWidget):
...@@ -229,18 +224,18 @@ class IntegerMemoryWindow(QWidget): ...@@ -229,18 +224,18 @@ class IntegerMemoryWindow(QWidget):
def __init__(self, memory_module: Memory, bit_length: int): def __init__(self, memory_module: Memory, bit_length: int):
super().__init__() super().__init__()
self._sign = Sign.NONE
# Create base buttons, they are exclusive by default # Create base buttons, they are exclusive by default
# so need a seperate QButtonGroup since these three # so need a seperate QButtonGroup since these three
# have nothing to do with the edit/view buttons # have nothing to do with the edit/view buttons
self.decimal_button = QRadioButton("Decimal") self.dec_signed_button = QRadioButton("Decimal Signed")
self.dec_unsigned_button = QRadioButton("Decimal Unsigned")
self.bin_button = QRadioButton("Binary") self.bin_button = QRadioButton("Binary")
self.hex_button = QRadioButton("Hexadecimal") self.hex_button = QRadioButton("Hexadecimal")
self.base_group = QButtonGroup() self.base_group = QButtonGroup()
self.base_group.addButton(self.decimal_button, 1) self.base_group.addButton(self.dec_signed_button, 1)
self.base_group.addButton(self.bin_button, 2) self.base_group.addButton(self.dec_unsigned_button, 2)
self.base_group.addButton(self.hex_button, 3) self.base_group.addButton(self.bin_button, 3)
self.base_group.addButton(self.hex_button, 4)
# Create edit/view buttons, they are exclusive by default # Create edit/view buttons, they are exclusive by default
self.edit_button = QRadioButton("Edit") self.edit_button = QRadioButton("Edit")
...@@ -250,18 +245,11 @@ class IntegerMemoryWindow(QWidget): ...@@ -250,18 +245,11 @@ class IntegerMemoryWindow(QWidget):
self.edit_group.addButton(self.view_button, 2) self.edit_group.addButton(self.view_button, 2)
# Create signed/unsigned buttons, they are exclusive by default # Create signed/unsigned buttons, they are exclusive by default
self.signed_button = QRadioButton("Signed")
self.unsigned_button = QRadioButton("Unsigned")
self.signed_group = QButtonGroup()
self.signed_group.addButton(self.signed_button, 1)
self.signed_group.addButton(self.unsigned_button, 2)
# Connect them to the 'set_base' function # Connect them to the 'set_base' function
self.base_group.buttonClicked.connect(self._set_base) self.base_group.buttonClicked.connect(self._set_base)
# Connect them to the 'set_edit' function # Connect them to the 'set_edit' function
self.edit_group.buttonClicked.connect(self._set_edit) self.edit_group.buttonClicked.connect(self._set_edit)
# Connect them to the 'set_sign' function
self.signed_group.buttonClicked.connect(self._set_sign)
# Create a layout that expands vertically # Create a layout that expands vertically
# so that the buttons can be displayed below the # so that the buttons can be displayed below the
...@@ -273,16 +261,12 @@ class IntegerMemoryWindow(QWidget): ...@@ -273,16 +261,12 @@ class IntegerMemoryWindow(QWidget):
# Create a layout that expands horizontally, so that # Create a layout that expands horizontally, so that
# all buttons appear in one row # all buttons appear in one row
self.first_button_layout = QHBoxLayout() self.first_button_layout = QHBoxLayout()
self.first_button_layout.addWidget(self.decimal_button) self.first_button_layout.addWidget(self.dec_signed_button)
self.first_button_layout.addWidget(self.dec_unsigned_button)
self.first_button_layout.addWidget(self.bin_button) self.first_button_layout.addWidget(self.bin_button)
self.first_button_layout.addWidget(self.hex_button) self.first_button_layout.addWidget(self.hex_button)
self.layout.addLayout(self.first_button_layout) self.layout.addLayout(self.first_button_layout)
self.sign_button_layout = QHBoxLayout()
self.sign_button_layout.addWidget(self.signed_button)
self.sign_button_layout.addWidget(self.unsigned_button)
self.layout.addLayout(self.sign_button_layout)
self.second_button_layout = QHBoxLayout() self.second_button_layout = QHBoxLayout()
self.second_button_layout.addWidget(self.edit_button) self.second_button_layout.addWidget(self.edit_button)
self.second_button_layout.addWidget(self.view_button) self.second_button_layout.addWidget(self.view_button)
...@@ -290,12 +274,10 @@ class IntegerMemoryWindow(QWidget): ...@@ -290,12 +274,10 @@ class IntegerMemoryWindow(QWidget):
# Set the default base to decimal and disable editing # Set the default base to decimal and disable editing
# from start # from start
self.decimal_button.toggle() self.bin_button.toggle()
self.view_button.toggle() self.view_button.toggle()
self.signed_button.toggle()
self._set_base() self._set_base()
self._set_edit() self._set_edit()
self._set_sign()
# Sets the size of each column to the smallest possible # Sets the size of each column to the smallest possible
# width that allows all content in each box to be visible # width that allows all content in each box to be visible
...@@ -304,29 +286,19 @@ class IntegerMemoryWindow(QWidget): ...@@ -304,29 +286,19 @@ class IntegerMemoryWindow(QWidget):
) )
def _set_base(self): def _set_base(self):
base = Base.DECIMAL
pressed_button_id = self.base_group.checkedId() pressed_button_id = self.base_group.checkedId()
if pressed_button_id == 1: if pressed_button_id == 1:
base = Base.DECIMAL base = Base.DECIMAL_SIGNED
if pressed_button_id == 2: elif pressed_button_id == 2:
base = Base.DECIMAL_UNSIGNED
elif pressed_button_id == 3:
base = Base.BINARY base = Base.BINARY
if pressed_button_id == 3: else:
base = Base.HEXADECIMAL base = Base.HEXADECIMAL
self._memory_table.set_base(base) self._memory_table.set_base(base)
self._memory_table.update() self._memory_table.update()
def _set_sign(self):
sign = Sign.NONE
pressed_button_id = self.signed_group.checkedId()
if pressed_button_id == 1:
sign = Sign.SIGNED
if pressed_button_id == 2:
sign = Sign.UNSIGNED
self._memory_table.set_sign(sign)
self._memory_table.update()
def _set_edit(self): def _set_edit(self):
pressed_button_id = self.edit_group.checkedId() pressed_button_id = self.edit_group.checkedId()
if pressed_button_id == 1: if pressed_button_id == 1:
...@@ -366,7 +338,6 @@ class IntegerMemoryTable(QTableWidget): ...@@ -366,7 +338,6 @@ class IntegerMemoryTable(QTableWidget):
self.setHorizontalHeaderLabels(["+" + str(i) for i in range(4)]) self.setHorizontalHeaderLabels(["+" + str(i) for i in range(4)])
self.make_table_uneditable() self.make_table_uneditable()
self.base = Base.NONE self.base = Base.NONE
self._sign = Sign.NONE
self._errorMessageWidget = QErrorMessage() self._errorMessageWidget = QErrorMessage()
vertical_headers = [] vertical_headers = []
...@@ -393,7 +364,7 @@ class IntegerMemoryTable(QTableWidget): ...@@ -393,7 +364,7 @@ class IntegerMemoryTable(QTableWidget):
value = memory_content[i] value = memory_content[i]
row = i // self._column_size row = i // self._column_size
col = i % self._column_size col = i % self._column_size
if self.base == Base.DECIMAL: if self.base == Base.DECIMAL_UNSIGNED or self.base == Base.DECIMAL_SIGNED:
value = self._get_dec_from_sign(value) value = self._get_dec_from_sign(value)
elif self.base == Base.BINARY: elif self.base == Base.BINARY:
value = str(bin(int(value)))[2:] # remove '0b' value = str(bin(int(value)))[2:] # remove '0b'
...@@ -426,11 +397,8 @@ class IntegerMemoryTable(QTableWidget): ...@@ -426,11 +397,8 @@ class IntegerMemoryTable(QTableWidget):
def set_base(self, base: Base): def set_base(self, base: Base):
self.base = base self.base = base
def set_sign(self, sign: Sign):
self._sign = sign
def _get_dec_from_sign(self, value: int) -> str: def _get_dec_from_sign(self, value: int) -> str:
if self._sign == Sign.UNSIGNED: if self.base == Base.DECIMAL_UNSIGNED:
return str(int(value)) return str(int(value))
# Any value above or equal to 'threshold' must have the MSB set to 1 # Any value above or equal to 'threshold' must have the MSB set to 1
...@@ -486,13 +454,13 @@ class IntegerMemoryTable(QTableWidget): ...@@ -486,13 +454,13 @@ class IntegerMemoryTable(QTableWidget):
value = int(value, 2) value = int(value, 2)
elif self.base == Base.HEXADECIMAL: elif self.base == Base.HEXADECIMAL:
value = int(value, 16) value = int(value, 16)
elif self.base == Base.DECIMAL: elif self.base == Base.DECIMAL_SIGNED or self.base == Base.DECIMAL_UNSIGNED:
value = int(value) value = int(value)
except ValueError: except ValueError:
msg = None msg = None
if self.base == Base.BINARY: if self.base == Base.BINARY:
msg = "You must enter a binary number (e.g. 0b101)." msg = "You must enter a binary number (e.g. 0b101)."
elif self.base == Base.DECIMAL: elif self.base == Base.DECIMAL_SIGNED or self.base == Base.DECIMAL_UNSIGNED:
msg = "You must enter a decimal number (e.g. 107)." msg = "You must enter a decimal number (e.g. 107)."
elif self.base == Base.HEXADECIMAL: elif self.base == Base.HEXADECIMAL:
msg = "You must enter a hexadecimal number (e.g. 0xc3)." msg = "You must enter a hexadecimal number (e.g. 0xc3)."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment