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, UnicodeAttr
29
30from .containers import Container
31
32class FlowContainer(Container):
33	"""
34	An implementation of a flow container that can contain other widgets.
35	The widgets can be sorted vertical per row or horizontal per column.
36	If the space in the container is too small to put all the components in one row or column,
37	it uses multiple rows or columns.
38
39	"""
40
41	ATTRIBUTES = Container.ATTRIBUTES + [ IntAttr('alignment'), ]
42
43	DEFAULT_LAYOUT = 'Horizontal'
44	DEFAULT_ALIGNMENT = 4 # Center
45
46	def __init__(self,
47				 parent = None,
48				 name = None,
49				 size = None,
50				 min_size = None,
51				 max_size = None,
52				 fixed_size = None,
53				 margins = None,
54				 padding = None,
55				 helptext = None,
56				 position = None,
57				 style = None,
58				 hexpand = None,
59				 vexpand = None,
60				 font = None,
61				 base_color = None,
62				 background_color = None,
63				 foreground_color = None,
64				 selection_color = None,
65				 border_color = None,
66				 outline_color = None,
67				 border_size = None,
68				 outline_size = None,
69				 position_technique = None,
70				 is_focusable = None,
71				 comment = None,
72				 background_image = None,
73				 opaque = None,
74				 layout = None,
75				 spacing = None,
76				 uniform_size = None,
77				 _real_widget = None,
78				 alignment = None):
79
80		if _real_widget is None: _real_widget = fifechan.FlowContainer()
81
82		super(FlowContainer,self).__init__(parent=parent,
83										   name=name,
84										   size=size,
85										   min_size=min_size,
86										   max_size=max_size,
87										   fixed_size=fixed_size,
88										   margins=margins,
89										   padding=padding,
90										   helptext=helptext,
91										   position=position,
92										   style=style,
93										   hexpand=hexpand,
94										   vexpand=vexpand,
95										   font=font,
96										   base_color=base_color,
97										   background_color=background_color,
98										   foreground_color=foreground_color,
99										   selection_color=selection_color,
100										   border_color=border_color,
101										   outline_color=outline_color,
102										   border_size=border_size,
103										   outline_size=outline_size,
104										   position_technique=position_technique,
105										   is_focusable=is_focusable,
106										   comment=comment,
107										   background_image=background_image,
108										   opaque=opaque,
109										   layout=layout,
110										   spacing=spacing,
111										   uniform_size=uniform_size,
112										   _real_widget=_real_widget)
113
114		if alignment is not None: self.alignment = alignment
115		else: self.alignment = self.DEFAULT_ALIGNMENT
116
117
118	def clone(self, prefix):
119		containerClone = FlowContainer(None,
120						self._createNameWithPrefix(prefix),
121						self.size,
122						self.min_size,
123						self.max_size,
124						self.fixed_size,
125						self.margins,
126						self.padding,
127						self.helptext,
128						self.position,
129						self.style,
130						self.hexpand,
131						self.vexpand,
132						self.font,
133						self.base_color,
134						self.background_color,
135						self.foreground_color,
136						self.selection_color,
137						self.border_color,
138						self.outline_color,
139						self.border_size,
140						self.outline_size,
141						self.position_technique,
142						self.is_focusable,
143						self.comment,
144						self.background_image,
145						self.opaque,
146						self.layout,
147						self.spacing,
148						self.uniform_size,
149						None,
150						self.alignment)
151
152		containerClone.addChildren(self._cloneChildren(prefix))
153		return containerClone
154
155	def _setAlignment(self, alignment): self.real_widget.setAlignment(alignment)
156	def _getAlignment(self): self.real_widget.getAlignment()
157	alignment = property(_getAlignment, _setAlignment)
158
159	def adjustContent(self):
160		self.real_widget.adjustContent()
161