NEW form.SaveToDisk and form.LoadFromDisk!
Another user submitted feature request
This commit is contained in:
parent
75970ade87
commit
667000ea2a
|
@ -1,24 +1,5 @@
|
|||
# from tkinter.filedialog import asksaveasfilename, askopenfilename
|
||||
import pickle
|
||||
import PySimpleGUI as sg
|
||||
|
||||
|
||||
def save(values):
|
||||
sfilename = sg.PopupGetFile('Save Settings', save_as=True, no_window=True)
|
||||
if not sfilename:
|
||||
return
|
||||
with open(sfilename, 'wb') as sf:
|
||||
pickle.dump(values, sf)
|
||||
|
||||
|
||||
def load(form):
|
||||
dfilename = sg.PopupGetFile('Load Settings', no_window=True)
|
||||
if not dfilename:
|
||||
return
|
||||
with open(dfilename, 'rb') as df:
|
||||
form.Fill(pickle.load(df))
|
||||
|
||||
|
||||
def Everything():
|
||||
sg.ChangeLookAndFeel('TanBlue')
|
||||
|
||||
|
@ -62,9 +43,13 @@ def Everything():
|
|||
button, values = form.Read()
|
||||
|
||||
if button is 'SaveSettings':
|
||||
save(values)
|
||||
filename = sg.PopupGetFile('Save Settings', save_as=True, no_window=True)
|
||||
form.SaveToDisk(filename)
|
||||
# save(values)
|
||||
elif button is 'LoadSettings':
|
||||
load(form)
|
||||
filename = sg.PopupGetFile('Load Settings', no_window=True)
|
||||
form.LoadFromDisk(filename)
|
||||
# load(form)
|
||||
elif button in ['Exit', None]:
|
||||
break
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import tkinter.font
|
|||
import datetime
|
||||
import sys
|
||||
import textwrap
|
||||
import pickle
|
||||
|
||||
|
||||
# ----====----====----==== Constants the user CAN safely change ====----====----====----#
|
||||
|
@ -1361,10 +1362,29 @@ class FlexForm:
|
|||
def Fill(self, values_dict):
|
||||
FillFormWithValues(self, values_dict)
|
||||
|
||||
|
||||
def FindElement(self, key):
|
||||
return _FindElementFromKeyInSubForm(self, key)
|
||||
|
||||
|
||||
def SaveToDisk(self, filename):
|
||||
try:
|
||||
results = BuildResults(self, False, self)
|
||||
with open(filename, 'wb') as sf:
|
||||
pickle.dump(results[1], sf)
|
||||
except:
|
||||
print('*** Error saving form to disk ***')
|
||||
|
||||
|
||||
def LoadFromDisk(self, filename):
|
||||
try:
|
||||
with open(filename, 'rb') as df:
|
||||
self.Fill(pickle.load(df))
|
||||
except:
|
||||
print('*** Error loading form to disk ***')
|
||||
|
||||
|
||||
|
||||
def GetScreenDimensions(self):
|
||||
if self.TKrootDestroyed:
|
||||
return None, None
|
||||
|
|
Loading…
Reference in New Issue