forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileMgr.py
More file actions
executable file
·52 lines (47 loc) · 1.99 KB
/
FileMgr.py
File metadata and controls
executable file
·52 lines (47 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import imp
class FileMgr:
""" To handle data file """
def __init__(self, editor=None):
self.editor = editor
def saveToFile(self, fileName):
try:
f = open(fileName, 'w')
f.write("from panda3d.core import *\n")
f.write("\nif hasattr(base, 'le'):\n")
f.write(" objectMgr = base.le.objectMgr\n")
f.write(" animMgr = base.le.animMgr\n")
f.write(" ui = base.le.ui\n")
f.write(" ui.sceneGraphUI.reset()\n\n")
f.write("else:\n")
f.write(" objectMgr = base.objectMgr\n")
f.write("# temporary place holder for nodepath\n")
f.write("objects = {}\n")
f.write("animMgr.keyFramesInfo = "+str(self.editor.animMgr.keyFramesInfo)+"\n")
f.write("animMgr.curveAnimation = "+str(self.editor.animMgr.curveAnimation)+"\n")
saveData = self.editor.objectMgr.getSaveData()
for data in saveData:
f.write(data)
f.write('\n')
saveDataLayers = self.editor.ui.layerEditorUI.getSaveData()
for data in saveDataLayers:
f.write(data)
f.write('\n')
f.close()
self.editor.updateStatusReadout('Sucessfully saved to %s'%fileName)
self.editor.fNeedToSave = False
except IOError:
print('failed to save %s'%fileName)
if f:
f.close()
def loadFromFile(self, fileName):
dirname, moduleName = os.path.split(fileName)
if moduleName.endswith('.py'):
moduleName = moduleName[:-3]
file, pathname, description = imp.find_module(moduleName, [dirname])
try:
module = imp.load_module(moduleName, file, pathname, description)
self.editor.updateStatusReadout('Sucessfully opened file %s'%fileName)
self.editor.fNeedToSave = False
except:
print('failed to load %s'%fileName)