[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
|
@ -7,12 +7,15 @@ import bumblebee.engine
|
|||
|
||||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine):
|
||||
super(Module, self).__init__(engine)
|
||||
super(Module, self).__init__(engine,
|
||||
bumblebee.output.Widget(full_text=self.utilization)
|
||||
)
|
||||
self._utilization = psutil.cpu_percent(percpu=False)
|
||||
|
||||
def widgets(self):
|
||||
self._utilization = psutil.cpu_percent(percpu=False)
|
||||
def utilization(self):
|
||||
return "{:05.02f}%".format(self._utilization)
|
||||
|
||||
return bumblebee.output.Widget(full_text="{:05.02f}%".format(self._utilization))
|
||||
def update(self, widgets):
|
||||
self._utilization = psutil.cpu_percent(percpu=False)
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue