示例#1
0
 def Attach(self, Timeout=30000, Wait=True):
     if self.AttachmentStatus == apiAttachSuccess:
         return
     if not self.isAlive():
         try:
             self.start()
         except AssertionError:
             raise ISkypeAPIError('Skype API closed')
     try:
         self.wait = True
         t = threading.Timer(Timeout / 1000.0, self.__Attach_ftimeout)
         if Wait:
             t.start()
         while self.wait:
             self.win_skype = self.get_skype()
             if self.win_skype != None:
                 break
             else:
                 time.sleep(1.0)
         else:
             raise ISkypeAPIError('Skype attach timeout')
     finally:
         t.cancel()
     c = ICommand(-1, 'NAME %s' % self.FriendlyName, '', True, Timeout)
     self.SendCommand(c, True)
     if c.Reply != 'OK':
         self.win_skype = None
         self.SetAttachmentStatus(apiAttachRefused)
         return
     self.SendCommand(ICommand(-1, 'PROTOCOL %s' % self.Protocol), True)
     self.SetAttachmentStatus(apiAttachSuccess)
示例#2
0
文件: darwin.py 项目: zwets/htcondor
 def Attach(self, Timeout=30000, Wait=True):
     if self.AttachmentStatus in (apiAttachPendingAuthorization,
                                  apiAttachSuccess):
         return
     try:
         self.start()
     except AssertionError:
         pass
     t = threading.Timer(Timeout / 1000.0, self.__Attach_ftimeout)
     try:
         self.init_observer()
         self.client_id = -1
         self.SetAttachmentStatus(apiAttachPendingAuthorization)
         self.post('SKSkypeAPIAttachRequest')
         self.wait = True
         if Wait:
             t.start()
         while self.wait and self.AttachmentStatus == apiAttachPendingAuthorization:
             time.sleep(1.0)
     finally:
         t.cancel()
     if not self.wait:
         self.SetAttachmentStatus(apiAttachUnknown)
         raise ISkypeAPIError('Skype attach timeout')
     self.SendCommand(ICommand(-1, 'PROTOCOL %s' % self.Protocol))
示例#3
0
 def Attach(self, Timeout=30000, Wait=True):
     try:
         if not self.isAlive():
             self.StartWatcher()
             self.start()
     except AssertionError:
         pass
     try:
         self.wait = True
         t = threading.Timer(Timeout / 1000.0, self.__Attach_ftimeout)
         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 = _SkypeNotifyCallback(
                         self.bus, self.notify)
             except dbus.DBusException:
                 if not Wait:
                     break
                 time.sleep(1.0)
             else:
                 break
         else:
             raise ISkypeAPIError('Skype attach timeout')
     finally:
         t.cancel()
     c = ICommand(-1, 'NAME %s' % self.FriendlyName, '', True, Timeout)
     if self.skype_out:
         self.SendCommand(c)
     if c.Reply != 'OK':
         self.skype_out = None
         self.SetAttachmentStatus(apiAttachRefused)
         return
     self.SendCommand(ICommand(-1, 'PROTOCOL %s' % self.Protocol))
     self.SetAttachmentStatus(apiAttachSuccess)
示例#4
0
 def Attach(self, Timeout=30000, Wait=True):
     if self.Skype:
         return
     if not self.isAlive():
         raise ISkypeAPIError('Skype API closed')
     self.DebugPrint('->', 'SkypeControlAPIDiscover')
     fhwnd = self.GetForegroundWindow()
     try:
         if fhwnd:
             windll.user32.SetForegroundWindow(self.hwnd)
         if not windll.user32.SendMessageTimeoutA(
                 _HWND_BROADCAST, self._SkypeControlAPIDiscover, self.hwnd,
                 None, 2, 5000, None):
             raise ISkypeAPIError(
                 'Could not broadcast Skype discover message')
         # wait (with timeout) till the WindProc() attaches
         self.Wait = True
         t = threading.Timer(Timeout / 1000, self.__Attach_ftimeout)
         if Wait:
             t.start()
         while self.Wait and self.AttachmentStatus not in (
                 apiAttachSuccess, apiAttachRefused):
             if self.AttachmentStatus == apiAttachPendingAuthorization:
                 # disable the timeout
                 t.cancel()
             elif self.AttachmentStatus == apiAttachAvailable:
                 # rebroadcast
                 self.DebugPrint('->', 'SkypeControlAPIDiscover')
                 windll.user32.SetForegroundWindow(self.hwnd)
                 if not windll.user32.SendMessageTimeoutA(
                         _HWND_BROADCAST, self._SkypeControlAPIDiscover,
                         self.hwnd, None, 2, 5000, None):
                     raise ISkypeAPIError(
                         'Could not broadcast Skype discover message')
             time.sleep(0.01)
         t.cancel()
     finally:
         if fhwnd:
             windll.user32.SetForegroundWindow(fhwnd)
     # check if we got the Skype window's hwnd
     if self.Skype:
         self.SendCommand(ICommand(-1, 'PROTOCOL %s' % self.Protocol))
     elif not self.Wait:
         raise ISkypeAPIError('Skype attach timeout')
示例#5
0
 def SetFriendlyName(self, FriendlyName):
     self.FriendlyName = FriendlyName
     if self.skype_out:
         self.SendCommand(ICommand(-1, 'NAME %s' % FriendlyName))