New feature - option to remove title bar from forms! Targets for Calendar buttons, hiding tabbed forms until completely built before showing,

This commit is contained in:
MikeTheWatchGuy 2018-09-05 19:57:32 -04:00
parent 86f2f17e24
commit ce352ea0bf
2 changed files with 39 additions and 13 deletions

View File

@ -1,9 +1,10 @@
import PySimpleGUI as sg
layout = [[sg.T('Calendar Test')],
[sg.CalendarButton('Choose Date', key='date')],
[sg.In('', size=(20,1))],
[sg.CalendarButton('Choose Date', target=(1,0), key='date')],
[sg.Ok(key=1)]]
form = sg.FlexForm('Calendar')
form = sg.FlexForm('Calendar', no_titlebar=True)
b,v = form.LayoutAndRead(layout)
sg.Popup(v['date'])

View File

@ -822,6 +822,7 @@ class Button(Element):
# Buttons modify targets or return from the form
# If modifying target, get the element object at the target and modify its StrVar
target = self.Target
target_element = None
if target[0] == ThisRow:
target = [self.Position[0], target[1]]
if target[1] < 0:
@ -889,7 +890,7 @@ class Button(Element):
elif self.BType == BUTTON_TYPE_CALENDAR_CHOOSER: # this is a return type button so GET RESULTS and destroy window
root = tk.Toplevel()
root.title('Calendar Chooser')
self.TKCal = TKCalendar(master=root, firstweekday=calendar.SUNDAY)
self.TKCal = TKCalendar(master=root, firstweekday=calendar.SUNDAY, target_element=target_element)
self.TKCal.pack(expand=1, fill='both')
# self.ParentForm.TKRroot.mainloop()
root.update()
@ -1209,13 +1210,14 @@ class TKCalendar(ttk.Frame):
datetime = calendar.datetime.datetime
timedelta = calendar.datetime.timedelta
def __init__(self, master=None, **kw):
def __init__(self, master=None, target_element=None, **kw):
"""
WIDGET-SPECIFIC OPTIONS
locale, firstweekday, year, month, selectbackground,
selectforeground
"""
self._TargetElement = target_element
# remove custom options from kw before initializating ttk.Frame
fwday = kw.pop('firstweekday', calendar.MONDAY)
year = kw.pop('year', self.datetime.now().year)
@ -1226,7 +1228,6 @@ class TKCalendar(ttk.Frame):
self._date = self.datetime(year, month, 1)
self._selection = None # no date selected
ttk.Frame.__init__(self, master, **kw)
# instantiate proper calendar class
@ -1374,6 +1375,10 @@ class TKCalendar(ttk.Frame):
text = '%02d' % text
self._selection = (text, item, column)
self._show_selection(text, bbox)
year, month = self._date.year, self._date.month
try:
self._TargetElement.Update(self.datetime(year, month, int(self._selection[0])))
except: pass
def _prev_month(self):
"""Updated calendar to show the previous month."""
@ -1842,8 +1847,8 @@ def RealtimeButton(button_text, image_filename=None, image_size=(None, None),ima
def DummyButton(button_text, image_filename=None, image_size=(None, None),image_subsample=None,border_width=None,scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None):
return Button(BUTTON_TYPE_CLOSES_WIN_ONLY, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key)
# ------------------------- GENERIC BUTTON Element lazy function ------------------------- #
def CalendarButton(button_text, image_filename=None, image_size=(None, None), image_subsample=None, border_width=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None):
return Button(BUTTON_TYPE_CALENDAR_CHOOSER, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, button_text=button_text, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key)
def CalendarButton(button_text, target=(None,None), image_filename=None, image_size=(None, None), image_subsample=None, border_width=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None):
return Button(BUTTON_TYPE_CALENDAR_CHOOSER, target=target, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, button_text=button_text, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key)
##################################### ----- RESULTS ------ ##################################################
def AddToReturnDictionary(form, element, value):
@ -2486,10 +2491,6 @@ def ConvertFlexToTK(MyFlexForm):
if not MyFlexForm.IsTabbedForm:
master.title(MyFlexForm.Title)
InitializeResults(MyFlexForm)
try:
master.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
except:
pass
try:
if MyFlexForm.NoTitleBar:
MyFlexForm.TKroot.wm_overrideredirect(True)
@ -2518,13 +2519,12 @@ def ConvertFlexToTK(MyFlexForm):
move_string = '+%i+%i'%(int(x),int(y))
master.geometry(move_string)
master.attributes('-alpha', 255) # Make window visible again
master.update_idletasks() # don't forget
return
# ----====----====----====----====----==== STARTUP TK ====----====----====----====----====----#
def ShowTabbedForm(title, *args, auto_close=False, auto_close_duration=DEFAULT_AUTOCLOSE_TIME, fav_icon=DEFAULT_WINDOW_ICON):
def ShowTabbedForm(title, *args, auto_close=False, auto_close_duration=DEFAULT_AUTOCLOSE_TIME, fav_icon=DEFAULT_WINDOW_ICON, no_titlebar=False):
# takes as input (form, rows, tab name) for each tab
global _my_windows
@ -2533,6 +2533,11 @@ def ShowTabbedForm(title, *args, auto_close=False, auto_close_duration=DEFAULT_A
uber.TKroot = root
if title is not None:
root.title(title)
try:
root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
except:
pass
if not len(args):
print('******************* SHOW TABBED FORMS ERROR .... no arguments')
return
@ -2548,6 +2553,7 @@ def ShowTabbedForm(title, *args, auto_close=False, auto_close_duration=DEFAULT_A
# ATTENTION: this applies the new style 'combostyle' to all ttk.Combobox
# framestyle.theme_use('framestyle')
tab_control = ttk.Notebook(root)
for num,x in enumerate(args):
form, rows, tab_name = x
form.AddRows(rows)
@ -2573,7 +2579,16 @@ def ShowTabbedForm(title, *args, auto_close=False, auto_close_duration=DEFAULT_A
icon = fav_icon if not _my_windows.user_defined_icon else _my_windows.user_defined_icon
try: uber.TKroot.iconbitmap(icon)
except: pass
try:
if no_titlebar:
uber.TKroot.wm_overrideredirect(True)
except:
pass
try:
root.attributes('-alpha', 255) # hide window while building it. makes for smoother 'paint'
except:
pass
root.mainloop()
if id: root.after_cancel(id)
@ -2587,6 +2602,10 @@ def StartupTK(my_flex_form):
ow = _my_windows.NumOpenWindows
# print('Starting TK open Windows = {}'.format(ow))
root = tk.Tk() if not ow else tk.Toplevel()
try:
root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
except:
pass
# root.wm_overrideredirect(True)
if my_flex_form.BackgroundColor is not None and my_flex_form.BackgroundColor != COLOR_SYSTEM_DEFAULT:
root.configure(background=my_flex_form.BackgroundColor)
@ -2597,6 +2616,12 @@ def StartupTK(my_flex_form):
# root.bind('<Destroy>', MyFlexForm.DestroyedCallback())
ConvertFlexToTK(my_flex_form)
my_flex_form.SetIcon(my_flex_form.WindowIcon)
try:
root.attributes('-alpha', 255) # hide window while building it. makes for smoother 'paint'
except:
pass
if my_flex_form.ReturnKeyboardEvents and not my_flex_form.NonBlocking:
root.bind("<KeyRelease>", my_flex_form._KeyboardCallback)
root.bind("<MouseWheel>", my_flex_form._MouseWheelCallback)