diff --git a/README.rst b/README.rst index e235d1a..6989b9a 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. @@ -218,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 121b504..bbcc9d5 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() @@ -294,6 +294,7 @@ def test_calendar_get_set(self): 'firstweekday', 'weekenddays', 'showweeknumbers', + 'weeknumberoffset', 'showothermonthdays', 'selectbackground', 'selectforeground', @@ -316,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 b3cecab..aefd705 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. @@ -182,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) ------------------------------- @@ -255,14 +261,15 @@ 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) # --- 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) @@ -311,6 +318,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 +339,7 @@ def __init__(self, master=None, **kw): 'maxdate', 'mindate', 'showweeknumbers', + 'weeknumberoffset', 'showothermonthdays', 'firstweekday', 'weekenddays', @@ -355,6 +364,7 @@ def __init__(self, master=None, **kw): 'headersforeground', 'disableddaybackground', 'disableddayforeground', + 'day_names', 'tooltipforeground', 'tooltipbackground', 'tooltipalpha', @@ -378,6 +388,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', @@ -400,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, @@ -874,6 +886,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]: