Ejemplo n.º 1
0
    def OnCopyData(self, hwnd, mesg, wParam, lParam):
        copyData = cast(lParam, PCOPYDATASTRUCT)
        hEvent = cast(copyData.contents.lpData, POINTER(HEVENT))
        if not (
            copyData.contents.dwData == 0
            and copyData.contents.cbData == sizeof(HEVENT)
            and hEvent.contents.dwHookType == WH_KEYBOARD
        ):
            eg.eventThread.Call(eg.Print, "return")
            return
        mTime = time.clock()
        msg = MSG()
        while PeekMessage(byref(msg), 0, WM_INPUT, WM_INPUT, PM_REMOVE):
            self.OnRawInput(0, msg.message, msg.wParam, msg.lParam)
        vKey = hEvent.contents.wParam
        repeatCount = hEvent.contents.lParam & 0xFFFF
        keyState = (hEvent.contents.lParam >> 30) & 0x01
        extended = (hEvent.contents.lParam >> 24) & 0x01
        if (hEvent.contents.lParam >> 31) & 0x01:
            transition = "KEYUP"
            state = False
        else:
            transition = "KEYDOWN"
            state = True
        info = "%f Hook %s: %s(%d), keyState=%d, extended=%d" % (
            mTime,
            transition,
            VK_KEYS[vKey],
            hEvent.contents.wParam,
            keyState,
            extended,
        )
        if GetAsyncKeyState(162): #LCtrl
            info += "LCtrl "
        if GetAsyncKeyState(163): #RCtrl
            info += "RCtrl "
        i = 0
        while i < len(self.buf):
            rawKeyboardData = self.buf[i]
            if rawKeyboardData.tick < time.clock() - 0.2:
                eg.eventThread.Call(eg.Print, "*** removed to old message")
                del self.buf[i]
                continue
            if (
                rawKeyboardData.vKey == vKey
                and rawKeyboardData.state == state
            ):
                del self.buf[i]
#                if rawKeyboardData.device != 65603:
#                    eg.eventThread.Call(eg.Print, "blocked")
#                    return 1
                eg.eventThread.Call(eg.Print, info)
                return 0
            i += 1
        eg.eventThread.Call(eg.Print, "not found")
Ejemplo n.º 2
0
    def OnCopyData(self, hwnd, mesg, wParam, lParam):
        copyData = cast(lParam, PCOPYDATASTRUCT)
        hEvent = cast(copyData.contents.lpData, POINTER(HEVENT))
        if not (
            copyData.contents.dwData == 0
            and copyData.contents.cbData == sizeof(HEVENT)
            and hEvent.contents.dwHookType == WH_KEYBOARD
        ):
            eg.eventThread.Call(eg.Print, "return")
            return
        mTime = time.clock()
        msg = MSG()
        while PeekMessage(byref(msg), 0, WM_INPUT, WM_INPUT, PM_REMOVE):
            self.OnRawInput(0, msg.message, msg.wParam, msg.lParam)
        vKey = hEvent.contents.wParam
        repeatCount = hEvent.contents.lParam & 0xFFFF
        keyState = (hEvent.contents.lParam >> 30) & 0x01
        extended = (hEvent.contents.lParam >> 24) & 0x01
        if (hEvent.contents.lParam >> 31) & 0x01:
            transition = "KEYUP"
            state = False
        else:
            transition = "KEYDOWN"
            state = True
        info = "%f Hook %s: %s(%d), keyState=%d, extended=%d" % (
            mTime,
            transition,
            VK_KEYS[vKey],
            hEvent.contents.wParam,
            keyState,
            extended,
        )
        if GetAsyncKeyState(162): #LCtrl
            info += "LCtrl "
        if GetAsyncKeyState(163): #RCtrl
            info += "RCtrl "
        i = 0
        while i < len(self.buf):
            rawKeyboardData = self.buf[i]
            if rawKeyboardData.tick < time.clock() - 0.2:
                eg.eventThread.Call(eg.Print, "*** removed to old message")
                del self.buf[i]
                continue
            if (
                rawKeyboardData.vKey == vKey
                and rawKeyboardData.state == state
            ):
                del self.buf[i]
#                if rawKeyboardData.device != 65603:
#                    eg.eventThread.Call(eg.Print, "blocked")
#                    return 1
                eg.eventThread.Call(eg.Print, info)
                return 0
            i += 1
        eg.eventThread.Call(eg.Print, "not found")
Ejemplo n.º 3
0
def CreatePowerClass(lParam, cls):
    powerBroadcast = cast(lParam, POINTER(cls))
    powerSetting = powerBroadcast.contents.PowerSetting
    data = powerBroadcast.contents.Data
    msgs = POWER_MESSAGES.get(powerSetting, None)
    if msgs is not None:
        return msgs.get(data, None)
Ejemplo n.º 4
0
def CreatePowerClass(lParam, cls):
    powerBroadcast = cast(lParam, POINTER(cls))
    powerSetting = powerBroadcast.contents.PowerSetting
    data = powerBroadcast.contents.Data
    msgs = POWER_MESSAGES.get(powerSetting, None)
    if msgs is not None:
        return msgs.get(data, None)
Ejemplo n.º 5
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
Ejemplo n.º 6
0
 def Stop(self):
     self.messageProcs.clear()
     eg.ThreadWorker.Stop(self, 5.0)
     if not UnregisterClass(
         cast(self.classAtom, LPCTSTR),
         GetModuleHandle(None)
     ):
         raise WinError()
Ejemplo n.º 7
0
 def Stop(self):
     self.messageProcs.clear()
     eg.ThreadWorker.Stop(self, 5.0)
     if not UnregisterClass(
         cast(self.classAtom, LPCTSTR),
         GetModuleHandle(None)
     ):
         raise WinError()
Ejemplo n.º 8
0
def GetClipboardText():
    if not SafeOpenClipboard():
        return
    text = u""

    try:
        hClipMem = GetClipboardData(CF_UNICODETEXT)
        if hClipMem:
            text = cast(GlobalLock(hClipMem), c_wchar_p).value
            GlobalUnlock(hClipMem)
        else:
            hClipMem = GetClipboardData(CF_TEXT)
            if hClipMem:
                text = cast(GlobalLock(hClipMem), c_char_p).value
                GlobalUnlock(hClipMem)
                text = text.decode(eg.systemEncoding)
    finally:
        CloseClipboard()

    # replace CR+LF with \n
    text = text.replace("\r\n", "\n")
    return text
Ejemplo n.º 9
0
def GetClipboardText():
    if not SafeOpenClipboard():
        return
    text = u""

    try:
        hClipMem = GetClipboardData(CF_UNICODETEXT)
        if hClipMem:
            text = cast(GlobalLock(hClipMem), c_wchar_p).value
            GlobalUnlock(hClipMem)
        else:
            hClipMem = GetClipboardData(CF_TEXT)
            if hClipMem:
                text = cast(GlobalLock(hClipMem), c_char_p).value
                GlobalUnlock(hClipMem)
                text = text.decode(eg.systemEncoding)
    finally:
        CloseClipboard()

    # replace CR+LF with \n
    text = text.replace("\r\n", "\n")
    return text
Ejemplo n.º 10
0
    def ScanDevices(self):
        nDevices = UINT(0)
        if -1 == GetRawInputDeviceList(None, byref(nDevices),
                                       sizeof(RAWINPUTDEVICELIST)):
            raise WinError()
        rawInputDeviceList = (RAWINPUTDEVICELIST * nDevices.value)()
        if -1 == GetRawInputDeviceList(
                cast(rawInputDeviceList, PRAWINPUTDEVICELIST), byref(nDevices),
                sizeof(RAWINPUTDEVICELIST)):
            raise WinError()

        cbSize = UINT()
        for i in range(nDevices.value):
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICENAME, None, byref(cbSize))
            deviceName = create_unicode_buffer(cbSize.value)
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICENAME, byref(deviceName),
                                  byref(cbSize))
            ridDeviceInfo = RID_DEVICE_INFO()
            cbSize.value = ridDeviceInfo.cbSize = sizeof(RID_DEVICE_INFO)
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICEINFO, byref(ridDeviceInfo),
                                  byref(cbSize))
            if ridDeviceInfo.dwType != RIM_TYPEKEYBOARD:
                continue
            print "hDevice:", rawInputDeviceList[i].hDevice
            print "Type:", RIM_TYPES[rawInputDeviceList[i].dwType]
            print "DeviceName:", deviceName.value
            if ridDeviceInfo.dwType == RIM_TYPEHID:
                hid = ridDeviceInfo.hid
                print "dwVendorId: %04X" % hid.dwVendorId
                print "dwProductId: %04X" % hid.dwProductId
                print "dwVersionNumber: %04X" % hid.dwVersionNumber
                print "usUsagePage:", hid.usUsagePage
                print "usUsage:", hid.usUsage
            if ridDeviceInfo.dwType == RIM_TYPEKEYBOARD:
                kbd = ridDeviceInfo.keyboard
                print "dwType:", kbd.dwType
                print "dwSubType:", kbd.dwSubType
                print "dwKeyboardMode:", kbd.dwKeyboardMode
                print "dwNumberOfFunctionKeys:", kbd.dwNumberOfFunctionKeys
                print "dwNumberOfIndicators:", kbd.dwNumberOfIndicators
                print "dwNumberOfKeysTotal:", kbd.dwNumberOfKeysTotal
            if ridDeviceInfo.dwType == RIM_TYPEMOUSE:
                mouse = ridDeviceInfo.mouse
                print "dwId:", mouse.dwId
                print "dwNumberOfButtons:", mouse.dwNumberOfButtons
                print "dwSampleRate:", mouse.dwSampleRate
                print "fHasHorizontalWheel:", mouse.fHasHorizontalWheel
            print
Ejemplo n.º 11
0
 def OnRawInput(self, hwnd, mesg, wParam, lParam):
     pcbSize = UINT()
     GetRawInputData(
         lParam, RID_INPUT, None, byref(pcbSize), sizeof(RAWINPUTHEADER)
     )
     buf = create_string_buffer(pcbSize.value)
     GetRawInputData(
         lParam, RID_INPUT, buf, byref(pcbSize), sizeof(RAWINPUTHEADER)
     )
     pRawInput = cast(buf, POINTER(RAWINPUT))
     keyboard = pRawInput.contents.data.keyboard
     if keyboard.VKey == 0xFF:
         eg.eventThread.Call(eg.Print, "0xFF")
         return 0
      #print "Scan code:", keyboard.MakeCode
     info = ""
     mTime = time.clock()
     if keyboard.Message == WM_KEYDOWN:
         transition = "KEYDOWN"
     elif keyboard.Message == WM_KEYUP:
         transition = "KEYUP"
     else:
         transition = " %d" % keyboard.Message
     info = "%f " % mTime
     info += "RawI %s: %s(%d), " % (
         transition,
         VK_KEYS[keyboard.VKey],
         keyboard.VKey
     )
     if GetAsyncKeyState(162): #LCtrl
         info += "LCtrl "
     if GetAsyncKeyState(163): #RCtrl
         info += "RCtrl "
     info += "Scan: %d, " % keyboard.MakeCode
     info += "Extra: %d, " % keyboard.ExtraInformation
     info += "Device: %r, " % pRawInput.contents.header.hDevice
     #print "Flags:", keyboard.Flags
     rawKeyboardData = RawKeyboardData(
         keyboard.VKey,
         pRawInput.contents.header.hDevice,
         keyboard.Message in (WM_KEYDOWN, WM_SYSKEYDOWN),
         time.clock()
     )
     self.buf.append(rawKeyboardData)
     eg.eventThread.Call(eg.Print, info)
     if GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT:
         return DefWindowProc(hwnd, mesg, wParam, lParam)
     return 0
Ejemplo n.º 12
0
 def OnRawInput(self, hwnd, mesg, wParam, lParam):
     pcbSize = UINT()
     GetRawInputData(
         lParam, RID_INPUT, None, byref(pcbSize), sizeof(RAWINPUTHEADER)
     )
     buf = create_string_buffer(pcbSize.value)
     GetRawInputData(
         lParam, RID_INPUT, buf, byref(pcbSize), sizeof(RAWINPUTHEADER)
     )
     pRawInput = cast(buf, POINTER(RAWINPUT))
     keyboard = pRawInput.contents.data.keyboard
     if keyboard.VKey == 0xFF:
         eg.eventThread.Call(eg.Print, "0xFF")
         return 0
      #print "Scan code:", keyboard.MakeCode
     info = ""
     mTime = time.clock()
     if keyboard.Message == WM_KEYDOWN:
         transition = "KEYDOWN"
     elif keyboard.Message == WM_KEYUP:
         transition = "KEYUP"
     else:
         transition = " %d" % keyboard.Message
     info = "%f " % mTime
     info += "RawI %s: %s(%d), " % (
         transition,
         VK_KEYS[keyboard.VKey],
         keyboard.VKey
     )
     if GetAsyncKeyState(162): #LCtrl
         info += "LCtrl "
     if GetAsyncKeyState(163): #RCtrl
         info += "RCtrl "
     info += "Scan: %d, " % keyboard.MakeCode
     info += "Extra: %d, " % keyboard.ExtraInformation
     info += "Device: %r, " % pRawInput.contents.header.hDevice
     #print "Flags:", keyboard.Flags
     rawKeyboardData = RawKeyboardData(
         keyboard.VKey,
         pRawInput.contents.header.hDevice,
         keyboard.Message in (WM_KEYDOWN, WM_SYSKEYDOWN),
         time.clock()
     )
     self.buf.append(rawKeyboardData)
     eg.eventThread.Call(eg.Print, info)
     if GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT:
         return DefWindowProc(hwnd, mesg, wParam, lParam)
     return 0
