[go: up one dir, main page]

Menu

[dfe9bc]: / ui / layout.py  Maximize  Restore  History

Download this file

99 lines (80 with data), 2.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# ******************************************************
# * Copyright © 2017-2023 - Jordan Irwin (AntumDeluge) *
# ******************************************************
# * This software is licensed under the MIT license. *
# * See: LICENSE.txt for details. *
# ******************************************************
## Custom sizer classes.
#
# @module ui.layout
import wx
## @todo Doxygen
class _SizerBase:
## Retains spacer at end of items
#
# FIXME: Detect spacer as last item, otherwise call Add instead of Insert
def AddKeepLast(self, item, proportion=0, flag=0, border=0, userData=None):
last_index = self.GetItemCount() - 1
return self.Insert(last_index, item, proportion, flag, border, userData)
#self.Add(item, proportion, flag, border, userData)
## Re-define in inherited classes
def Insert(self, idx, item, proportion, flag, border, userData):
pass
## Re-define in inherited classes
def GetChildren(self):
return list()
## Retrieves all sizers contained with the sizer
def GetChildSizers(self):
sizers = []
for SIZER in self.GetChildren():
SIZER = SIZER.GetSizer()
if SIZER:
sizers.append(SIZER)
return tuple(sizers)
## Retrieves all windows contained within the sizer
def GetChildWindows(self):
windows = []
for WIN in self.GetChildren():
WIN = WIN.GetWindow()
if WIN:
windows.append(WIN)
return tuple(windows)
## Retrieves item at give index
#
# @param index
# \b \e Integer index of item to retrieve
# @param sizer
# Get sizer instance instead of window
def GetItemAtIndex(self, index, sizer=False):
items = self.GetChildren()
if items:
if sizer:
return items[0].GetSizer()
return items[0].GetWindow()
## Returns the number of items in the sizer
#
# Compatibility method for legacy wx versions
def GetItemCount(self):
if wx.MAJOR_VERSION > 2:
return wx.Sizer.GetItemCount(self)
return len(self.GetChildren())
## Finds index of an item
def GetItemIndex(self, item):
index = 0
for I in self.GetChildren():
S = I.GetSizer()
I = I.GetWindow()
if not I:
I = S
if I == item:
return index
index += 1
return None
## @todo Doxygen
class Sizer(wx.Sizer, _SizerBase):
def __init__(self):
wx.Sizer.__init__(self)
## @todo Doxygen
class BoxSizer(wx.BoxSizer, _SizerBase):
def __init__(self, orient):
wx.BoxSizer.__init__(self, orient)