Merge pull request #1256 from PySimpleGUI/Dev-latest

BIG CHANGE do_not_clear defaults to TRUE now :-) Enjoy!
This commit is contained in:
PySimpleGUI 2019-03-21 08:43:14 -04:00 committed by GitHub
commit c267b2ecb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 27 deletions

View File

@ -533,7 +533,7 @@ class Element():
class InputText(Element): class InputText(Element):
def __init__(self, default_text='', size=(None, None), disabled=False, password_char='', def __init__(self, default_text='', size=(None, None), disabled=False, password_char='',
justification=None, background_color=None, text_color=None, font=None, tooltip=None, justification=None, background_color=None, text_color=None, font=None, tooltip=None,
change_submits=False, enable_events=False, do_not_clear=False, key=None, focus=False, pad=None, right_click_menu=None, visible=True): change_submits=False, enable_events=False, do_not_clear=True, key=None, focus=False, pad=None, right_click_menu=None, visible=True):
''' '''
InputText InputText
:param default_text: :param default_text:
@ -1071,7 +1071,7 @@ class Spin(Element):
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Multiline(Element): class Multiline(Element):
def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None),
auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False,do_not_clear=False, key=None, focus=False, font=None, pad=None, tooltip=None, right_click_menu=None, visible=True): auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False,do_not_clear=True, key=None, focus=False, font=None, pad=None, tooltip=None, right_click_menu=None, visible=True):
''' '''
Multiline Multiline
:param default_text: :param default_text:

View File

@ -509,7 +509,7 @@ class InputText(Element):
def __init__(self, default_text='', size=(None,None), disabled=False, password_char='', def __init__(self, default_text='', size=(None,None), disabled=False, password_char='',
justification=None, background_color=None, text_color=None, font=None, tooltip=None, justification=None, background_color=None, text_color=None, font=None, tooltip=None,
change_submits=False, enable_events=False, change_submits=False, enable_events=False,
do_not_clear=False, key=None, focus=False, pad=None, visible=True, size_px=(None,None)): do_not_clear=True, key=None, focus=False, pad=None, visible=True, size_px=(None,None)):
''' '''
Input a line of text Element Input a line of text Element
:param default_text: Default value to display :param default_text: Default value to display
@ -1039,7 +1039,7 @@ class Spin(Element):
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Multiline(Element, QWidget): class Multiline(Element, QWidget):
def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None),
auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=False, auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=True,
key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)): key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)):
''' '''
Multiline Element Multiline Element
@ -1128,7 +1128,7 @@ class Multiline(Element, QWidget):
# ScrolledOutput # # ScrolledOutput #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class MultilineOutput(Element): class MultilineOutput(Element):
def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=False, key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)): def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=True, key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)):
''' '''
Multiline Element Multiline Element
:param default_text: :param default_text:
@ -2664,9 +2664,6 @@ class Table(Element):
return QWidget.eventFilter(self, widget, event) return QWidget.eventFilter(self, widget, event)
def __del__(self): def __del__(self):
super().__del__() super().__del__()

View File

