From 18c4a6d135701cce0e6e9f8789683d3263594f53 Mon Sep 17 00:00:00 2001 From: kennykfung <36523247+kennykfung@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:26:08 -0800 Subject: [PATCH 1/5] add weeknumber offset feature add weeknumber offset feature to allow user to change the default isocalendar returned weeknumber. this is an offset and default is 0 --- tkcalendar/calendar_.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tkcalendar/calendar_.py b/tkcalendar/calendar_.py index b3cecab..585c6b6 100644 --- a/tkcalendar/calendar_.py +++ b/tkcalendar/calendar_.py @@ -83,6 +83,9 @@ def __init__(self, master=None, **kw): showweeknumbers : bool (default is True) whether to display week numbers. + weeknumberoffset : int (default is 0) + to adjust the week numbers + showothermonthdays : bool (default is True) whether to display the last days of the previous month and the first of the next month. @@ -311,6 +314,7 @@ def __init__(self, master=None, **kw): raise ValueError("'selectmode' option should be 'none' or 'day'.") # --- show week numbers showweeknumbers = kw.pop('showweeknumbers', True) + weeknumberoffset = kw.pop('weeknumberoffset', 0) # --- style self.style = ttk.Style(self) @@ -331,6 +335,7 @@ def __init__(self, master=None, **kw): 'maxdate', 'mindate', 'showweeknumbers', + 'weeknumberoffset', 'showothermonthdays', 'firstweekday', 'weekenddays', @@ -378,6 +383,7 @@ def __init__(self, master=None, **kw): 'mindate': mindate, 'maxdate': maxdate, 'showweeknumbers': showweeknumbers, + 'weeknumberoffset': weeknumberoffset, 'showothermonthdays': kw.pop('showothermonthdays', True), 'selectbackground': active_bg, 'selectforeground': 'white', @@ -874,6 +880,7 @@ def _display_days_without_othermonthdays(self): _, week_nb, d = self._date.isocalendar() if d == 7 and self['firstweekday'] == 'sunday': week_nb += 1 + week_nb += self['weeknumberoffset'] modulo = max(week_nb, 52) for i_week in range(6): if i_week == 0 or cal[i_week][0][0]: From 797ce6d27f8a432f352ff4431ce45d500d1c034b Mon Sep 17 00:00:00 2001 From: kennykfung <36523247+kennykfung@users.noreply.github.com> Date: Tue, 6 Dec 2022 17:27:02 -0800 Subject: [PATCH 2/5] add weeknumber offset feature add weeknumber offset feature to allow user to change the default isocalendar returned weeknumber. this is an offset and default is 0 --- README.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e235d1a..70e3449 100644 --- a/README.rst +++ b/README.rst @@ -103,7 +103,10 @@ Widget keyword options showweeknumbers : bool (default is True) whether to display week numbers. - + + weeknumberoffset : int (default is 0) + to adjust the week numbers + showothermonthdays : bool (default is True) whether to display the last days of the previous month and the first of the next month. From 7ff65d8166a40feadfd0d3c1543fef6810360961 Mon Sep 17 00:00:00 2001 From: kennykfung Date: Tue, 6 Dec 2022 22:31:18 -0800 Subject: [PATCH 3/5] Update test_calendar.py update the test with new option --- tests/test_calendar.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_calendar.py b/tests/test_calendar.py index 121b504..22f722b 100644 --- a/tests/test_calendar.py +++ b/tests/test_calendar.py @@ -294,6 +294,7 @@ def test_calendar_get_set(self): 'firstweekday', 'weekenddays', 'showweeknumbers', + 'weeknumberoffset', 'showothermonthdays', 'selectbackground', 'selectforeground', From b37ce48259c920e75ac168f463b78d59deee215e Mon Sep 17 00:00:00 2001 From: kennykfung <36523247+kennykfung@users.noreply.github.com> Date: Wed, 7 Dec 2022 23:33:51 +0000 Subject: [PATCH 4/5] fix unittest issue to handle when textvariable is '' --- tests/test_calendar.py | 2 +- tkcalendar/calendar_.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_calendar.py b/tests/test_calendar.py index 22f722b..975c568 100644 --- a/tests/test_calendar.py +++ b/tests/test_calendar.py @@ -229,7 +229,7 @@ def test_calendar_textvariable(self): widget.pack() self.window.update() self.assertEqual('', var.get()) - self.assertEqual('', widget.get_date()) + self.assertEqual('1/3/15', widget.get_date()) # if textvariable == '' then year/month/day should still be horner self.assertEqual(date(2015, 1, 1), widget._date) widget.selection_set(date(2018, 11, 21)) self.window.update() diff --git a/tkcalendar/calendar_.py b/tkcalendar/calendar_.py index 585c6b6..1fe1604 100644 --- a/tkcalendar/calendar_.py +++ b/tkcalendar/calendar_.py @@ -265,7 +265,7 @@ def __init__(self, master=None, **kw): # --- date today = self.date.today() - if self._textvariable is not None: + if self._textvariable is not None and self._textvariable.get() != '': # the variable overrides day, month and year keywords try: self._sel_date = parse_date(self._textvariable.get(), locale) From c3e6cb3d4b40ad12a461cce6c7fc6fec10e537fc Mon Sep 17 00:00:00 2001 From: kennykfung <36523247+kennykfung@users.noreply.github.com> Date: Thu, 8 Dec 2022 22:19:11 +0000 Subject: [PATCH 5/5] add day_names feature --- README.rst | 3 +++ tests/test_calendar.py | 1 + tkcalendar/calendar_.py | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 70e3449..6989b9a 100644 --- a/README.rst +++ b/README.rst @@ -221,6 +221,9 @@ Widget keyword options tooltipdelay : int delay in ms before displaying the tooltip + day_names : 'wide' or 'short' or 'abbreviated'or 'narrow' (default = 'abbreviated') + contorl the fromat of the day name. Ex: 'Tuesday', 'Tu', 'Tue', 'T' + Virtual Events ~~~~~~~~~~~~~~ diff --git a/tests/test_calendar.py b/tests/test_calendar.py index 975c568..bbcc9d5 100644 --- a/tests/test_calendar.py +++ b/tests/test_calendar.py @@ -317,6 +317,7 @@ def test_calendar_get_set(self): 'headersforeground', 'disableddaybackground', 'disableddayforeground', + 'day_names', 'tooltipbackground', 'tooltipforeground', 'tooltipalpha', diff --git a/tkcalendar/calendar_.py b/tkcalendar/calendar_.py index 1fe1604..aefd705 100644 --- a/tkcalendar/calendar_.py +++ b/tkcalendar/calendar_.py @@ -185,6 +185,9 @@ def __init__(self, master=None, **kw): disableddayforeground : str foreground color of days in disabled state + day_names : 'wide' or 'short' or 'abbreviated'or 'narrow' (default = 'abbreviated') + contorl the fromat of the day name. Ex: 'Tuesday', 'Tu', 'Tue', 'T' + Tooltip Options (for calevents) ------------------------------- @@ -258,7 +261,8 @@ def __init__(self, master=None, **kw): locale = kw.pop("locale", default_locale()) if locale is None: locale = 'en' - self._day_names = get_day_names('abbreviated', locale=locale) + day_names = kw.pop('day_names', 'abbreviated') + self._day_names = get_day_names(day_names, locale=locale) self._month_names = get_month_names('wide', locale=locale) date_pattern = self._get_date_pattern(kw.pop("date_pattern", "short"), locale) @@ -360,6 +364,7 @@ def __init__(self, master=None, **kw): 'headersforeground', 'disableddaybackground', 'disableddayforeground', + 'day_names', 'tooltipforeground', 'tooltipbackground', 'tooltipalpha', @@ -406,6 +411,7 @@ def __init__(self, master=None, **kw): 'headersforeground': 'black', 'disableddaybackground': dis_bg, 'disableddayforeground': dis_fg, + 'day_names': day_names, 'tooltipforeground': 'gray90', 'tooltipbackground': 'black', 'tooltipalpha': 0.8,