示例#1
0
    def updateDisplay(self):
        """Update window display from settings."""
        self.launchAtStartup.setState_(get_pref('launchAtStartup'))
        self.iconset.selectCellWithTag_(1 if get_pref('iconset') ==
                                        'grayscale' else 0)

        self.randomize.setState_(get_pref('randomize'))
        self.copyonly.setState_(get_pref('copyonly'))
        self.copyonly.setState_(get_pref('retinascale'))

        dropboxdir = detect_dropbox_folder()
        self.dropboxdir.setStringValue_(dropboxdir
                                        or u'None. Install Dropbox?')
        self.dropboxid.setStringValue_(get_pref('dropboxid'))

        customurl = get_pref('customurl')
        if not customurl:  # Default.
            self.url_select.selectCellWithTag_(0)
            self.url_text.setEnabled_(False)
            self.url_text.setStringValue_('')
            self.url_example.setStringValue_(
                share_url(EXAMPLE_FILENAME, url=''))
        else:  # Custom.
            self.url_select.selectCellWithTag_(1)
            self.url_text.setEnabled_(True)
            self.url_text.setStringValue_(customurl)
            self.url_example.setStringValue_(
                share_url(EXAMPLE_FILENAME, url=customurl))
示例#2
0
    def saveSettings_(self, sender):
        """Save changed settings."""
        set_pref('launchAtStartup', bool(self.launchAtStartup.state()))
        launch_at_startup(bool(self.launchAtStartup.state()))

        # Iconset
        iconset_sel = self.iconset.selectedCell().tag()
        if iconset_sel == 1:  # Grayscale
            set_pref('iconset', 'grayscale')
        else:
            set_pref('iconset', 'default')
        upshot = NSApplication.sharedApplication().delegate()
        upshot.update_menu()

        set_pref('randomize', bool(self.randomize.state()))
        set_pref('copyonly', bool(self.copyonly.state()))
        set_pref('retinascale', bool(self.retinascale.state()))

        try:
            set_pref('dropboxid', int(self.dropboxid.stringValue()))
        except ValueError:
            pass

        # Custom URL settings.
        if self.url_select.selectedCell().tag() == 0:  # Default
            self.url_text.setStringValue_('')
            self.url_text.setEnabled_(False)
            self.url_example.setStringValue_(
                share_url(EXAMPLE_FILENAME, url=''))
            set_pref('customurl', '')
        else:  # Custom
            self.url_text.setEnabled_(True)
            self.url_example.setStringValue_(
                share_url(EXAMPLE_FILENAME, url=self.url_text.stringValue()))
            set_pref('customurl', self.url_text.stringValue())
示例#3
0
    def saveSettings_(self, sender):
        """Save changed settings."""
        set_pref("launchAtStartup", bool(self.launchAtStartup.state()))
        launch_at_startup(bool(self.launchAtStartup.state()))

        # Iconset
        iconset_sel = self.iconset.selectedCell().tag()
        if iconset_sel == 1:  # Grayscale
            set_pref("iconset", "grayscale")
        else:
            set_pref("iconset", "default")
        upshot = NSApplication.sharedApplication().delegate()
        upshot.update_menu()

        set_pref("randomize", bool(self.randomize.state()))
        set_pref("copyonly", bool(self.copyonly.state()))

        try:
            set_pref("dropboxid", int(self.dropboxid.stringValue()))
        except ValueError:
            pass

        # Custom URL settings.
        if self.url_select.selectedCell().tag() == 0:  # Default
            self.url_text.setStringValue_("")
            self.url_text.setEnabled_(False)
            self.url_example.setStringValue_(share_url(EXAMPLE_FILENAME, url=""))
            set_pref("customurl", "")
        else:  # Custom
            self.url_text.setEnabled_(True)
            self.url_example.setStringValue_(share_url(EXAMPLE_FILENAME, url=self.url_text.stringValue()))
            set_pref("customurl", self.url_text.stringValue())
