forked from MathieuDuponchelle/Kerious-Resource-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.py
95 lines (82 loc) · 3.22 KB
/
activity.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import gtk
import logging
from sections import GraphicSection
from krfparser import KrfParser
from indent import indent
#TODO : connect to "page changed" to change currentSection
class KSEActivityView(gtk.Notebook):
"""
Contained by : :class: `mainwindow`
:param fileName: optional string from the arguments.
:param instance: the :class: KSEWindow
"""
def __init__(self, fileName, instance):
self.logger = logging.getLogger("KRFEditor")
gtk.Notebook.__init__(self)
self.show()
self.xmlHandler = None
self.app = instance
self.graphics = GraphicSection(self.app)
self.currentSection = self.graphics
# self.soundeffects = Section(SoundEffectsPanel())
# self.musics = Section(MusicPanel())
self.append_page(self.graphics, gtk.Label("Graphics Section"))
# self.append_page(self.soundeffects, gtk.Label("Sound Effects Section"))
# self.append_page(self.musics, gtk.Label("Musics Section"))
if fileName:
self.openProject(fileName)
else:
self.newProject()
self.path = fileName
def closeFile(self, fileName = None):
self.graphics.resetTree()
self.soundeffects.resetTree()
self.musics.resetTree()
self.xmlHandler = None
def parseAst(self, ast):
ret = False
if len(ast.sections) is 1:
for section in ast.sections[0].sections:
if section.name == "graphics":
self.graphics.createTree(section)
elif section.name == "sound":
for soundSection in section.sections:
if soundSection.name == "effects":
self.soundeffects.createTree(soundSection)
elif soundSection.name == "musics":
self.musics.createTree(soundSection)
return ret
def newProject(self):
pass
def openProject(self, fileName):
userOk = False
if self.xmlHandler is not None:
print "Should pop \"do you want to save?\""
else:
userOk = True
if userOk:
try:
self.xmlHandler = KrfParser(fileName)
except IOError:
ErrorMessage("The file you're trying to open doesn't exist")
self.logger.error("User tried to open invalid path as a resource file : %s", fileName)
return
self.logger.info("User opened a resource file with filename : %s", fileName)
if self.xmlHandler.isValid():
self.graphics.createTree(self.xmlHandler)
self.path = fileName
else:
ErrorMessage("The file you opened is not a valid KRF. Begone !")
self.logger.error("User tried to open an invalid KRF : %s", fileName)
def saveProjectAs(self, fileName):
node = self.xmlHandler.find("graphics")
indent(node)
self.xmlHandler.write(fileName)
def saveProject(self):
if self.path == None:
return
node = self.xmlHandler.find("graphics")
indent(node)
self.xmlHandler.write(self.path)
def export(self):
self.currentSection.export()