def __init__(self, dest_widget, src_hdl=0x00010010): """Crée un stream.""" if sys.platform == 'win32': self._destWidget = dest_widget self._src_hdl = src_hdl self.src_window_dc = win32gui.GetDC(self._src_hdl) # Récupère l'handle et le DC du dest_widget self._dest_hdl = dest_widget.winfo_id() self.dest_window_dc = win32gui.GetDC(self._dest_hdl) # Crée un DC compatible pour la sauvegarde self.mem_dc = win32gui.CreateCompatibleDC(self.dest_window_dc) if self.mem_dc is None: log.add("Échec de la création du compatibleDC.") return self.dest_rect_dc = win32gui.GetClientRect(self._dest_hdl) self.src_rect_dc = win32gui.GetClientRect(self._src_hdl) win32gui.SetStretchBltMode(self.dest_window_dc, win.HALFTONE) self._hasToRun = False self.timer = InfiniteTimer(1 / 24, self.run) elif sys.platform == 'linux': """TODO : Lalie ?""" pass
def _ScaleBlit(bmp, dc, dst_rect): sX = float(dst_rect.width) / float(bmp.GetWidth()) sY = float(dst_rect.height) / float(bmp.GetHeight()) dc.SetUserScale(sX, sY) old_mode = None if os.name == 'nt': h_dst = dc.GetHDC() try: old_mode = win32gui.SetStretchBltMode(h_dst, win32con.HALFTONE) except: pass if sX == 0: x = 0 else: x = dst_rect.x / sX if sY == 0: y = 0 else: y = dst_rect.y / sY if sys.platform == "darwin": # magic! y = round(y) x += 0.2 dc.SetDeviceOrigin(x, y) dc.DrawBitmap(bmp, 0, 0, True) dc.SetDeviceOrigin(0, 0) else: dc.DrawBitmap(bmp, x, y, True) if os.name == 'nt': try: win32gui.SetStretchBltMode(h_dst, old_mode) except: pass dc.SetUserScale(1, 1)
def OnPaint(self, hWnd, msg, wparam, lparam): dc, ps = win32gui.BeginPaint(hWnd) wndrect = win32gui.GetClientRect(hWnd) wndwidth = wndrect[2] - wndrect[0] wndheight = wndrect[3] - wndrect[1] if os.path.isfile(FILENAME): hBitmap = win32gui.LoadImage(0, FILENAME, win32con.IMAGE_BITMAP, 0, 0, win32con.LR_LOADFROMFILE) hdcBitmap = win32gui.CreateCompatibleDC(dc) hOldBitmap = win32gui.SelectObject(hdcBitmap, hBitmap) bminfo = win32gui.GetObject(hBitmap) win32gui.SetStretchBltMode(dc, win32con.COLORONCOLOR) win32gui.StretchBlt(dc, 0, 0, wndwidth, wndheight, hdcBitmap, 0, 0, bminfo.bmWidth, bminfo.bmHeight, win32con.SRCCOPY) win32gui.SelectObject(hdcBitmap, hOldBitmap) win32gui.EndPaint(hWnd, ps) return 0
def find_window(source_handle=0x00010100, dest_widget=self.tv): """Trouve la fenêtre spécifiée à l'aide de source_handle puis la copie sur le DC de dest_widget.""" if isinstance(source_handle, str): if source_handle != "" and source_handle != entry_hint: source_handle = int(str(source_handle), 16) else: source_handle = None source_window_dc = win32gui.GetDC(source_handle) target_handle = dest_widget.winfo_id() target_window_dc = win32gui.GetDC(target_handle) mem_dc = win32gui.CreateCompatibleDC(target_window_dc) if mem_dc is None: log.add("Échec de la création du compatibleDC.") return dest_rect_dc = win32gui.GetClientRect(target_handle) print(dest_rect_dc) win32gui.SetStretchBltMode(target_window_dc, HALFTONE) # Copie le DC de la source vers le DC de destination en le redimensionnant win32gui.StretchBlt(target_window_dc, 0, 0, dest_rect_dc[const.win32_RIGHT], dest_rect_dc[const.win32_BOTTOM], source_window_dc, 0, 0, win32api.GetSystemMetrics(SM_CXSCREEN), win32api.GetSystemMetrics(SM_CYSCREEN), SRCCOPY) source_bitmap = win32gui.CreateCompatibleBitmap( target_window_dc, dest_rect_dc[const.win32_RIGHT] - dest_rect_dc[const.win32_LEFT], dest_rect_dc[const.win32_BOTTOM] - dest_rect_dc[const.win32_TOP]) if source_bitmap is None: log.add("Échec création bitmap.") return win32gui.SelectObject(mem_dc, source_bitmap)
def update(self, src_hdl, fps): """Met à jour les paramètres du stream.""" if sys.platform == 'win32': if isinstance(src_hdl, str): if not src_hdl == "" and not src_hdl == entry_hint: self._src_hdl = int(src_hdl, 16) else: self._src_hdl = 0x00010010 elif isinstance(src_hdl, int): pass else: log.add( "Entrée incorrecte, l'entrée utilisateur devrait être un int, mais est de type : " + str(type(src_hdl))) self.src_window_dc = win32gui.GetDC(self._src_hdl) self.dest_window_dc = win32gui.GetDC(self._dest_hdl) # Crée un DC compatible pour la sauvegarde self.mem_dc = win32gui.CreateCompatibleDC(self.dest_window_dc) if self.mem_dc is None: log.add("Échec de la création du compatibleDC.") return self.dest_rect_dc = win32gui.GetClientRect(self._dest_hdl) self.src_rect_dc = win32gui.GetClientRect(self._src_hdl) win32gui.SetStretchBltMode(self.dest_window_dc, win.HALFTONE) self.timer.cancel() self.timer = InfiniteTimer(1 / float(fps), self.run) if self._hasToRun: self.timer.start() log.add("Paramètres stream rafraîchis.") elif sys.platform == 'linux': """TODO : . . . ...""" pass