[ create a new paste ] login | about

Link: http://codepad.org/83WhqC7o    [ raw code | output | fork ]

Python, pasted on Nov 2:
    import ctypes

    FindFirstChangeNotification = \
            ctypes.windll.kernel32.FindFirstChangeNotificationW
    FindNextChangeNotification = \
            ctypes.windll.kernel32.FindNextChangeNotification
    FindCloseChangeNotification = \
            ctypes.windll.kernel32.FindCloseChangeNotification
    WaitForMultipleObjects = \
            ctypes.windll.kernel32.WaitForMultipleObjects
    CreateEvent = ctypes.windll.kernel32.CreateEventW
    SetEvent = ctypes.windll.kernel32.SetEvent
    ResetEvent = ctypes.windll.kernel32.ResetEvent
    CloseHandle = ctypes.windll.kernel32.CloseHandle
    import threading

    class DirectoryWatchThread(threading.Thread):
        def __init__(self):
            threading.Thread.__init__(self)
            self.directory = None
            self.event = CreateEvent(0, 0, 0, 0)

        def run(self):
            handle = FindFirstChangeNotification(
                    ctypes.c_wchar_p(self.directory), 0, 3)
            if handle == 0xffffffff:
                CloseHandle(self.event)
                return 

            handles = (ctypes.c_uint * 2)()
            handles[0] = self.event
            handles[1] = handle
            while True:
                ret = WaitForMultipleObjects(2,
                        ctypes.addressof(handles), 0, -1)
                if ret == 0:
                    CloseHandle(self.event)
                    FindCloseChangeNotification(handle)
                    break
                window.command_Refresh()
                FindNextChangeNotification(handle)

        def stop(self):
            SetEvent(self.event)

    import cfiler_filelist
    def rebind_setLister(self):
        original_setLister = self.setLister
        def setLister(lister):
            if hasattr(self, "watch_thread"):
                self.watch_thread.stop()
                del self.watch_thread
            if isinstance(lister, cfiler_filelist.lister_Default):
                self.watch_thread = DirectoryWatchThread()
                self.watch_thread.directory = lister.location
                self.watch_thread.start()
            if lister: original_setLister(lister)
        self.setLister = setLister
    rebind_setLister(window.left_pane.file_list)
    rebind_setLister(window.right_pane.file_list)


Output:
1
2
3
4
  Line 1
    import ctypes
    ^
IndentationError: unexpected indent


Create a new paste based on this one


Comments: