def run(self): path = self._path self._streamRef = FSEventStreamCreate( kCFAllocatorDefault, self.eventsCallback, path, [path], kFSEventStreamEventIdSinceNow, # sinceWhen 1.0, # latency 0, ) if self._streamRef is None: Util.trace("FSEventStreamCreate is failed") return if False: FSEventStreamShow(self._streamRef) FSEventStreamScheduleWithRunLoop(self._streamRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode) startedOK = FSEventStreamStart(self._streamRef) if not startedOK: Util.trace("failed to start the FSEventStream") return # if True: # timer = CFRunLoopTimerCreate( # FSEventStreamGetSinceWhen(streamRef), # CFAbsoluteTimeGetCurrent() + settings.flush_seconds, # settings.flush_seconds, # 0, 0, timer_callback, streamRef) # CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode) CFRunLoopRun()
def __del__(self): Util.trace("destroy DirCheck instance") streamRef = self._streamRef # Stop / Invalidate / Release FSEventStreamStop(streamRef) FSEventStreamInvalidate(streamRef) FSEventStreamRelease(streamRef)
def _dumpVariable( self ): Util.trace( "---------------------------" ) Util.trace( "index: " + str( self.index_ ) ) Util.trace( "name: " + str( self.name_ ) ) #Util.trace( "ext: " + str( self.ext_ ) ) Util.trace( "mtime: " + str( self.mtime_ ) ) Util.trace( "bgColor: " + str( self.bgColor_ ) )
def Cmd_Open( vfiler, event ): """ 関連づけられたプログラムでファイルを開く """ listCtrl = vfiler.getFocusedListCtrl() focusedItemIndex = listCtrl.GetFocusedItem() cmd = "open %s" %( listCtrl.getItemAbsPath( focusedItemIndex ) ) Util.trace( cmd ) os.system( cmd )
def moveDir( self, moveDirDirection ): """ Key入力によってディレクトリを移動する """ nextPath = "" if moveDirDirection==self.MOVE_DIR_UP: nextPath = self.curDir + "/.." elif moveDirDirection==self.MOVE_DIR_DOWN: nextPath = self.getItemAbsPath( self.GetFocusedItem() ) if os.path.isdir( nextPath ): Util.trace( "moveDir %s -> %s" %(self.getCurDir(), nextPath) ) nextPath = os.path.normpath( nextPath ) self.changeDir( nextPath )
def eventsCallback(self, streamRef, clientInfo, numEvents, eventPaths, eventMarsks, eventIDs): fullPath = clientInfo print ("callback: clientInfo[%s]" % (clientInfo)) for i in range(numEvents): path = eventPaths[i] if path[-1] == "/": path = path[:-1] print "eventPath => %s" % (path) if path == self._path: self._isChanged = True eventMarsk = eventMarsks[i] if eventMarsk & kFSEventStreamEventFlagMustScanSubDirs: Util.trace("kFSEventStreamEventFlagMustScanSubDirs") recursive = True elif eventMarsk & kFSEventStreamEventFlagUserDropped: Util.trace("kFSEventStreamEventFlagUserDropped") recursive = True path = fullPath elif eventMarsk & kFSEventStreamEventFlagKernelDropped: Util.trace("kFSEventStreamEventFlagKernelDropped") recursive = 1 path = fullPath else: Util.trace("recive FSEvent callback") recursive = False
def deleteElem( self ): """ 選択中エレメントをファイルリストから削除する """ focusedItemIndex = self.GetFocusedItem() if self.getElemCount() and focusedItemIndex>=0: forcusedElem = self.getElem( focusedItemIndex ) # elemListから削除 self.elemList.remove( forcusedElem ) # GUIから削除 self.DeleteItem( focusedItemIndex ) # FileSystemから削除 cmd = "rm -rf %s" %( forcusedElem.getAbsPath() ) Util.trace( cmd ) os.system( cmd )
def copyElem( self ): """ 選択中エレメントを非フォーカスペインのディレクトリへコピーする """ focusedItemIndex = self.GetFocusedItem() if self.getElemCount() and focusedItemIndex>=0: forcusedElem = self.getElem( focusedItemIndex ) srcPath = forcusedElem.getAbsPath() destPath = None unfocusedPane = self.getFrame().getUnFocusedPane() if unfocusedPane: destPath = unfocusedPane.getCurDir() if destPath and destPath!=os.path.dirname( srcPath ): cmd = "cp -rf %s %s" %( srcPath, destPath ) Util.trace( cmd ) os.system( cmd )
def Cmd_Delete( vfiler, event ): """ 選択中エレメントをファイルリストから削除する """ listCtrl = vfiler.getFocusedListCtrl() focusedItemIndex = listCtrl.GetFocusedItem() if listCtrl.getElemCount() and focusedItemIndex>=0: forcusedElem = listCtrl.getElem( focusedItemIndex ) # elemListから削除 listCtrl.elemList.remove( forcusedElem ) # GUIから削除 listCtrl.DeleteItem( focusedItemIndex ) # FileSystemから削除 cmd = "rm -rf %s" %( forcusedElem.getAbsPath() ) Util.trace( cmd ) os.system( cmd )
def Cmd_Copy( vfiler, event ): """ 選択中エレメントを非フォーカスペインのディレクトリへコピーする """ listCtrl = vfiler.getFocusedListCtrl() focusedItemIndex = listCtrl.GetFocusedItem() if listCtrl.getElemCount() and focusedItemIndex>=0: forcusedElem = listCtrl.getElem( focusedItemIndex ) srcPath = forcusedElem.getAbsPath() destPath = None unfocusedPane = vfiler.getUnFocusedPane() if unfocusedPane: destPath = unfocusedPane.getCurDir() if destPath and destPath!=os.path.dirname( srcPath ): cmd = "cp -rf %s %s" %( srcPath, destPath ) Util.trace( cmd ) os.system( cmd )
def updateFileList( self, curDir=None, filterFmt=None ): """ ファイルリストを更新 """ if curDir==None: curDir = self.curDir self.removeFileList() self.elemList = [] Util.trace( "curDir [%s] updateFileList" %(curDir) ) listdir = os.listdir( curDir ) # ディレクトリ群、ファイル群の順番にソート dirInfoList = [] fileInfoList = [] for e in listdir: info = {} if filterFmt!=None: p = re.compile( filterFmt, re.IGNORECASE ) if not p.search( e ): continue# マッチしなかったらフィルターする info["name"] = e absPath = "%s/%s" %( curDir, e ) if os.path.isdir( absPath ): info["isDir"] = True dirInfoList.append( info ) else: info["isDir"] = False fileInfoList.append( info ) infoList = dirInfoList + fileInfoList # リストに追加 iFile = 0 for info in infoList: if info["isDir"]: #Util.trace( "add DIR " + e ) elem = ElemDir( iFile, self, info["name"] ) else: #Util.trace( "add FILE " + e ) elem = ElemFile( iFile, self, info["name"] ) elem.update() self.elemList.append( elem ) iFile += 1 # フォーカスがあるときに常に項目を選択状態にするため、Select if len( self.elemList ): self.Select( 0, True )
def setListMode( self, listMode ): Util.trace( "change list mode %d => %d" %(self.listMode, listMode) ) self.listMode = listMode
def updateIncSearch( self, searchWord ): """ 検索ワードを受け取って、Incremental検索結果を更新 """ Util.trace( "search of " + searchWord ) self.updateFileList( filterFmt=searchWord ) self.setListMode( ListCtrl.LIST_MODE_FILTERED )
def removeFileList( self ): """ ファイルリストを削除 """ Util.trace( "removeFileList" ) self.DeleteAllItems()
def Cmd_Move( vfiler, event ): Util.trace( "NOT IMPLEMENT!" )
def Cmd_FileEdit( vfiler, event ): listCtrl = vfiler.getFocusedListCtrl() focusedItemIndex = listCtrl.GetFocusedItem() cmd = "mvim --remote-silent %s" %( listCtrl.getItemAbsPath( focusedItemIndex ) ) Util.trace("file edit command( %s )" %(cmd) ) os.system( cmd )