diff --git a/README.md b/README.md index b47ca54..8857f2d 100644 --- a/README.md +++ b/README.md @@ -285,7 +285,7 @@ Just about everything in Gooey's overall look and feel can be customized by pass | terminal_panel_color | HEX value of the terminal's panel | | terminal_font_color | HEX value of the font displayed in Gooey's terminal | | terminal_font_family | Name of the Font Family to use in the terminal | -| terminal_font_weight | Weight of the font (NORMAL\|BOLD) | +| terminal_font_weight | Weight of the font (`constants.FONTWEIGHT_NORMAL`, `constants.FONTWEIGHT_XXX`) | | terminal_font_size | Point size of the font displayed in the terminal | | error_color | HEX value of the text displayed when a validation error occurs | | richtext_controls | Switch on/off the console support for terminal control sequences (limited support for font weight and color). Defaults to : False. See [docs](https://github.com/chriskiehl/Gooey/tree/master/docs) for additional details | diff --git a/docs/releases/1.0.5-release-notes.md b/docs/releases/1.0.5-release-notes.md new file mode 100644 index 0000000..3bfaf0a --- /dev/null +++ b/docs/releases/1.0.5-release-notes.md @@ -0,0 +1,12 @@ +## Gooey 1.0.5 Released! + + +## Breaking Changes + +* (documentation breaking)`terminal_font_weight`'s public documented API allowed the strings "NORMAL" and "BOLD" while its internal implementation relied on numeric font weights (light=200, normal=300, etc..). The documentation was updated to show the correct usage and a constants file was added to the public API. + +## Bug Fixes + + + + diff --git a/gooey/__init__.py b/gooey/__init__.py index bebfacb..bd84683 100644 --- a/gooey/__init__.py +++ b/gooey/__init__.py @@ -2,4 +2,5 @@ import os from gooey.python_bindings.gooey_decorator import Gooey from gooey.python_bindings.gooey_parser import GooeyParser from gooey.gui.util.freeze import localResourcePath as local_resource_path +from gooey.python_bindings import constants __version__ = '1.0.4' diff --git a/gooey/gui/components/console.py b/gooey/gui/components/console.py index 5795a33..d58c514 100644 --- a/gooey/gui/components/console.py +++ b/gooey/gui/components/console.py @@ -91,7 +91,7 @@ class Console(wx.Panel): return self.textbox.GetValue() def layoutComponent(self): - self.SetBackgroundColour(self.buildSpec.get('terminal_bg_color', '#F0F0F0')) + self.SetBackgroundColour(self.buildSpec.get('terminal_panel_color', '#F0F0F0')) sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddSpacer(10) sizer.Add(self.text, 0, wx.LEFT, 20) diff --git a/gooey/python_bindings/config_generator.py b/gooey/python_bindings/config_generator.py index e590ca2..5ee0b89 100644 --- a/gooey/python_bindings/config_generator.py +++ b/gooey/python_bindings/config_generator.py @@ -1,7 +1,7 @@ import os import sys import warnings - +import textwrap from gooey.python_bindings import argparse_to_json from gooey.gui.util.quoting import quote from gooey.python_bindings import constants @@ -92,7 +92,7 @@ def create_from_parser(parser, source_path, **kwargs): 'terminal_panel_color': kwargs.get('terminal_panel_color', '#F0F0F0'), 'terminal_font_color': kwargs.get('terminal_font_color', '#000000'), 'terminal_font_family': kwargs.get('terminal_font_family', None), - 'terminal_font_weight': kwargs.get('terminal_font_weight', None), + 'terminal_font_weight': get_font_weight(kwargs), 'terminal_font_size': kwargs.get('terminal_font_size', None), 'richtext_controls': kwargs.get('richtext_controls', False), 'error_color': kwargs.get('error_color', '#ea7878') @@ -117,3 +117,37 @@ def create_from_parser(parser, source_path, **kwargs): build_spec['show_sidebar'] = True return build_spec + + + +def get_font_weight(kwargs): + error_msg = textwrap.dedent(''' + Unknown font weight {}. + + The available weights can be found in the `constants` module. + They're prefixed with "FONTWEIGHT" (e.g. `FONTWEIGHT_BOLD`) + + example code: + + ``` + from gooey import constants + @Gooey(terminal_font_weight=constants.FONTWEIGHT_NORMAL) + ``` + ''') + weights = { + constants.FONTWEIGHT_THIN, + constants.FONTWEIGHT_EXTRALIGHT, + constants.FONTWEIGHT_LIGHT, + constants.FONTWEIGHT_NORMAL, + constants.FONTWEIGHT_MEDIUM, + constants.FONTWEIGHT_SEMIBOLD, + constants.FONTWEIGHT_BOLD, + constants.FONTWEIGHT_EXTRABOLD, + constants.FONTWEIGHT_HEAVY, + constants.FONTWEIGHT_EXTRAHEAVY + } + weight = kwargs.get('terminal_font_weight', constants.FONTWEIGHT_NORMAL) + if weight not in weights: + raise ValueError(error_msg.format(weight)) + return weight + diff --git a/gooey/python_bindings/constants.py b/gooey/python_bindings/constants.py index 3641020..be122f4 100644 --- a/gooey/python_bindings/constants.py +++ b/gooey/python_bindings/constants.py @@ -3,3 +3,14 @@ SIDEBAR = 'SIDEBAR' TABBED = 'TABBED' INLINE = 'INLINE' HIDDEN = 'HIDDEN' + +FONTWEIGHT_THIN = 100 +FONTWEIGHT_EXTRALIGHT = 200 +FONTWEIGHT_LIGHT = 300 +FONTWEIGHT_NORMAL = 400 +FONTWEIGHT_MEDIUM = 500 +FONTWEIGHT_SEMIBOLD = 600 +FONTWEIGHT_BOLD = 700 +FONTWEIGHT_EXTRABOLD = 800 +FONTWEIGHT_HEAVY = 900 +FONTWEIGHT_EXTRAHEAVY = 1000 diff --git a/gooey/tests/test_application.py b/gooey/tests/test_application.py index 9447dec..dbacb77 100644 --- a/gooey/tests/test_application.py +++ b/gooey/tests/test_application.py @@ -5,6 +5,7 @@ from collections import namedtuple from unittest.mock import patch from unittest.mock import MagicMock +from python_bindings import constants from tests.harness import instrumentGooey @@ -75,7 +76,23 @@ class TestGooeyApplication(unittest.TestCase): exitmock.assert_called() + def testTerminalColorChanges(self): + ## Issue #625 terminal panel color wasn't being set due to a typo + parser = self.basicParser() + expectedColors = [(255, 0, 0, 255), (255, 255, 255, 255), (100, 100, 100,100)] + for expectedColor in expectedColors: + with instrumentGooey(parser, terminal_panel_color=expectedColor) as (app, gapp): + foundColor = gapp.console.GetBackgroundColour() + self.assertEqual(tuple(foundColor), expectedColor) + + def testFontWeightsGetSet(self): + ## Issue #625 font weight wasn't being correctly passed to the terminal + for weight in [constants.FONTWEIGHT_LIGHT, constants.FONTWEIGHT_BOLD]: + parser = self.basicParser() + with instrumentGooey(parser, terminal_font_weight=weight) as (app, gapp): + terminal = gapp.console.textbox + self.assertEqual(terminal.GetFont().GetWeight(), weight) def basicParser(self): diff --git a/gooey/tests/test_config_generator.py b/gooey/tests/test_config_generator.py index 1964b71..9fd10d3 100644 --- a/gooey/tests/test_config_generator.py +++ b/gooey/tests/test_config_generator.py @@ -1,6 +1,7 @@ import unittest from argparse import ArgumentParser +from python_bindings import constants from python_bindings.config_generator import create_from_parser @@ -26,6 +27,29 @@ class TextConfigGenerator(unittest.TestCase): buildspec = create_from_parser(blank_parser, "") self.assertEqual(buildspec['program_description'], '') + def test_valid_font_weights(self): + """ + Asserting that only valid font-weights are allowable. + """ + all_valid_weights = range(100, 1001, 100) + for weight in all_valid_weights: + parser = ArgumentParser(description="test parser") + buildspec = create_from_parser(parser, "", terminal_font_weight=weight) + self.assertEqual(buildspec['terminal_font_weight'], weight) + + def test_font_weight_defaults_to_normal(self): + parser = ArgumentParser(description="test parser") + # no font_weight explicitly provided + buildspec = create_from_parser(parser, "") + self.assertEqual(buildspec['terminal_font_weight'], constants.FONTWEIGHT_NORMAL) + + + def test_invalid_font_weights_throw_error(self): + parser = ArgumentParser(description="test parser") + with self.assertRaises(ValueError): + invalid_weight = 9123 + buildspec = create_from_parser(parser, "", terminal_font_weight=invalid_weight) + if __name__ == '__main__': unittest.main() \ No newline at end of file