Exemplo n.º 1
0
def __get_hwnd_dpi(window_handle):
    '''Tkinterを高DPIのディスプレイに対応させるため、DPIとスケーリングを再計算する関数。'''

    if os.name == 'nt':
        from ctypes import windll, pointer, wintypes
        try:
            windll.shcore.SetProcessDpiAwareness(1)
        except Exception:
            # Windows serverやバージョンの低いWindowsでは失敗する
            pass

        # 拡大率を100%に設定
        DPI100pc = 96
        # MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2
        DPI_type = 0

        winH = wintypes.HWND(window_handle)
        monitorhandle = windll.user32.MonitorFromWindow(winH, wintypes.DWORD(2))

        X = wintypes.UINT()
        Y = wintypes.UINT()

        try:
            windll.shcore.GetDpiForMonitor(monitorhandle, DPI_type, pointer(X), pointer(Y))
            return X.value, Y.value, (X.value + Y.value) / (2 * DPI100pc)
        except Exception:
            # Windows標準のDPIとスケーリング
            return 96, 96, 1
    else:
        return None, None, 1
Exemplo n.º 2
0
 def disable(self):
     BaseModule.disable(self)
     mainWindow = Application.mainWindow
     hwnd = wintypes.HWND(mainWindow.winId().__int__())
     for i in range(3):
         user32.UnregisterHotKey(hwnd, i)
     del mainWindow.nativeEventHandlers[self.nativeEventIdx]
Exemplo n.º 3
0
def get_hwnd_dpi(window_handle):
    """
    To detect high DPI displays and avoid need to set Windows compatibility flags

    :param window_handle:
    :return:
    """

    import os
    if os.name == "nt":
        from ctypes import windll, pointer, wintypes
        windll.shcore.SetProcessDpiAwareness(1)
        dpi100pc = 96  # DPI 96 is 100% scaling
        dpi_type = 0  # MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2
        win_h = wintypes.HWND(window_handle)
        monitorhandle = windll.user32.MonitorFromWindow(
            win_h, wintypes.DWORD(2))  # MONITOR_DEFAULTTONEAREST = 2
        x = wintypes.UINT()
        y = wintypes.UINT()
        # noinspection PyBroadException
        try:
            windll.shcore.GetDpiForMonitor(monitorhandle, dpi_type, pointer(x),
                                           pointer(y))
            return x.value, y.value, (x.value + y.value) / (2 * dpi100pc)
        except Exception:
            return 96, 96, 1  # Assume standard Windows DPI & scaling
    else:
        return None, None, 1  # What to do for other OSs?
Exemplo n.º 4
0
def Get_HWND_DPI(window_handle):
    # To detect high DPI displays and avoid need to set Windows compatibility flags
    import os

    if os.name == "nt":
        from ctypes import windll, pointer, wintypes

        try:
            windll.shcore.SetProcessDpiAwareness(1)
        except Exception:
            pass  # this will fail on Windows Server and maybe early Windows
        DPI100pc = 96  # DPI 96 is 100% scaling
        DPI_type = 0  # MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2
        winH = wintypes.HWND(window_handle)
        monitorhandle = windll.user32.MonitorFromWindow(
            winH, wintypes.DWORD(2)
        )  # MONITOR_DEFAULTTONEAREST = 2
        X = wintypes.UINT()
        Y = wintypes.UINT()
        try:
            windll.shcore.GetDpiForMonitor(
                monitorhandle, DPI_type, pointer(X), pointer(Y)
            )
            return X.value, Y.value, (X.value + Y.value) / (2 * DPI100pc)
        except Exception:
            return 96, 96, 1  # Assume standard Windows DPI & scaling
    else:
        return None, None, 1  # What to do for other OSs?
Exemplo n.º 5
0
 def enable(self):
     BaseModule.enable(self)
     mainWindow = Application.mainWindow
     hwnd = wintypes.HWND(mainWindow.winId().__int__())
     user32.RegisterHotKey(hwnd, 0, 0, VK_MEDIA_NEXT_TRACK)
     user32.RegisterHotKey(hwnd, 1, 0, VK_MEDIA_PREV_TRACK)
     user32.RegisterHotKey(hwnd, 2, 0, VK_MEDIA_PLAY_PAUSE)
     self.nativeEventIdx = len(Application.mainWindow.nativeEventHandlers)
     Application.mainWindow.nativeEventHandlers.append(
         self.nativeEventHandler)
Exemplo n.º 6
0
 def get_window_rect(self, idx):
     """ 핸들에 대응하는 윈도우의 좌표정보를 반환한다
     param:
         <int> hwnd: 윈도우 핸들
     return:
         <tuple> x1, y1, x2, y2
     """
     f = windll.dwmapi.DwmGetWindowAttribute
     rect = wintypes.RECT()
     DWMWA_EXTENDED_FRAME_BOUNDS = 9
     f(wintypes.HWND(self.bslist[idx][0]),
       wintypes.DWORD(DWMWA_EXTENDED_FRAME_BOUNDS), byref(rect),
       sizeof(rect))
     return rect.left, rect.top, rect.right, rect.bottom
