Robot Framework Integrated Development Environment (RIDE)
flowsizer.py
Go to the documentation of this file.
1 #-------------------------------------------------------------------------------
2 # Class: FlowSizer
3 # Defines a horizontal or vertical flow layout sizer for wxPython
4 # Written by: David C. Morrill
5 # Date: 01/12/2006
6 # (c) Copyright 2006 by Enthought, Inc.
7 # License: BSD Style.
8 #-------------------------------------------------------------------------------
9 
10 # This code has been modified after inclusion and is no longer generic.
11 # You should probably not use this in your own projects.
12 #
13 # Copyright 2008-2015 Nokia Networks
14 # Copyright 2016- Robot Framework Foundation
15 #
16 # Licensed under the Apache License, Version 2.0 (the "License");
17 # you may not use this file except in compliance with the License.
18 # You may obtain a copy of the License at
19 #
20 # http://www.apache.org/licenses/LICENSE-2.0
21 #
22 # Unless required by applicable law or agreed to in writing, software
23 # distributed under the License is distributed on an "AS IS" BASIS,
24 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 # See the License for the specific language governing permissions and
26 # limitations under the License.
27 
28 import wx
29 from wx import Sizer
30 
31 
32 
36 class HorizontalFlowSizer(Sizer):
37 
40  _DEFAUL_WIDTH = 200
41 
42 
45  def __init__(self):
46  Sizer.__init__(self)
47  self._frozen_frozen = False
48  self._needed_size_needed_size = None
49  self._height_height = 0
50 
51 
54  def CalcMin(self):
55  return wx.Size(0, 0)
56 
57 
61  def RecalcSizes(self):
62  x0, y0 = self.GetPosition()
63  dx, dy = self.GetSize()
64  dy = self._height_height or dy
65  if self._is_error_width_is_error_width(dx):
66  dx = HorizontalFlowSizer._DEFAUL_WIDTH
67  else:
68  HorizontalFlowSizer._DEFAUL_WIDTH = dx
69  x_border = x0 + dx
70  x, y = x0, y0
71  mdy = sdy = 0
72  cur_max = 0
73  for item in self.GetChildren():
74  idx, idy = item.CalcMin()
75  expand = item.GetFlag() & wx.EXPAND
76  if (x > x0) and ((x + idx) > x_border):
77  x = x0
78  y += (mdy + sdy)
79  mdy = sdy = 0
80  cur_max = max(idy, cur_max)
81  if expand:
82  idy = cur_max
83  if item.IsSpacer():
84  sdy = max(sdy, idy)
85  if x == x0:
86  idx = 0
87  item.SetDimension(wx.Point(x, y), wx.Size(idx, idy))
88  item.Show(True)
89  x += idx
90  mdy = max(mdy, idy)
91  newheight = y + mdy + sdy - y0
92  if newheight != self._height_height:
93  self._height_height = newheight
94  # Enforce that the parent window recalculates needed height
95  self._send_resize_event_send_resize_event()
96 
97  def _send_resize_event(self):
98  frame = self.GetContainingWindow().GetTopLevelParent()
99  frame.ProcessEvent(wx.SizeEvent(frame.Size, frame.Id))
100 
101  def _is_error_width(self, dx):
102  # It seems that there are several widths that notify that the width
103  # calculation was unsuccessful. The erroneous widths are:
104  # 94 in windows xp
105  # 100 in windows 7
106  # 0 everywhere
107  return dx in [0, 94, 100]
108 
109  @property
110  height = property
111 
112  def height(self):
113  return self._height_height
A sizer which lays out component left to right top to bottom.
Definition: flowsizer.py:36
def CalcMin(self)
Calculates the minimum size needed by the sizer.
Definition: flowsizer.py:54
def RecalcSizes(self)
Layout the contents of the sizer based on the sizer's current size and position.
Definition: flowsizer.py:61
def __init__(self)
Initializes the object:
Definition: flowsizer.py:45