ExtendedCalendarCtrl

ExtendedCalendarCtrl.py

Updated see version 2.0 below

A custom class using wx.adv.GenericCalendarCtrl with the ability to customise the calendar and the output format,
 based on some of the attributes of minidatepicker.py

Incorporating user defined holidays, official holidays, notes, marked dates and restricted dates.

Works with wx.DateTime or python datetime values
Uses wx.adv.GenericCalendarCtrl
Uses wx.Locale to enable different languages for the calendar

Developed and tested on Linux, wxPython 4.2.1 gtk3 wxWidgets 3.2.2.1

You may run ExtendedCalendarCtrl.py from the command line, it contains its own built-in demonstration and
it's recommended that you look at that demonstration code.

You may also run EccDemoSimple.py, that is a simplistic demonstration of how to import and utilise
    ExtendedCalendarCtrl in your own environment.

EccDemo2.py gives examples of adding notes and holidays to an ExtendedCalendarCtrl.

It is recommended that you install the python module 'holidays' (pip install --upgrade holidays)
    before testing, as it does add significantly, to the utility of ExtendedCalendarCtrl.

An attempt has been made to allow days marked with attributes denoting Holiday, Marked and Restricted to live with each other

ExtendedCalendarCtrl.zip (267.6 KB)

Version 2.0

Version 2 Fixes a bug in the calendar date range function. by insisting the dates passed into
function SetCalendarDateRange be wx.DateTime format i.e, the month numbers start from 0
So January is 0 and December is 11.
The bug showed up when inputting 12 for December and it returns October rather than reporting an error,
I’ve no idea why!
>>> wx.DateTime(24, 12, 2023)
<wx.DateTime: “Tue Oct 24 00:00:00 2023”>

        Adds the ability to load and save the Calendar's Holidays, Notes, Restricted, Marked Dictionaries etc
        to file, removing the need to load them separately, every time.
        This allows for predefined calendar events to be loaded based on various criteria
        It also means that items can be added to the dictionaries seperately by the user and those items
        will be retained for each user, by basing the CalSaveFile name on something unique to the user.
        This is a simplistic step before you decide to hold these items and load them from a database,
        which would be the proper way of doing it.

        To enable this functionality the python module 'ast' (abstract syntax tree) is used
        Why ast and not pickle or json, because pickle is not human readable and json struggles with
         tuple keys to dictionaries.
        I wanted human readable and editable files that can be simply written and read, without a
         plethora of type fiddling. The ast module, provided a round peg in a round hole solution.
        If there are drawbacks to this approach, I'm unaware of them.

        The text file is a simple text line file, with 1 entry per item e.g.

        {(0, 1, 1): "New Year's Day\n2nd Note", (0, 1, -11): 'First Monday of the year', (0, 1, -23): '3rd Tuesday of the year', (0, 1, -99): 'Last day of January', (0, 1, -35): 'The last Wednesday of January', (0, 2, 1): '1st February', (2023, 2, -5): 'Every Friday in February', (2023, 8, 7): 'Marked for no reason whatsoever', (2023, 8, 15): 'A holiday August 15 2023', (2023, 8, 20): 'Marked for reason X', (0, 9, -98): 'Last weekday of September', (0, 12, 25): 'Merry Christmas!', (0, 2, -99): 'Last day of February'}
        {(0, 1): [1], (0, 2): [1], (2023, 8): [15], (0, 12): [25, 26]}
        ['DE', 'ST', '']
        [['GB', 'ENG', ''], ['ES', 'AN', '']]
        {}
        {}
        [[], []]

        These 7 entries represent the Notes, defined holidays, public holidays, additional public holidays,
         restricted dates, marked dates and calendar date range, respectively and must be in that order
         and that number.
         Even if there no entry, it must be represented as an empty structure, be that a dictionary
         a list or list of lists.

        The additional functions are:
            LoadDataFrom(CalSaveFile=None)  - defining the path and file name to use
            SaveData(CalSaveFile=None)      - defining the path and file name to use
                                              if the filename is not present the filename used
                                              to load from will be used.



You may run ExtendedCalendarCtrl.py from the command line, it contains its own built-in demonstration and
it's recommended that you look at that demonstration code.

All of the demonstration programs run from the command line.
EccDemoSimple.py is a simplistic demonstration of how to import and utilise
    ExtendedCalendarCtrl in your own environment.

EccDemo2.py gives examples of adding notes and holidays to an ExtendedCalendarCtrl.

EccDemoSave.py provides an example of loading the calendar notes, event etc from a file

EccDemoSave2.py gives examples of adding notes and holidays to an ExtendedCalendarCtrl, whilst loading
 calendar notes etc from a file.
It also saves new notes and holidays for loading next time the calendar is loaded.

ExtendedCalendarCtrl_V2_0.zip (274.8 KB)

That’s super cool that you created a new wxPython widget!

Just love it when something like this pops up exactly when I need it :). I’ll give it a try soon.