Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dropbox integration #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*.pyc
.#*
# Weird aliases from the original source
repos.sh

# Translations (I think)
*.mo
.gitignore
locale/
/locale/

# Python compiled
*.pyc
32 changes: 25 additions & 7 deletions README
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
Snapshot tools for linux deepin.
Fork of deepin-scrot that automatically uploads crops to Dropbox. I made this for myself, so it's not really easy to
use or highly configurable, but feel free to make it reusable.

* First generate mo files.
Swith `deepin-scrot` directory to execute updateTranslate.sh like below:
./updateTranslate.sh
SYNOPSIS
Deepin Scrot with the ability to save your snapshots directly to Dropbox. It works like this:
- Take a snapshot the usual way.
- Select "Save to Dropbox" instead of the old "Save" button.
- The program saves the snapshot to your public Dropbox folder, generates the public URL for it, puts it into your
clipboard and plays a sound as feedback.

* Quick start:
Switch `src` directory to execute deepinScrot.py like below command:
cd ./src && ./deepinScrot.py

INSTALLING
Run setup-ubuntu.sh or setup-opensuse.sh with root privileges. Then change the values at the bottom of the
constant.py file to match your Dropbox configuration.


RUNNING
Go to the src folder and run:

python deepinScrot.py

or

./deepinScrot.py

TODO
Change the "Save to Dropbox" icon to show the Dropbox logo instead of a floppy disk.
5 changes: 5 additions & 0 deletions setup-opensuse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

zypper install xclip python-gtk-devel python-xlib
${DIR}/updateTranslate.sh
3 changes: 3 additions & 0 deletions setup-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
apt-get install xclip
python updateTranslate.sh
9 changes: 8 additions & 1 deletion src/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@
SCROT_MODE_WINDOW = 2

DEFAULT_FILENAME = "DeepinScrot-"
DEFAULT_FONT = "文泉驿微米黑"
DEFAULT_FONT = "文泉驿微米黑"

# BEGIN Dropbox config
DROPBOX_SCREENSHOTS_FOLDER = '/path/to/Dropbox/Public/screenshots/' # Change this!
DROPBOX_PUBLIC_ID = 'XXXXXXYYYYYYZZZZZ' # Change this!
DROPBOX_SCREENSHOTS_URL = 'http://dl.dropbox.com/u/%s/screenshots/' % DROPBOX_PUBLIC_ID
CLIPBOARD_NOTIFICATION_SOUND = '/usr/share/sounds/gnome/default/alerts/drip.ogg'
# END Dropbox config
30 changes: 26 additions & 4 deletions src/mainscrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import uuid

from action import *
import pyperclip
from utils import *
from math import *
from draw import *
Expand Down Expand Up @@ -428,6 +430,9 @@ def initToolbar(self):
self.actionSaveButton = self.createOtherButton("save", __("Tip save"))
self.actionSaveButton.connect("button-press-event", lambda w, e: self.saveSnapshotToFile())

self.actionSaveButton = self.createOtherButton("dropbox", "Save to Dropbox!")
self.actionSaveButton.connect("button-press-event", lambda w, e: self.saveSnapshotToFile(True))

separatorLabel = gtk.Button()
drawSeparator(separatorLabel, 'sep')
self.toolBox.pack_start(separatorLabel)
Expand Down Expand Up @@ -1010,8 +1015,25 @@ def keyPress(self, widget, event):
if self.keyBindings.has_key(keyEventName):
self.keyBindings[keyEventName]()

def saveSnapshotToFile(self):
def play_sound(self, path):
command = 'play %s' % path
os.system(command)

def copy_to_clipboard(self, filename):
url = os.path.join(DROPBOX_SCREENSHOTS_URL, filename)
pyperclip.setcb(url)
self.play_sound(CLIPBOARD_NOTIFICATION_SOUND)

def saveSnapshotToFile(self, to_dropbox=False):
'''Save file to file.'''
if to_dropbox:
filename = '%s.png' % str(uuid.uuid1())
path = os.path.join(DROPBOX_SCREENSHOTS_FOLDER, filename)
self.saveSnapshot(path, self.saveFiletype)
print "Save snapshot to %s" % path
self.copy_to_clipboard(filename)
return

