Package horizons :: Package gui :: Package tabs :: Module overviewtab
[hide private]
[frames] | no frames]

Source Code for Module horizons.gui.tabs.overviewtab

  1  # ################################################### 
  2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
  3  # team@unknown-horizons.org 
  4  # This file is part of Unknown Horizons. 
  5  # 
  6  # Unknown Horizons is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the 
 18  # Free Software Foundation, Inc., 
 19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 20  # ################################################### 
 21   
 22  from horizons.component.namedcomponent import NamedComponent 
 23  from horizons.gui.tabs.tabinterface import TabInterface 
 24  from horizons.i18n import gettext as T, gettext_lazy as LazyT 
 25   
 26   
27 -class OverviewTab(TabInterface):
28 widget = 'overviewtab.xml' 29 icon_path = 'icons/tabwidget/common/building_overview' 30 helptext = LazyT("Overview") 31 32 has_stance = False 33
34 - def __init__(self, instance, widget=None, icon_path=None):
35 self.instance = instance 36 super().__init__(widget=widget, icon_path=icon_path)
37
38 - def init_widget(self):
39 # set player emblem 40 if self.widget.child_finder('player_emblem'): 41 if self.instance.owner is not None: 42 player_color = self.instance.owner.color.name 43 else: 44 player_color = 'no_player' 45 emblem = 'content/gui/images/tabwidget/emblems/emblem_%s.png' 46 self.widget.child_finder('player_emblem').image = emblem % player_color 47 48 if self.__class__.has_stance: 49 self.init_stance_widget()
50
51 - def refresh(self):
52 if (hasattr(self.instance, 'name') or self.instance.has_component(NamedComponent)) and self.widget.child_finder('name'): 53 name_widget = self.widget.child_finder('name') 54 # Named objects can't be translated. 55 if self.instance.has_component(NamedComponent): 56 name_widget.text = self.instance.get_component(NamedComponent).name 57 else: 58 name_widget.text = T(self.instance.name) 59 60 if hasattr(self.instance, 'running_costs') and \ 61 self.widget.child_finder('running_costs'): 62 self.widget.child_finder('running_costs').text = \ 63 str(self.instance.running_costs) 64 65 self.widget.adaptLayout()
66
67 - def show(self):
68 super().show() 69 if not self.instance.has_change_listener(self.refresh): 70 self.instance.add_change_listener(self.refresh) 71 if not self.instance.has_remove_listener(self.on_instance_removed): 72 self.instance.add_remove_listener(self.on_instance_removed) 73 if hasattr(self.instance, 'settlement') and \ 74 self.instance.settlement is not None and \ 75 not self.instance.settlement.has_change_listener(self._schedule_refresh): 76 # listen for settlement name changes displayed as tab headlines 77 self.instance.settlement.add_change_listener(self._schedule_refresh)
78
79 - def hide(self):
80 super().hide() 81 if self.instance is not None: 82 self.instance.discard_change_listener(self.refresh) 83 self.instance.discard_remove_listener(self.on_instance_removed) 84 if hasattr(self.instance, 'settlement') and self.instance.settlement is not None: 85 self.instance.settlement.discard_change_listener(self._schedule_refresh)
86
87 - def on_instance_removed(self):
88 self.on_remove() 89 self.instance = None
90
91 - def init_stance_widget(self):
92 """Call this for tabs with stances.""" 93 stance_widget = self.widget.findChild(name='stance') 94 if stance_widget is not None: 95 stance_widget.init(self.instance) 96 self.add_remove_listener(stance_widget.remove)
97 98
99 -class GroundUnitOverviewTab(OverviewTab):
100 widget = 'overview_groundunit.xml' 101 helptext = LazyT("Unit overview") 102 103 has_stance = True 104
105 - def init_widget(self):
106 super().init_widget() 107 health_widget = self.widget.findChild(name='health') 108 health_widget.init(self.instance) 109 self.add_remove_listener(health_widget.remove) 110 weapon_storage_widget = self.widget.findChild(name='weapon_storage') 111 weapon_storage_widget.init(self.instance) 112 self.add_remove_listener(weapon_storage_widget.remove)
113 114 115 #added from old groundunittabs.py 116 #class GroundUnitOverviewTab(OverviewTab): 117 # widget = 'overview_war_groundunit.xml' 118 # helptext = LazyT("Groundunit overview") 119 # 120 # def init_widget(self): 121 # super(GroundUnitOverviewTab, self).init_widget() 122 123
124 -class GenericOverviewTab(OverviewTab):
125 """Name and running costs.""" 126 widget = 'overview_generic.xml'
127