示例#4
0
    def saveSettings_(self, sender):
        """Save changed settings."""
        set_pref('launchAtStartup', bool(self.launchAtStartup.state()))
        launch_at_startup(bool(self.launchAtStartup.state()))

        set_pref('autoupdate', bool(self.autoupdate.state()))
        upshot = NSApplication.sharedApplication().delegate()
        upshot.updater.sparkle.setAutomaticallyChecksForUpdates_(
            bool(self.autoupdate.state()))

        set_pref('randomize', bool(self.randomize.state()))
        set_pref('copyonly', bool(self.copyonly.state()))
        set_pref('retinascale', bool(self.retinascale.state()))

        try:
            set_pref('dropboxid', int(self.dropboxid.stringValue()))
        except ValueError:
            pass

        # Custom URL settings.
        example_filename = (EXAMPLE_FILENAME_SHORT if get_pref('randomize')
                            else EXAMPLE_FILENAME_LONG)
        if self.url_select.selectedCell().tag() == 0:  # Default
            self.url_text.setStringValue_('')
            self.url_text.setEnabled_(False)
            self.url_example.setStringValue_(
                share_url(example_filename, url=''))
            set_pref('customurl', '')
        else:  # Custom
            self.url_text.setEnabled_(True)
            self.url_example.setStringValue_(
                share_url(example_filename, url=self.url_text.stringValue()))
            set_pref('customurl', self.url_text.stringValue())
示例#5
0
    def saveSettings_(self, sender):
        """Save changed settings."""
        set_pref('launchAtStartup', bool(self.launchAtStartup.state()))
        launch_at_startup(bool(self.launchAtStartup.state()))

        # Iconset
        iconset_sel = self.iconset.selectedCell().tag()
        if iconset_sel == 1:  # Grayscale
            set_pref('iconset', 'grayscale')
        else:
            set_pref('iconset', 'default')
        upshot = NSApplication.sharedApplication().delegate()
        upshot.update_menu()

        set_pref('randomize', bool(self.randomize.state()))
        set_pref('copyonly', bool(self.copyonly.state()))
        set_pref('retinascale', bool(self.retinascale.state()))

        try:
            set_pref('dropboxid', int(self.dropboxid.stringValue()))
        except ValueError:
            pass

        # Custom URL settings.
        if self.url_select.selectedCell().tag() == 0:  # Default
            self.url_text.setStringValue_('')
            self.url_text.setEnabled_(False)
            self.url_example.setStringValue_(share_url(EXAMPLE_FILENAME,
                                                       url=''))
            set_pref('customurl', '')
        else:  # Custom
            self.url_text.setEnabled_(True)
            self.url_example.setStringValue_(
                share_url(EXAMPLE_FILENAME, url=self.url_text.stringValue()))
            set_pref('customurl', self.url_text.stringValue())
示例#6
0
    def updateDisplay(self):
        """Update window display from settings."""
        self.launchAtStartup.setState_(get_pref('launchAtStartup'))
        self.iconset.selectCellWithTag_(
            1 if get_pref('iconset') == 'grayscale' else 0)

        self.randomize.setState_(get_pref('randomize'))
        self.copyonly.setState_(get_pref('copyonly'))
        self.copyonly.setState_(get_pref('retinascale'))

        dropboxdir = detect_dropbox_folder()
        self.dropboxdir.setStringValue_(
            dropboxdir or u'None. Install Dropbox?')
        self.dropboxid.setStringValue_(get_pref('dropboxid'))

        customurl = get_pref('customurl')
        if not customurl:  # Default.
            self.url_select.selectCellWithTag_(0)
            self.url_text.setEnabled_(False)
            self.url_text.setStringValue_('')
            self.url_example.setStringValue_(share_url(EXAMPLE_FILENAME,
                                                       url=''))
        else:  # Custom.
            self.url_select.selectCellWithTag_(1)
            self.url_text.setEnabled_(True)
            self.url_text.setStringValue_(customurl)
            self.url_example.setStringValue_(share_url(EXAMPLE_FILENAME,
                                                       url=customurl))
