Package muntjac :: Package ui :: Module expand_layout
[hide private]
[frames] | no frames]

Source Code for Module muntjac.ui.expand_layout

 1  # Copyright (C) 2012 Vaadin Ltd.  
 2  # Copyright (C) 2012 Richard Lincoln 
 3  #  
 4  # Licensed under the Apache License, Version 2.0 (the "License");  
 5  # you may not use this file except in compliance with the License.  
 6  # You may obtain a copy of the License at  
 7  #  
 8  #     http://www.apache.org/licenses/LICENSE-2.0  
 9  #  
10  # Unless required by applicable law or agreed to in writing, software  
11  # distributed under the License is distributed on an "AS IS" BASIS,  
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13  # See the License for the specific language governing permissions and  
14  # limitations under the License. 
15   
16  """Defines a layout that will give one of it's components as much space as 
17  possible, while still showing the other components in the layout.""" 
18   
19  from warnings import warn 
20   
21  from muntjac.ui.ordered_layout import OrderedLayout 
22   
23   
24 -class ExpandLayout(OrderedLayout):
25 """A layout that will give one of it's components as much space as 26 possible, while still showing the other components in the layout. The 27 other components will in effect be given a fixed sized space, while the 28 space given to the expanded component will grow/shrink to fill the rest 29 of the space available - for instance when re-sizing the window. 30 31 Note that this layout is 100% in both directions by default 32 (L{setSizeFull}). Remember to set the units if you want to 33 specify a fixed size. If the layout fails to show up, check that the 34 parent layout is actually giving some space. 35 36 @deprecated: Deprecated in favor of the new OrderedLayout 37 """ 38
39 - def __init__(self, orientation=None):
40 warn('use OrderedLayout', DeprecationWarning) 41 42 self._expanded = None 43 44 if orientation is None: 45 self.ORIENTATION_VERTICAL 46 47 super(ExpandLayout, self).__init__(orientation) 48 self.setSizeFull()
49 50
51 - def expand(self, c):
52 """@param c: Component which container will be maximized 53 """ 54 if self._expanded is not None: 55 try: 56 self.setExpandRatio(self._expanded, 0.0) 57 except ValueError: 58 pass # Ignore error if component has been removed 59 60 self._expanded = c 61 if self._expanded is not None: 62 self.setExpandRatio(self._expanded, 1.0) 63 64 self.requestRepaint()
65 66
67 - def addComponent(self, c, index=None):
68 if index is None: 69 super(ExpandLayout, self).addComponent(c) 70 else: 71 super(ExpandLayout, self).addComponent(c, index) 72 if self._expanded is None: 73 self.expand(c)
74 75
76 - def addComponentAsFirst(self, c):
77 super(ExpandLayout, self).addComponentAsFirst(c) 78 if self._expanded is None: 79 self.expand(c)
80 81
82 - def removeComponent(self, c):
83 super(ExpandLayout, self).removeComponent(c) 84 if c == self._expanded: 85 try: 86 self.expand(self.getComponentIterator().next()) 87 except StopIteration: 88 self.expand(None)
89 90
91 - def replaceComponent(self, oldComponent, newComponent):
92 super(ExpandLayout, self).replaceComponent(oldComponent, newComponent) 93 if oldComponent == self._expanded: 94 self.expand(newComponent)
95