Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed screenshot feature

  • Loading branch information...
commit 06b2d079ddd8629973b8ed7fadbc33be3876c9b1 1 parent 16a6e99
@lavelle authored
Showing with 32 additions and 97 deletions.
  1. +1 −1  clipcloud.py
  2. +6 −6 main.py
  3. +4 −1 readme.md
  4. +19 −86 screenshot.py
  5. +2 −3 setup.py
View
2  clipcloud.py
@@ -63,7 +63,7 @@ def clipcloud():
screenshot_parser = subparsers.add_parser('snap')
screenshot_parser.add_argument('-m', '--mode', dest='mode',
help="The way the area of the screen to be captured is defined",
- default='screen', choices=['screen', 'draw'])
+ default='screen', choices=['screen', 'select'])
screenshot_parser.set_defaults(func=screenshot)
# Create the parser for options that only apply to viewing the history
View
12 main.py
@@ -3,7 +3,7 @@
Contains the functions for managing each major task the program can perform
such as uploading files and taking screenshots
-The actual code to perform these actions is in separate modules, this once just ties them together
+The actual code to perform these actions is in separate modules, this one just ties them together
"""
import os
@@ -140,13 +140,13 @@ def handle_files(self, paths, filenames, share_to):
def screenshot(args):
"""Take a screenshot and upload it to Dropbox."""
-
from screenshot import Screenshot
- # Import the screenshot module and take a screenshot with the mode the user specified
- path, filename = Screenshot().capture(args.mode)
- # Upload the screenshot
- c.handle_files([path], [filename], args.share)
+ screenshot = Screenshot(args.mode)
+
+ screenshot.capture()
+
+ c.handle_files([screenshot.path], [filename], args.share)
def upload(args):
View
5 readme.md
@@ -17,7 +17,7 @@ cd ClipCloud
### Arguments:
- `up </path/to/file/or/folder> [second file, third file...]`: Upload the specified files and folders.
-- `snap [-m mode]`: Take a screenshot and upload it. Mode can be `draw` or `screen`. Defaults to `screen`.
+- `snap [-m mode]`: Take a screenshot and upload it. Mode can be `select` or `screen`. Defaults to `screen`. Only works on OS X.
- `history [-l number_of_records] [-t sort_by] [-b start] [-d direction]`: Show a history of the files you've uploaded previously. Defaults to the last 10 records.
- `revisit <operation> <id>`: Do something with a previously uploaded file. `id` specifies which file to upload. `operation` can be either `upload`, `remote` or `local`.
- `text [-e extension]`: Share the contents of your clipboard. Currently uploads to Dropbox, support for Github Gists planned. Extenstion defaults to `txt`.
@@ -33,5 +33,8 @@ cd ClipCloud
## Changelog
+### 0.2
+- Fixed screenshot feature
+
### 0.1
- Inital release
View
105 screenshot.py
@@ -1,108 +1,41 @@
import os
from settings import *
from time import time
-import wx
-
-
-class ScreenshotArea(wx.Frame):
- def __init__(self):
- style = (wx.STAY_ON_TOP | wx.RESIZE_BORDER)
- wx.Frame.__init__(self, None, style=style)
-
- #self.SetClientSize()
- self.Move(wx.Point(200, 200))
- self.SetTransparent(128)
-
- #self.Bind(wx.EVT_MOTION, self.OnMouse) # enabling moving the window breaks resizing.
- self.Bind(wx.EVT_KEY_UP, self.keypress)
-
- print 'Please resize the rectangle to cover the area you wish to capture in your screenshot, then press enter'
-
- self.Show(True)
-
- def keypress(self, event):
- global pos # find a way not to do this.
-
- if event.GetKeyCode() == wx.WXK_RETURN:
- a, b, width, height = self.GetClientRect()
- x, y = self.GetPosition()
- pos = (x, y, width, height)
-
- self.Close(force=True)
- else:
- event.Skip()
-
- # def OnMouse(self, event):
- # """implement dragging"""
- # if not event.Dragging():
- # self._dragPos = None
- # return
- # self.CaptureMouse()
- # if not self._dragPos:
- # self._dragPos = event.GetPosition()
- # else:
- # pos = event.GetPosition()
- # displacement = self._dragPos - pos
- # self.SetPosition(self.GetPosition() - displacement)
+import subprocess
class Screenshot:
- def take_screenshot(self, pos=None):
- """
- Capture the pixel data of the screen and save it to a PNG filename
+ def __init__(self, mode):
+ if PLATFORM != 'Darwin':
+ print 'Screenshot tool only works on OS X'
+ exit(1)
- Arguments
- - pos: A tuple of length 4 defining the top, left, height and width of the rectangle to capture
- If omitted it defaults to the entire screen
- """
+ self.flags = self.build_flags(mode)
+ self.filename = self.build_filename()
+ self.path = os.path.join(SCREENSHOT_PATH, self.filename)
- # Create a new Device Context representing the user's primary screen
- screen = wx.ScreenDC()
+ def build_flags(self, mode):
+ flags = '-'
- # Determine the position and dimensions of the screenshot
- if pos:
- x, y, width, height = pos
- else:
- x, y = 0, 0
- width, height = screen.GetSize()
+ # Don't play camera shutter sound effect
+ flags += 'x'
- # Create a bitmap object to represent the final image
- bmp = wx.EmptyBitmap(width, height)
- # Create a Device Context to hold the pixel data
- mem = wx.MemoryDC(bmp)
- # Write the pixel data of the screen to the Device Context
- mem.Blit(0, 0, width, height, screen, x, y)
- # Free up memory by releasing the pixel data
- del mem
+ flags += 'm' if mode == 'screen' else 'i'
- # Create a unique filename for the screenshot from the current time
- filename = 'screenshot_' + str(int(time())) + '.png'
- path = os.path.join(SCREENSHOT_PATH, filename)
- # Save the bitmap data to the file
- bmp.SaveFile(path, wx.BITMAP_TYPE_PNG)
+ return flags
- self.path = path
- self.filename = filename
+ def build_filename(self):
+ return 'screenshot_%s.png' % str(int(time()))
- def capture(self, mode):
+ def capture(self):
"""
Take a screenshot
Arguments:
- mode: The type of screenshot to capture, either the entire screen or a custom rectangle
- Returns: The path to the image file that the screenshot was saved to
+ Returns the path to the image file that the screenshot was saved to
and the name of the file without the full path
"""
- self.app = wx.App(False)
-
- if mode == 'screen':
- self.take_screenshot()
-
- elif mode == 'draw':
- ScreenshotArea()
- self.app.MainLoop()
- self.take_screenshot(pos=pos)
-
- return self.path, self.filename
+ subprocess.call(['screencapture', self.flags, self.path])
View
5 setup.py
@@ -5,7 +5,7 @@
setup(
name='ClipCloud',
- version='0.1',
+ version='0.2',
url='https://github.com/lavelle/ClipCloud',
author='Giles Lavelle',
@@ -28,8 +28,7 @@
'message',
'pyjson',
'screenshot',
- 'settings',
- 'tray'
+ 'settings'
],
entry_points={
'console_scripts': ['clipcloud=clipcloud:main']
Please sign in to comment.
Something went wrong with that request. Please try again.