示例#7
0
    def saveSettings_(self, sender):
        """Save changed settings."""
        set_pref('launchAtStartup', bool(self.launchAtStartup.state()))
        launch_at_startup(bool(self.launchAtStartup.state()))

        set_pref('autoupdate', bool(self.autoupdate.state()))
        upshot = NSApplication.sharedApplication().delegate()
        upshot.updater.sparkle.setAutomaticallyChecksForUpdates_(
            bool(self.autoupdate.state()))

        set_pref('randomize', bool(self.randomize.state()))
        set_pref('copyonly', bool(self.copyonly.state()))
        set_pref('retinascale', bool(self.retinascale.state()))

        try:
            set_pref('dropboxid', int(self.dropboxid.stringValue()))
        except ValueError:
            pass

        # Custom URL settings.
        example_filename = (EXAMPLE_FILENAME_SHORT if get_pref('randomize')
                            else EXAMPLE_FILENAME_LONG)
        if self.url_select.selectedCell().tag() == 0:  # Default
            self.url_text.setStringValue_('')
            self.url_text.setEnabled_(False)
            self.url_example.setStringValue_(share_url(example_filename,
                                                       url=''))
            set_pref('customurl', '')
        else:  # Custom
            self.url_text.setEnabled_(True)
            self.url_example.setStringValue_(
                share_url(example_filename, url=self.url_text.stringValue()))
            set_pref('customurl', self.url_text.stringValue())
示例#8
0
    def handle_screenshot_candidate(self, f):
        """Given a candidate file, handle it if it's a screenshot."""
        # The file could be anything. Only act if it's a screenshot.
        if not utils.is_screenshot(f):
            log.debug('%s is missing or not a screenshot.' % f)
            return

        # Do not act on files that are too old (so we don't swallow old files
        # that are not new screenshots).
        now = time.time()
        filename_time = utils.timestamp_from_filename(
            f)  # Parse time out of filename.
        if (now - os.path.getctime(f) > TIME_THRESHOLD or not filename_time
                or now - filename_time > TIME_THRESHOLD):
            log.debug('Ignoring %s, too old.' % f)
            return

        # Create target dir if needed.
        if not os.path.isdir(SHARE_DIR):
            log.debug('Creating share dir %s' % SHARE_DIR)
            os.makedirs(SHARE_DIR)

        # Determine target filename in share directory.
        log.debug('Moving %s to %s' % (f, SHARE_DIR))
        if utils.get_pref('randomize'):  # Randomize file names?
            ext = os.path.splitext(f)[1]
            while True:
                shared_name = utils.randname() + ext
                target_file = os.path.join(SHARE_DIR, shared_name)
                if not os.path.exists(target_file):
                    log.debug('New file name is: %s' % shared_name)
                    break
        else:
            shared_name = os.path.basename(f)
            target_file = os.path.join(SHARE_DIR, shared_name)

        # Move/copy file there.
        if (utils.get_pref('retinascale')
                and utils.resampleRetinaImage(f, target_file)):
            if not utils.get_pref('copyonly'):
                os.unlink(f)
        else:
            if utils.get_pref('copyonly'):
                shutil.copy(f, target_file)
            else:
                shutil.move(f, target_file)

        # Create shared URL.
        url = utils.share_url(urllib.quote(shared_name))
        log.debug('Share URL is %s' % url)

        log.debug('Copying to clipboard.')
        utils.pbcopy(url)

        # Notify user.
        notify('Screenshot shared!',
               'Your URL is: %s\n\n'
               'Click here to view file.' % url,
               context=target_file,
               callback=self.notify_callback)
