示例#1
0
    def Run(self):
        while 1:
            handles = [self.stopEvent, self.adminEvent]
            if self.watchEvent is not None:
                handles.append(self.watchEvent)
            rc = win32event.WaitForMultipleObjects(handles, 0, win32event.INFINITE)
            if rc == win32event.WAIT_OBJECT_0:
                break
            elif rc == win32event.WAIT_OBJECT_0 + 1:
                self.RefreshEvent()
            else:
                win32api.PostMessage(self.hwnd, MSG_CHECK_EXTERNAL_FILE, 0, 0)
                try:
                    # If the directory has been removed underneath us, we get this error.
                    win32api.FindNextChangeNotification(self.watchEvent)
                except win32api.error as exc:
                    print(
                        "Can not watch file",
                        self.doc.GetPathName(),
                        "for changes -",
                        exc.strerror,
                    )
                    break

        # close a circular reference
        self.doc = None
        if self.watchEvent:
            win32api.FindCloseChangeNotification(self.watchEvent)
示例#2
0
	def RefreshEvent(self):
		self.hwnd = self.doc.GetFirstView().GetSafeHwnd()
		if self.watchEvent is not None:
			win32api.FindCloseChangeNotification(self.watchEvent)
			self.watchEvent = None
		path = self.doc.GetPathName()
		if path: path = os.path.dirname(path)
		if path:
			filter = win32con.FILE_NOTIFY_CHANGE_FILE_NAME | \
					 win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES | \
					 win32con.FILE_NOTIFY_CHANGE_LAST_WRITE
			try:
				self.watchEvent = win32api.FindFirstChangeNotification(path, 0, filter)
			except win32api.error, exc:
				print "Can not watch file", path, "for changes -", exc.strerror
示例#3
0
文件: mdview.py 项目: stania/mdview
 def wfc(self, *args, **kwargs): #wait for change
     subpath = self._get_subpath(args)
     if settings.debug: print "wfc:", subpath
     f = os.path.abspath(os.path.join(get_base_dir(), subpath))
     parent = os.path.dirname(f)
     timeout = kwargs.has_key("timeout") and int(kwargs["timeout"]) or 60000
     try:
         print "watching", f
         handle = win32api.FindFirstChangeNotification(parent, 0, 0x010)
         ret = win32event.WaitForSingleObject(handle, int(timeout))
         if ret is win32event.WAIT_TIMEOUT:
             raise cherrypy.HTTPError(304) 
         time.sleep(0.2)
         return self.default_dispatcher(None, args, **kwargs)
     except pywintypes.error as e: #@UndefinedVariable
         print e[2]
         raise cherrypy.HTTPError(500)
     finally:
         if handle:
             win32api.FindCloseChangeNotification(handle)
示例#4
0
                print "Can not watch file", path, "for changes -", exc.strerror

    def SignalStop(self):
        win32event.SetEvent(self.stopEvent)

    def Run(self):
        while 1:
            handles = [self.stopEvent, self.adminEvent]
            if self.watchEvent is not None:
                handles.append(self.watchEvent)
            rc = win32event.WaitForMultipleObjects(handles, 0,
                                                   win32event.INFINITE)
            if rc == win32event.WAIT_OBJECT_0:
                break
            elif rc == win32event.WAIT_OBJECT_0 + 1:
                self.RefreshEvent()
            else:
                win32api.PostMessage(self.hwnd, MSG_CHECK_EXTERNAL_FILE, 0, 0)
                try:
                    # If the directory has been removed underneath us, we get this error.
                    win32api.FindNextChangeNotification(self.watchEvent)
                except win32api.error, exc:
                    print "Can not watch file", self.doc.GetPathName(
                    ), "for changes -", exc.strerror
                    break

        # close a circular reference
        self.doc = None
        if self.watchEvent:
            win32api.FindCloseChangeNotification(self.watchEvent)
示例#5
0
文件: spy.py 项目: connoryang/1v1dec
 def __del__(self):
     for handle in self.handles.keys():
         win32api.FindCloseChangeNotification(handle)