Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def makeGroup(self, parent, thissizer, group, *args):
'''
Messily builds the (potentially) nested and grouped layout
Note! Mutates `self.reifiedWidgets` in place with the widgets as they're
instantiated! I cannot figure out how to split out the creation of the
widgets from their styling without WxPython violently exploding
TODO: sort out the WX quirks and clean this up.
'''
# determine the type of border , if any, the main sizer will use
if getin(group, ['options', 'show_border'], False):
boxDetails = wx.StaticBox(parent, -1, self.getName(group) or '')
boxSizer = wx.StaticBoxSizer(boxDetails, wx.VERTICAL)
else:
boxSizer = wx.BoxSizer(wx.VERTICAL)
boxSizer.AddSpacer(10)
if group['name']:
groupName = wx_util.h1(parent, self.getName(group) or '')
groupName.SetForegroundColour(getin(group, ['options', 'label_color']))
boxSizer.Add(groupName, 0, wx.TOP | wx.BOTTOM | wx.LEFT, 8)
group_description = getin(group, ['description'])
if group_description:
description = AutoWrappedStaticText(parent, label=group_description, target=boxSizer)
description.SetForegroundColour(getin(group, ['options', 'description_color']))
description.SetMinSize((0, -1))
boxSizer.Add(description, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
def createWidgets(self):
"""
Instantiate the Gooey Widgets that are used within the RadioGroup
"""
from gooey.gui.components import widgets
return [getattr(widgets, item['type'])(self, item)
for item in getin(self.widgetInfo, ['data', 'widgets'], [])]
def apply_default_rewrites(spec):
top_level_subgroups = list(spec['widgets'].keys())
for subgroup in top_level_subgroups:
path = ['widgets', subgroup, 'contents']
contents = getin(spec, path)
for group in contents:
if group['name'] == 'positional arguments':
group['name'] = 'Required Arguments'
if group['name'] == 'optional arguments':
group['name'] = 'Optional Arguments'
return spec
def arrange(self, *args, **kwargs):
title = getin(self.widgetInfo, ['options', 'title'], _('choose_one'))
if getin(self.widgetInfo, ['options', 'show_border'], False):
boxDetails = wx.StaticBox(self, -1, title)
boxSizer = wx.StaticBoxSizer(boxDetails, wx.VERTICAL)
else:
boxSizer = wx.BoxSizer(wx.VERTICAL)
boxSizer.AddSpacer(10)
boxSizer.Add(wx_util.h1(self, title), 0)
for btn, widget in zip(self.radioButtons, self.widgets):
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(btn,0, wx.RIGHT, 4)
sizer.Add(widget, 1, wx.EXPAND)
boxSizer.Add(sizer, 1, wx.ALL | wx.EXPAND, 5)
self.SetSizer(boxSizer)
instantiated! I cannot figure out how to split out the creation of the
widgets from their styling without WxPython violently exploding
TODO: sort out the WX quirks and clean this up.
'''
# determine the type of border , if any, the main sizer will use
if getin(group, ['options', 'show_border'], False):
boxDetails = wx.StaticBox(parent, -1, self.getName(group) or '')
boxSizer = wx.StaticBoxSizer(boxDetails, wx.VERTICAL)
else:
boxSizer = wx.BoxSizer(wx.VERTICAL)
boxSizer.AddSpacer(10)
if group['name']:
groupName = wx_util.h1(parent, self.getName(group) or '')
groupName.SetForegroundColour(getin(group, ['options', 'label_color']))
boxSizer.Add(groupName, 0, wx.TOP | wx.BOTTOM | wx.LEFT, 8)
group_description = getin(group, ['description'])
if group_description:
description = AutoWrappedStaticText(parent, label=group_description, target=boxSizer)
description.SetForegroundColour(getin(group, ['options', 'description_color']))
description.SetMinSize((0, -1))
boxSizer.Add(description, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
# apply an underline when a grouping border is not specified
# unless the user specifically requests not to show it
if not getin(group, ['options', 'show_border'], False) and group['name'] \
and getin(group, ['options', 'show_underline'], True):
boxSizer.Add(wx_util.horizontal_rule(parent), 0, wx.EXPAND | wx.LEFT, 10)
ui_groups = self.chunkWidgets(group)
def chunkWidgets(self, group):
''' chunk the widgets up into groups based on their sizing hints '''
ui_groups = []
subgroup = []
for index, item in enumerate(group['items']):
if getin(item, ['options', 'full_width'], False):
ui_groups.append(subgroup)
ui_groups.append([item])
subgroup = []
else:
subgroup.append(item)
if len(subgroup) == getin(group, ['options', 'columns'], 2) \
or item == group['items'][-1]:
ui_groups.append(subgroup)
subgroup = []
return ui_groups
TODO: sort out the WX quirks and clean this up.
'''
# determine the type of border , if any, the main sizer will use
if getin(group, ['options', 'show_border'], False):
boxDetails = wx.StaticBox(parent, -1, self.getName(group) or '')
boxSizer = wx.StaticBoxSizer(boxDetails, wx.VERTICAL)
else:
boxSizer = wx.BoxSizer(wx.VERTICAL)
boxSizer.AddSpacer(10)
if group['name']:
groupName = wx_util.h1(parent, self.getName(group) or '')
groupName.SetForegroundColour(getin(group, ['options', 'label_color']))
boxSizer.Add(groupName, 0, wx.TOP | wx.BOTTOM | wx.LEFT, 8)
group_description = getin(group, ['description'])
if group_description:
description = AutoWrappedStaticText(parent, label=group_description, target=boxSizer)
description.SetForegroundColour(getin(group, ['options', 'description_color']))
description.SetMinSize((0, -1))
boxSizer.Add(description, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
# apply an underline when a grouping border is not specified
# unless the user specifically requests not to show it
if not getin(group, ['options', 'show_border'], False) and group['name'] \
and getin(group, ['options', 'show_underline'], True):
boxSizer.Add(wx_util.horizontal_rule(parent), 0, wx.EXPAND | wx.LEFT, 10)
ui_groups = self.chunkWidgets(group)
for uigroup in ui_groups:
sizer = wx.BoxSizer(wx.HORIZONTAL)
for item in uigroup:
widget = self.reifyWidget(parent, item)
# !Mutate the reifiedWidgets instance variable in place
self.reifiedWidgets.append(widget)
sizer.Add(widget, 1, wx.ALL | wx.EXPAND, 5)
boxSizer.Add(sizer, 0, wx.ALL | wx.EXPAND, 5)
# apply the same layout rules recursively for subgroups
hs = wx.BoxSizer(wx.HORIZONTAL)
for e, subgroup in enumerate(group['groups']):
self.makeGroup(parent, hs, subgroup, 1, wx.EXPAND)
if len(group['groups']) != e:
hs.AddSpacer(5)
# self.makeGroup(parent, hs, subgroup, 1, wx.ALL | wx.EXPAND, 5)
itemsPerColumn = getin(group, ['options', 'columns'], 2)
if e % itemsPerColumn or (e + 1) == len(group['groups']):
boxSizer.Add(hs, *args)
hs = wx.BoxSizer(wx.HORIZONTAL)
group_top_margin = getin(group, ['options', 'margin_top'], 1)
marginSizer = wx.BoxSizer(wx.VERTICAL)
marginSizer.Add(boxSizer, 1, wx.EXPAND | wx.TOP, group_top_margin)
thissizer.Add(marginSizer, *args)
# apply the same layout rules recursively for subgroups
hs = wx.BoxSizer(wx.HORIZONTAL)
for e, subgroup in enumerate(group['groups']):
self.makeGroup(parent, hs, subgroup, 1, wx.EXPAND)
if len(group['groups']) != e:
hs.AddSpacer(5)
# self.makeGroup(parent, hs, subgroup, 1, wx.ALL | wx.EXPAND, 5)
itemsPerColumn = getin(group, ['options', 'columns'], 2)
if e % itemsPerColumn or (e + 1) == len(group['groups']):
boxSizer.Add(hs, *args)
hs = wx.BoxSizer(wx.HORIZONTAL)
group_top_margin = getin(group, ['options', 'margin_top'], 1)
marginSizer = wx.BoxSizer(wx.VERTICAL)
marginSizer.Add(boxSizer, 1, wx.EXPAND | wx.TOP, group_top_margin)
thissizer.Add(marginSizer, *args)
def createRadioButtons(self):
# button groups in wx are statefully determined via a style flag
# on the first button (what???). All button instances are part of the
# same group until a new button is created with the style flag RG_GROUP
# https://wxpython.org/Phoenix/docs/html/wx.RadioButton.html
# (What???)
firstButton = wx.RadioButton(self, style=wx.RB_GROUP)
firstButton.SetValue(False)
buttons = [firstButton]
for _ in getin(self.widgetInfo, ['data','widgets'], [])[1:]:
buttons.append(wx.RadioButton(self))
return buttons