示例#9
0
文件: upshot.py 项目: fwenzel/upshot
    def handle_screenshot_candidate(self, f):
        """Given a candidate file, handle it if it's a screenshot."""
        # The file could be anything. Only act if it's a screenshot.
        if not utils.is_screenshot(f):
            log.debug('%s is missing or not a screenshot.' % f)
            return

        # Do not act on files that are too old (so we don't swallow old files
        # that are not new screenshots).
        now = time.time()
        filename_time = utils.timestamp_from_filename(f)  # Parse time out of filename.
        if (now - os.path.getctime(f) > TIME_THRESHOLD or
            not filename_time or
            now - filename_time > TIME_THRESHOLD):
            log.debug('Ignoring %s, too old.' % f)
            return

        # Create target dir if needed.
        if not os.path.isdir(SHARE_DIR):
            log.debug('Creating share dir %s' % SHARE_DIR)
            os.makedirs(SHARE_DIR)

        # Determine target filename in share directory.
        log.debug('Moving %s to %s' % (f, SHARE_DIR))
        if utils.get_pref('randomize'):  # Randomize file names?
            ext = os.path.splitext(f)[1]
            while True:
                shared_name = utils.randname() + ext
                target_file = os.path.join(SHARE_DIR, shared_name)
                if not os.path.exists(target_file):
                    log.debug('New file name is: %s' % shared_name)
                    break
        else:
            shared_name = os.path.basename(f)
            target_file = os.path.join(SHARE_DIR, shared_name)

        # Move/copy file there.
        if (utils.get_pref('retinascale') and
            utils.resampleRetinaImage(f, target_file)):
            if not utils.get_pref('copyonly'):
                os.unlink(f)
        else:
            if utils.get_pref('copyonly'):
                shutil.copy(f, target_file)
            else:
                shutil.move(f, target_file)

        # Create shared URL.
        url = utils.share_url(urllib.quote(shared_name))
        log.debug('Share URL is %s' % url)

        log.debug('Copying to clipboard.')
        utils.pbcopy(url)

        # Notify user.
        notify('Screenshot shared!',
               'Your URL is: %s\n\n'
               'Click here to view file.' % url,
               context=target_file, callback=self.notify_callback)
示例#10
0
    def updateDisplay(self):
        """Update window display from settings."""
        self.launchAtStartup.setState_(get_pref("launchAtStartup"))
        self.iconset.selectCellWithTag_(1 if get_pref("iconset") == "grayscale" else 0)

        self.randomize.setState_(get_pref("randomize"))
        self.copyonly.setState_(get_pref("copyonly"))

        dropboxdir = detect_dropbox_folder()
        self.dropboxdir.setStringValue_(dropboxdir or u"None. Install Dropbox?")
        self.dropboxid.setStringValue_(get_pref("dropboxid"))

        customurl = get_pref("customurl")
        if not customurl:  # Default.
            self.url_select.selectCellWithTag_(0)
            self.url_text.setEnabled_(False)
            self.url_text.setStringValue_("")
            self.url_example.setStringValue_(share_url(EXAMPLE_FILENAME, url=""))
        else:  # Custom.
            self.url_select.selectCellWithTag_(1)
            self.url_text.setEnabled_(True)
            self.url_text.setStringValue_(customurl)
            self.url_example.setStringValue_(share_url(EXAMPLE_FILENAME, url=customurl))
示例#11
0
文件: upshot.py 项目: bwinton/upshot
    def handle_screenshot_candidate(self, f):
        """Given a candidate file, handle it if it's a screenshot."""
        # Do not act on files that are too old (so we don't swallow files
        # that are not new screenshots).
        if os.path.getctime(f) - time.time() > TIME_THRESHOLD:
            return

        # The file could be anything. Only act if it's a screenshot.
        if not utils.is_screenshot(f):
            return

        # Create target dir if needed.
        if not os.path.isdir(SHARE_DIR):
            log.debug('Creating share dir %s' % SHARE_DIR)
            os.makedirs(SHARE_DIR)

        # Move image file to target dir.
        log.debug('Moving %s to %s' % (f, SHARE_DIR))
        if utils.get_pref('randomize'):  # Randomize file names?
            ext = os.path.splitext(f)[1]
            while True:
                shared_name = utils.randname() + ext
                target_file = os.path.join(SHARE_DIR, shared_name)
                if not os.path.exists(target_file):
                    log.debug('New file name is: %s' % shared_name)
                    if utils.get_pref('copyonly'):
                        shutil.copy(f, target_file)
                    else:
                        shutil.move(f, target_file)
                    break
        else:
            shared_name = os.path.basename(f)
            shutil.move(f, SHARE_DIR)
            target_file = os.path.join(SHARE_DIR, shared_name)

        # Create shared URL
        url = utils.share_url(urllib.quote(shared_name))
        logging.debug('Share URL is %s' % url)

        logging.debug('Copying to clipboard.')
        utils.pbcopy(url)

        # Notify user.
        growl = Growler.alloc().init()
        growl.setCallback(self.notify_callback)
        growl.notify('Screenshot shared!',
                     'Your URL is: %s\n\n'
                     'Click here to view file.' % url,
                     context=target_file)