Пример #1
0
 def __init__(self, *args, **kwargs):
     self.__alive = True
     self.__queue = deque()
     self.__setupFunc = partial(self.Setup, *args, **kwargs)
     self.__wakeEvent = CreateEvent(None, 0, 0, None)
     self.__dummyEvent = CreateEvent(None, 0, 0, None)
     self.__events = (HANDLE * 1)(self.__wakeEvent)
     self.__thread = Thread(
         group=None,
         target=self.__MainLoop,
         name=self.__class__.__name__,
     )
Пример #2
0
 def ThreadLoop(self, startupEvent):
     try:
         hDir = CreateFile(
             self.path, FILE_LIST_DIRECTORY,
             FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING,
             FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0)
         if hDir == INVALID_HANDLE_VALUE:
             self.startException = FormatError()
             startupEvent.set()
             return
         overlapped = OVERLAPPED()
         overlapped.hEvent = CreateEvent(None, 1, 0, None)
         buffer = (c_byte * BUFSIZE)()
         events = (HANDLE * 2)(overlapped.hEvent, self.stopEvent)
         flags = (FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME
                  | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE
                  | FILE_NOTIFY_CHANGE_LAST_WRITE
                  | FILE_NOTIFY_CHANGE_SECURITY)
         includeSubdirs = self.includeSubdirs
         renamePath = None
         bytesReturned = DWORD()
         noneCallback = cast(None, LPOVERLAPPED_COMPLETION_ROUTINE)
         startupEvent.set()
         while 1:
             ReadDirectoryChangesW(hDir, buffer, BUFSIZE, includeSubdirs,
                                   flags, byref(bytesReturned),
                                   byref(overlapped), noneCallback)
             rc = MsgWaitForMultipleObjects(2, events, 0, INFINITE,
                                            QS_ALLINPUT)
             if rc == WAIT_OBJECT_0:
                 res = GetOverlappedResult(hDir, byref(overlapped),
                                           byref(bytesReturned), 1)
                 address = addressof(buffer)
                 while True:
                     fni = FILE_NOTIFY_INFORMATION.from_address(address)
                     length = fni.FileNameLength / WCHAR_SIZE
                     fileName = wstring_at(address + 12, length)
                     action = fni.Action
                     fullFilename = os.path.join(self.path, fileName)
                     if action == FILE_ACTION_ADDED:
                         self.TriggerEvent("Created", (fullFilename, ))
                     elif action == FILE_ACTION_REMOVED:
                         self.TriggerEvent("Deleted", (fullFilename, ))
                     elif action == FILE_ACTION_MODIFIED:
                         self.TriggerEvent("Updated", (fullFilename, ))
                     elif action == FILE_ACTION_RENAMED_OLD_NAME:
                         renamePath = fullFilename
                     elif action == FILE_ACTION_RENAMED_NEW_NAME:
                         self.TriggerEvent("Renamed",
                                           (renamePath, fullFilename))
                         renamePath = None
                     if fni.NextEntryOffset == 0:
                         break
                     address += fni.NextEntryOffset
             elif rc == WAIT_OBJECT_0 + 1:
                 break
         CloseHandle(hDir)
     except:
         self.thread = None
         raise
Пример #3
0
 def __call__(
         self,
         osdText="",
         fontInfo=None,
         foregroundColour=(255, 255, 255),
         backgroundColour=(0, 0, 0),
         alignment=0,
         offset=(0, 0),
         displayNumber=0,
         timeout=3.0,
         skin=None
 ):
     if isinstance(skin, bool):
         skin = SKINS[0] if skin else None
     self.osdFrame.timer.cancel()
     osdText = eg.ParseString(osdText)
     event = CreateEvent(None, 0, 0, None)
     wx.CallAfter(
         self.osdFrame.ShowOSD,
         osdText,
         fontInfo,
         foregroundColour,
         backgroundColour,
         alignment,
         offset,
         displayNumber,
         timeout,
         event,
         skin
     )
     eg.actionThread.WaitOnEvent(event)