dialog = gtk.FileChooserDialog(
"Save..",
self.window,
Expand Down Expand Up @@ -1061,9 +1083,9 @@ def saveSnapshotToFile(self):

response = dialog.run()
if response == gtk.RESPONSE_ACCEPT:
filename = dialog.get_filename()
self.saveSnapshot(filename, self.saveFiletype)
print "Save snapshot to %s" % (filename)
path = dialog.get_filename()
self.saveSnapshot(path, self.saveFiletype)
print "Save snapshot to %s" % path
elif response == gtk.RESPONSE_REJECT:
self.adjustToolbar()
self.showToolbar()
Expand Down
156 changes: 156 additions & 0 deletions src/pyperclip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Pyperclip v1.3
# A cross-platform clipboard module for Python. (only handles plain text for now)
# By Al Sweigart al@coffeeghost.net

# Usage:
# import pyperclip
# pyperclip.copy('The text to be copied to the clipboard.')
# spam = pyperclip.paste()

# On Mac, this module makes use of the pbcopy and pbpaste commands, which should come with the os.
# On Linux, this module makes use of the xclip command, which should come with the os. Otherwise run "sudo apt-get install xclip"


# Copyright (c) 2010, Albert Sweigart
# All rights reserved.
#
# BSD-style license:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the pyperclip nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY Albert Sweigart "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Albert Sweigart BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Change Log:
# 1.2 Use the platform module to help determine OS.
# 1.3 Changed ctypes.windll.user32.OpenClipboard(None) to ctypes.windll.user32.OpenClipboard(0), after some people ran into some TypeError

import platform, os

def winGetClipboard():
ctypes.windll.user32.OpenClipboard(0)
pcontents = ctypes.windll.user32.GetClipboardData(1) # 1 is CF_TEXT
data = ctypes.c_char_p(pcontents).value
#ctypes.windll.kernel32.GlobalUnlock(pcontents)
ctypes.windll.user32.CloseClipboard()
return data

def winSetClipboard(text):
GMEM_DDESHARE = 0x2000
ctypes.windll.user32.OpenClipboard(0)
ctypes.windll.user32.EmptyClipboard()
try:
# works on Python 2 (bytes() only takes one argument)
hCd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE, len(bytes(text))+1)
except TypeError:
# works on Python 3 (bytes() requires an encoding)
hCd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE, len(bytes(text, 'ascii'))+1)
pchData = ctypes.windll.kernel32.GlobalLock(hCd)
try:
# works on Python 2 (bytes() only takes one argument)
ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pchData), bytes(text))
except TypeError:
# works on Python 3 (bytes() requires an encoding)
ctypes.cdll.msvcrt.strcpy(ctypes.c_char_p(pchData), bytes(text, 'ascii'))
ctypes.windll.kernel32.GlobalUnlock(hCd)
ctypes.windll.user32.SetClipboardData(1,hCd)
ctypes.windll.user32.CloseClipboard()

def macSetClipboard(text):
outf = os.popen('pbcopy', 'w')
outf.write(text)
outf.close()

def macGetClipboard():
outf = os.popen('pbpaste', 'r')
content = outf.read()
outf.close()
return content

def gtkGetClipboard():
return gtk.Clipboard().wait_for_text()

def gtkSetClipboard(text):
cb = gtk.Clipboard()
cb.set_text(text)
cb.store()

def qtGetClipboard():
return str(cb.text())

def qtSetClipboard(text):
cb.setText(text)

def xclipSetClipboard(text):
outf = os.popen('xclip -selection c', 'w')
outf.write(text)
outf.close()

def xclipGetClipboard():
outf = os.popen('xclip -selection c -o', 'r')
content = outf.read()
outf.close()
return content

def xselSetClipboard(text):
outf = os.popen('xsel -i', 'w')
outf.write(text)
outf.close()

def xselGetClipboard():
outf = os.popen('xsel -o', 'r')
content = outf.read()
outf.close()
return content


if os.name == 'nt' or platform.system() == 'Windows':
import ctypes
getcb = winGetClipboard
setcb = winSetClipboard
elif os.name == 'mac' or platform.system() == 'Darwin':
getcb = macGetClipboard
setcb = macSetClipboard
elif os.name == 'posix' or platform.system() == 'Linux':
xclipExists = os.system('which xclip') == 0
if xclipExists:
getcb = xclipGetClipboard
setcb = xclipSetClipboard
else:
xselExists = os.system('which xsel') == 0
if xselExists:
getcb = xselGetClipboard
setcb = xselSetClipboard
try:
import gtk
getcb = gtkGetClipboard
setcb = gtkSetClipboard
except:
try:
import PyQt4.QtCore
import PyQt4.QtGui
app = QApplication([])
cb = PyQt4.QtGui.QApplication.clipboard()
getcb = qtGetClipboard
setcb = qtSetClipboard
except:
raise Exception('Pyperclip requires the gtk or PyQt4 module installed, or the xclip command.')
copy = setcb
paste = getcb
Binary file added theme/default/action/dropbox_hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added theme/default/action/dropbox_normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added theme/default/action/dropbox_press.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.