Skip to content
Snippets Groups Projects
Commit 26983cf7 authored by Thomas Holene Løkkeborg's avatar Thomas Holene Løkkeborg
Browse files

#98 fikset bug med freetextmodule & gjør codephrasemodule testbar

FreeTextModule fikk ulik størrelse avhengig av skjerm
parent 541f82b5
No related branches found
No related tags found
1 merge request!73#98 Kodefrasemodul
Pipeline #83645 failed with stages
in 1 minute and 23 seconds
...@@ -159,7 +159,11 @@ class TextEditWithSizeOfContent(QTextEdit): ...@@ -159,7 +159,11 @@ class TextEditWithSizeOfContent(QTextEdit):
def sizeHint(self): def sizeHint(self):
"""Give size hint using width of text.""" """Give size hint using width of text."""
return QSize(self.document().size().toSize()) size = QSize(self.document().size().toSize())
# NOTE that the following is not respected for dimensions below 100,100
size.setWidth(max(100, size.width()))
size.setHeight(max(100, size.height()))
return size
# NOTE: calling updateGeometry here is not the best solution, refer to # NOTE: calling updateGeometry here is not the best solution, refer to
# LineEditWithSizeOfContent and TableWithSizeOfContent. Should update this # LineEditWithSizeOfContent and TableWithSizeOfContent. Should update this
......
...@@ -14,6 +14,7 @@ from soitool.modules.module_base import ( ...@@ -14,6 +14,7 @@ from soitool.modules.module_base import (
HEADLINE_FONT, HEADLINE_FONT,
event_is_ctrl_plus, event_is_ctrl_plus,
event_is_ctrl_minus, event_is_ctrl_minus,
TABLE_CELL_DEFAULT_FONT,
) )
from soitool.modules.fit_to_contents_widgets import ( from soitool.modules.fit_to_contents_widgets import (
TableWithSizeOfContent, TableWithSizeOfContent,
...@@ -53,8 +54,14 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta): ...@@ -53,8 +54,14 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta):
Parameters Parameters
---------- ----------
data : list
Data to initialize module from. See `self.initialize_from_data` for
format.
database : soitool.database.Database database : soitool.database.Database
Database to fetch categoried words from. Database to fetch categoried words from.
category : str
Category to fetch words from to use as codes. If not passed a unique
category will be chosen at random.
Raises Raises
------ ------
...@@ -65,7 +72,7 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta): ...@@ -65,7 +72,7 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta):
used_categories = [] used_categories = []
"""List of categories that are used by other instances of this class.""" """List of categories that are used by other instances of this class."""
def __init__(self, size=None, data=None, database=None): def __init__(self, data=None, database=None, category=None):
self.type = CodePhraseModule.__name__ self.type = CodePhraseModule.__name__
QWidget.__init__(self) QWidget.__init__(self)
ModuleBase.__init__(self) ModuleBase.__init__(self)
...@@ -73,6 +80,7 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta): ...@@ -73,6 +80,7 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta):
self.line_edit_header = LineEditWithSizeOfContent("Kodefraser") self.line_edit_header = LineEditWithSizeOfContent("Kodefraser")
self.line_edit_header.setFont(HEADLINE_FONT) self.line_edit_header.setFont(HEADLINE_FONT)
self.table = TableWithSizeOfContent(0, 2) self.table = TableWithSizeOfContent(0, 2)
self.table.setFont(TABLE_CELL_DEFAULT_FONT)
# Qt should let this widget be exactly the size of it's sizeHint # Qt should let this widget be exactly the size of it's sizeHint
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
...@@ -93,7 +101,7 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta): ...@@ -93,7 +101,7 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta):
# Initialize either default values or from data. Either way from this # Initialize either default values or from data. Either way from this
# point on the widget should never have less than one row # point on the widget should never have less than one row
if data is None and size is None: if data is None:
self.initialize_default() self.initialize_default()
else: else:
self.initialize_from_data(data) self.initialize_from_data(data)
...@@ -122,18 +130,26 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta): ...@@ -122,18 +130,26 @@ class CodePhraseModule(ModuleBase, QWidget, metaclass=Meta):
self.set_code_table_item(i, row[CODE_COLUMN]) self.set_code_table_item(i, row[CODE_COLUMN])
self.set_phrase_table_item(i, row[PHRASE_COLUMN]) self.set_phrase_table_item(i, row[PHRASE_COLUMN])
def initialize_default(self): def initialize_default(self, category=None):
"""Initialize to default values. """Initialize to default values.
Prepares `self.category` and `self.available_words` from Prepares `self.category` and `self.available_words` from
`self.database`. `self.database`.
Parameters
----------
category : str
Category to use. If 'None' will choose one from the database.
Raises Raises
------ ------
NoMoreAvailableCategories NoMoreAvailableCategories
Indicates that there are no more categories to choose from. Indicates that there are no more categories to choose from.
""" """
self.category = self.get_category() if category is not None:
self.category = category
else:
self.category = self.get_category()
self.available_words = self.database.get_category_words(self.category) self.available_words = self.database.get_category_words(self.category)
for _ in range(START_ROWS): for _ in range(START_ROWS):
self.add_row() self.add_row()
......
...@@ -20,6 +20,7 @@ from soitool.modules.module_authentication_board import ( ...@@ -20,6 +20,7 @@ from soitool.modules.module_authentication_board import (
) )
from soitool.modules.module_subtractorcodes import SubtractorcodesModule from soitool.modules.module_subtractorcodes import SubtractorcodesModule
from soitool.modules.module_predefined_codes import PredefinedCodesModule from soitool.modules.module_predefined_codes import PredefinedCodesModule
from soitool.modules.module_code_phrase import CodePhraseModule
from soitool.new_module_dialog import MODULE_CHOICES from soitool.new_module_dialog import MODULE_CHOICES
from soitool.soi_workspace_widget import DATABASE_MODULES from soitool.soi_workspace_widget import DATABASE_MODULES
from soitool.database import Database from soitool.database import Database
...@@ -107,8 +108,9 @@ class TestModulesAcrossResolutions(unittest.TestCase): ...@@ -107,8 +108,9 @@ class TestModulesAcrossResolutions(unittest.TestCase):
{"x": 0, "y": 0, "page": 1, "name": "PredefinedCodesModule"}, {"x": 0, "y": 0, "page": 1, "name": "PredefinedCodesModule"},
{"x": 654, "y": 0, "page": 1, "name": "AuthenticationBoardModule"}, {"x": 654, "y": 0, "page": 1, "name": "AuthenticationBoardModule"},
{"x": 1061.5, "y": 0, "page": 1, "name": "SubtractorcodesModule"}, {"x": 1061.5, "y": 0, "page": 1, "name": "SubtractorcodesModule"},
{"x": 1287.0, "y": 0, "page": 1, "name": "FreeTextModule"}, {"x": 1287.0, "y": 0, "page": 1, "name": "CodePhraseModule"},
{"x": 1387.0, "y": 0, "page": 1, "name": "TableModule"}, {"x": 1489.0, "y": 0, "page": 1, "name": "FreeTextModule"},
{"x": 1589.0, "y": 0, "page": 1, "name": "TableModule"},
] ]
# For use with modules that require a database # For use with modules that require a database
...@@ -137,9 +139,19 @@ class TestModulesAcrossResolutions(unittest.TestCase): ...@@ -137,9 +139,19 @@ class TestModulesAcrossResolutions(unittest.TestCase):
QTimer.singleShot(0, press_enter) QTimer.singleShot(0, press_enter)
if module in DATABASE_MODULES: if module in DATABASE_MODULES:
soi.add_module(module.__name__, module(database=database)) if module == CodePhraseModule:
# CodePhraseModule needs a category injected in it's init.
# Choosing "Tresort" because it contains words short enough to
# not expand the module beyond default width
module_instance = module(
database=database, category="Tresort"
)
else:
module_instance = module(database=database)
else: else:
soi.add_module(module.__name__, module()) module_instance = module()
soi.add_module(module.__name__, module_instance)
soi.reorganize() soi.reorganize()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment