1# -*- coding: utf-8 -*-
2
3# ####################################################################
4#  Copyright (C) 2005-2013 by the FIFE team
5#  http://www.fifengine.net
6#  This file is part of FIFE.
7#
8#  FIFE is free software; you can redistribute it and/or
9#  modify it under the terms of the GNU Lesser General Public
10#  License as published by the Free Software Foundation; either
11#  version 2.1 of the License, or (at your option) any later version.
12#
13#  This library is distributed in the hope that it will be useful,
14#  but WITHOUT ANY WARRANTY; without even the implied warranty of
15#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16#  Lesser General Public License for more details.
17#
18#  You should have received a copy of the GNU Lesser General Public
19#  License along with this library; if not, write to the
20#  Free Software Foundation, Inc.,
21#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22# ####################################################################
23
24from __future__ import absolute_import
25from fife import fife
26from fife import fifechan
27
28from fife.extensions.pychan.attrs import IntAttr, IntListAttr
29
30from .containers import Container
31
32class AdjustingContainer(Container):
33	"""
34	This is the adjusting container class. It provides space in which child widgets can
35	be position via the position attribute.
36
37	New Attributes
38	==============
39
40	  - colums - Integer: The number of columns to divide the widgets into.
41	  - alignments: The alignment per column.
42	"""
43
44	ATTRIBUTES = Container.ATTRIBUTES + [ IntAttr('columns'),
45										  IntListAttr('alignments'),
46										]
47	DEFAULT_NUMBER_COLUMNS = 3
48
49	def __init__(self,
50				 parent = None,
51				 name = None,
52				 size = None,
53				 min_size = None,
54				 max_size = None,
55				 fixed_size = None,
56				 margins = None,
57				 padding = None,
58				 helptext = None,
59				 position = None,
60				 style = None,
61				 hexpand = None,
62				 vexpand = None,
63				 font = None,
64				 base_color = None,
65				 background_color = None,
66				 foreground_color = None,
67				 selection_color = None,
68				 border_color = None,
69				 outline_color = None,
70				 border_size = None,
71				 outline_size = None,
72				 position_technique = None,
73				 is_focusable = None,
74				 comment = None,
75				 background_image = None,
76				 opaque = None,
77				 layout = None,
78				 spacing = None,
79				 uniform_size = None,
80				 _real_widget = None,
81				 columns = None,
82				 alignments = None):
83
84		if _real_widget is None: _real_widget = fifechan.AdjustingContainer()
85
86		super(AdjustingContainer,self).__init__(parent=parent,
87												name=name,
88												size=size,
89												min_size=min_size,
90												max_size=max_size,
91												fixed_size=fixed_size,
92												margins=margins,
93												padding=padding,
94												helptext=helptext,
95												position=position,
96												style=style,
97												hexpand=hexpand,
98												vexpand=vexpand,
99												font=font,
100												base_color=base_color,
101												background_color=background_color,
102												foreground_color=foreground_color,
103												selection_color=selection_color,
104												border_color=border_color,
105												outline_color=outline_color,
106												border_size=border_size,
107												outline_size=outline_size,
108												position_technique=position_technique,
109												is_focusable=is_focusable,
110												comment=comment,
111												background_image=background_image,
112												opaque=opaque,
113												layout=layout,
114												spacing=spacing,
115												uniform_size=uniform_size,
116												_real_widget=_real_widget)
117
118		if columns is not None:
119			self.columns = columns
120		else:
121			self.columns = self.DEFAULT_NUMBER_COLUMNS
122
123		if alignments is not None:
124			self.alignments = alignments
125
126	def clone(self, prefix):
127		containerClone = AdjustingContainer(None,
128						self._createNameWithPrefix(prefix),
129						self.size,
130						self.min_size,
131						self.max_size,
132						self.fixed_size,
133						self.margins,
134						self.padding,
135						self.helptext,
136						self.position,
137						self.style,
138						self.hexpand,
139						self.vexpand,
140						self.font,
141						self.base_color,
142						self.background_color,
143						self.foreground_color,
144						self.selection_color,
145						self.border_color,
146						self.outline_color,
147						self.border_size,
148						self.outline_size,
149						self.position_technique,
150						self.is_focusable,
151						self.comment,
152						self.background_image,
153						self.opaque,
154						self.layout,
155						self.spacing,
156						self.uniform_size,
157						None,
158						self.columns,
159						self.alignments)
160
161		containerClone.addChildren(self._cloneChildren(prefix))
162		return containerClone
163
164	def _setNumberColumns(self, number):
165		self.real_widget.setNumberOfColumns(number)
166	def _getNumberColumns(self):
167		self.real_widget.getNumberOfColumns()
168	columns = property(_getNumberColumns, _setNumberColumns)
169
170	def _setColumnAlignment(self, column, alignment):
171		self.real_widget.setColumnAlignment(column, alignment)
172	def _getColumnAlignment(self, column):
173		self.real_widget.getColumnAlignment(column)
174	column_alignment = property(_getColumnAlignment, _setColumnAlignment)
175
176	def _setColumnAlignments(self, alignments):
177		i = 0
178		if alignments is not None:
179			for a in alignments:
180				self.real_widget.setColumnAlignment(i, a)
181				i += 1
182		else:
183			cols = self.columns
184			while i < cols:
185				self.real_widget.setColumnAlignment(i, 0)
186				i += 1
187	def _getColumnAlignments(self):
188		alignments = []
189		cols = self.columns
190		i = 0
191		while i < cols:
192			alignments.append(self.column_alignment(i))
193			i += 1
194		return alignments
195	alignments = property(_getColumnAlignments, _setColumnAlignments)
196
197