[core] Widget creation/update overhaul
Until now, widgets were re-created during each iteration. For multiple, reasons, using static widget objects is much easier, so instead of creating new widgets continuously, modules now create the widgets during instantiation and get the list of widgets passed as parameter whenever an update occurs. During the update, they can still manipulate the widget list by removing and adding elements as needed. Advantages: * Less memory fragmentation (fewer (de)allocations) * Easier event management (widgets now have static IDs) * Easier module code (widget contents can simply be the result of a callback) see #23
This commit is contained in:
parent
60ae92c8e3
commit
f645203579
9 changed files with 65 additions and 17 deletions
25
tests/test_module.py
Normal file
25
tests/test_module.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# pylint: disable=C0103,C0111,W0703
|
||||
|
||||
import unittest
|
||||
|
||||
from bumblebee.engine import Module
|
||||
from tests.util import MockWidget
|
||||
|
||||
class TestModule(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.widget = MockWidget("foo")
|
||||
self.moduleWithoutWidgets = Module(engine=None, widgets=None)
|
||||
self.moduleWithOneWidget = Module(engine=None, widgets=self.widget)
|
||||
self.moduleWithMultipleWidgets = Module(engine=None,
|
||||
widgets=[self.widget, self.widget, self.widget]
|
||||
)
|
||||
|
||||
def test_empty_widgets(self):
|
||||
self.assertEquals(self.moduleWithoutWidgets.widgets(), [])
|
||||
|
||||
def test_single_widget(self):
|
||||
self.assertEquals(self.moduleWithOneWidget.widgets(), [self.widget])
|
||||
|
||||
def test_multiple_widgets(self):
|
||||
for widget in self.moduleWithMultipleWidgets.widgets():
|
||||
self.assertEquals(widget, self.widget)
|
Loading…
Add table
Add a link
Reference in a new issue