Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 145 lines (113 sloc) 3.873 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
import httplib
import urllib2
import xml.dom.minidom

import win32con
import wx

import screengrab
import ConfigParser

UPDATE_CHECK_URL = 'http://dl.getdropbox.com/u/521887/dropbox_screen_grabber/latest'

settingsDefault = {
'user_id': '',
'dropbox_directory': '',
'copy_url_to_clipboard': '0',
'shorten_urls': '0',
'enable_toast_notifications': '1',

'image_format': 'PNG',
'image_quality': 'Very High',
'filename_prefix': 'screengrab',
'screenshot_save_directory': '',

'hot_key1_modifier': 'Shift',
'hot_key1_key_code': 'F10',
'hot_key2_modifier': 'Shift',
'hot_key2_key_code': 'F11',

'resize_image': '0',
'resize_value': '95%',
'auto_grab': '0',
'auto_grab_type': 'Full screen',
'auto_grab_interval': '60 minutes',
}

settings = {}

modifiers = {
'Ctrl': win32con.MOD_CONTROL,
'Alt': win32con.MOD_ALT,
'Shift': win32con.MOD_SHIFT,
'Win': win32con.MOD_WIN
}
keyCodes = {
'F10': win32con.VK_F10,
'F11': win32con.VK_F11,
'F12': win32con.VK_F12
}

def loadSettings():
config = wx.Config('dropbox_screen_grabber')

for key, value in settingsDefault.iteritems():
settings[key] = config.Read(key, value)

def saveSettings(settingsNew):
config = wx.Config('dropbox_screen_grabber')

for key, value in settingsNew.iteritems():
if type(value) == bool:
value = '1' if value else '0'

config.Write(key, str(value))

# Only path relative to Dropbox public directory is allowed
if settingsNew.has_key('screenshot_save_directory'):
saveDirectory = settingsNew['screenshot_save_directory']
saveDirectory = saveDirectory[len(screengrab.get_public_folder_path()) + 1:] if (saveDirectory.find(screengrab.get_public_folder_path()) != -1 and len(saveDirectory) > len(screengrab.get_public_folder_path())) else None

if not saveDirectory:
config.Write('screenshot_save_directory', '')
else:
config.Write('screenshot_save_directory', saveDirectory)

def getAutoGrabIntervalValueInMs(interval):
"""
Parses the input string and returns the auto-grab interval in
milliseconds.
"""
interval = int(interval[:interval.find(' ')])
interval = (interval * 60 * 1000)

return interval

def exportSettings(filePath):
"""
Save current settings to a file.
"""
config = ConfigParser.RawConfigParser()

config.add_section('general')
for key, value in settings.iteritems():
config.set('general', key, value)

with open(filePath, 'wb') as file:
config.write(file)

def importSettings(filePath):
"""
Restore settings from a file.
"""

config = ConfigParser.RawConfigParser()
config.read(filePath)

items = dict(config.items('general'))
settingsImported = dict([(k,v) for k, v in items.iteritems() \
if settingsDefault.has_key(k)])

# Allow importing files with missing keys for backwards-compatibility
# if len(settingsImported) != len(settingsDefault):
# raise Exception('Could not parse settings file')

saveSettings(settingsImported)

def restoreToDefault():
"""
Restore settings to default.
"""
saveSettings(settingsDefault)

def get_latest_version():
request = urllib2.Request(UPDATE_CHECK_URL)
request.add_header('User-Agent', 'Python Client - Dropbox Screen Grabber')
opener = urllib2.build_opener()

response = opener.open(request).read()

data = xml.dom.minidom.parseString(response)

version = releaseDate = downloadUrl = None
for node in data.childNodes:
for node2 in node.childNodes:
if node2.nodeType == xml.dom.minidom.Node.ELEMENT_NODE:
for node3 in node2.childNodes:
if node3.nodeType == xml.dom.minidom.Node.TEXT_NODE:
if node2.tagName == 'version':
version = node3.data
elif node2.tagName == 'release-date':
releaseDate = node3.data
elif node2.tagName == 'url-download':
downloadUrl = node3.data

return (version, releaseDate, downloadUrl)
Something went wrong with that request. Please try again.