def _onOpenNewEditEntity(self, msg): if self._currentEntity is not None: if self._currentEntity.getName() == msg.entityName: return if not self._askToSaveEntity(): return loader = self._app._editorNative.getEntityLoader() try: newEntity = loader.loadEntity(msg.entityName) except Exception as e: Log.error( "[_EventManager:_onOpenNewEditEntity] Can't load entity '{0}' (Exception: {1})" .format(msg.entityName, e)) traceback.print_tb(e.__traceback__) return if newEntity is None: return if not newEntity.loadToNative(): Log.error( "[_EventManager:_onOpenNewEditEntity] Can't load entity '{0}' to native" .format(msg.entityName)) return if self._currentEntity is not None: self._currentEntity.unloadFromNative() self._currentEntity = newEntity SendMessage(MsgSetEditEntity(self._currentEntity))
def onEntityDoubleClickFromFileTree(self, entityName): if self._currentEntity is not None: if self._currentEntity.getName() == entityName: return if not self._askToSaveEntity(): return loader = self._app._editorNative.getEntityLoader() try: newEntity = loader.loadEntity(entityName) except Exception as e: Log.error( "[_EventManager:onEntityDoubleClickFromFileTree] Can't load entity '{0}' (Exception: {1})" .format(entityName, e)) return if newEntity is None: return if not newEntity.loadToNative(): Log.error( "[_EventManager:onEntityDoubleClickFromFileTree] Can't load entity '{0}' to native" .format(entityName)) return if self._currentEntity is not None: self._currentEntity.unloadFromNative() self._currentEntity = newEntity self._currentEntity._syncWithNative() GetMainViewManager().onEntityDoubleClickFromFileTree( self._currentEntity)
def _setItemForPreview(self, item): if item.__class__ != FileNode: self._clearPreview() return path = item.getFullPath() fileSize = os.path.getsize(path) self._sizeInfo.show() self._sizeInfo.setText("<b>Size:</b> {0}".format( _convertSize(fileSize))) if item._type == FileNodeType.Image: image = QPixmap(path) if image.isNull(): self._dimInfo.hide() self._previewLabel.setText("<b>No Preivew</b>") Log.error( "[FilePreview:_setItemForPreview] Can't load image: '{0}'". format(path)) else: self._dimInfo.show() self._dimInfo.setText("<b>Dimension:</b> {0}x{1}".format( image.width(), image.height())) self._scaleFactor = 1 self._previewLabel.setPixmap( _scalePixmap(image, self._scrollArea.width() - 2, self._scrollArea.height() - 2)) self._previewLabel.adjustSize() else: self._clearPreview()
def init(self): assetsRootDir = self._appConfig.getAssetsRootPath() if not os.path.exists(assetsRootDir): Log.error( "[AssetsModel:init] Can't find assets root dir: '{0}'".format( assetsRootDir)) return False self._resourceRootDir = DirNode(None, assetsRootDir) self._scanDir(self._resourceRootDir) return True
def init(self): eventsFile = "{0}/Sounds/Events.json".format( self._appConfig.getAssetsRootPath()) if not os.path.exists(eventsFile): Log.error( "[SoundEventsModel:init] Can't find events config: '{0}'". format(eventsFile)) return False with open(eventsFile, 'r') as tFile: data = json.load(tFile) for item in data["Events"]: event = SoundEvent() event._name = item["name"] if len(event._name) == 0: continue self._root._children.append(event) return True
def init(self): assetsRootDir = self._appConfig.getAssetsRootPath() if not os.path.exists(assetsRootDir): Log.error( "[AssetsModel:init] Can't find assets root dir: '{0}'".format( assetsRootDir)) return False self._resourceRootDir = DirNode() self._resourceRootDir._name = assetsRootDir self._scanDir(self._resourceRootDir) self._setTypeRecursive(self._resourceRootDir.findChild("Entities"), FileNodeType.Entity) self._setTypeRecursive(self._resourceRootDir.findChild("Images"), FileNodeType.Image) self._setTypeRecursive(self._resourceRootDir.findChild("Sounds"), FileNodeType.Sound) return True
def removeNode(self, node): filePath = node.getFullPath() if os.path.exists(filePath): try: if os.path.isdir(filePath): Log.debug( "[AssetsModel:removeNode] Remove dir: '{0}'".format( filePath)) shutil.rmtree(filePath) else: Log.debug( "[AssetsModel:removeNode] Remove file: '{0}'".format( filePath)) os.remove(filePath) except Exception as e: Log.error( "[AssetsModel:removeNode] Can't remove file: '{0}' (Error: {1})" .format(filePath, e.__str__())) return False node._parent._children.remove(node) return True
def createNewEntity(self, parentNode, fileName): if len(fileName) == 0: Log.error( "[AssetsModel:createNewEntity] Can't create with empty name") return None filePath = "{0}/{1}".format(parentNode.getFullPath(), fileName) if os.path.exists(filePath): Log.error( "[AssetsModel:createNewEntity] Can't create file: '{0}' (Error: already exists)" .format(filePath)) return None try: CreateVoidEntity(filePath) except Exception as e: Log.error( "[AssetsModel:createNewEntity] Can't create file: '{0}' (Error: {1})" .format(filePath, e.__str__())) return None Log.debug("[AssetsModel:createNewEntity] Create file: '{0}'".format( filePath)) node = FileNode() node._name = fileName node._parent = parentNode node._type = FileNodeType.Entity parentNode._children.append(node) return node
def createNewDir(self, parentNode, fileName): if len(fileName) == 0: Log.error( "[AssetsModel:createNewDir] Can't create with empty name") return None dirPath = "{0}/{1}".format(parentNode.getFullPath(), fileName) if os.path.exists(dirPath): Log.error( "[AssetsModel:createNewDir] Can't create dir: '{0}' (Error: already exists)" .format(dirPath)) return None try: os.mkdir(dirPath) except Exception as e: Log.error( "[AssetsModel:createNewDir] Can't create dir: '{0}' (Error: {1})" .format(dirPath, e.__str__())) return None Log.debug( "[AssetsModel:createNewDir] Create dir: '{0}'".format(dirPath)) node = DirNode() node._name = fileName node._parent = parentNode parentNode._children.append(node) return node
def _init(self): self._appConfig = AppConfig() self._editorNative = EditorNative(self._appConfig) if not self._editorNative.init(): Log.error("[EditorView:_init] Can't init native editor") return False self._assetsModel = AssetsModel(self._appConfig) if not self._assetsModel.init(): Log.error("[EditorView:_init] Can't init assets model") return False self._logicsModel = LogicsModel(self._editorNative) if not self._logicsModel.init(): Log.error("[EditorView:_init] Can't init logics model") return False self._soundEventsModel = SoundEventsModel(self._appConfig) if not self._soundEventsModel.init(): Log.error("[EditorView:_init] Can't init sound events model") return False return True
def renameNode(self, node, newName): srcPath = node.getFullPath() trgPath = "{0}/{1}".format(node.getParentFullPath(), newName) if os.path.exists(trgPath): Log.error( "[AssetsModel:renameNode] Target path already exists: '{0}'". format(trgPath)) return False if not os.path.exists(srcPath): Log.error("[AssetsModel:renameNode] Can't find source path: '{0}'". format(srcPath)) return False try: os.replace(srcPath, trgPath) except Exception as e: Log.error( "[AssetsModel:renameNode] Can't rename file: '{0}' to '{1}' (Error: {2})" .format(srcPath, trgPath, e.__str__())) return False Log.debug( "[AssetsModel:renameNode] Rename file: '{0}' to '{1}'".format( srcPath, trgPath)) node._name = newName return True