def act(context, input=None, default=None, **syntaxes):
    '''
    Required action method
    
    input dictates what fills the placeholder if there is no selection:
    - word
    - line
    
    default and syntaxes will replace $EDITOR_SELECTION with a URL escaped version
    of the selected text (or input, if no selected text)
    '''
    text, range = tea.get_single_selection(context)
    if text is None:
        range = tea.get_single_range(context)
        if input == 'word':
            text, range = tea.get_word(context, range)
        elif input == 'line':
            text, range = tea.get_line(context, range)
    # If we still don't have text, there's nothing to work with
    if text is None:
        return False
    # URL escape the selected text
    text = urllib.quote_plus(text)
    url = tea.select_from_zones(context, range, default, **syntaxes)
    # Got the URL, let's run the URL
    # DEPRECATED: please use $EDITOR_SELECTION instead
    url = url.replace('$SELECTED_TEXT', text)
    url = url.replace('$EDITOR_SELECTION', text)
    NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_(url))
    # Because this gets passed through to Obj-C, using int prevents beeping
    return True
 def webView_decidePolicyForNavigationAction_request_frame_decisionListener_(self, webView, info, request, frame, listener):
     # intercept link clicks so that they are opened in Safari
     theURL = info[WebActionOriginalURLKey]
     if theURL.scheme() == "file":
         listener.use()
     else:
         listener.ignore()
         NSWorkspace.sharedWorkspace().openURL_(theURL)
    def revealFile_(self, sender):
        if self.transfer and self.transfer.file_path:
            path = self.transfer.file_path
        elif self.oldTransferInfo:
            path = self.oldTransferInfo.file_path
        else:
            return

        dirname = os.path.dirname(path)
        NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(path, dirname)
    def webView_decidePolicyForNavigationAction_request_frame_decisionListener_(self, webView, info, request, frame, listener):
        # intercept when user clicks on links so that we process them in different ways
        theURL = info[WebActionOriginalURLKey]

        if self.delegate and hasattr(self.delegate, 'getWindow'):
            window = self.delegate.getWindow()
            if window and window.startScreenSharingWithUrl(theURL.absoluteString()):
                return

        if theURL.scheme() == "file":
            listener.use()
        else:
            # use system wide web browser
            listener.ignore()
            NSWorkspace.sharedWorkspace().openURL_(theURL)
    def changeStatus(self, newstate, fail_reason=None):
        if self.direction == "active":
            if newstate == STREAM_CONNECTED:
                ip, port = self.stream.handler.address
                self.sessionController.log_info("Connecting viewer to vnc://127.0.0.1:%s" % port)
                url = NSURL.URLWithString_("vnc://localhost:%i" % (port))
                NSWorkspace.sharedWorkspace().openURL_(url)
        else:
            self.statusWindow.makeKeyAndOrderFront_(None)
            #self.statusItem.update(self, newstate)
            if self.statusLabel and self.statusWindow:
                if newstate == STREAM_CONNECTED:
                    label = "%s requests your screen. Please confirm when asked." % self.sessionController.getTitleShort()
                    self.statusProgress.setHidden_(False)
                    self.statusProgress.startAnimation_(None)
                elif newstate == STREAM_DISCONNECTING:
                    self.statusLabel.setStringValue_("Terminating Screen Sharing...")
                    self.statusProgress.setHidden_(True)
                    self.start_auto_close_timer()
                elif newstate == STREAM_CANCELLING:
                    self.statusLabel.setStringValue_("Cancelling Screen Sharing...")
                    self.statusProgress.setHidden_(True)
                    self.start_auto_close_timer()
                elif newstate == STREAM_PROPOSING:
                    self.statusProgress.setHidden_(True)
                    self.stopButton.setHidden_(False)
                    self.stopButton.setTitle_('Cancel Proposal')
                elif newstate == STREAM_CONNECTING:
                    self.statusLabel.setStringValue_("Offering Screen Sharing...")
                elif newstate == STREAM_FAILED:
                    label = "Could not start screen sharing:\n%s" % (self.sessionController.failureReason or fail_reason) if self.sessionController.failureReason or fail_reason else "Could not start screen sharing"
                    self.statusLabel.setStringValue_("Screen Sharing Failed")
                    self.statusProgress.setHidden_(True)
                elif newstate == STREAM_IDLE:
                    if self.status in (STREAM_CONNECTING, STREAM_PROPOSING):
                        self.statusLabel.setStringValue_("Screen Sharing Rejected")
                    else:
                        self.statusLabel.setStringValue_("Screen Sharing Ended")
                    self.statusProgress.setHidden_(True)

        if newstate == STREAM_IDLE:
            #if self.direction == "passive":
                #self.statusItem.remove(self)
            self.removeFromSession()
            self.start_auto_close_timer()

        self.status = newstate
        MediaStream.changeStatus(self, newstate, fail_reason)
    def initWithFrame_oldTransfer_(self, frame, transferInfo):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.oldTransferInfo = transferInfo

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            filename = transferInfo.file_path
            if filename.endswith(".download"):
                filename = filename[:-len(".download")]

            self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(filename))

            self.nameText.setStringValue_(os.path.basename(filename))
            self.fromText.setStringValue_('To %s from account %s' % (transferInfo.remote_uri, transferInfo.local_uri) if transferInfo.direction=='outgoing' else 'From %s to account %s' % (transferInfo.remote_uri, transferInfo.local_uri))

            time_print = format_date(transferInfo.time)
            if transferInfo.status == "completed":
                t = NSLocalizedString("Completed transfer of ", "Label")
                status = t + "%s %s" % (format_size(transferInfo.file_size, 1024), time_print)
            else:
                if transferInfo.direction == "outgoing":
                    status = '%s %s' % (transferInfo.status.title(), time_print)
                    self.retryButton.setHidden_(False)
                else:
                    #status = "%s of %s"%(format_size(transferInfo.bytes_transfered, 1024), format_size(transferInfo.file_size, 1024))
                    status = "%s %s" % (transferInfo.status.title(), time_print)

            self.sizeText.setStringValue_(status)
            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.relayoutForDone()
            self.done = True
        return self
    def revealFile_(self, sender):
        if self.transfer and self.transfer.file_path:
            path = self.transfer.file_path
        elif self.oldTransferInfo:
            environ = NSProcessInfo.processInfo().environment()
            inSandbox = environ.objectForKey_("APP_SANDBOX_CONTAINER_ID")
            if inSandbox is not None:
                download_folder = unicodedata.normalize('NFC', NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, True)[0])
                NSWorkspace.sharedWorkspace().openFile_(download_folder)
                return
            path = self.oldTransferInfo.file_path
        else:
            return

        dirname = os.path.dirname(path)
        NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(path, dirname)
    def initWithFrame_oldTransfer_(self, frame, transferInfo):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.oldTransferInfo = transferInfo

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            filename = transferInfo.file_path
            if filename.endswith(".download"):
                filename = filename[:-len(".download")]

            self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(filename))

            self.nameText.setStringValue_(os.path.basename(filename))
            self.fromText.setStringValue_('To %s' % transferInfo.remote_uri if transferInfo.direction=='outgoing' else 'From %s' % transferInfo.remote_uri)

            if transferInfo.status == "completed":
                status = "%s %s Completed"%(format_size(transferInfo.file_size, 1024), unichr(0x2014))
            else:
                error = transferInfo.status

                if transferInfo.direction == "outgoing":
                    status = error
                else:
                    status = "%s of %s"%(format_size(transferInfo.bytes_transfered, 1024), format_size(transferInfo.file_size, 1024))
                    status = "%s %s %s"%(status, unichr(0x2014), error)
            self.sizeText.setStringValue_(status)
            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.relayoutForDone()
            self.done = True
        return self
    def initWithFrame_transfer_(self, frame, transfer):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.transfer = transfer
            NotificationCenter().add_observer(self, sender=transfer)

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            filename = self.transfer.file_path

            if type(self.transfer) == OutgoingPushFileTransferHandler:
                self.fromText.setStringValue_(u"To:  %s" % self.transfer.account.id)
            else:
                if filename.endswith(".download"):
                    filename = filename[:-len(".download")]
                self.fromText.setStringValue_(u"From:  %s" % self.transfer.account.id)
            self.nameText.setStringValue_(os.path.basename(filename))

            if os.path.exists(filename):
                self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(filename))
            else:
                tmp_folder = ApplicationData.get('.tmp_file_transfers')
                if not os.path.exists(tmp_folder):
                    os.mkdir(tmp_folder, 0700)

                tmpf = tmp_folder + "/tmpf" + os.path.splitext(filename)[1]
                open(tmpf, "w+").close()
                self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(tmpf))
                os.remove(tmpf)

            self.updateProgressInfo()
            self.progressBar.setIndeterminate_(True)
            self.progressBar.startAnimation_(None)
            self.progressBar.setHidden_(True)

            self.checksumProgressBar.setIndeterminate_(False)
            self.checksumProgressBar.startAnimation_(None)
            self.checksumProgressBar.setHidden_(False)

            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.originalHeight = NSHeight(frame)
        return self
    def revealFile_(self, sender):
        if self.transfer and self.transfer.ft_info and self.transfer.ft_info.file_path:
            path = self.transfer.ft_info.file_path
        elif self.oldTransferInfo:
            environ = NSProcessInfo.processInfo().environment()
            inSandbox = environ.objectForKey_("APP_SANDBOX_CONTAINER_ID")
            if inSandbox is not None:
                download_folder = unicodedata.normalize(
                    'NFC',
                    NSSearchPathForDirectoriesInDomains(
                        NSDownloadsDirectory, NSUserDomainMask, True)[0])
                NSWorkspace.sharedWorkspace().openFile_(download_folder)
                return
            path = self.oldTransferInfo.file_path
        else:
            return

        dirname = os.path.dirname(path)
        NSWorkspace.sharedWorkspace().selectFile_inFileViewerRootedAtPath_(
            path, dirname)
    def webView_decidePolicyForNavigationAction_request_frame_decisionListener_(
            self, webView, info, request, frame, listener):
        # intercept when user clicks on links so that we process them in different ways
        theURL = info[WebActionOriginalURLKey]

        if self.delegate and hasattr(self.delegate, 'getWindow'):
            window = self.delegate.getWindow()
            if window and window.showConferenceSharedScreen(
                    theURL.absoluteString()):
                return

        if theURL.scheme() == "file":
            listener.use()
        else:
            # use system wide web browser
            if theURL.absoluteString() in list(self.delegate.sessionController.
                                               screensharing_urls.values()):
                self.delegate.chatWindowController.showConferenceSharedScreen(
                    theURL.absoluteString())
            else:
                listener.ignore()
                NSWorkspace.sharedWorkspace().openURL_(theURL)
    def initWithFrame_transfer_(self, frame, transfer):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.transfer = transfer
            NotificationCenter().add_observer(self, sender=transfer)

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            self.file_path = os.path.basename(self.transfer.ft_info.file_path)
            self.nameText.setStringValue_(self.file_path)
            self.remote_uri = self.transfer.ft_info.remote_uri
            self.local_uri = self.transfer.ft_info.local_uri

            if type(self.transfer) == OutgoingPushFileTransferHandler:
                self.fromText.setStringValue_("To:  %s" %
                                              self.transfer.account.id)
            else:
                self.fromText.setStringValue_("From:  %s" %
                                              self.transfer.account.id)
            self.revealButton.setHidden_(True)

            # XXX: there should be a better way to do this!
            tmp_folder = ApplicationData.get('.tmp_file_transfers')
            makedirs(tmp_folder, 0o700)
            tmpf = tmp_folder + "/tmpf-" + self.file_path.decode(
            ) if isinstance(self.file_path, bytes) else self.file_path
            with open(tmpf, "wb+"):
                self.updateIcon(
                    NSWorkspace.sharedWorkspace().iconForFile_(tmpf))
            unlink(tmpf)

            self.updateProgressInfo()
            self.progressBar.setIndeterminate_(True)
            self.progressBar.startAnimation_(None)

            self.checksumProgressBar.setIndeterminate_(False)
            self.checksumProgressBar.startAnimation_(None)

            if transfer.direction == 'outgoing':
                self.progressBar.setHidden_(True)
                self.checksumProgressBar.setHidden_(False)
            else:
                self.progressBar.setHidden_(False)
                self.checksumProgressBar.setHidden_(True)

            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.originalHeight = NSHeight(frame)
        return self
    def initWithFrame_oldTransfer_(self, frame, transferInfo):
        self = NSView.initWithFrame_(self, frame)
        if self:
            self.oldTransferInfo = transferInfo
            self.file_path = transferInfo.file_path
            self.remote_uri = transferInfo.remote_uri
            self.local_uri = transferInfo.local_uri

            NSBundle.loadNibNamed_owner_("FileTransferItemView", self)

            self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_(
                self.file_path))

            self.nameText.setStringValue_(os.path.basename(self.file_path))
            self.fromText.setStringValue_(
                'To %s from account %s' %
                (transferInfo.remote_uri,
                 transferInfo.local_uri) if transferInfo.direction ==
                'outgoing' else 'From %s to account %s' %
                (transferInfo.remote_uri, transferInfo.local_uri))

            self.revealButton.setHidden_(not os.path.exists(self.file_path))

            time_print = format_date(transferInfo.time)
            if transferInfo.status == "completed":
                self.sizeText.setTextColor_(NSColor.blueColor())
                t = NSLocalizedString("Completed transfer of ", "Label")
                status = t + "%s %s" % (format_size(transferInfo.file_size,
                                                    1024), time_print)
            else:
                self.sizeText.setTextColor_(NSColor.redColor())
                status = "%s %s" % (transferInfo.status.title(), time_print)

            self.sizeText.setStringValue_(status)
            frame.size = self.view.frame().size
            self.setFrame_(frame)
            self.addSubview_(self.view)
            self.relayoutForDone()
            if transferInfo.direction == "outgoing" and transferInfo.status != "completed" and os.path.exists(
                    self.file_path):
                self.retryButton.setHidden_(False)
            self.done = True
        return self