Пример #4
0
    def StatusCheckLoop(self):
        hComm = self.hFile
        waitingOnStatusHandle = False
        dwCommEvent = DWORD()
        dwOvRes = DWORD()
        commMask = (
            EV_BREAK | EV_CTS | EV_DSR | EV_ERR | EV_RING
            | EV_RLSD | EV_RXCHAR | EV_RXFLAG | EV_TXEMPTY
        )

        if not SetCommMask(self.hFile, commMask):
            raise SerialError("error setting communications mask")

        osStatus = OVERLAPPED(0)
        osStatus.hEvent = CreateEvent(None, 1, 0, None)
        if not osStatus.hEvent:
            raise SerialError("error creating event")

        while True:
            # Issue a status event check if one hasn't been issued already.
            if not waitingOnStatusHandle:
                if WaitCommEvent(hComm, byref(dwCommEvent), byref(osStatus)):
                    # WaitCommEvent returned immediately.
                    # Deal with status event as appropriate.
                    self.ReportStatusEvent(dwCommEvent.value)
                else:
                    if GetLastError() == ERROR_IO_PENDING:
                        waitingOnStatusHandle = True
                    else:
                        raise SerialError("error in WaitCommEvent")

            # Check on overlapped operation
            if waitingOnStatusHandle:
                # Wait a little while for an event to occur.
                res = WaitForSingleObject(osStatus.hEvent, 1000)
                if res == WAIT_OBJECT_0:
                    if GetOverlappedResult(
                        hComm, byref(osStatus), byref(dwOvRes), 0
                    ):
                        # Status event is stored in the event flag
                        # specified in the original WaitCommEvent call.
                        # Deal with the status event as appropriate.
                        self.ReportStatusEvent(dwCommEvent.value)
                    else:
                        # An error occurred in the overlapped operation;
                        # call GetLastError to find out what it was
                        # and abort if it is fatal.
                        raise SerialError()
                    # Set waitingOnStatusHandle flag to indicate that a new
                    # WaitCommEvent is to be issued.
                    waitingOnStatusHandle = True
                elif res == WAIT_TIMEOUT:
                    print "timeout"
                else:
                    # This indicates a problem with the OVERLAPPED structure's
                    # event handle.
                    CloseHandle(osStatus.hEvent)
                    raise SerialError("error in the WaitForSingleObject")

        CloseHandle(osStatus.hEvent)
Пример #5
0
 def __call__(self,
              title="",
              body="",
              alias="",
              payload="",
              blocking=False,
              options=0,
              mbType=0,
              autoClose=0):
     title = eg.ParseString(title)
     body = eg.ParseString(body)
     alias = eg.ParseString(alias)
     payload = eg.ParseString(payload)
     if not isinstance(autoClose, int):
         try:
             autoClose = int(eg.ParseString(autoClose))
         except:
             autoClose = 0
     if mbType:
         event = CreateEvent(None, 0, 0, None) if blocking else None
         wx.CallAfter(self.showTweakedBox, None, title, body, alias,
                      payload, options, autoClose, event)
         if blocking:
             #print "Waiting ..."
             eg.actionThread.WaitOnEvent(event, 999999999999)
             return self.retCode
     else:
         if blocking:
             return self.showMessageBox(title, body, alias, payload,
                                        options)
         else:
             Thread(target=self.showMessageBox,
                    args=(title, body, alias, payload, options)).start()
             return None
Пример #6
0
 def __init__(self, callback):
     Thread.__init__(self, target=self.ThreadLoop)
     self.timeout = INFINITE
     self.lock = Lock()
     self.callback = callback
     self.event = CreateEvent(None, 0, 0, None)
     self.start()
Пример #7
0
 def GetToken(self):
     flag = True
     while flag: 
         token = format(randrange(16777216), '06x')
         flag = token in self.queryData
     event = CreateEvent(None, 0, 0, None)
     self.queryData[token] = event
     return token