@ -494,7 +494,7 @@ class InputText(Element):
def __init__(self, default_text='', size=(None, None), disabled=False, password_char='', def __init__(self, default_text='', size=(None, None), disabled=False, password_char='',
justification=None, background_color=None, text_color=None, font=None, tooltip=None, justification=None, background_color=None, text_color=None, font=None, tooltip=None,
change_submits=False, enable_events=False, change_submits=False, enable_events=False,
do_not_clear=False, key=None, focus=False, pad=None, visible=True, size_px=(None, None)): do_not_clear=True, key=None, focus=False, pad=None, visible=True, size_px=(None, None)):
''' '''
Input a line of text Element Input a line of text Element
:param default_text: Default value to display :param default_text: Default value to display
@ -949,7 +949,7 @@ class Spin(Element):
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Multiline(Element): class Multiline(Element):
def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None),
auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=False, auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=True,
key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)): key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)):
''' '''
Multiline Element Multiline Element
@ -1039,7 +1039,7 @@ class Multiline(Element):
# Multiline Output # # Multiline Output #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class MultilineOutput(Element): class MultilineOutput(Element):
def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=False, key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)): def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=True, key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)):
''' '''
Multiline Element Multiline Element
:param default_text: :param default_text:
@ -5080,6 +5080,7 @@ def _ProgressMeter(title, max_value, *args, orientation=None, bar_color=(None, N
if local_orientation[0].lower() == 'h': if local_orientation[0].lower() == 'h':
single_line_message, width, height = ConvertArgsToSingleString(*args) single_line_message, width, height = ConvertArgsToSingleString(*args)
bar2.TextToDisplay = single_line_message bar2.TextToDisplay = single_line_message
bar2.TextToDisplay = single_line_message
bar2.MaxValue = max_value bar2.MaxValue = max_value
bar2.CurrentValue = 0 bar2.CurrentValue = 0
bar_text = Text(single_line_message, size=(width, height + 3), auto_size_text=True) bar_text = Text(single_line_message, size=(width, height + 3), auto_size_text=True)

View File

@ -534,7 +534,7 @@ class InputText(Element):
def __init__(self, default_text='', size=(None,None), disabled=False, password_char='', def __init__(self, default_text='', size=(None,None), disabled=False, password_char='',
justification=None, background_color=None, text_color=None, font=None, tooltip=None, justification=None, background_color=None, text_color=None, font=None, tooltip=None,
change_submits=False, enable_events=False, change_submits=False, enable_events=False,
do_not_clear=False, key=None, focus=False, pad=None, visible=True, size_px=(None,None)): do_not_clear=True, key=None, focus=False, pad=None, visible=True, size_px=(None,None)):
''' '''
Input a line of text Element Input a line of text Element
:param default_text: Default value to display :param default_text: Default value to display
@ -1004,7 +1004,7 @@ class Spin(Element):
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Multiline(Element): class Multiline(Element):
def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None),
auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=False, auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=True,
key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)): key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)):
''' '''
Multiline Element Multiline Element
@ -1093,7 +1093,7 @@ class Multiline(Element):
# Multiline Output # # Multiline Output #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class MultilineOutput(Element): class MultilineOutput(Element):
def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=False, key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)): def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, enable_events=False, do_not_clear=True, key=None, focus=False, font=None, pad=None, tooltip=None, visible=True, size_px=(None,None)):
''' '''
Multiline Element Multiline Element
:param default_text: :param default_text:
@ -1557,7 +1557,7 @@ class Button(Element):
self.ParentForm.MasterFrame.Close() self.ParentForm.MasterFrame.Close()
if self.ParentForm.NonBlocking: if self.ParentForm.NonBlocking:
Window.DecrementOpenCount() Window.DecrementOpenCount()
self.ParentForm._Close() # self.ParentForm._Close()
elif self.BType == BUTTON_TYPE_READ_FORM: # Read Button elif self.BType == BUTTON_TYPE_READ_FORM: # Read Button
# first, get the results table built # first, get the results table built
# modify the Results table in the parent FlexForm object # modify the Results table in the parent FlexForm object
@ -2695,6 +2695,9 @@ class SystemTray:
self.DataBase64 = data_base64 self.DataBase64 = data_base64
if Window.highest_level_app is None: if Window.highest_level_app is None:
self.App = Window.highest_level_app = wx.App(False) self.App = Window.highest_level_app = wx.App(False)
# This could be a very dangerous thing to add!
# It was needed in order for an application to run the Tray in a Thread
self.App.SetAssertMode(wx.APP_ASSERT_SUPPRESS)
else: else:
self.App = Window.highest_level_app self.App = Window.highest_level_app
self.Tooltip = tooltip self.Tooltip = tooltip
@ -2846,10 +2849,13 @@ class SystemTray:
:return: :return:
''' '''
self.TrayIcon.Hide() self.Hide()
# Don't close app because windows could be depending on it # Don't close app because windows could be depending on it
# self.App.quit() # self.App.quit()
def DisableAsserts(self):
wx.DisableAsserts()
def Update(self, menu=None, tooltip=None,filename=None, data=None, data_base64=None,): def Update(self, menu=None, tooltip=None,filename=None, data=None, data_base64=None,):
''' '''
@ -3029,7 +3035,7 @@ class Window:
self.DisableMinimize = disable_minimize self.DisableMinimize = disable_minimize
self.App = None # type: wx.App self.App = None # type: wx.App
self.MasterFrame = None # type: wx.Frame self.MasterFrame = None # type: wx.Frame
self.MasterPanel = None # type wx.Panel self.MasterPanel = None # type: wx.Panel
self.IgnoreClose = False self.IgnoreClose = False
@ -3109,6 +3115,7 @@ class Window:
# If a button or keyboard event happened but no results have been built, build the results # If a button or keyboard event happened but no results have been built, build the results
if self.LastKeyboardEvent is not None or self.LastButtonClicked is not None: if self.LastKeyboardEvent is not None or self.LastButtonClicked is not None:
return BuildResults(self, False, self) return BuildResults(self, False, self)
return self.ReturnValues return self.ReturnValues
# ------------------------- SetIcon - set the window's fav icon ------------------------- # # ------------------------- SetIcon - set the window's fav icon ------------------------- #
@ -3164,8 +3171,8 @@ class Window:
except: except:
pass # if user has already closed the frame will get an error pass # if user has already closed the frame will get an error
if self.CurrentlyRunningMainloop: # if self.CurrentlyRunningMainloop:
self.App.ExitMainLoop() # self.App.ExitMainLoop()
def callback_keyboard_char(self, event:wx.KeyEvent): def callback_keyboard_char(self, event:wx.KeyEvent):
self.LastButtonClicked = None self.LastButtonClicked = None
@ -3378,7 +3385,7 @@ class Window:
return None return None
self.TKrootDestroyed = True self.TKrootDestroyed = True
self.RootNeedsDestroying = True self.RootNeedsDestroying = True
self.__del__() # self.__del__()
return None return None
def Close(self): def Close(self):
@ -3453,13 +3460,24 @@ class Window:
else: else:
self.RootNeedsDestroying = True self.RootNeedsDestroying = True
self.App.ExitMainLoop() # kick the users out of the mainloop self.App.ExitMainLoop() # kick the users out of the mainloop
print('exiting mainloop')
self.MasterFrame.Destroy() self.MasterFrame.Destroy()
timer = wx.Timer(self.App)
self.App.Bind(wx.EVT_TIMER, self.timer_timeout)
timer.Start(milliseconds=100, oneShot=wx.TIMER_ONE_SHOT)
# self.CurrentlyRunningMainloop = True
# print(f'In main {self.Title}')
################################# CALL GUWxTextCtrlI MAINLOOP ############################
self.App.MainLoop()
# self.CurrentlyRunningMainloop = False
timer.Stop()
print('after mainloop in close')
self.TKrootDestroyed = True self.TKrootDestroyed = True
self.RootNeedsDestroying = True self.RootNeedsDestroying = True
# if self.CurrentlyRunningMainloop:
# print("quitting window")
# self.QTApplication.exit() # kick the users out of the mainloop
@property @property
def Size(self): def Size(self):
@ -6313,7 +6331,7 @@ def Popup(*args, title=None, button_color=None, background_color=None, text_colo
if non_blocking: if non_blocking:
PopupButton = DummyButton # important to use or else button will close other windows too! PopupButton = DummyButton # important to use or else button will close other windows too!
else: else:
PopupButton = CloseButton PopupButton = Button
# show either an OK or Yes/No depending on paramater # show either an OK or Yes/No depending on paramater
if custom_text != (None, None): if custom_text != (None, None):
if type(custom_text) is not tuple: if type(custom_text) is not tuple:
@ -6346,6 +6364,7 @@ def Popup(*args, title=None, button_color=None, background_color=None, text_colo
return button, window return button, window
else: else:
button, values = window.Read() button, values = window.Read()
window.Close()
return button return button
@ -6738,7 +6757,7 @@ def PopupGetFolder(message, title=None, default_path='', no_window=False, size=(
layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color)], layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color)],
[InputText(default_text=default_path, size=size), FolderBrowse(initial_folder=initial_folder)], [InputText(default_text=default_path, size=size), FolderBrowse(initial_folder=initial_folder)],
[CloseButton('Ok', size=(60, 20), bind_return_key=True), CloseButton('Cancel', size=(60, 20))]] [Button('Ok', size=(60, 20), bind_return_key=True), Button('Cancel', size=(60, 20))]]
_title = title if title is not None else message _title = title if title is not None else message
window = Window(title=_title, icon=icon, auto_size_text=True, button_color=button_color, window = Window(title=_title, icon=icon, auto_size_text=True, button_color=button_color,
@ -6747,7 +6766,7 @@ def PopupGetFolder(message, title=None, default_path='', no_window=False, size=(
location=location) location=location)
(button, input_values) = window.Layout(layout).Read() (button, input_values) = window.Layout(layout).Read()
window.Close()
if button != 'Ok': if button != 'Ok':
return None return None
else: else:
@ -6804,7 +6823,7 @@ def PopupGetFile(message, title=None, default_path='', default_extension='', sav
layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color)], layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color)],
[InputText(default_text=default_path, size=(30,1)), browse_button], [InputText(default_text=default_path, size=(30,1)), browse_button],
[CButton('Ok', size=(60, 20), bind_return_key=True), CButton('Cancel', size=(60, 20))]] [Button('Ok', size=(60, 20), bind_return_key=True), Button('Cancel', size=(60, 20))]]
_title = title if title is not None else message _title = title if title is not None else message
@ -6813,6 +6832,7 @@ def PopupGetFile(message, title=None, default_path='', default_extension='', sav
no_titlebar=no_titlebar, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location) no_titlebar=no_titlebar, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location)
(button, input_values) = window.Layout(layout).Read() (button, input_values) = window.Layout(layout).Read()
window.Close()
# window.Close() # window.Close()
if button != 'Ok': if button != 'Ok':
return None return None
@ -6909,6 +6929,7 @@ def main():
while True: while True:
event, values = window.Read() event, values = window.Read()
print(event, values) print(event, values)
if event in (None, 'Exit'): if event in (None, 'Exit'):
break break
window.Close() window.Close()