def attach(self, timeout, wait=True): self.acquire() try: try: if not self.isAlive(): self.start_watcher() self.start() except AssertionError: pass try: self.wait = True t = threading.Timer(timeout2float(timeout), lambda: setattr(self, 'wait', False)) if wait: t.start() while self.wait: if not wait: self.wait = False try: if not self.skype_out: self.skype_out = self.bus.get_object( 'com.Skype.API', '/com/Skype') if not self.skype_in: self.skype_in = SkypeNotify(self.bus, self.notify) except dbus.DBusException: if not wait: break time.sleep(1.0) else: break else: raise SkypeAPIError('Skype attach timeout') finally: t.cancel() command = Command('NAME %s' % self.friendly_name, '', True, timeout) if self.skype_out: self.release() try: self.send_command(command) finally: self.acquire() if command.Reply != 'OK': self.skype_out = None self.set_attachment_status(apiAttachRefused) return self.set_attachment_status(apiAttachSuccess) finally: self.release() command = Command('PROTOCOL %s' % self.protocol, Blocking=True) self.send_command(command) self.protocol = int(command.Reply.rsplit(None, 1)[-1])
def attach(self, timeout, wait=True): if self.attachment_status in (apiAttachPendingAuthorization, apiAttachSuccess): return self.acquire() try: try: self.start() except AssertionError: pass t = threading.Timer(timeout2float(timeout), lambda: setattr(self, 'wait', False)) try: self.init_observer() self.client_id = -1 self.set_attachment_status(apiAttachPendingAuthorization) self.post('SKSkypeAPIAttachRequest') self.wait = True if wait: t.start() while self.wait and self.attachment_status == apiAttachPendingAuthorization: if self.run_main_loop: time.sleep(1.0) else: EventLoop.run(1.0) finally: t.cancel() if not self.wait: self.set_attachment_status(apiAttachUnknown) raise SkypeAPIError('Skype attach timeout') finally: self.release() command = Command('PROTOCOL %s' % self.protocol, Blocking=True) self.send_command(command) self.protocol = int(command.Reply.rsplit(None, 1)[-1])
def attach(self, timeout, wait=True): if self.skype is not None and windll.user32.IsWindow(self.skype): return self.acquire() self.skype = None try: if not self.isAlive(): try: self.start() except AssertionError: raise SkypeAPIError('Skype API closed') # wait till the thread initializes while not self.hwnd: time.sleep(0.01) self.logger.debug('broadcasting SkypeControlAPIDiscover') fhwnd = self.get_foreground_window() try: if fhwnd: windll.user32.SetForegroundWindow(self.hwnd) if not windll.user32.SendMessageTimeoutA( HWND_BROADCAST, self.SkypeControlAPIDiscover, self.hwnd, None, 2, 5000, None): raise SkypeAPIError( 'Could not broadcast Skype discover message') # wait (with timeout) till the WindProc() attaches self.wait = True t = threading.Timer(timeout2float(timeout), lambda: setattr(self, 'wait', False)) if wait: t.start() while self.wait and self.attachment_status not in ( apiAttachSuccess, apiAttachRefused): if self.attachment_status == apiAttachPendingAuthorization: # disable the timeout t.cancel() elif self.attachment_status == apiAttachAvailable: # rebroadcast self.logger.debug( 'broadcasting SkypeControlAPIDiscover') windll.user32.SetForegroundWindow(self.hwnd) if not windll.user32.SendMessageTimeoutA( HWND_BROADCAST, self.SkypeControlAPIDiscover, self.hwnd, None, 2, 5000, None): raise SkypeAPIError( 'Could not broadcast Skype discover message') time.sleep(0.01) t.cancel() finally: if fhwnd: windll.user32.SetForegroundWindow(fhwnd) finally: self.release() # check if we got the Skype window's hwnd if self.skype is not None: command = Command('PROTOCOL %s' % self.protocol, Blocking=True) self.send_command(command) self.protocol = int(command.Reply.rsplit(None, 1)[-1]) elif not self.wait: raise SkypeAPIError('Skype attach timeout')
def attach(self, timeout, wait=True): if self.attachment_status == apiAttachSuccess: return self.acquire() try: if not self.isAlive(): try: self.start() except AssertionError: raise SkypeAPIError('Skype API closed') try: self.wait = True t = threading.Timer(timeout2float(timeout), lambda: setattr(self, 'wait', False)) if wait: t.start() while self.wait: self.win_skype = self.get_skype() if self.win_skype is not None: break else: time.sleep(1.0) else: raise SkypeAPIError('Skype attach timeout') finally: t.cancel() command = Command('NAME %s' % self.friendly_name, '', True, timeout) self.release() try: self.send_command(command, True) finally: self.acquire() if command.Reply != 'OK': self.win_skype = None self.set_attachment_status(apiAttachRefused) return self.set_attachment_status(apiAttachSuccess) finally: self.release() command = Command('PROTOCOL %s' % self.protocol, Blocking=True) self.send_command(command, True) self.protocol = int(command.Reply.rsplit(None, 1)[-1])
def set_friendly_name(self, friendly_name): SkypeAPIBase.set_friendly_name(self, friendly_name) if self.skype_out: self.send_command(Command('NAME %s' % friendly_name))