This commit is contained in:
parent
586610d17d
commit
60e0394859
@ -407,14 +407,29 @@ class MainFrame(forms.MainFrame):
|
||||
self.AddLine(item, line['title'], data)
|
||||
|
||||
try:
|
||||
infile = 'data.opl'
|
||||
wx.BeginBusyCursor()
|
||||
self.do_nothing = True
|
||||
|
||||
selector = wx.FileDialog(
|
||||
self,
|
||||
'Select file to load project',
|
||||
'',
|
||||
'',
|
||||
'Opal files (*.opl)|*.opl|Text files (*.txt)|*.txt',
|
||||
wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
|
||||
|
||||
if selector.ShowModal() == wx.ID_OK:
|
||||
|
||||
filename = selector.GetPath()
|
||||
data = {}
|
||||
# with open(infile, 'rb') as f:
|
||||
# data = json.loads(zlib.decompress(f.read()))
|
||||
with open(infile, 'r') as f:
|
||||
|
||||
if selector.GetFilterIndex() == 0:
|
||||
with open(filename, 'rb') as f:
|
||||
data = json.loads(zlib.decompress(f.read()))
|
||||
else:
|
||||
with open(filename, 'r') as f:
|
||||
data = json.loads(f.read())
|
||||
|
||||
pprint(data)
|
||||
|
||||
tid = data['tid']
|
||||
model_label = data['model']
|
||||
@ -433,15 +448,14 @@ class MainFrame(forms.MainFrame):
|
||||
|
||||
root = self.m_plots.GetRootItem()
|
||||
WalkPlots(data['plots'], root)
|
||||
self.m_plots.ExpandAll(root)
|
||||
self.m_plots.ExpandAll()
|
||||
|
||||
# except KeyError, e:
|
||||
# wx.MessageBox("Can't parse saved file!", 'Error!')
|
||||
# except ValueError, e:
|
||||
# wx.MessageBox("Can't parse saved file!", 'Error!')
|
||||
except Exception, e:
|
||||
# wx.MessageBox("Can't load file", 'Error')
|
||||
wx.MessageBox("Can't load saved file", 'Error', wx.ICON_ERROR | wx.OK)
|
||||
print 'Oops', type(e), e
|
||||
finally:
|
||||
wx.EndBusyCursor()
|
||||
self.do_nothing = False
|
||||
|
||||
def OnSaveProject(self, event):
|
||||
|
||||
@ -493,7 +507,19 @@ class MainFrame(forms.MainFrame):
|
||||
dest.append([title, lines])
|
||||
item1 = self.m_plots.GetNextSibling(item1)
|
||||
|
||||
try:
|
||||
wx.BeginBusyCursor()
|
||||
self.do_nothing = True
|
||||
|
||||
selector = wx.FileDialog(
|
||||
self,
|
||||
'Select file to save project',
|
||||
'',
|
||||
self.model.GetTitle() + ' project',
|
||||
'Opal files (*.opl)|*.opl|Text files (*.txt)|*.txt',
|
||||
wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
|
||||
|
||||
if selector.ShowModal() == wx.ID_OK:
|
||||
|
||||
data = {}
|
||||
|
||||
@ -509,11 +535,24 @@ class MainFrame(forms.MainFrame):
|
||||
|
||||
# pprint(data)
|
||||
dump = json.dumps(data, indent = 2)
|
||||
with open('data.opl', 'w') as f:
|
||||
# f.write(zlib.compress(dump, 9))
|
||||
|
||||
filename = selector.GetPath()
|
||||
# сохраняем в упакованный бинарный формат
|
||||
if selector.GetFilterIndex() == 0:
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(zlib.compress(dump, 9))
|
||||
|
||||
# сохраняем в простой текстовый формат
|
||||
else:
|
||||
with open(filename, 'w') as f:
|
||||
f.write(dump)
|
||||
|
||||
except Exception as e:
|
||||
wx.MessageBox("Can't save the project", 'Error', wx.ICON_ERROR | wx.OK)
|
||||
print e
|
||||
finally:
|
||||
wx.EndBusyCursor()
|
||||
self.do_nothing = False
|
||||
|
||||
# Функции непосредственной работы с моделями:
|
||||
# создание, изменение, дублирование и прочее
|
||||
|
Loading…
Reference in New Issue
Block a user