Пример #8
0
 def __start__(self):
     self.stopEvent = CreateEvent(None, 1, 0, None)
     self.startException = None
     startupEvent = threading.Event()
     self.thread = threading.Thread(target=self.ThreadLoop,
                                    name="ProcessWatcherThread",
                                    args=(startupEvent, ))
     self.thread.start()
     startupEvent.wait(3)
     if self.startException is not None:
         raise self.Exception(self.startException)
Пример #9
0
 def __start__(self, path, includeSubdirs):
     self.stopEvent = CreateEvent(None, 1, 0, None)
     self.path = path
     self.startException = None
     self.includeSubdirs = includeSubdirs
     startupEvent = threading.Event()
     self.thread = threading.Thread(target=self.ThreadLoop,
                                    name="DirectoryWatcherThread",
                                    args=(startupEvent, ))
     self.thread.start()
     startupEvent.wait(3)
     if self.startException is not None:
         raise self.Exception(self.startException)
Пример #10
0
    def __init__(self, hFile=0):
        Thread.__init__(self, target=self.ReceiveThreadProc)
        self.hFile = int(hFile)
        self.osWriter = OVERLAPPED()
        self.osWriter.hEvent = CreateEvent(None, 0, 0, None)
        self.osReader = OVERLAPPED()
        self.osReader.hEvent = CreateEvent(None, 1, 0, None)
        self.dwRead = DWORD()
        self.comstat = COMSTAT()
        self.dcb = DCB()
        self.dcb.DCBlength = sizeof(DCB)
        self.oldCommTimeouts = COMMTIMEOUTS()

        self.readEventCallback = None
        self.readEventLock = Lock()
        self.readEventLock.acquire()
        self.readCondition = Condition()
        self.buffer = ""
        self.keepAlive = True
        self.stopEvent = CreateEvent(None, 1, 0, None)
        self.callbackThread = Thread(target=self.CallbackThreadProc,
                                     name="SerialReceiveThreadProc")
Пример #11
0
 def SendCommand(self, cmd, room, value, wait=True):
     if wait:
         event = CreateEvent(None, 0, 0, None)
         self.event = (COMMANDS[cmd], event)
     hwnd = GetHwnd()
     if hwnd:
         SendMessage(hwnd, WM_COMMAND, COMMANDS[cmd] + room, value)
         if wait:
             eg.actionThread.WaitOnEvent(event)
             res = self.result
             self.result = None
             return res
     else:
         eg.PrintError(self.text.err1)
Пример #12
0
        def onBurn(evt):
            if self.data == [cpy(EMPTY_CHAR)]:
                MessageBox(self.panel,
                           text.message3,
                           text.messBoxTit4,
                           wx.ICON_EXCLAMATION,
                           plugin=self,
                           time=10)
                return
            if not self.GetConnected():
                MessageBox(self.panel,
                           text.message2,
                           text.messBoxTit2,
                           wx.ICON_EXCLAMATION,
                           plugin=self,
                           time=10)
                return

            max = 1 + len(self.data)
            dlg = wx.ProgressDialog(self.text.progress,
                                    self.text.wait,
                                    maximum=max,
                                    parent=self.panel,
                                    style=wx.PD_CAN_ABORT
                                    | wx.PD_APP_MODAL)
            dlg.SetIcon(self.info.icon.GetWxIcon())

            keepGoing = True
            count = 0
            for i, ch in enumerate(self.data):
                event = CreateEvent(None, 0, 0, None)
                item = list(ch[2])
                item.append(i)
                item.append(ord(ch[1]))
                self.queue.put(((COMMANDS["Burn"], item), event))
                eg.actionThread.WaitOnEvent(event)
                count += 1
                (keepGoing, skip) = dlg.Update(count)
            self.queue.put(((COMMANDS["Burn"], (len(self.data), )), event))
            count += 1
            eg.actionThread.WaitOnEvent(event)
            (keepGoing, skip) = dlg.Update(count, self.text.done)
            self.eechars = len(self.data)