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