Ejemplo n.º 13
0
 def MsgHandler(self, dummyHwnd, dummyMsg, dummyWParam, lParam):
     dataArray = cast(lParam, PUBYTE)
     value = tuple(dataArray[i] for i in range(self.dataSize))
     self.callback(value)
     return 1
Ejemplo n.º 14
0
    def ScanDevices(self):
        nDevices = UINT(0)
        if -1 == GetRawInputDeviceList(
            None,
            byref(nDevices),
            sizeof(RAWINPUTDEVICELIST)
        ):
            raise WinError()
        rawInputDeviceList = (RAWINPUTDEVICELIST * nDevices.value)()
        if -1 == GetRawInputDeviceList(
            cast(rawInputDeviceList, PRAWINPUTDEVICELIST),
            byref(nDevices),
            sizeof(RAWINPUTDEVICELIST)
        ):
            raise WinError()

        cbSize = UINT()
        for i in range(nDevices.value):
            GetRawInputDeviceInfo(
                rawInputDeviceList[i].hDevice,
                RIDI_DEVICENAME,
                None,
                byref(cbSize)
            )
            deviceName = create_unicode_buffer(cbSize.value)
            GetRawInputDeviceInfo(
                rawInputDeviceList[i].hDevice,
                RIDI_DEVICENAME,
                byref(deviceName),
                byref(cbSize)
            )
            ridDeviceInfo = RID_DEVICE_INFO()
            cbSize.value = ridDeviceInfo.cbSize = sizeof(RID_DEVICE_INFO)
            GetRawInputDeviceInfo(
                rawInputDeviceList[i].hDevice,
                RIDI_DEVICEINFO,
                byref(ridDeviceInfo),
                byref(cbSize)
            )
            if ridDeviceInfo.dwType != RIM_TYPEKEYBOARD:
                continue
            print "hDevice:", rawInputDeviceList[i].hDevice
            print "Type:", RIM_TYPES[rawInputDeviceList[i].dwType]
            print "DeviceName:", deviceName.value
            if ridDeviceInfo.dwType == RIM_TYPEHID:
                hid = ridDeviceInfo.hid
                print "dwVendorId: %04X" % hid.dwVendorId
                print "dwProductId: %04X" % hid.dwProductId
                print "dwVersionNumber: %04X" % hid.dwVersionNumber
                print "usUsagePage:", hid.usUsagePage
                print "usUsage:", hid.usUsage
            if ridDeviceInfo.dwType == RIM_TYPEKEYBOARD:
                kbd = ridDeviceInfo.keyboard
                print "dwType:", kbd.dwType
                print "dwSubType:", kbd.dwSubType
                print "dwKeyboardMode:", kbd.dwKeyboardMode
                print "dwNumberOfFunctionKeys:", kbd.dwNumberOfFunctionKeys
                print "dwNumberOfIndicators:", kbd.dwNumberOfIndicators
                print "dwNumberOfKeysTotal:", kbd.dwNumberOfKeysTotal
            if ridDeviceInfo.dwType == RIM_TYPEMOUSE:
                mouse = ridDeviceInfo.mouse
                print "dwId:", mouse.dwId
                print "dwNumberOfButtons:", mouse.dwNumberOfButtons
                print "dwSampleRate:", mouse.dwSampleRate
                print "fHasHorizontalWheel:", mouse.fHasHorizontalWheel
            print
Ejemplo n.º 15
0
 def MsgHandler(self, dummyHwnd, dummyMsg, dummyWParam, lParam):
     dataArray = cast(lParam, PUBYTE)
     value = tuple(dataArray[i] for i in range(self.dataSize))
     self.callback(value)
     return 1
