diff --git a/gooey/gui/components/header.py b/gooey/gui/components/header.py index 19343d8..1868726 100644 --- a/gooey/gui/components/header.py +++ b/gooey/gui/components/header.py @@ -95,7 +95,14 @@ class FrameHeader(wx.Panel): def build_heading_sizer(self): sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddStretchSpacer(1) - sizer.Add(self._header, 0) - sizer.Add(self._subheader, 0) + if self.buildSpec['header_show_title']: + sizer.Add(self._header, 0) + else: + self._header.Hide() + + if self.buildSpec['header_show_subtitle']: + sizer.Add(self._subheader, 0) + else: + self._subheader.Hide() sizer.AddStretchSpacer(1) return sizer diff --git a/gooey/tests/harness.py b/gooey/tests/harness.py index 876b25d..935f0bf 100644 --- a/gooey/tests/harness.py +++ b/gooey/tests/harness.py @@ -5,6 +5,7 @@ import wx from gui import application from python_bindings.config_generator import create_from_parser from python_bindings.gooey_decorator import defaults +from util.functional import merge @contextmanager @@ -13,7 +14,7 @@ def instrumentGooey(parser, **kwargs): Context manager used during testing for setup/tear down of the WX infrastructure during subTests. """ - buildspec = create_from_parser(parser, "", **defaults) + buildspec = create_from_parser(parser, "", **merge(defaults, kwargs)) app, gooey = application.build_app(buildspec) try: yield (app, gooey) diff --git a/gooey/tests/test_header.py b/gooey/tests/test_header.py new file mode 100644 index 0000000..9368ed2 --- /dev/null +++ b/gooey/tests/test_header.py @@ -0,0 +1,66 @@ +import unittest +from argparse import ArgumentParser +from itertools import * + +from tests.harness import instrumentGooey + + +class TestGooeyHeader(unittest.TestCase): + + def make_parser(self): + parser = ArgumentParser(description='description') + return parser + + def test_header_visibility(self): + """ + Test that the title and subtitle components correctly show/hide + based on config settings. + + Verifying Issue #497 + """ + for testdata in self.testcases(): + with self.subTest(testdata): + with instrumentGooey(self.make_parser(), **testdata) as (app, gooeyApp): + header = gooeyApp.header + + self.assertEqual( + header._header.IsShown(), + testdata.get('header_show_title', True) + ) + + self.assertEqual( + header._subheader.IsShown(), + testdata.get('header_show_subtitle', True) + ) + + + def test_header_string(self): + """ + Verify that string in the buildspec get correctly + placed into the UI. + """ + parser = ArgumentParser(description='Foobar') + with instrumentGooey(parser, program_name='BaZzEr') as (app, gooeyApp): + self.assertEqual(gooeyApp.header._header.GetLabelText(), 'BaZzEr') + self.assertEqual(gooeyApp.header._subheader.GetLabelText(), 'Foobar') + + + def testcases(self): + """ + Generate a powerset of all possible combinations of + the header parameters (empty, some present, all present, all combos) + """ + iterable = product(['header_show_title', 'header_show_subtitle'], [True, False]) + allCombinations = list(powerset(iterable)) + return [{k: v for k,v in args} + for args in allCombinations] + + +def powerset(iterable): + "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" + s = list(iterable) + return chain.from_iterable(combinations(s, r) for r in range(len(s)+1)) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/gooey/tests/test_radiogroup.py b/gooey/tests/test_radiogroup.py index 54ad285..d47372e 100644 --- a/gooey/tests/test_radiogroup.py +++ b/gooey/tests/test_radiogroup.py @@ -94,7 +94,7 @@ class TestRadioGroupBehavior(unittest.TestCase): for scenario in testcase['scenario']: targetButton = scenario['clickButton'] - event = wx.CommandEvent(wx.wxEVT_LEFT_DOWN, wx.NewId()) + event = wx.CommandEvent(wx.wxEVT_LEFT_DOWN, wx.Window.NewControlId()) event.SetEventObject(radioGroup.radioButtons[targetButton]) radioGroup.radioButtons[targetButton].ProcessEvent(event)