Coverage for src/robotide/editor/flowsizer.py: 86%

52 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-06 10:40 +0100

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 

28import wx 

29from wx import Sizer 

30 

31 

32class HorizontalFlowSizer(Sizer): 

33 """ 

34 A sizer which lays out component left to right top to bottom. Java uses 

35 these quite heavily 

36 """ 

37 _DEFAUL_WIDTH = 200 

38 

39 def __init__(self): 

40 """ 

41 Initializes the object: 

42 """ 

43 Sizer.__init__(self) 1ca

44 self._frozen = False 1ca

45 self._needed_size = None 1ca

46 self._height = 0 1ca

47 

48 def CalcMin(self): 

49 """ 

50 Calculates the minimum size needed by the sizer. 

51 """ 

52 return wx.Size(0, 0) 1ca

53 

54 def RecalcSizes(self): 

55 """ 

56 Layout the contents of the sizer based on the sizer's current size 

57 and position. 

58 """ 

59 x0, y0 = self.GetPosition() 1a

60 dx, dy = self.GetSize() 1a

61 dy = self._height or dy 1a

62 if self._is_error_width(dx): 1a

63 dx = HorizontalFlowSizer._DEFAUL_WIDTH 1a

64 else: 

65 HorizontalFlowSizer._DEFAUL_WIDTH = dx 1a

66 x_border = x0 + dx 1a

67 x, y = x0, y0 1a

68 mdy = sdy = 0 1a

69 cur_max = 0 1a

70 for item in self.GetChildren(): 1a

71 idx, idy = item.CalcMin() 1a

72 expand = item.GetFlag() & wx.EXPAND 1a

73 if (x > x0) and ((x + idx) > x_border): 1a

74 x = x0 1a

75 y += (mdy + sdy) 1a

76 mdy = sdy = 0 1a

77 cur_max = max(idy, cur_max) 1a

78 if expand: 78 ↛ 79line 78 didn't jump to line 79 because the condition on line 78 was never true1a

79 idy = cur_max 

80 if item.IsSpacer(): 80 ↛ 81line 80 didn't jump to line 81 because the condition on line 80 was never true1a

81 sdy = max(sdy, idy) 

82 if x == x0: 

83 idx = 0 

84 item.SetDimension(wx.Point(x, y), wx.Size(idx, idy)) 1a

85 item.Show(True) 1a

86 x += idx 1a

87 mdy = max(mdy, idy) 1a

88 newheight = y + mdy + sdy - y0 1a

89 if newheight != self._height: 1a

90 self._height = newheight 1a

91 # Enforce that the parent window recalculates needed height 

92 self._send_resize_event() 1a

93 

94 def _send_resize_event(self): 

95 frame = self.GetContainingWindow().GetTopLevelParent() 1a

96 frame.ProcessEvent(wx.SizeEvent(frame.Size, frame.Id)) 1a

97 

98 def _is_error_width(self, dx): 

99 # It seems that there are several widths that notify that the width 

100 # calculation was unsuccessful. The erroneous widths are: 

101 # 94 in windows xp 

102 # 100 in windows 7 

103 # 0 everywhere 

104 return dx in [0, 94, 100] 1a

105 

106 @property 

107 def height(self): 

108 return self._height