diff --git a/soitool/coder.py b/soitool/coder.py index 3439f53eadb9d14e077f1455812e99d89776f345..42f5d29d67314db917defe4b41d0d6bb6ec65dd8 100644 --- a/soitool/coder.py +++ b/soitool/coder.py @@ -13,12 +13,13 @@ def get_code(code_length, mode="ascii", space_interval=0, space_amount=1): Parameters ---------- code_length : int - The length of the code + The length of the code. mode : string 'ascii' for letters, 'digits' for digits and 'combo' for combination of letters and digits, by default 'ascii'. space_interval : int - Spaces will be inserted to code each interval if not 0, by default 0. + Spaces will be inserted into code each interval for readability if not + 0, by default 0. space_amount : int Amount of spaces per interval, by default 1. @@ -40,12 +41,6 @@ def get_code(code_length, mode="ascii", space_interval=0, space_amount=1): "Invalid value for argument 'mode': " "'{}'".format(mode) ) - if not isinstance(space_interval, int): - raise ValueError( - "Invalid value for argument 'separate_interval': " - "'{}'".format(space_interval) - ) - i = 0 while i < code_length: letter = secrets.choice(characters) @@ -75,7 +70,8 @@ def get_code_set( 'ascii' for letters (default), 'digits' for digits and 'combo' for combination of letters and digits. space_interval : int - Spaces will be inserted to code each interval if not 0, by default 0. + Spaces will be inserted into code each interval for readability if not + 0, by default 0. space_amount : int Amount of spaces per interval, by default 1. diff --git a/soitool/media/authenticationboardmodule.PNG b/soitool/media/authenticationboardmodule.PNG index 439ad8b1928211b7a4c8341377123fb2d7dbd303..0a92c03e3e403e6cb1bd41716b7feacc5d050b69 100644 Binary files a/soitool/media/authenticationboardmodule.PNG and b/soitool/media/authenticationboardmodule.PNG differ diff --git a/soitool/modules/module_authentication_board.py b/soitool/modules/module_authentication_board.py index 31329915f5c2689e72dc0abefb7e72f464c313e8..663f2ab791a70a2fe4da2624baa3515d931ff117 100644 --- a/soitool/modules/module_authentication_board.py +++ b/soitool/modules/module_authentication_board.py @@ -8,12 +8,18 @@ from soitool.modules.code_table_base import CodeTableBase START_NO_OF_CODES = 10 # Maximum value is len(ROW_IDENTIFIERS) CODE_LENGTH = 25 -CODE_CHARACTER_TYPE = "ascii" # Has to be 'ascii', 'digits' or 'combo' + +# Has to be 'ascii', 'digits' or 'combo' # Codes will consist of A-Z if 'ascii', 0-9 if 'digits' and A-Z+0-9 if 'combo'. -ROW_IDENTIFIERS = string.ascii_uppercase # Characters for first column, +CODE_CHARACTER_TYPE = "ascii" + +# Characters for first column, # it's length determines maximum number of codes (rows). -SPACE_INTERVAL = 5 # Adds space between sets of characters, 0 => no spaces +ROW_IDENTIFIERS = string.ascii_uppercase + +# Adds space between sets of characters, 0 => no spaces # If code is 123456 and interval is 2, code will be 12 34 56 +SPACE_INTERVAL = 5 SPACE_AMOUNT = 2 HEADLINE_TEXT = "Autentiseringstavle" diff --git a/soitool/modules/module_freetext.py b/soitool/modules/module_freetext.py index 4c3ab4fecc34754f61558675ee35550c90f79888..95066bceea66e73d73013f3b930fecd92ef1484d 100644 --- a/soitool/modules/module_freetext.py +++ b/soitool/modules/module_freetext.py @@ -162,19 +162,6 @@ class FreeTextModule(ModuleBase, QWidget, metaclass=Meta): size = self.sizeHint() return (size.width(), size.height()) - def set_pos(self, pos): - """Set position of widget. - - Parameters - ---------- - pos : QPoint - Position (x, y). - """ - self.move(pos) - - def render_onto_pdf(self): - """Render onto pdf.""" - def get_data(self): """Return list containing module data. diff --git a/soitool/modules/module_table.py b/soitool/modules/module_table.py index 433587a1248d644433df24ae7c7ddafda7448a80..030ad405ddfc7142d84f0ac45697af09e7c685e3 100644 --- a/soitool/modules/module_table.py +++ b/soitool/modules/module_table.py @@ -50,7 +50,7 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta): self.setRowCount(START_ROWS) # Resize width and height of rows, columns and window - resize_table(self) + resize_table(self, resize_row=True, resize_column=True) # Set header-items for i in range(self.columnCount()): @@ -74,7 +74,9 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta): self.setFixedWidth(size["width"]) self.setFixedHeight(size["height"]) - self.cellChanged.connect(resize_table(self)) + self.cellChanged.connect( + lambda: resize_table(self, resize_row=True, resize_column=True) + ) def keyPressEvent(self, event): """Launch actions when specific combinations of keys are pressed. @@ -129,24 +131,24 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta): """Add column to the right of selected column.""" self.insertColumn(self.currentColumn() + 1) self.set_header_item(self.currentColumn() + 1, "") - resize_table(self) + resize_table(self, resize_row=True, resize_column=True) def remove_column(self): """Remove selected column if two or more columns exist.""" if self.columnCount() > 1: self.removeColumn(self.currentColumn()) - resize_table(self) + resize_table(self, resize_row=True, resize_column=True) def add_row(self): """Add row below selected row.""" self.insertRow(self.currentRow() + 1) - resize_table(self) + resize_table(self, resize_row=True, resize_column=True) def remove_row(self): """Remove selected row if two or more rows exist (including header).""" if self.rowCount() > 2 and self.currentRow() != 0: self.removeRow(self.currentRow()) - resize_table(self) + resize_table(self, resize_row=True, resize_column=True) def get_size(self): """Return size of widget.""" diff --git a/test/test_module_authentication_board.py b/test/test_module_authentication_board.py index 3178351df8e47eead23ab1784b2cded18add24cb..5b3262e48055e0290b8676076e562da3b73913c5 100644 --- a/test/test_module_authentication_board.py +++ b/test/test_module_authentication_board.py @@ -83,6 +83,11 @@ class TestDefaultAuthenticationBoardModule(unittest.TestCase): self.module.show() QTest.qWaitForWindowExposed(self.module) + # From experience it can happen that the widget is not fully + # initialized before the QTest.keyClicks below. By calling + # processEvents here we give Qt the opportunity to catch up with us + app.processEvents() + old_row_count = self.module.rowCount() # Use shortcut 'Ctrl + +' @@ -111,6 +116,11 @@ class TestDefaultAuthenticationBoardModule(unittest.TestCase): self.module.show() QTest.qWaitForWindowExposed(self.module) + # From experience it can happen that the widget is not fully + # initialized before the QTest.keyClicks below. By calling + # processEvents here we give Qt the opportunity to catch up with us + app.processEvents() + old_row_count = self.module.rowCount() # First row is selected on startup, it contains headline