From 62ae1cdfc5516d145e97d4b01fd52f45c34d8670 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Mon, 25 May 2015 16:31:24 -0400 Subject: [PATCH] pep8 for wx_utils --- gooey/gui/util/wx_util.py | 46 +++++++++++----------------- gooey/gui/widgets/calender_dialog.py | 2 +- gooey/gui/widgets/choosers.py | 4 +-- gooey/gui/widgets/components.py | 4 +-- gooey/gui/windows/advanced_config.py | 8 ++--- gooey/gui/windows/base_window.py | 4 +-- gooey/gui/windows/header.py | 2 +- gooey/gui/windows/sidebar.py | 2 +- 8 files changed, 31 insertions(+), 41 deletions(-) diff --git a/gooey/gui/util/wx_util.py b/gooey/gui/util/wx_util.py index c842b66..ed1133d 100644 --- a/gooey/gui/util/wx_util.py +++ b/gooey/gui/util/wx_util.py @@ -1,52 +1,42 @@ """ -Collection of Utility methods for creating pre-styled wxWidgets items +Collection of Utility methods for creating often used, pre-styled wx Widgets """ -__author__ = 'Chris' - - import wx -def MakeBold(statictext): +def make_bold(statictext): pointsize = statictext.GetFont().GetPointSize() font = wx.Font(pointsize, wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False) statictext.SetFont(font) +def dark_grey(statictext): + darkgray = (54, 54, 54) + statictext.SetForegroundColour(darkgray) -def _bold_static_text(parent, text_label): - text = wx.StaticText(parent, label=text_label) - font_size = text.GetFont().GetPointSize() - bold = wx.Font(font_size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD) - text.SetFont(bold) - return text +def h1(parent, label): + return _header(parent, label, (wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False)) +def h2(parent, label): + return _header(parent, label, (wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_NORMAL, False)) -def H1(parent, label): +def _header(parent, label, styles): text = wx.StaticText(parent, label=label) font_size = text.GetFont().GetPointSize() - font = wx.Font(font_size * 1.2, wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_BOLD, False) + font = wx.Font(font_size * 1.2, *styles) text.SetFont(font) return text -def H2(parent, label): - text = wx.StaticText(parent, label=label) - font_size = text.GetFont().GetPointSize() - font = wx.Font(font_size * 1.2, wx.FONTFAMILY_DEFAULT, wx.FONTWEIGHT_NORMAL, wx.FONTWEIGHT_NORMAL, False) - text.SetFont(font) - return text - -def HorizontalRule(parent): - line = wx.StaticLine(parent, -1, style=wx.LI_HORIZONTAL) - line.SetSize((10, 10)) - return line +def horizontal_rule(parent): + return _rule(parent, wx.LI_HORIZONTAL) def vertical_rule(parent): - line = wx.StaticLine(parent, -1, style=wx.LI_VERTICAL) + return _rule(parent, wx.LI_VERTICAL) + +def _rule(parent, direction): + line = wx.StaticLine(parent, -1, style=direction) line.SetSize((10, 10)) return line -def MakeDarkGrey(statictext): - darkgray = (54, 54, 54) - statictext.SetForegroundColour(darkgray) + diff --git a/gooey/gui/widgets/calender_dialog.py b/gooey/gui/widgets/calender_dialog.py index 2de5f12..7eff9ae 100644 --- a/gooey/gui/widgets/calender_dialog.py +++ b/gooey/gui/widgets/calender_dialog.py @@ -16,7 +16,7 @@ class CalendarDlg(wx.Dialog): vertical_container = wx.BoxSizer(wx.VERTICAL) vertical_container.AddSpacer(10) - vertical_container.Add(wx_util.H1(self, label='Select a Date'), 0, wx.LEFT | wx.RIGHT, 15) + vertical_container.Add(wx_util.h1(self, label='Select a Date'), 0, wx.LEFT | wx.RIGHT, 15) vertical_container.AddSpacer(10) vertical_container.Add(self.datepicker, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 15) diff --git a/gooey/gui/widgets/choosers.py b/gooey/gui/widgets/choosers.py index 65e8b5b..d215646 100644 --- a/gooey/gui/widgets/choosers.py +++ b/gooey/gui/widgets/choosers.py @@ -60,13 +60,13 @@ class AbstractChooser(object): base_text = wx.StaticText(parent, label=self.data['help_msg']) # if self.data['nargs']: # base_text.SetLabelText(base_text.GetLabelText() + self.CreateNargsMsg(action)) - wx_util.MakeDarkGrey(base_text) + wx_util.dark_grey(base_text) return base_text def CreateNameLabelWidget(self, parent): label = self.data['title'].title() text = wx.StaticText(parent, label=label) - wx_util.MakeBold(text) + wx_util.make_bold(text) return text def OnResize(self, evt): diff --git a/gooey/gui/widgets/components.py b/gooey/gui/widgets/components.py index 2855f75..b59ce55 100644 --- a/gooey/gui/widgets/components.py +++ b/gooey/gui/widgets/components.py @@ -56,12 +56,12 @@ class BaseGuiComponent(object): if self.data['nargs'] else self.data['help']) base_text = wx.StaticText(parent, label=label_text or '') - wx_util.MakeDarkGrey(base_text) + wx_util.dark_grey(base_text) return base_text def createTitle(self, parent): text = wx.StaticText(parent, label=self.data['display_name'].title()) - wx_util.MakeBold(text) + wx_util.make_bold(text) return text def formatExtendedHelpMsg(self, data): diff --git a/gooey/gui/windows/advanced_config.py b/gooey/gui/windows/advanced_config.py index f088ad7..0a2287c 100644 --- a/gooey/gui/windows/advanced_config.py +++ b/gooey/gui/windows/advanced_config.py @@ -46,9 +46,9 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader): container.AddSpacer(15) if self.widgets.required_args: - container.Add(wx_util.H1(self, i18n.translate("required_args_msg")), 0, wx.LEFT | wx.RIGHT, PADDING) + container.Add(wx_util.h1(self, i18n.translate("required_args_msg")), 0, wx.LEFT | wx.RIGHT, PADDING) container.AddSpacer(5) - container.Add(wx_util.HorizontalRule(self), *STD_LAYOUT) + container.Add(wx_util.horizontal_rule(self), *STD_LAYOUT) container.AddSpacer(20) self.CreateComponentGrid(container, self.widgets.required_args, cols=self._build_spec['requireds_cols']) @@ -58,9 +58,9 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader): if self.widgets.optional_args: container.AddSpacer(10) - container.Add(wx_util.H1(self, i18n.translate("optional_args_msg")), 0, wx.LEFT | wx.RIGHT, PADDING) + container.Add(wx_util.h1(self, i18n.translate("optional_args_msg")), 0, wx.LEFT | wx.RIGHT, PADDING) container.AddSpacer(5) - container.Add(wx_util.HorizontalRule(self), *STD_LAYOUT) + container.Add(wx_util.horizontal_rule(self), *STD_LAYOUT) container.AddSpacer(20) self.CreateComponentGrid(container, self.widgets.optional_args, cols=self._build_spec['optionals_cols']) diff --git a/gooey/gui/windows/base_window.py b/gooey/gui/windows/base_window.py index d69dcd6..151f7b4 100644 --- a/gooey/gui/windows/base_window.py +++ b/gooey/gui/windows/base_window.py @@ -62,7 +62,7 @@ class BaseWindow(wx.Frame): def _do_layout(self): sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.head_panel, 0, wx.EXPAND) - sizer.Add(wx_util.HorizontalRule(self), 0, wx.EXPAND) + sizer.Add(wx_util.horizontal_rule(self), 0, wx.EXPAND) if self.build_spec['layout_type'] == 'column': print 'hello!' @@ -75,7 +75,7 @@ class BaseWindow(wx.Frame): sizer.Add(self.runtime_display, 1, wx.EXPAND) self.runtime_display.Hide() - sizer.Add(wx_util.HorizontalRule(self), 0, wx.EXPAND) + sizer.Add(wx_util.horizontal_rule(self), 0, wx.EXPAND) sizer.Add(self.foot_panel, 0, wx.EXPAND) self.SetSizer(sizer) diff --git a/gooey/gui/windows/header.py b/gooey/gui/windows/header.py index 965a791..4229419 100644 --- a/gooey/gui/windows/header.py +++ b/gooey/gui/windows/header.py @@ -39,7 +39,7 @@ class FrameHeader(wx.Panel): self.SetMinSize((120, 80)) def _init_components(self, heading, subheading): - self._header = wx_util.H1(self, heading) + self._header = wx_util.h1(self, heading) self._subheader = wx.StaticText(self, label=subheading) diff --git a/gooey/gui/windows/sidebar.py b/gooey/gui/windows/sidebar.py index 928496e..96a90d0 100644 --- a/gooey/gui/windows/sidebar.py +++ b/gooey/gui/windows/sidebar.py @@ -31,7 +31,7 @@ class Sidebar(wx.Panel): container = wx.BoxSizer(wx.VERTICAL) container.AddSpacer(15) - container.Add(wx_util.H1(self, 'Actions'), *STD_LAYOUT) + container.Add(wx_util.h1(self, 'Actions'), *STD_LAYOUT) container.AddSpacer(5) thing = wx.ListBox(self, -1, choices=['Connect', 'process', 'commit', 'fetch']) container.Add(thing, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)