Package horizons :: Package gui :: Package widgets :: Module icongroup
[hide private]
[frames] | no frames]

Source Code for Module horizons.gui.widgets.icongroup

  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 fife.extensions.pychan.widgets import HBox, Icon, VBox 
 23  from fife.extensions.pychan.widgets.common import IntAttr 
 24   
 25   
26 -class TilingBackground:
27 """The TilingBackground is a shortcut for several Icons combined to one group. 28 It usually serves as auxiliary widget if a tiling background image is desired, 29 but the layout also requires some kind of border around those tiling panels. 30 Default attributes are set in the widgets inheriting from TilingBackground. 31 """
32 - def __init__(self, amount, base_path, start_img, tiles_img, final_img, **kwargs):
33 super().__init__() # TODO: check if call is needed 34 # Note: Don't set the tile amount in the constructor, 35 # as it will not layout correctly, blame pychan for it :-) 36 self.__tile_amount = amount 37 self.start_img = base_path + start_img 38 self.tiles_img = base_path + tiles_img 39 self.final_img = base_path + final_img
40
41 - def _get_tile_amount(self):
42 return self.__tile_amount
43
44 - def _set_tile_amount(self, amount):
45 if amount == self.__tile_amount and amount > 0: 46 # Default amount of 0 should still add top/bottom graphics once 47 return 48 self.__tile_amount = amount 49 self.removeAllChildren() 50 start_img = Icon(image=self.start_img, name=self.name + '0') 51 self.addChild(start_img) 52 for i in range(self.amount): 53 mid = Icon(image=self.tiles_img, name=self.name + str(i + 1)) 54 self.addChild(mid) 55 self.addChild(Icon(image=self.final_img, name=self.name + str(self.amount + 1)))
56 57 amount = property(_get_tile_amount, _set_tile_amount)
58 59
60 -class TooltipBG(VBox, TilingBackground):
61 """Not usable from xml!"""
62 - def __init__(self, **kwargs):
63 VBox.__init__(self, name='tooltip_background', padding=0) 64 TilingBackground.__init__(self, 65 amount=0, 66 base_path="content/gui/images/background/widgets/tooltip_bg_", 67 start_img="top.png", tiles_img="middle.png", final_img="bottom.png", 68 **kwargs)
69 70
71 -class TabBG(VBox, TilingBackground):
72 """Intended to be used for any tab we display. 73 Uses content/gui/images/tabwidget/main_bg_*.png. 74 @param amount: amount of 50px tiles/panels in between top and bottom icon 75 """ 76 ATTRIBUTES = VBox.ATTRIBUTES + [IntAttr('amount')] 77
78 - def __init__(self, **kwargs):
79 VBox.__init__(self, name='tab_background_icons', padding=0) 80 TilingBackground.__init__(self, 81 amount=0, 82 base_path="content/gui/images/tabwidget/main_bg_", 83 start_img="top.png", tiles_img="fill.png", final_img="bottom.png", 84 **kwargs)
85 86
87 -class TilingHBox(HBox, TilingBackground):
88 """Currently mostly used by cityinfo, thus using its arguments as defaults. 89 90 Another use case is the TilingProgressBar. 91 @param amount: amount of 10px tiles/panels in between left and right icon 92 """ 93 ATTRIBUTES = HBox.ATTRIBUTES + [IntAttr('amount')] 94
95 - def __init__(self, **kwargs):
96 HBox.__init__(self, name='city_info_background', padding=0) 97 TilingBackground.__init__(self, 98 amount=0, 99 base_path="content/gui/images/background/widgets/cityinfo_", 100 start_img="left.png", tiles_img="fill.png", final_img="right.png", 101 **kwargs)
102 103
104 -class hr(Icon):
105 - def __init__(self, **kwargs):
106 super().__init__(image="content/gui/images/background/hr.png", **kwargs)
107