f645203579
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
32 lines
639 B
Python
32 lines
639 B
Python
# pylint: disable=C0103,C0111,W0613
|
|
|
|
from bumblebee.output import Widget
|
|
|
|
def assertWidgetAttributes(test, widget):
|
|
test.assertTrue(isinstance(widget, Widget))
|
|
test.assertTrue(hasattr(widget, "full_text"))
|
|
|
|
class MockOutput(object):
|
|
def start(self):
|
|
pass
|
|
|
|
def stop(self):
|
|
pass
|
|
|
|
def draw(self, widgets, engine):
|
|
engine.stop()
|
|
|
|
def flush(self):
|
|
pass
|
|
|
|
class MockWidget(object):
|
|
def __init__(self, text):
|
|
self._text = text
|
|
|
|
def update(self, widgets):
|
|
pass
|
|
|
|
def full_text(self):
|
|
return self._text
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|