tkcalendar icon indicating copy to clipboard operation
tkcalendar copied to clipboard

optionally allow empty/whitespace values

Open teauxfu opened this issue 4 years ago • 2 comments

Rationale

Sometimes one might want to allow a DateEntry to be blank, such as when building a form. As mentioned in #53 the behavior of automatically inserting a date on initialization / when clicking the DateEntry can be a little surprising, but is pretty easy to work around by using the Entry's set method.

This PR would allow one to specify this behavior by passing in an optional kwarg allow_empty when initializing a DateEntry, such that the widget would start off blank and could be left blank by deleting its contents.

Changes

  • adds allow_empty kwarg to __init__,
  • adds _allow_empty attribute and considers it in _validate_date
  • leaves the Entry blank on init if _allow_empty == True
  • added an if clause to drop_down to prevent attempting to parse an empty value

empty strings and whitespace are treated equally

Pros

  • The behavior is optional and must be requested, but can easily be requested
  • One can achieve the expected behavior without having to resort to adding extra buttons to a form
  • set_date and get_date still complain if they find the empty value (this seems appropriate)

Cons

The idea is to make sure that the entry always contains a valid date when the content of the entry is retrieved.

  • ~~This optional behavior isn't accounted for in the tests.~~ I'm not very familiar with writing tests, but if you have suggestions/hints I'd be happy to try to add some coverage.

teauxfu avatar Apr 24 '21 05:04 teauxfu

Codecov Report

Merging #76 (7014009) into master (a979184) will decrease coverage by 0.34%. The diff coverage is 75.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
- Coverage   92.69%   92.34%   -0.35%     
==========================================
  Files           9        9              
  Lines        2011     2024      +13     
==========================================
+ Hits         1864     1869       +5     
- Misses        147      155       +8     
Impacted Files Coverage Δ
tkcalendar/dateentry.py 87.65% <75.00%> (-2.39%) :arrow_down:
tests/test_tooltip.py 78.87% <0.00%> (-2.82%) :arrow_down:
tests/test_dateentry.py 98.37% <0.00%> (-1.63%) :arrow_down:
tkcalendar/tooltip.py 84.00% <0.00%> (-1.60%) :arrow_down:
tkcalendar/calendar_.py 94.69% <0.00%> (+0.11%) :arrow_up:
tests/test_calendar.py 92.60% <0.00%> (+0.41%) :arrow_up:
tests/base_widget_testcase.py 90.47% <0.00%> (+9.52%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0c6aa7c...7014009. Read the comment docs.

codecov[bot] avatar Apr 24 '21 05:04 codecov[bot]

I've added a simple test case so as not to decrease the coverage, but I see that some checks are still failing. Specifically, the OSX tests on Travis are failing.

From the error messages it's not apparent to me what the problem is in relation to this PR @j4321 @nprobert @drepekh please advise 😅

ERROR: This script does not work on Python 3.5 The minimum supported Python version is 3.6. Please use https://bootstrap.pypa.io/pip/3.5/get-pip.py instead.

and

ERROR: Failure: ModuleNotFoundError (No module named 'pytest')

----------------------------------------------------------------------

Traceback (most recent call last):

  File "/Users/travis/build/j4321/tkcalendar/venv/lib/python3.6/site-packages/nose/failure.py", line 39, in runTest

    raise self.exc_val.with_traceback(self.tb)

  File "/Users/travis/build/j4321/tkcalendar/venv/lib/python3.6/site-packages/nose/loader.py", line 418, in loadTestsFromName

    addr.filename, addr.module)

  File "/Users/travis/build/j4321/tkcalendar/venv/lib/python3.6/site-packages/nose/importer.py", line 47, in importFromPath

    return self.importFromDir(dir_path, fqname)

  File "/Users/travis/build/j4321/tkcalendar/venv/lib/python3.6/site-packages/nose/importer.py", line 94, in importFromDir

    mod = load_module(part_fqname, fh, filename, desc)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 235, in load_module

    return load_source(name, filename, file)

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 172, in load_source

    module = _load(spec)

  File "<frozen importlib._bootstrap>", line 684, in _load

  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 678, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "/Users/travis/build/j4321/tkcalendar/terryfy/test_travisparse.py", line 11, in <module>

    import pytest

teauxfu avatar Apr 25 '21 02:04 teauxfu