Skip to content

Commit

Permalink
* Slightly refactored productiontab gui code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisOelmueller committed Apr 17, 2012
1 parent ec0c408 commit b359ed3
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions horizons/gui/tabs/productiontabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,9 @@ def refresh(self):

# fill it with input and output resources
in_res_container = container.findChild(name="input_res")
for in_res in production.get_consumed_resources():
filled = float(self.instance.get_component(StorageComponent).inventory[in_res]) * 100 / \
self.instance.get_component(StorageComponent).inventory.get_limit(in_res)
in_res_container.addChild( \
ImageFillStatusButton.init_for_res(self.instance.session.db,\
in_res, \
self.instance.get_component(StorageComponent).inventory[in_res], \
filled, \
use_inactive_icon=False, \
uncached=True) \
)
self._add_resource_icons(in_res_container, production.get_consumed_resources())
out_res_container = container.findChild(name="output_res")
for out_res in production.get_produced_res():
filled = float(self.instance.get_component(StorageComponent).inventory[out_res]) * 100 / \
self.instance.get_component(StorageComponent).inventory.get_limit(out_res)
out_res_container.addChild( \
ImageFillStatusButton.init_for_res(self.instance.session.db, \
out_res, \
self.instance.get_component(StorageComponent).inventory[out_res], \
filled, \
use_inactive_icon=False, \
uncached=True) \
)

self._add_resource_icons(out_res_container, production.get_produced_resources())

# fix pychans lack of dynamic container sizing
# the container in the xml must provide a height attribute, that is valid for
Expand Down Expand Up @@ -149,6 +128,14 @@ def _refresh_utilisation(self):
utilisation = int(round(self.instance.get_component(Producer).capacity_utilisation * 100))
self.widget.child_finder('capacity_utilisation').text = unicode(utilisation) + u'%'

def _add_resource_icons(self, container, resources):
for res in resources:
inventory = self.instance.get_component(StorageComponent).inventory
filled = (inventory[res] * 100) // inventory.get_limit(res)
container.addChild(
ImageFillStatusButton.init_for_res(self.instance.session.db, res,
inventory[res], filled, use_inactive_icon=False, uncached=True))

def show(self):
super(ProductionOverviewTab, self).show()
Scheduler().add_new_object(Callback(self._refresh_utilisation), self, run_in = GAME_SPEED.TICKS_PER_SECOND, loops = -1)
Expand Down

0 comments on commit b359ed3

Please sign in to comment.