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

Source Code for Module horizons.gui.widgets.pickbeltwidget

  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.gui.style import NOTHING 
 23  from horizons.gui.util import load_uh_widget 
 24  from horizons.gui.widgets.imagebutton import ImageButton, OkButton 
 25  from horizons.gui.windows import Window 
 26  from horizons.util.python.callback import Callback 
 27   
 28   
29 -class PickBeltWidget:
30 """Base class for widget with sections behaving as pages""" 31 sections = () # Tuple with widget name and Label 32 widget_xml = '' # xml to load for the widget 33 pickbelt_start_pos = (5, 150) 34 page_pos = (185, 45) 35
36 - def __init__(self):
37 self.page_widgets = {} 38 self.widget = load_uh_widget(self.widget_xml, center_widget=True) 39 40 # Lists holding pickbelt ImageButtons, placed to the left/right of the book 41 self.buttons = {'left': [], 'right': []} 42 43 for i, (name, text) in enumerate(self.sections): 44 self.page_widgets[i] = self.widget.findChild(name=name) 45 46 # Create the required pickbelts 47 for i, (name, text) in enumerate(self.sections): 48 for side in self.buttons: 49 pickbelt = ImageButton(text=text) 50 pickbelt.name = '{}_{}'.format(name, side) 51 pickbelt.path = 'images/background/pickbelt_{}'.format(side) 52 pickbelt.font = "pickbelt" 53 54 pickbelt.capture(Callback(self.update_view, i), event_name="mouseClicked") 55 56 start_x, start_y = self.pickbelt_start_pos 57 pickbelt.position = (start_x + 5 * i, start_y + 70 * i) 58 59 container = self.widget.findChild(name="{}_pickbelts".format(side)) 60 container.addChild(pickbelt) 61 self.buttons[side].append(pickbelt) 62 63 self.widget.show() # Hack to initially setup the pickbelts properly 64 self.update_view() 65 self.widget.hide() # Hack to initially setup the pickbelts properly
66
67 - def get_widget(self):
68 return self.widget
69
70 - def update_view(self, number=0):
71 for page in self.page_widgets.values(): 72 page.hide() 73 self.page_widgets[number].show() 74 # Setup the pickbelts according to selection 75 for belts in self.buttons.values(): 76 for belt in belts: 77 belt.show() 78 split = number + 1 79 for belt in self.buttons['left'][split:] + self.buttons['right'][:split]: 80 belt.hide()
81 82
83 -class CreditsPickbeltWidget(PickBeltWidget, Window):
84 """Widget for credits dialog with pickbelt style pages""" 85 widget_xml = 'credits.xml' 86 sections = ( 87 ('credits_team_2016', 'UH-Team New'), 88 ('credits_team_2015', 'UH-Team Old'), 89 ('credits_patchers', 'Patchers'), 90 ('credits_translators', 'Translators'), 91 ('credits_packagers', 'Packagers'), 92 ('credits_thanks', 'Thanks'), 93 ) 94
95 - def __init__(self, windows):
96 Window.__init__(self, windows) 97 PickBeltWidget.__init__(self) 98 99 # Overwrite a few style pieces 100 for box in self.widget.findChildren(name='box'): 101 box.margins = (30, 0) # to get some indentation 102 box.padding = 3 103 for listbox in self.widget.findChildren(name='translators'): 104 listbox.background_color = NOTHING 105 106 self.widget.findChild(name=OkButton.DEFAULT_NAME).capture(self._windows.close)
107
108 - def show(self):
109 self.widget.show()
110
111 - def hide(self):
112 self.widget.hide()
113