summaryrefslogtreecommitdiff
path: root/src/ui.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ui.py124
1 files changed, 85 insertions, 39 deletions
diff --git a/src/ui.py b/src/ui.py
index d5f9cdf..864b9ed 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -204,44 +204,74 @@ class KPPathNodeList(QtGui.QWidget):
item = self.KPPathNodeItem(self.tree, layer, associate)
def loadLayer(self, layer):
- item = self.KPPathNodeItem(self.tree, layer, layer.associate)
- def removeLayer(self, associate):
- trash = None
+ # If there is a folder path available...
+ if layer.folder != '':
+ folder = layer.folder.split('/')
- for itemI in xrange(self.tree.topLevelItemCount()):
- item = self.tree.topLevelItem(itemI)
+ # Remove the last empty
+ folder.pop()
- if item.associate == associate:
- trash = item
- else:
- trash = self.removeRecursor(item, associate)
+ myFolder = None
+
+ # Go Through each subfolder
+ for subfolder in folder:
+ itemList = self.findFolder(subfolder)
+
+ if itemList:
+ myFolder = itemList
+
+ else:
+ if myFolder:
+ item = QtGui.QTreeWidgetItem(myFolder)
+ else:
+ item = QtGui.QTreeWidgetItem(self.tree)
+
+ item.setIcon(0, KP.icon('Folder'))
+ item.setText(0, subfolder)
+ item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsDropEnabled | Qt.ItemIsEditable | Qt.ItemIsEnabled)
+ myFolder = item
- if trash != None:
- break
+ # Now that we've got all the folders, put it in!
+ self.KPPathNodeItem(myFolder, layer, layer.associate)
- parent = trash.parent()
- if parent:
- parent.takeChild(trash)
else:
- self.tree.takeTopLevelItem(self.tree.indexOfTopLevelItem(trash))
+ self.KPPathNodeItem(self.tree, layer, layer.associate)
- def removeRecursor(self, parent, associate):
- trash = None
+ def findFolder(self, matchString):
- for itemI in xrange(parent.childCount()):
- item = parent.child(itemI)
+ itemList = QtGui.QTreeWidgetItemIterator(self.tree, QtGui.QTreeWidgetItemIterator.Editable)
- if item.associate == associate:
- trash = item
- else:
- trash = self.removeRecursor(item, associate)
+ while itemList.value():
+ item = itemList.value()
+
+ if str(item.text(0)) == matchString:
+ return item
+
+ itemList += 1
- if trash != None:
- return trash
-
return None
+ def removeLayer(self, associate):
+ itemList = QtGui.QTreeWidgetItemIterator(self.tree, QtGui.QTreeWidgetItemIterator.NotEditable)
+
+ while itemList.value():
+ item = itemList.value()
+
+ if not isinstance(item, self.KPPathNodeItem):
+ continue
+
+ if item.associate == associate:
+ parent = item.parent()
+ if parent:
+ parent.removeChild(item)
+ else:
+ index = self.tree.indexFromItem(item).row()
+ self.tree.takeTopLevelItem(self.tree.indexOfTopLevelItem(item))
+ return
+
+ itemList += 1
+
def getLayers(self):
layerList = []
for itemI in xrange(self.tree.topLevelItemCount()):
@@ -264,6 +294,27 @@ class KPPathNodeList(QtGui.QWidget):
else:
layerList.append(item.layer)
+ def setLayerFolders(self):
+
+ itemList = QtGui.QTreeWidgetItemIterator(self.tree, QtGui.QTreeWidgetItemIterator.NotEditable)
+
+ while itemList.value():
+ item = itemList.value()
+
+ if not isinstance(item, self.KPPathNodeItem):
+ continue
+
+ item.layer.folder = ''
+ daddy = item.parent()
+
+ while daddy:
+ item.layer.folder = str(daddy.text(0)) + '/' + item.layer.folder
+
+ daddy = daddy.parent()
+
+ itemList += 1
+
+
selectedLayerChanged = QtCore.pyqtSignal(KPLayer)
@@ -1373,15 +1424,17 @@ class KPMainWindow(QtGui.QMainWindow):
target = unicode(QtGui.QFileDialog.getExistingDirectory(self, 'Choose a folder'))
for fileName in os.listdir(target):
-
- if fileName[:-6] == ".kpmap":
+ print fileName
+
+ if fileName[-6:] == ".kpmap":
import mapfile
- obj = mapfile.load(open(target, 'rb').read())
- obj.save()
- obj.export(target + filename[:-6] + '.kpbin')
+ print 'Found a map'
+ obj = mapfile.load(open(target + "/" + fileName, 'rb').read())
+ # obj.save()
+ obj.export(target + "/" + fileName[:-6] + '.kpbin')
- print 'Saved and Exported {0}'.format(filename[:-6])
+ print 'Saved and Exported {0}'.format(fileName[:-6])
# Edit
@@ -1510,7 +1563,6 @@ class KPMainWindow(QtGui.QMainWindow):
loaded = mapfile.load(data)
file.close()
- print loaded
settings = KP.app.settings
presetList = []
@@ -1524,15 +1576,9 @@ class KPMainWindow(QtGui.QMainWindow):
presetList = []
presets = []
- print presetList, presets
- print dir(presetList)
-
presetList.extend(loaded[0])
presets.extend(loaded[1])
- print presetList
- print presets
-
settings.setValue('AnimationPresets', mapfile.dump(presetList))
settings.setValue('AnimationPresetData', mapfile.dump(presets))