Browse Source

improved layout and style controls

pull/473/head
Chris 6 years ago
parent
commit
e0b577aac8
6 changed files with 59 additions and 15 deletions
  1. 20
      gooey/gui/components/config.py
  2. 12
      gooey/gui/components/widgets/bases.py
  3. 3
      gooey/gui/components/widgets/checkbox.py
  4. 7
      gooey/gui/components/widgets/listbox.py
  5. 5
      gooey/gui/components/widgets/radio_group.py
  6. 27
      gooey/gui/components/widgets/textarea.py

20
gooey/gui/components/config.py

@ -77,7 +77,7 @@ class ConfigPage(ScrolledPanel):
def layoutComponent(self):
sizer = wx.BoxSizer(wx.VERTICAL)
for item in self.rawWidgets['contents']:
self.makeGroup(self, sizer, item, 0, wx.EXPAND)
self.makeGroup(self, sizer, item, 0, wx.EXPAND | wx.ALL, 10)
self.SetSizer(sizer)
@ -108,7 +108,9 @@ class ConfigPage(ScrolledPanel):
boxSizer.Add(description, 0, wx.EXPAND | wx.LEFT, 10)
# apply an underline when a grouping border is not specified
if not getin(group, ['options', 'show_border'], False) and group['name']:
# 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)
@ -125,13 +127,23 @@ class ConfigPage(ScrolledPanel):
# 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.ALL | wx.EXPAND, 5)
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)
if e % getin(group, ['options', 'columns'], 2) \
or e == len(group['groups']):
boxSizer.Add(hs, *args)
hs = wx.BoxSizer(wx.HORIZONTAL)
thissizer.Add(boxSizer, *args)
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 chunkWidgets(self, group):

12
gooey/gui/components/widgets/bases.py

@ -60,15 +60,21 @@ class TextContainer(BaseWidget):
def arrange(self, *args, **kwargs):
wx_util.make_bold(self.label)
wx_util.dark_grey(self.help_text)
wx_util.withColor(self.label, self._options['label_color'])
wx_util.withColor(self.help_text, self._options['help_color'])
wx_util.withColor(self.error, self._options['error_color'])
self.help_text.SetMinSize((0,-1))
layout = wx.BoxSizer(wx.VERTICAL)
layout.Add(self.label)
if self._options.get('show_label', True):
layout.Add(self.label)
else:
layout.AddStretchSpacer(1)
layout.AddSpacer(2)
if self.help_text:
if self.help_text and self._options.get('show_help', True):
layout.Add(self.help_text, 1, wx.EXPAND)
layout.AddSpacer(2)
else:

3
gooey/gui/components/widgets/checkbox.py

@ -13,7 +13,8 @@ class CheckBox(TextContainer):
def arrange(self, *args, **kwargs):
wx_util.make_bold(self.label)
wx_util.dark_grey(self.help_text)
wx_util.withColor(self.label, self._options['label_color'])
wx_util.withColor(self.help_text, self._options['help_color'])
wx_util.withColor(self.error, self._options['error_color'])
self.error.Hide()

7
gooey/gui/components/widgets/listbox.py

@ -1,18 +1,17 @@
from gooey.gui.components.widgets.bases import TextContainer
import wx
from gooey.gui import formatters
from gooey.gui.lang.i18n import _
from gooey.gui.components.widgets.bases import TextContainer
class Listbox(TextContainer):
def getWidget(self, parent, *args, **options):
default = _('select_option')
height = self._options.get('height', 60)
return wx.ListBox(
parent=parent,
choices=self._meta['choices'],
size=(-1,60),
size=(-1, height),
style=wx.LB_MULTIPLE
)

5
gooey/gui/components/widgets/radio_group.py

@ -13,6 +13,7 @@ class RadioGroup(BaseWidget):
self._parent = parent
self.info = widgetInfo
self._id = widgetInfo['id']
self._options = widgetInfo['options']
self.widgetInfo = widgetInfo
self.error = wx.StaticText(self, label='')
self.radioButtons = self.createRadioButtons()
@ -58,9 +59,11 @@ class RadioGroup(BaseWidget):
boxDetails = wx.StaticBox(self, -1, title)
boxSizer = wx.StaticBoxSizer(boxDetails, wx.VERTICAL)
else:
title = wx_util.h1(self, title)
title.SetForegroundColour(self._options['label_color'])
boxSizer = wx.BoxSizer(wx.VERTICAL)
boxSizer.AddSpacer(10)
boxSizer.Add(wx_util.h1(self, title), 0)
boxSizer.Add(title, 0)
for btn, widget in zip(self.radioButtons, self.widgets):
sizer = wx.BoxSizer(wx.HORIZONTAL)

27
gooey/gui/components/widgets/textarea.py

@ -1,6 +1,29 @@
import wx
from gooey.gui.components.widgets.core.text_input import MultilineTextInput
from gooey.gui.components.widgets.textfield import TextField
from gooey.gui.components.widgets.bases import TextContainer
from gooey.gui import formatters
class Textarea(TextContainer):
def getWidget(self, parent, *args, **options):
widgetHeight = self._options.get('height', -1)
return wx.TextCtrl(
parent=parent,
size=(-1, widgetHeight),
style=wx.TE_MULTILINE | wx.TE_READONLY
)
def getWidgetValue(self):
return self.widget.GetValue()
def setValue(self, value):
self.widget.Clear()
self.widget.AppendText(str(value))
self.widget.SetInsertionPoint(0)
def formatOutput(self, metatdata, value):
return formatters.general(metatdata, value)
class Textarea(TextField):
widget_class = MultilineTextInput
Loading…
Cancel
Save