def __scanDirectoryRecursively(self, dirname): """ Generates a list of Filename objects: all of the files (not directories) within and below the indicated dirname. """ contents = [] for dirpath, dirnames, filenames in os.walk(dirname.toOsSpecific()): dirpath = Filename.fromOsSpecific(dirpath) if dirpath == dirname: dirpath = Filename('') else: dirpath.makeRelativeTo(dirname) for filename in filenames: contents.append(Filename(dirpath, filename)) return contents
def onDetails(self, evt, item): assetName = self.treeLibrary.GetItemText(item) parent = self.treeLibrary.GetItemParent(item) assetType = self.treeLibrary.GetItemText(parent) if assetType == "Meshes": asset = self.lib.meshes[assetName] elif assetType == "Textures": asset = self.lib.textures[assetName] elif assetType == "Actors": asset = self.lib.actors[assetName] elif assetType == "Animations": asset = self.lib.animations[assetName] elif assetType == "Shaders": asset = self.lib.shaders[assetName] elif assetType == "Sounds": asset = self.lib.sounds[assetName] elif assetType == "Terrains": asset = self.lib.terrains[assetName] dlg = EditAssetUI(self, asset) updateNeeded = False if dlg.ShowModal() == wx.ID_OK: newAssetName = Util.toAssetName(dlg.txtAssetName.GetValue()) if newAssetName != asset.name: try: if assetType == "Meshes": self.lib.renameMesh(asset.name, newAssetName) elif assetType == "Textures": self.lib.renameTexture(asset.name, newAssetName) elif assetType == "Actors": self.lib.renameActor(asset.name, newAssetName) elif assetType == "Animations": self.lib.renameAnimation(asset.name, newAssetName) elif assetType == "Shaders": self.lib.renameShader(asset.name, newAssetName) elif assetType == "Sounds": self.lib.renameSound(asset.name, newAssetName) elif assetType == "Terrains": self.lib.renameTerrain(asset.name, newAssetName) except LELibrary.DuplicateNameError: alert = wx.MessageDialog(self, "Name already in use. Aborting operation.",\ caption="Duplicate Name", style=wx.OK|wx.ICON_HAND) alert.ShowModal() return else: updateNeeded = True if dlg.txtNewFileLink.GetValue(): dest = Filename.fromOsSpecific(dlg.txtNewFileLink.GetValue()) dest.setDirname(asset.getFullFilename().getDirname()) if not os.path.exists(dest.toOsSpecific()): try: asset.relink(dlg.txtNewFileLink.GetValue()) updateNeeded = True except IOError as e: print e alert = wx.MessageDialog(self, "Could not copy file to '" + e.filename + "'. Permission denied.",\ caption="File Error", style=wx.OK|wx.ICON_HAND) alert.ShowModal() else: destFilename = Filename(dest) destFilename.makeRelativeTo(self.lib.projDir) if destFilename in self.lib.filenameIndex: if self.lib.filenameIndex[destFilename] != asset: alert = wx.MessageDialog(self, "Cannot overwrite other asset named '" + self.lib.filenameIndex[destFilename].name + "'.",\ caption = "Cannot overwrite file", style=wx.OK|wx.ICON_HAND) alert.ShowModal() return alert = wx.MessageDialog(self, "Overwrite file: " + dest.toOsSpecific() + " ?",\ caption="Overwrite File?", style=wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION) if alert.ShowModal() == wx.ID_YES: try: asset.relink(dlg.txtNewFileLink.GetValue()) updateNeeded = True except IOError as e: print e alert = wx.MessageDialog(self, "Could not copy file to '" + e.filename + "'. Permission denied.",\ caption="File Error", style=wx.OK|wx.ICON_HAND) alert.ShowModal() if assetType == "Actors": if dlg.txtNewAnimLink.GetValue(): try: # Create the animation asset newAnim = Library.Animation( dlg.txtAnimName.GetValue(), Filename.fromOsSpecific( dlg.txtNewAnimLink.GetValue())) self.editor.lib.addAnimation(newAnim) # Add the animation asset to the actor's animations list asset.anims[dlg.txtAnimName.GetValue()] = newAnim updateNeeded = True except IOError as e: print e alert = wx.MessageDialog(self, "Could not copy file to '" + e.filename + "'. Permission denied.",\ caption="File Error", style=wx.OK|wx.ICON_HAND) alert.ShowModal() if updateNeeded: if self.editor.saved: dlg = wx.MessageDialog(self, "This will save the project.", style=wx.OK) dlg.ShowModal() self.editor.save() self.editor.load(self.editor.currentProj.filename, resetViews=False, setSaved=False) self.update()
def onDetails(self, evt, item): assetName = self.treeLibrary.GetItemText(item) parent = self.treeLibrary.GetItemParent(item) assetType = self.treeLibrary.GetItemText(parent) if assetType == "Meshes": asset = self.lib.meshes[assetName] elif assetType == "Textures": asset = self.lib.textures[assetName] elif assetType == "Actors": asset = self.lib.actors[assetName] elif assetType == "Animations": asset = self.lib.animations[assetName] elif assetType == "Shaders": asset = self.lib.shaders[assetName] elif assetType == "Sounds": asset = self.lib.sounds[assetName] elif assetType == "Terrains": asset = self.lib.terrains[assetName] dlg = EditAssetUI(self, asset) updateNeeded = False if dlg.ShowModal() == wx.ID_OK: newAssetName = Util.toAssetName(dlg.txtAssetName.GetValue()) if newAssetName != asset.name: try: if assetType == "Meshes": self.lib.renameMesh(asset.name, newAssetName) elif assetType == "Textures": self.lib.renameTexture(asset.name, newAssetName) elif assetType == "Actors": self.lib.renameActor(asset.name, newAssetName) elif assetType == "Animations": self.lib.renameAnimation(asset.name, newAssetName) elif assetType == "Shaders": self.lib.renameShader(asset.name, newAssetName) elif assetType == "Sounds": self.lib.renameSound(asset.name, newAssetName) elif assetType == "Terrains": self.lib.renameTerrain(asset.name, newAssetName) except LELibrary.DuplicateNameError: alert = wx.MessageDialog(self, "Name already in use. Aborting operation.",\ caption="Duplicate Name", style=wx.OK|wx.ICON_HAND) alert.ShowModal() return else: updateNeeded = True if dlg.txtNewFileLink.GetValue(): dest = Filename.fromOsSpecific(dlg.txtNewFileLink.GetValue()) dest.setDirname(asset.getFullFilename().getDirname()) if not os.path.exists(dest.toOsSpecific()): try: asset.relink(dlg.txtNewFileLink.GetValue()) updateNeeded = True except IOError as e: print e alert = wx.MessageDialog(self, "Could not copy file to '" + e.filename + "'. Permission denied.",\ caption="File Error", style=wx.OK|wx.ICON_HAND) alert.ShowModal() else: destFilename = Filename(dest) destFilename.makeRelativeTo(self.lib.projDir) if destFilename in self.lib.filenameIndex: if self.lib.filenameIndex[destFilename] != asset: alert = wx.MessageDialog(self, "Cannot overwrite other asset named '" + self.lib.filenameIndex[destFilename].name + "'.",\ caption = "Cannot overwrite file", style=wx.OK|wx.ICON_HAND) alert.ShowModal() return alert = wx.MessageDialog(self, "Overwrite file: " + dest.toOsSpecific() + " ?",\ caption="Overwrite File?", style=wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION) if alert.ShowModal() == wx.ID_YES: try: asset.relink(dlg.txtNewFileLink.GetValue()) updateNeeded = True except IOError as e: print e alert = wx.MessageDialog(self, "Could not copy file to '" + e.filename + "'. Permission denied.",\ caption="File Error", style=wx.OK|wx.ICON_HAND) alert.ShowModal() if assetType == "Actors": if dlg.txtNewAnimLink.GetValue(): try: # Create the animation asset newAnim = Library.Animation(dlg.txtAnimName.GetValue(), Filename.fromOsSpecific(dlg.txtNewAnimLink.GetValue())) self.editor.lib.addAnimation(newAnim) # Add the animation asset to the actor's animations list asset.anims[dlg.txtAnimName.GetValue()] = newAnim updateNeeded = True except IOError as e: print e alert = wx.MessageDialog(self, "Could not copy file to '" + e.filename + "'. Permission denied.",\ caption="File Error", style=wx.OK|wx.ICON_HAND) alert.ShowModal() if updateNeeded: if self.editor.saved: dlg = wx.MessageDialog(self, "This will save the project.", style=wx.OK) dlg.ShowModal() self.editor.save() self.editor.load(self.editor.currentProj.filename, resetViews=False, setSaved=False) self.update()