def with_clipboard_lock(self, success_callback, failure_callback, retries=RETRY, delay=DELAY): log("with_clipboard_lock%s", (success_callback, failure_callback, retries, delay)) r = OpenClipboard(self.window) if r: log("OpenClipboard(%#x)=%s", self.window, r) try: r = success_callback() log("%s()=%s", success_callback, r) if r: return finally: r = CloseClipboard() log("CloseClipboard()=%s", r) e = WinError(GetLastError()) owner = GetClipboardOwner() log("OpenClipboard(%#x)=%s, current owner: %s", self.window, e, get_owner_info(owner, self.window)) if retries <= 0: failure_callback( "OpenClipboard: too many failed attempts, giving up") return #try again later: GLib.timeout_add(delay, self.with_clipboard_lock, success_callback, failure_callback, retries - 1, delay + 5)
def wnd_proc(self, hwnd, msg, wparam, lparam): r = DefWindowProcW(hwnd, msg, wparam, lparam) if msg in CLIPBOARD_EVENTS: owner = GetClipboardOwner() log("clipboard event: %s, current owner: %s", CLIPBOARD_EVENTS.get(msg), get_owner_info(owner, self.window)) if msg == WM_CLIPBOARDUPDATE and owner != self.window: owner = GetClipboardOwner() owner_info = get_owner_info(owner, self.window) if is_blacklisted(owner_info): #ie: don't try to sync from VirtualBox log("CLIPBOARDUPDATE coming from '%s' ignored", owner_info) return r for proxy in self._clipboard_proxies.values(): if not proxy._block_owner_change: proxy.schedule_emit_token() return r
def with_clipboard_lock(self, success_callback, failure_callback, retries=5, delay=5): r = OpenClipboard(self.window) if r: log("OpenClipboard(%#x)=%s", self.window, r) try: success_callback() return finally: CloseClipboard() log("OpenClipboard(%#x)=%s, owner=%#x", self.window, WinError(GetLastError()), GetClipboardOwner()) if retries <= 0: failure_callback( "OpenClipboard: too many failed attemps, giving up") return #try again later: glib.timeout_add(delay, self.with_clipboard_lock, success_callback, failure_callback, retries - 1, delay + 5)