Ejemplo n.º 16
0
    def OnSelectionChanged(self, event):
        dwControlID = self.GetPyData(event.GetItem())
        panel = self.panel
        panel.DestroyChildren()
        sizer = wx.BoxSizer(wx.VERTICAL)

        idCtrl = wx.StaticText(panel, -1, "ID: " + str(dwControlID))
        sizer.Add(idCtrl)
        if dwControlID is None:
            panel.SetSizerAndFit(sizer)
            return

        mixerControl = MIXERCONTROL()
        mixerLineControls = MIXERLINECONTROLS()
        mixerLineControls.cbStruct = sizeof(MIXERLINECONTROLS)
        mixerLineControls.cControls = 1
        mixerLineControls.dwControlID = dwControlID
        mixerLineControls.pamxctrl = pointer(mixerControl)
        mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL)
        err = mixerGetLineControls(
            self.mixerHandle,
            byref(mixerLineControls),
            MIXER_GETLINECONTROLSF_ONEBYID
        )
        if err:
            print "error", err
            return

        idCtrl = wx.StaticText(panel, -1, "Name: " + mixerControl.szName)
        sizer.Add(idCtrl)

        idCtrl = wx.StaticText(panel, -1, "Short Name: " + mixerControl.szShortName)
        sizer.Add(idCtrl)

        dwControlType = mixerControl.dwControlType

        controlClass = MIXER_CONTROL_CLASSES[dwControlType & MIXERCONTROL_CT_CLASS_MASK]
        idCtrl = wx.StaticText(panel, -1, "Classification: " + controlClass["name"])
        sizer.Add(idCtrl)

        controlClassTypeName = controlClass["types"][dwControlType]
        idCtrl = wx.StaticText(panel, -1, "Type: " + controlClassTypeName)
        sizer.Add(idCtrl)

        fdwControl =  mixerControl.fdwControl
        cMultipleItems = 0
        numMultipleItems = 1
        flagNames = []
        if fdwControl & MIXERCONTROL_CONTROLF_DISABLED:
            flagNames.append("Disabled")
        if fdwControl & MIXERCONTROL_CONTROLF_MULTIPLE:
            flagNames.append("Multiple(%i)" % mixerControl.cMultipleItems)
            numMultipleItems = mixerControl.cMultipleItems
            cMultipleItems = mixerControl.cMultipleItems
        if fdwControl & MIXERCONTROL_CONTROLF_UNIFORM:
            flagNames.append("Uniform")
        idCtrl = wx.StaticText(panel, -1, "Flags: " + ", ".join(flagNames))
        sizer.Add(idCtrl)

        valueType = CONTROLTYPES[dwControlType][1]
        valueTypeName = MIXERCONTROLDETAILS_NAMES[valueType]
        idCtrl = wx.StaticText(panel, -1, "Value Type: " + valueTypeName)
        sizer.Add(idCtrl)

        if dwControlType == MIXERCONTROL_CONTROLTYPE_CUSTOM:
            cChannels = 0
        elif fdwControl & MIXERCONTROL_CONTROLF_UNIFORM:
            cChannels = 1
        else:
            # TODO: Get the number of channels
            cChannels = 2
        details = (valueType * (cChannels * numMultipleItems))()
        mixerControlDetails = MIXERCONTROLDETAILS()
        mixerControlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS)
        mixerControlDetails.dwControlID = dwControlID
        mixerControlDetails.cChannels = cChannels
        mixerControlDetails.cMultipleItems = cMultipleItems
        mixerControlDetails.cbDetails = sizeof(details)
        mixerControlDetails.paDetails = cast(pointer(details), c_void_p)
        pmxcd = valueType()
        mixerGetControlDetails(
            self.mixerHandle,
            byref(mixerControlDetails),
            MIXER_GETCONTROLDETAILSF_VALUE
        )
        values = []
        for i in range(cChannels * numMultipleItems):
            if valueType == MIXERCONTROLDETAILS_BOOLEAN:
                values.append(details[i].fValue)
            elif valueType == MIXERCONTROLDETAILS_SIGNED:
                values.append(details[i].lValue)
            elif valueType == MIXERCONTROLDETAILS_UNSIGNED:
                values.append(details[i].dwValue)

        idCtrl = wx.StaticText(panel, -1, "Value: %r" % values)
        sizer.Add(idCtrl)

        if dwControlType & MIXERCONTROL_CT_CLASS_MASK == MIXERCONTROL_CT_CLASS_LIST:
            labels = (MIXERCONTROLDETAILS_LISTTEXT * (cChannels * numMultipleItems))()
            mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_LISTTEXT)
            mixerControlDetails.paDetails = cast(pointer(labels), c_void_p)
            mixerGetControlDetails(
                self.mixerHandle,
                byref(mixerControlDetails),
                MIXER_GETCONTROLDETAILSF_LISTTEXT
            )
            for i in range(cChannels * numMultipleItems):
                print labels[i].szName
        panel.SetSizerAndFit(sizer)
Ejemplo n.º 17
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