def mouseDragged_(self, event): self.is_dragging = True if hasattr(self.window().delegate(), "dragMyVideoViewWithinWindow"): # drag the view within its window self.currentLocation = event.locationInWindow() self.performDrag() else: # drag the whole window screenVisibleFrame = NSScreen.mainScreen().visibleFrame() windowFrame = self.window().frame() newOrigin = windowFrame.origin currentLocation = event.locationInWindow() newOrigin.x += (currentLocation.x - self.initialLocation.x) newOrigin.y += (currentLocation.y - self.initialLocation.y) if ((newOrigin.y + windowFrame.size.height) > (screenVisibleFrame.origin.y + screenVisibleFrame.size.height)): newOrigin.y = screenVisibleFrame.origin.y + ( screenVisibleFrame.size.height - windowFrame.size.height) self.window().setFrameOrigin_(newOrigin)
def performDrag(self): if not self.currentLocation: return newOrigin = self.frame().origin offset_x = self.initialLocation.x - self.initialOrigin.x offset_y = self.initialLocation.y - self.initialOrigin.y newOrigin.x = self.currentLocation.x - offset_x newOrigin.y = self.currentLocation.y - offset_y if newOrigin.x < 10: newOrigin.x = 10 if newOrigin.y < 10: newOrigin.y = 10 if self.window().delegate().full_screen: parentFrame = NSScreen.mainScreen().visibleFrame() else: parentFrame = self.window().frame() if newOrigin.x > parentFrame.size.width - 10 - self.frame().size.width: newOrigin.x = parentFrame.size.width - 10 - self.frame().size.width if newOrigin.y > parentFrame.size.height - 30 - self.frame( ).size.height: newOrigin.y = parentFrame.size.height - 30 - self.frame( ).size.height if ((newOrigin.y + self.frame().size.height) > (parentFrame.origin.y + parentFrame.size.height)): newOrigin.y = parentFrame.origin.y + (parentFrame.size.height - self.frame().size.height) if abs(newOrigin.x - self.window().delegate().myVideoViewTL.frame().origin.x) > abs( newOrigin.x - self.window().delegate().myVideoViewTR.frame().origin.x): letter2 = "R" else: letter2 = "L" if abs(newOrigin.y - self.window().delegate().myVideoViewTL.frame().origin.y) > abs( newOrigin.y - self.window().delegate().myVideoViewBL.frame().origin.y): letter1 = "B" else: letter1 = "T" finalFrame = "myVideoView" + letter1 + letter2 self.start_origin = newOrigin self.final_origin = getattr(self.window().delegate(), finalFrame).frame().origin NSUserDefaults.standardUserDefaults().setValue_forKey_( letter1 + letter2, "MyVideoCorner") self.setFrameOrigin_(newOrigin)
def mouseDragged_(self, event): screenVisibleFrame = NSScreen.mainScreen().visibleFrame() windowFrame = self.window().frame(); newOrigin = windowFrame.origin; currentLocation = event.locationInWindow() newOrigin.x += (currentLocation.x - self.initialLocation.x); newOrigin.y += (currentLocation.y - self.initialLocation.y); if ((newOrigin.y + windowFrame.size.height) > (screenVisibleFrame.origin.y + screenVisibleFrame.size.height)): newOrigin.y = screenVisibleFrame.origin.y + (screenVisibleFrame.size.height - windowFrame.size.height); self.window().setFrameOrigin_(newOrigin);
def mouseDraggedView_(self, event): if not self.initialLocation: return screenVisibleFrame = NSScreen.mainScreen().visibleFrame() windowFrame = self.window().frame() newOrigin = windowFrame.origin currentLocation = event.locationInWindow() newOrigin.x += (currentLocation.x - self.initialLocation.x) newOrigin.y += (currentLocation.y - self.initialLocation.y) if ((newOrigin.y + windowFrame.size.height) > (screenVisibleFrame.origin.y + screenVisibleFrame.size.height)): newOrigin.y = screenVisibleFrame.origin.y + (screenVisibleFrame.size.height - windowFrame.size.height) self.window().setFrameOrigin_(newOrigin);
def removeSession(self, session): self.sessionControllersManager.ringer.stop_ringing(session) if not self.sessions.has_key(session): return if self.answeringMachineTimers.has_key(session): self.answeringMachineTimers[session].invalidate() del self.answeringMachineTimers[session] if self.autoAnswerTimers.has_key(session): self.autoAnswerTimers[session].invalidate() del self.autoAnswerTimers[session] if len(self.sessions) <= 1: self.close() NotificationCenter().discard_observer(self, sender=session) view = self.sessions[session] view.removeFromSuperview() self.sessionsListView.relayout() frame = self.sessionsListView.frame() frame.origin.y = self.extraHeight - 14 frame.size.height = self.sessionsListView.minimumHeight() self.sessionsListView.setFrame_(frame) height = frame.size.height + self.extraHeight size = NSMakeSize(NSWidth(self.panel.frame()), height) screenSize = NSScreen.mainScreen().frame().size if size.height > (screenSize.height * 2) / 3: size.height = (screenSize.height * 2) / 3 frame = self.panel.frame() frame.size.height = size.height frame.size.height = NSHeight(self.panel.frameRectForContentRect_(frame)) self.panel.setFrame_display_animate_(frame, True, True) del self.sessions[session] if session in self.proposals: del self.proposals[session] if not self.sessions: self.unMuteAfterSpeechDidEnd()
def _addIncomingSession(self, session, streams, is_update_proposal): view = self.getItemView() self.sessions[session] = view settings = SIPSimpleSettings() stream_type_list = list(set(stream.type for stream in streams)) if len(self.sessions) == 1: if "screen-sharing" in stream_type_list: base_text = NSLocalizedString("Screen Sharing from %s", "Label") elif "video" in stream_type_list: base_text = NSLocalizedString("Video call from %s", "Label") elif "audio" in stream_type_list: base_text = NSLocalizedString("Audio call from %s", "Label") elif stream_type_list == ["file-transfer"]: base_text = NSLocalizedString("File transfer from %s", "Label") elif stream_type_list == ["chat"]: base_text = NSLocalizedString("Chat from %s", "Label") else: base_text = NSLocalizedString("Call from %s", "Label") title = base_text % format_identity_to_string(session.remote_identity, check_contact=True, format='compact') self.panel.setTitle_(title) if settings.sounds.enable_speech_synthesizer: self.speak_text = title self.startSpeechSynthesizerTimer() else: self.panel.setTitle_(NSLocalizedString("Multiple Incoming Calls", "Label")) NotificationCenter().add_observer(self, sender=session) subjectLabel = view.viewWithTag_(1) fromLabel = view.viewWithTag_(2) accountLabel = view.viewWithTag_(3) acceptButton = view.viewWithTag_(5) rejectButton = view.viewWithTag_(7) accepyOnlyButton = view.viewWithTag_(6) busyButton = view.viewWithTag_(8) callerIcon = view.viewWithTag_(99) chatIcon = view.viewWithTag_(31) audioIcon = view.viewWithTag_(32) fileIcon = view.viewWithTag_(33) screenIcon = view.viewWithTag_(34) videoIcon = view.viewWithTag_(35) stream_types = [s.type for s in streams] session_manager = SessionManager() have_audio_call = any(s for s in session_manager.sessions if s is not session and s.streams and 'audio' in (stream.type for stream in s.streams)) if not have_audio_call: self.startSpeechRecognition() typeCount = 0 if 'audio' in stream_types: frame = audioIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount audioIcon.setFrame_(frame) audioIcon.setHidden_(False) if not is_update_proposal: frame = view.frame() frame.size.height += 20 # give extra space for the counter label view.setFrame_(frame) if session.account.audio.auto_accept: have_audio_call = any(s for s in session_manager.sessions if s is not session and s.streams and 'audio' in (stream.type for stream in s.streams)) if not have_audio_call: self.enableAutoAnswer(view, session, session.account.audio.answer_delay) elif settings.answering_machine.enabled or (is_anonymous(session.remote_identity.uri) and session.account.pstn.anonymous_to_answering_machine): self.enableAnsweringMachine(view, session) if 'chat' in stream_types: frame = chatIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount chatIcon.setFrame_(frame) chatIcon.setHidden_(False) if 'screen-sharing' in stream_types: frame = screenIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount screenIcon.setFrame_(frame) screenIcon.setHidden_(False) if 'video' in stream_types: #have_video_call = any(s for s in session_manager.sessions if s is not session and s.streams and 'video' in (stream.type for stream in s.streams)) #if not have_video_call: # NSApp.delegate().contactsWindowController.showLocalVideoWindow() frame = videoIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount videoIcon.setFrame_(frame) videoIcon.setHidden_(False) is_file_transfer = False if 'file-transfer' in stream_types: is_file_transfer = True frame = fileIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount fileIcon.setFrame_(frame) fileIcon.setHidden_(False) if settings.file_transfer.auto_accept and NSApp.delegate().contactsWindowController.my_device_is_active: BlinkLogger().log_info(u"Auto answer enabled for file transfers from known contacts") self.enableAutoAnswer(view, session, random.uniform(10, 20)) self.sessionsListView.addSubview_(view) frame = self.sessionsListView.frame() frame.origin.y = self.extraHeight - 14 frame.size.height = self.sessionsListView.minimumHeight() self.sessionsListView.setFrame_(frame) height = frame.size.height + self.extraHeight size = NSMakeSize(NSWidth(self.panel.frame()), height) screenSize = NSScreen.mainScreen().frame().size if size.height > (screenSize.height * 2) / 3: size.height = (screenSize.height * 2) / 3 frame = self.panel.frame() frame.size.height = size.height frame.size.height = NSHeight(self.panel.frameRectForContentRect_(frame)) self.panel.setFrame_display_animate_(frame, True, True) self.sessionsListView.relayout() acceptButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(0)) rejectButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(2)) busyButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(3)) # no Busy or partial accept option for Stream Update Proposals busyButton.setHidden_(is_update_proposal or is_file_transfer) accepyOnlyButton.setHidden_(is_update_proposal) if is_file_transfer: busyButton.setAttributedTitle_("") if is_update_proposal: subject, only_button_title, only_button_object = self.format_subject_for_incoming_reinvite(session, streams) only_button_title = "" else: subject, only_button_title, only_button_object = self.format_subject_for_incoming_invite(session, streams) subjectLabel.setStringValue_(subject) accepyOnlyButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(only_button_object)) frame = subjectLabel.frame() frame.size.width = NSWidth(self.sessionsListView.frame()) - 80 - 40 * typeCount subjectLabel.setFrame_(frame) has_audio_streams = any(s for s in reduce(lambda a,b:a+b, [session.proposed_streams for session in self.sessions.keys()], []) if s.type=="audio") caller_contact = NSApp.delegate().contactsWindowController.getFirstContactMatchingURI(session.remote_identity.uri) if caller_contact: if caller_contact.icon: callerIcon.setImage_(caller_contact.icon) if not is_update_proposal and caller_contact.auto_answer and NSApp.delegate().contactsWindowController.my_device_is_active: if has_audio_streams: if not NSApp.delegate().contactsWindowController.has_audio: BlinkLogger().log_info(u"Auto answer enabled for this contact") video_requested = any(s for s in session.blink_supported_streams if s.type == "video") if video_requested and not settings.video.enable_when_auto_answer: blink_supported_streams = [s for s in session.blink_supported_streams if s.type != "video"] session.blink_supported_streams = blink_supported_streams self.enableAutoAnswer(view, session, session.account.audio.answer_delay) else: video_requested = any(s for s in session.blink_supported_streams if s.type == "video") if video_requested and not settings.video.enable_when_auto_answer: blink_supported_streams = [s for s in session.blink_supported_streams if s.type != "video"] session.blink_supported_streams = blink_supported_streams BlinkLogger().log_info(u"Auto answer enabled for this contact") self.enableAutoAnswer(view, session, session.account.audio.answer_delay) fromLabel.setStringValue_(u"%s" % format_identity_to_string(session.remote_identity, check_contact=True, format='full')) fromLabel.sizeToFit() if has_audio_streams: outdev = settings.audio.output_device indev = settings.audio.input_device if outdev == u"system_default": outdev = SIPManager()._app.engine.default_output_device if indev == u"system_default": indev = SIPManager()._app.engine.default_input_device outdev = outdev.strip() if outdev is not None else 'None' indev = indev.strip() if indev is not None else 'None' if outdev != indev: if indev.startswith('Built-in Mic') and outdev.startswith(u'Built-in Out'): self.deviceLabel.setStringValue_(NSLocalizedString("Using Built-in Microphone and Output", "Label")) else: self.deviceLabel.setStringValue_(NSLocalizedString("Using %s for output ", "Label") % outdev.strip() + NSLocalizedString(" and %s for input", "Label") % indev.strip()) else: self.deviceLabel.setStringValue_(NSLocalizedString("Using audio device", "Label") + " " + outdev.strip()) BlinkLogger().log_info(u"Using input/output audio devices: %s/%s" % (indev.strip(), outdev.strip())) self.deviceLabel.sizeToFit() self.deviceLabel.setHidden_(False) else: self.deviceLabel.setHidden_(True) acceptButton.setTitle_(NSLocalizedString("Accept", "Button title")) accepyOnlyButton.setTitle_(only_button_title or "") if False and sum(a.enabled for a in AccountManager().iter_accounts())==1: accountLabel.setHidden_(True) else: accountLabel.setHidden_(False) if isinstance(session.account, BonjourAccount): accountLabel.setStringValue_(NSLocalizedString("To Bonjour account", "Label")) else: to = format_identity_to_string(session.account) accountLabel.setStringValue_(NSLocalizedString("To %s", "Label") % to) accountLabel.sizeToFit() if len(self.sessions) == 1: self.acceptAllButton.setTitle_(NSLocalizedString("Accept", "Button title")) self.acceptAllButton.setHidden_(False) self.acceptButton.setTitle_(only_button_title or "") self.acceptButton.setHidden_(not only_button_title) self.rejectButton.setTitle_(NSLocalizedString("Reject", "Button title")) self.acceptAllButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(0)) self.rejectButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(2)) self.busyButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(3)) self.acceptButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(only_button_object)) self.answeringMachineButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(4)) self.conferenceButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(5)) self.busyButton.setHidden_(is_update_proposal or is_file_transfer) for i in (5, 6, 7, 8): view.viewWithTag_(i).setHidden_(True) else: self.acceptAllButton.setHidden_(False) self.acceptAllButton.setTitle_(NSLocalizedString("Accept All", "Button title")) self.acceptButton.setHidden_(True) self.busyButton.setHidden_(is_update_proposal or is_file_transfer) self.rejectButton.setTitle_(NSLocalizedString("Reject All", "Button title")) for v in self.sessions.values(): for i in (5, 6, 7, 8): btn = v.viewWithTag_(i) btn.setHidden_(len(btn.attributedTitle()) == 0) if not has_audio_streams or is_update_proposal: self.answeringMachineButton.setHidden_(True) else: self.answeringMachineButton.setHidden_(not settings.answering_machine.show_in_alert_panel) if not self.isConferencing: self.conferenceButton.setHidden_(True) else: self.conferenceButton.setHidden_(False)
def getSecondaryScreen(self): try: secondaryScreen = (screen for screen in NSScreen.screens() if screen != NSScreen.mainScreen() and screen.deviceDescription()[NSDeviceIsScreen] == 'YES').next() except (StopIteration, KeyError): secondaryScreen = None return secondaryScreen