Skip to content

Commit 24b2462

Browse files
author
Tom De Smedt
committed
nodebox.gui control spacing fix
1 parent 70e5298 commit 24b2462

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

nodebox/gui/controls.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,9 @@ def __init__(self, caption="", fixed=False, modal=True, x=0, y=0, width=175, hei
909909
}
910910
_popdefault(kwargs, "width")
911911
_popdefault(kwargs, "height")
912-
self.append(Label(caption, **kwargs))
912+
self.append(Label(caption))
913913
self.append(Close())
914+
#self.extend(kwargs.pop("controls", []), **kwargs)
914915
self.fixed = fixed # Draggable?
915916
self.modal = modal # Closeable?
916917
self._pack()
@@ -928,19 +929,19 @@ def controls(self):
928929
return iter(self[2:]) # self[0] is the Label,
929930
# self[1] is the Close action.
930931

931-
def insert(self, i, control, **kwargs):
932+
def insert(self, i, control):
932933
""" Inserts the control, or inserts all controls in the given Layout.
933934
"""
934935
if isinstance(control, Layout):
935936
# If the control is actually a Layout (e.g. ordered group of controls), apply it.
936-
control.apply(**kwargs)
937+
control.apply()
937938
Layer.insert(self, i, control)
938939

939-
def append(self, control, **kwargs):
940-
self.insert(len(self), control, **kwargs)
941-
def extend(self, controls, **kwargs):
940+
def append(self, control):
941+
self.insert(len(self), control)
942+
def extend(self, controls):
942943
for control in controls:
943-
self.append(control, **kwargs)
944+
self.append(control)
944945

945946
def _pack(self):
946947
# Center the caption in the label's header.
@@ -1046,6 +1047,8 @@ def draw(self):
10461047

10471048
class Layout(Layer):
10481049

1050+
SPACING = 10 # Spacing between controls in a Layout.
1051+
10491052
def __init__(self, controls=[], x=0, y=0, **kwargs):
10501053
""" A group of controls with a specific layout.
10511054
Controls can be added with Layout.append().
@@ -1056,11 +1059,14 @@ def __init__(self, controls=[], x=0, y=0, **kwargs):
10561059
kwargs["height"] = 0
10571060
Layer.__init__(self, x=x, y=y, **kwargs)
10581061
self._controls = {} # Lazy cache of (id, control)-children, see nested().
1062+
self.spacing = kwargs.get("spacing", Layout.SPACING)
10591063
self.extend(controls)
10601064

10611065
def insert(self, i, control):
1066+
""" Inserts the control, or inserts all controls in the given Layout.
1067+
"""
10621068
if isinstance(control, Layout):
1063-
# If the control is actually a Layout, apply it.
1069+
# If the control is actually a Layout (e.g. ordered group of controls), apply it.
10641070
control.apply()
10651071
Layer.insert(self, i, control)
10661072

@@ -1087,7 +1093,7 @@ def __getattr__(self, k):
10871093
return ctrl
10881094
raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, k)
10891095

1090-
def apply(self, spacing=0):
1096+
def apply(self):
10911097
""" Adjusts the position and size of the controls to match the layout.
10921098
"""
10931099
self.width = max(control.width for control in self)
@@ -1147,7 +1153,7 @@ def __init__(self, controls=[], x=0, y=0, width=125, **kwargs):
11471153
Labeled.__init__(self, controls, x=x, y=y, **kwargs)
11481154
self._maxwidth = width
11491155

1150-
def apply(self, spacing=10):
1156+
def apply(self):
11511157
""" Adjusts the position and width of all the controls in the layout:
11521158
- each control is placed next to its caption, with spacing in between,
11531159
- each caption is aligned to the right, and centered vertically,
@@ -1172,14 +1178,14 @@ def apply(self, spacing=10):
11721178
control._set_width(mw)
11731179
control._pack()
11741180
caption.x = dx + w1 - caption.width # halign right.
1175-
control.x = dx + w1 + (w1>0 and spacing)
1181+
control.x = dx + w1 + (w1>0 and self.spacing)
11761182
caption.y = dy + 0.5 * (control.height - caption.height) # valign center.
11771183
control.y = dy
1178-
dy += max(caption.height, control.height, 10) + spacing
1179-
self.width = w1 + max(w2, mw) + (w1>0 and spacing)
1180-
self.height = dy - spacing
1184+
dy += max(caption.height, control.height) + self.spacing
1185+
self.width = w1 + max(w2, mw) + (w1>0 and self.spacing)
1186+
self.height = dy - self.spacing
11811187

1182-
TOP, CENTER = "top", "center"
1188+
TOP, BOTTOM, CENTER = "top", "bottom", "center"
11831189

11841190
class Row(Labeled):
11851191

@@ -1192,13 +1198,13 @@ def __init__(self, controls=[], x=0, y=0, width=125, align=CENTER, **kwargs):
11921198
self._maxwidth = width
11931199
self._align = align
11941200

1195-
def apply(self, spacing=10):
1201+
def apply(self):
11961202
""" Adjusts the position and width of all the controls in the layout:
11971203
- each control is placed centrally below its caption, with spacing in between,
11981204
- the width of all Label, Button, Slider, Field controls is evened out.
11991205
"""
12001206
mw = self._maxwidth
1201-
da = self._align==TOP and 1.0 or 0.5
1207+
da = {TOP: 1.0, BOTTOM: 0.0, CENTER: 0.5}.get(self._align, 0.5)
12021208
h1 = max(control.height for control in self.controls)
12031209
h2 = max(caption.height for caption in self.captions)
12041210
dx = 0
@@ -1209,8 +1215,8 @@ def apply(self, spacing=10):
12091215
control._pack()
12101216
caption.x = dx + 0.5 * max(control.width - caption.width, 0) # halign center
12111217
control.x = dx + 0.5 * max(caption.width - control.width, 0) # halign center
1212-
caption.y = dy + h1 + (h2>0 and spacing)
1218+
caption.y = dy + h1 + (h2>0 and self.spacing)
12131219
control.y = dy + da * (h1 - control.height) # valign center
1214-
dx += max(caption.width, control.width, 10) + spacing
1215-
self.width = dx - spacing
1216-
self.height = h1 + h2 + (h2>0 and spacing)
1220+
dx += max(caption.width, control.width) + self.spacing
1221+
self.width = dx - self.spacing
1222+
self.height = h1 + h2 + (h2>0 and self.spacing)

nodebox/gui/theme/flag-checked.png

27 Bytes
Loading

nodebox/gui/theme/flag.png

-3 Bytes
Loading

nodebox/gui/theme/flag.psd

2.13 KB
Binary file not shown.

0 commit comments

Comments
 (0)