Beispiel #14
0
    def changeStatus(self, newstate, fail_reason=None):
        if self.direction == "active":
            if newstate == STREAM_CONNECTED:
                ip, port = self.stream.handler.address
                self.sessionController.log_info(
                    "Connecting screen sharing viewer to vnc://%s:%s" %
                    (ip, port))
                url = NSURL.URLWithString_("vnc://%s:%i" % (ip, port))
                NSWorkspace.sharedWorkspace().openURL_(url)
        else:
            self.statusWindow.makeKeyAndOrderFront_(None)
            #self.statusItem.update(self, newstate)
            if self.statusLabel and self.statusWindow:
                if newstate == STREAM_CONNECTED:
                    _t = self.sessionController.titleShort
                    label = NSLocalizedString(
                        "%s requests your screen. Please confirm when asked.",
                        "Label") % _t
                    self.statusProgress.setHidden_(False)
                    self.statusProgress.startAnimation_(None)
                elif newstate == STREAM_DISCONNECTING:
                    self.statusLabel.setStringValue_(
                        NSLocalizedString("Terminating Screen Sharing...",
                                          "Label"))
                    self.statusProgress.setHidden_(True)
                    self.start_auto_close_timer()
                elif newstate == STREAM_CANCELLING:
                    self.statusLabel.setStringValue_(
                        NSLocalizedString("Cancelling Screen Sharing...",
                                          "Label"))
                    self.statusProgress.setHidden_(True)
                    self.start_auto_close_timer()
                elif newstate == STREAM_PROPOSING:
                    self.statusProgress.setHidden_(True)
                    self.stopButton.setHidden_(False)
                    self.stopButton.setTitle_(
                        NSLocalizedString("Cancel Proposal", "Button title"))
                elif newstate == STREAM_CONNECTING:
                    self.statusLabel.setStringValue_(
                        NSLocalizedString("Offering Screen Sharing...",
                                          "Label"))
                elif newstate == STREAM_FAILED:
                    _t = self.sessionController.failureReason or fail_reason
                    e = NSLocalizedString(
                        "Error starting screen sharing session.", "Label")
                    label = e + "\n%s" % _t if self.sessionController.failureReason or fail_reason else e
                    self.statusLabel.setStringValue_("Screen Sharing Failed")
                    self.statusProgress.setHidden_(True)
                elif newstate == STREAM_IDLE:
                    if self.status in (STREAM_CONNECTING, STREAM_PROPOSING):
                        self.statusLabel.setStringValue_(
                            NSLocalizedString("Screen Sharing Failed",
                                              "Label"))
                    else:
                        self.statusLabel.setStringValue_(
                            NSLocalizedString("Screen Sharing Ended", "Label"))
                    self.statusProgress.setHidden_(True)

        if newstate == STREAM_IDLE:
            #if self.direction == "passive":
            #self.statusItem.remove(self)
            self.removeFromSession()
            self.start_auto_close_timer()

        self.status = newstate
        MediaStream.changeStatus(self, newstate, fail_reason)
 def activateFile_(self, sender):
     if self.transfer:
         NSWorkspace.sharedWorkspace().openFile_(self.transfer.file_path)
     elif self.oldTransferInfo:
         NSWorkspace.sharedWorkspace().openFile_(
             self.oldTransferInfo.file_path)
Beispiel #16
0
def show_gists():
    NSWorkspace.sharedWorkspace().openURL_(
        NSURL.URLWithString_(
            'https://gist.github.com/search?q=%40pudquick&ref=searchresults'))
Beispiel #17
0
def search_gists(search_string):
    NSWorkspace.sharedWorkspace().openURL_(
        NSURL.URLWithString_(
            'https://gist.github.com/search?q=%%40pudquick+%s&ref=searchresults'
            % search_string))
 def activateFile_(self, sender):
     if self.transfer:
         NSWorkspace.sharedWorkspace().openFile_(self.transfer.file_path)
     elif self.oldTransferInfo:
         NSWorkspace.sharedWorkspace().openFile_(self.oldTransferInfo.file_path)