Location parameter added to CalendarButton

This commit is contained in:
PySimpleGUI 2020-03-30 10:23:22 -04:00
parent 8fd075f21e
commit a29d8488c7
2 changed files with 8 additions and 4 deletions

View File

@ -6,10 +6,10 @@ import PySimpleGUI as sg
""" """
layout = [[sg.Text('Date Chooser Test Harness', key='-TXT-')], layout = [[sg.Text('Date Chooser Test Harness', key='-TXT-')],
[sg.Input(key='-IN-', size=(20,1)), sg.CalendarButton('Cal US No Buttons', close_when_date_chosen=True, target='-IN-')], [sg.Input(key='-IN-', size=(20,1)), sg.CalendarButton('Cal US No Buttons Location (0,0)', close_when_date_chosen=True, target='-IN-', location=(0,0))],
[sg.Input(key='-IN3-', size=(20,1)), sg.CalendarButton('Cal US Monday', close_when_date_chosen=False, target='-IN3-', begin_at_sunday_plus=1)], [sg.Input(key='-IN3-', size=(20,1)), sg.CalendarButton('Cal US Monday', close_when_date_chosen=False, target='-IN3-', begin_at_sunday_plus=1)],
[sg.Input(key='-IN2-', size=(20,1)), sg.CalendarButton('Cal German Feb 2020', target='-IN2-', default_date_m_d_y=(2,None,2020), locale='de_DE', begin_at_sunday_plus=1 )], [sg.Input(key='-IN2-', size=(20,1)), sg.CalendarButton('Cal German Feb 2020', target='-IN2-', default_date_m_d_y=(2,None,2020), locale='de_DE', begin_at_sunday_plus=1 )],
[sg.Input(key='-IN4-', size=(20,1)), sg.CalendarButton('Cal Format %m-%d', target='-IN4-', format='%m-%d', default_date_m_d_y=(2,None,2020), locale='de_DE', begin_at_sunday_plus=1 )], [sg.Input(key='-IN4-', size=(20,1)), sg.CalendarButton('Cal Format %m-%d Jan 2020', target='-IN4-', format='%m-%d', default_date_m_d_y=(1,None,2020), )],
[sg.Button('Read'), sg.Button('Date Popup'), sg.Exit()]] [sg.Button('Read'), sg.Button('Date Popup'), sg.Exit()]]
window = sg.Window('window', layout) window = sg.Window('window', layout)

View File

@ -2790,6 +2790,7 @@ class Button(Element):
self.CalendarCloseWhenChosen = False self.CalendarCloseWhenChosen = False
self.CalendarLocale = None self.CalendarLocale = None
self.CalendarFormat = None self.CalendarFormat = None
self.CalendarLocation = (None, None)
self.CalendarNoTitlebar = True self.CalendarNoTitlebar = True
self.CalendarBeginAtSundayPlus = 0 self.CalendarBeginAtSundayPlus = 0
self.InitialFolder = initial_folder self.InitialFolder = initial_folder
@ -2949,7 +2950,7 @@ class Button(Element):
else: else:
cur_month, cur_day, cur_year = self.CalendarDefaultDate_M_D_Y cur_month, cur_day, cur_year = self.CalendarDefaultDate_M_D_Y
date_chosen = popup_get_date(start_mon=cur_month, start_day=cur_day, start_year=cur_year, close_when_chosen=self.CalendarCloseWhenChosen, no_titlebar=self.CalendarNoTitlebar, begin_at_sunday_plus=self.CalendarBeginAtSundayPlus, locale=self.CalendarLocale) date_chosen = popup_get_date(start_mon=cur_month, start_day=cur_day, start_year=cur_year, close_when_chosen=self.CalendarCloseWhenChosen, no_titlebar=self.CalendarNoTitlebar, begin_at_sunday_plus=self.CalendarBeginAtSundayPlus, locale=self.CalendarLocale, location=self.CalendarLocation)
if date_chosen is not None: if date_chosen is not None:
month, day, year = date_chosen month, day, year = date_chosen
now = datetime.datetime.now() now = datetime.datetime.now()
@ -8941,7 +8942,7 @@ def CalendarButton(button_text, target=(None, None), close_when_date_chosen=True
image_filename=None, image_data=None, image_size=(None, None), image_filename=None, image_data=None, image_size=(None, None),
image_subsample=None, tooltip=None, border_width=None, size=(None, None), auto_size_button=None, image_subsample=None, tooltip=None, border_width=None, size=(None, None), auto_size_button=None,
button_color=None, disabled=False, font=None, bind_return_key=False, focus=False, pad=None, button_color=None, disabled=False, font=None, bind_return_key=False, focus=False, pad=None,
key=None, locale=None, format='%Y-%m-%d %H:%M:%S', begin_at_sunday_plus=0, no_titlebar=True, metadata=None): key=None, locale=None, format='%Y-%m-%d %H:%M:%S', begin_at_sunday_plus=0, no_titlebar=True, location=(None, None), metadata=None):
""" """
Button that will show a calendar chooser window. Fills in the target element with result Button that will show a calendar chooser window. Fills in the target element with result
@ -8989,6 +8990,8 @@ def CalendarButton(button_text, target=(None, None), close_when_date_chosen=True
:type format: str :type format: str
:param no_titlebar: if True no titlebar will be shown on the date chooser window :param no_titlebar: if True no titlebar will be shown on the date chooser window
:type no_titlebar: bool :type no_titlebar: bool
:param location: Location on the screen (x,y) to show the calendar popup window
:type location: (int, int)
:param metadata: Anything you want to store along with this button :param metadata: Anything you want to store along with this button
:type metadata: Any :type metadata: Any
:return: returns a button :return: returns a button
@ -9004,6 +9007,7 @@ def CalendarButton(button_text, target=(None, None), close_when_date_chosen=True
button.CalendarLocale = locale button.CalendarLocale = locale
button.CalendarFormat = format button.CalendarFormat = format
button.CalendarNoTitlebar = no_titlebar button.CalendarNoTitlebar = no_titlebar
button.CalendarLocation = location
button.CalendarBeginAtSundayPlus = begin_at_sunday_plus button.CalendarBeginAtSundayPlus = begin_at_sunday_plus
return button return button