Exemplo n.º 7
0
    def realDataCallBack(self, lRealHandle, dwDataType, pBuffer, dwBufSize, dwUser):
    
        if dwDataType == td.NET_DVR_SYSHEAD or dwDataType == td.NET_DVR_STREAMDATA:
            if dwBufSize > 0:
                    buff = bytearray(ctypes.string_at(pBuffer, dwBufSize))
                    
        try:
            if dwDataType == td.NET_DVR_SYSHEAD:
                
                hWnd = wintypes.HWND()
                if not self.playCtrl.PlayM4_GetPort(self.lPort):
                    print("1: Error:%r" % self.playCtrl.PlayM4_GetLastError(self.lPort[0]))
                    return 0
                print("lPort:%r" % self.lPort[0])
                
                if dwBufSize > 0:
                    res = self.playCtrl.PlayM4_SetStreamOpenMode(self.lPort[0], td.STREAME_REALTIME)
                    if not res:
                        print("2: Error:%r" % self.playCtrl.PlayM4_GetLastError(self.lPort[0]))
                        return 0
                    
                    b_res = self.playCtrl.PlayM4_OpenStreamEx(self.lPort[0], pBuffer, dwBufSize, 1024 * 100000)
                    if not b_res:
                        print("3: Error:%r" % self.playCtrl.PlayM4_GetLastError(self.lPort[0]))
                        return 0

                    b_res = self.playCtrl.PlayM4_SetDecCBStream(self.lPort[0], 1)  # 1 is Video Stream
                    if not b_res:
                        print("4: Error:%r" % self.playCtrl.PlayM4_GetLastError(self.lPort[0]))
                    
                    if not self.playCtrl.PlayM4_SetDecodeFrameType(self.lPort[0], td.DECODE_KEY_FRAME):  #td.DECODE_NORMAL
                        print("5: Error:%r" % self.playCtrl.PlayM4_GetLastError(self.lPort[0]))

                    if not self.playCtrl.PlayM4_SetDecCallBack(self.lPort[0], self.fSetDecCallBack):
                        print("7: Error:%r" % self.playCtrl.PlayM4_GetLastError(self.lPort[0]))
                    
                    if not self.playCtrl.PlayM4_Play(self.lPort[0], hWnd):
                        print("8: Error:%r" % self.playCtrl.PlayM4_GetLastError(self.lPort[0]))
                        return 0
                    
            elif dwDataType == td.NET_DVR_STREAMDATA:
                if dwBufSize > 0 & self.lPort[0] != -1:                    
                    # Put encoded video streaming package into decoder
                    b_res = self.playCtrl.PlayM4_InputData(self.lPort[0], pBuffer, dwBufSize)
                    if not b_res:
                        #print ('Error in PlayM4_InputData')
                        return 0
            return 1
        except Exception as e:
            print('Exception in real callback', e.message)
    def get_window_dpi_scaling(cls, window) -> float:
        if not cls.deactivate_automatic_dpi_awareness:
            if sys.platform == "darwin":
                return 1  # scaling works automatically on macOS

            elif sys.platform.startswith("win"):
                from ctypes import windll, pointer, wintypes

                DPI100pc = 96  # DPI 96 is 100% scaling
                DPI_type = 0  # MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2
                window_hwnd = wintypes.HWND(window.winfo_id())
                monitor_handle = windll.user32.MonitorFromWindow(window_hwnd, wintypes.DWORD(2))  # MONITOR_DEFAULTTONEAREST = 2
                x_dpi, y_dpi = wintypes.UINT(), wintypes.UINT()
                windll.shcore.GetDpiForMonitor(monitor_handle, DPI_type, pointer(x_dpi), pointer(y_dpi))
                return (x_dpi.value + y_dpi.value) / (2 * DPI100pc)

            else:
                return 1  # DPI awareness on Linux not implemented
        else:
            return 1
Exemplo n.º 9
0
def SetAppBar(appbarWindow, edge):

    info = _GetRegisterInfo(appbarWindow)
    info.edge = edge
    abd = APPBARDATA()
    abd.cbSize = wintypes.DWORD(sizeof(abd))
    abd.hWnd = wintypes.HWND(appbarWindow.GetHandle())

    if (edge == ABEdge.Float) and info.isRegistered:
        shell32.SHAppBarMessage(ABMsg.ABM_REMOVE, PAPPBARDATA(abd))
        info.isRegistered = False
        _RestoreWindow(appbarWindow)
        return

    elif not info.isRegistered:
        info.isRegistered = True
        info.callbackId = win32api.RegisterWindowMessage("AppBarMessage")
        shell32.SHAppBarMessage(ABMsg.ABM_NEW, PAPPBARDATA(abd))

    appbarWindow.SetWindowStyle(wx.FRAME_NO_TASKBAR | wx.CLIP_CHILDREN
                                | wx.STAY_ON_TOP)
    _ABSetPos(info.edge, appbarWindow)
Exemplo n.º 10
0
        v = v.reshape((h//2),(w//2))
        v = cv2.resize(v, None, fx=2, fy=2, 
                interpolation=cv2.INTER_NEAREST)
        
        yuv = cv2.merge((y,u,v))
        bgr = cv2.cvtColor(yuv, cv2.COLOR_YCrCb2BGR)
        
        cv2.imshow('', bgr)
        cv2.waitKey(20)

            
if __name__ == '__main__':
      
    player = windll.LoadLibrary('PlayCtrl.dll')
    
    hWnd = wintypes.HWND()
    lPort = pointer(c_long())
    if not player.PlayM4_GetPort(lPort):
        print("1: Error:%r" % player.PlayM4_GetLastError(lPort[0]))
        quit()
    
    res = player.PlayM4_SetStreamOpenMode(lPort[0], td.STREAME_REALTIME)
    if not res:
        print("2: Error:%r"%player.PlayM4_GetLastError(lPort[0]))
        quit()

    fid=open('video.mp4','rb')
    str1 = fid.read(40)
    b_str1 = bytes(str1)
    xxx = ctypes.c_char_p(b_str1)
    res = player.PlayM4_OpenStream(lPort[0], xxx, len(b_str1), 1024*1024)