-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OSX Screenshot with screencapture (#457)
* osx screenshot added * setter and getter for file_path * Update screenshot.py * Update screenshot.py * changing method take_shot() to take() * Fix README.rst * Fix Screenshot facade * Purge non-existing method from wifi facade * Set default path to /Users/<user>/Pictures folder, remote hardcoded timeout * Fix Screenshot example * Fix plyer __init__.py * Fix typos and missing values * Fix missing import, protocol <-> path error in 'screencapture'
- Loading branch information
Showing
6 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from kivy.app import App | ||
from kivy.lang import Builder | ||
from kivy.uix.boxlayout import BoxLayout | ||
|
||
|
||
Builder.load_string(''' | ||
#:import screenshot plyer.screenshot | ||
<ScreenshotDemo>: | ||
orientation: 'vertical' | ||
padding: '50dp' | ||
spacing: '20dp' | ||
Label: | ||
size_hint_y: None | ||
height: sp(40) | ||
text: 'Screenshot Location: ' + str(screenshot.file_path) | ||
Button: | ||
text: 'Capture Screenshot' | ||
on_release: screenshot.capture() | ||
''') | ||
|
||
|
||
class ScreenshotDemo(BoxLayout): | ||
'''Root Widget.''' | ||
|
||
|
||
class ScreenshotApp(App): | ||
|
||
def build(self): | ||
return ScreenshotDemo() | ||
|
||
|
||
if __name__ == "__main__": | ||
ScreenshotApp().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
''' | ||
Screenshot | ||
========== | ||
The :class:`Screenshot` is used for capturing a digital image of what | ||
is currently visible on the monitor. | ||
The default path for taking screenshot is set in each platform implementation. | ||
Simple Examples | ||
--------------- | ||
To get the file path:: | ||
>>> screenshot.file_path | ||
'/sdcard/test.jpg' | ||
To set the file path:: | ||
>>> screenshot.file_path = '/Users/OSXUser/Pictures/screenshot.png' | ||
To take screenshot:: | ||
>>> from plyer import screenshot | ||
>>> screenshot.capture() | ||
''' | ||
|
||
|
||
class Screenshot(object): | ||
''' | ||
Screenshot facade. | ||
''' | ||
|
||
_file_path = '' | ||
|
||
def __init__(self, file_path=None): | ||
self._file_path = file_path | ||
|
||
def capture(self): | ||
self._capture() | ||
|
||
@property | ||
def file_path(self): | ||
return self._file_path | ||
|
||
@file_path.setter | ||
def file_path(self, location): | ||
''' | ||
Location of the screenshot. | ||
''' | ||
|
||
self._file_path = location | ||
|
||
# private | ||
|
||
def _capture(self, **kwargs): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import subprocess | ||
from os.path import join | ||
from plyer.facades import Screenshot | ||
from plyer.utils import whereis_exe | ||
from plyer.platforms.macosx.storagepath import OSXStoragePath | ||
|
||
|
||
class OSXScreenshot(Screenshot): | ||
def __init__(self, file_path=None): | ||
default_path = join( | ||
OSXStoragePath().get_pictures_dir().replace('file://', ''), | ||
'screenshot.png' | ||
) | ||
super(OSXScreenshot, self).__init__(file_path or default_path) | ||
|
||
def _capture(self): | ||
subprocess.call([ | ||
'screencapture', | ||
self.file_path | ||
]) | ||
|
||
|
||
def instance(): | ||
if whereis_exe('screencapture'): | ||
return OSXScreenshot() | ||
else: | ||
return Screenshot() |