j4321 / tkcalendar

Calendar widget for Tkinter
https://pypi.python.org/pypi/tkcalendar
GNU General Public License v3.0
98 stars 33 forks source link

Cursor only on active days #56

Open Tech-GS opened 4 years ago

Tech-GS commented 4 years ago

I suggest that calendar numbers that do not fall into the mindate-maxdate range should not be highlighted with the cursor specified through the cursor="..." parameter. Here are the calendar_.pu code snippets to implement this:

class Calendar(ttk.Frame):

    def __init__(self, master=None, **kw):
        ...
        # curs = kw.pop("cursor", "")
        self.curs = kw.pop("cursor", "hand2")
        ttk.Frame.__init__(self, master, class_=classname, name=name)
        ...
        self._properties = {"cursor": self.curs,
            ...
        self._l_month = ttk.Button(f_month,
                                   style='L.%s.TButton' % self._style_prefixe, cursor=self.curs,
                                   command=self._prev_month)
        self._r_month = ttk.Button(f_month,
                                   style='R.%s.TButton' % self._style_prefixe, cursor=self.curs,
                                   command=self._next_month)
        self._l_year = ttk.Button(f_year, style='L.%s.TButton' % self._style_prefixe, cursor=self.curs,
                                  command=self._prev_year)
        self._r_year = ttk.Button(f_year, style='R.%s.TButton' % self._style_prefixe, cursor=self.curs,
                                  command=self._next_year)

    def _display_calendar(self):
        ...
        if maxdate is not None:
            mi, mj = self._get_day_coords(maxdate)
            if mi is not None:
                # for j in range(mj, 7):
                for j in range(mj + 1, 7):
                    self._calendar[mi][j].state(['disabled'])
                    self._calendar[mi][j].config(cursor='')
                for i in range(mi + 1, 6):
                    for j in range(7):
                        self._calendar[i][j].state(['disabled'])
                        self._calendar[i][j].config(cursor='')

        if mindate is not None:
            mi, mj = self._get_day_coords(mindate)
            if mi is not None:
                for j in range(mj):
                    self._calendar[mi][j].state(['disabled'])
                    self._calendar[mi][j].config(cursor='')
                for i in range(mi):
                    for j in range(7):
                        self._calendar[i][j].state(['disabled'])
                        self._calendar[i][j].config(cursor='')

    def _display_days_with_othermonthdays(self):
        ...
                label.configure(text=txt, style=style, cursor=self.curs)
Tech-GS commented 4 years ago

In _btns_date_range(), you also need to adjust the cursor of the buttons for changing the month and year.

j4321 commented 4 years ago

Thanks for the suggestion and your involvement in improving this module. It would be more convenient if you forked the repository, made your modifications and submitted a pull request. But if you are new to git I can take care of that, just let me know.