Skip to content

Commit

Permalink
Merge pull request #75 from trivedigaurav/maintenance
Browse files Browse the repository at this point in the history
Maintenance merge
  • Loading branch information
trivedigaurav committed Jul 12, 2014
2 parents 4a7f6b7 + b2810f5 commit c8b9632
Show file tree
Hide file tree
Showing 37 changed files with 2,417 additions and 125 deletions.
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
PYTHON = python
CHECKSCRIPT = plyer/tools/pep8checker/pep8kivy.py
PLYER_DIR = plyer/

build:
$(PYTHON) setup.py build_ext --inplace

force:
$(PYTHON) setup.py build_ext --inplace -f

debug:
$(PYTHON) setup.py build_ext --inplace -f -g

pdf:
$(MAKE) -C docs latex && make -C docs/build/latex all-pdf

html:
env USE_EMBEDSIGNATURE=1 $(MAKE) force
$(MAKE) -C docs html

style:
$(PYTHON) $(CHECKSCRIPT) $(PLYER_DIR)

stylereport:
$(PYTHON) $(CHECKSCRIPT) -html $(PLYER_DIR)

hook:
# Install pre-commit git hook to check your changes for styleguide
# consistency.
cp plyer/tools/pep8checker/pre-commit.githook .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

install:
python setup.py install

clean:
-rm -rf docs/build
-rm -rf build
-find plyer -iname '*.so' -exec rm {} \;
-find plyer -iname '*.pyc' -exec rm {} \;
-find plyer -iname '*.pyo' -exec rm {} \;

distclean: clean
-git clean -dxf -e debian
6 changes: 3 additions & 3 deletions plyer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
'''

__all__ = ('accelerometer', 'camera', 'gps', 'notification',
'tts', 'email', 'vibrator', 'sms', 'compass',
__all__ = ('accelerometer', 'camera', 'gps', 'notification',
'tts', 'email', 'vibrator', 'sms', 'compass',
'gyroscope', 'uniqueid', 'battery')

__version__ = '1.2.0'
Expand Down Expand Up @@ -51,7 +51,7 @@

#: Gyroscope proxy to :class:`plyer.facades.Gyroscope`
gyroscope = Proxy(
'Gyroscope', facades.Gyroscope)
'gyroscope', facades.Gyroscope)

#: UniqueID proxy to :class:`plyer.facades.UniqueID`
uniqueid = Proxy(
Expand Down
62 changes: 34 additions & 28 deletions plyer/facades.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class Accelerometer(object):

@property
def acceleration(self):
'''Property that returns values of the current acceleration sensors, as
a (x, y, z) tuple.
'''Property that returns values of the current acceleration
sensors, as a (x, y, z) tuple.
'''
return self.get_acceleration()

def enable(self):
'''Activate the accelerometer sensor. Throws an error if the hardware is
not available or not implemented on.
'''Activate the accelerometer sensor. Throws an error if the
hardware is not available or not implemented on.
'''
self._enable()

Expand Down Expand Up @@ -55,8 +55,9 @@ class Camera(object):
def take_picture(self, filename, on_complete):
'''Ask the OS to capture a picture, and store it at filename.
When the capture is done, on_complete will be called with the filename as
an argument. If the callback returns True, the filename will be unlinked.
When the capture is done, on_complete will be called with the filename
as an argument. If the callback returns True, the filename will be
unlinked.
:param filename: Name of the image file
:param on_complete: Callback that will be called when the operation is
Expand Down Expand Up @@ -219,7 +220,6 @@ class Vibrator(object):
.. note::
On Android your app needs the VIBRATE permission to
access the vibrator.
'''

def vibrate(self, time=1):
Expand All @@ -237,21 +237,25 @@ def pattern(self, pattern=[0, 1], repeat=-1):
optional repeat.
:param pattern: Pattern to vibrate with. Should be a list of
times in seconds. The first number is how long to wait before
vibrating, and subsequent numbers are times to vibrate and not
vibrate alternately. Defaults to ``[0, 1]``.
times in seconds. The first number is how long to wait
before vibrating, and subsequent numbers are times to
vibrate and not vibrate alternately.
Defaults to ``[0, 1]``.
:param repeat: Index at which to repeat the pattern. When the
vibration pattern reaches this index, it will start again from
the beginning. Defaults to ``-1``, which means no repeat.
vibration pattern reaches this index, it will start again
from the beginning. Defaults to ``-1``, which means no
repeat.
'''
self._pattern(pattern=pattern, repeat=repeat)

def _pattern(self, **kwargs):
raise NotImplementedError()

def exists(self):
'''Check if the device has a vibrator. Returns True or False.'''
'''Check if the device has a vibrator. Returns True or
False.
'''
return self._exists()

def _exists(self, **kwargs):
Expand Down Expand Up @@ -294,7 +298,7 @@ class Compass(object):

@property
def orientation(self):
'''Property that returns values of the current compass
'''Property that returns values of the current compass
(magnetic field) sensors, as a (x, y, z) tuple.
'''
return self.get_orientation()
Expand Down Expand Up @@ -365,13 +369,15 @@ def _get_orientation(self):
class UniqueID(object):
'''UniqueID facade.
.. note::
Returns the following depending on the platform:
* On Android your app needs the READ_PHONE_STATE permission and it
returns IMEI
* Mac OSX > 10.5, it returns the serial number of the device
* Linux, it returns the serial number using lshw
* Windows, it reads and returns MachineGUID from regkey.
* **Android**: IMEI
* **Mac OSX**: Serial number of the device
* **Linux**: Serial number using lshw
* **Windows**: MachineGUID from regkey
.. note::
On Android your app needs the READ_PHONE_STATE permission
.. versionadded:: 1.2.0
'''
Expand All @@ -392,17 +398,17 @@ def _get_uid(self, **kwargs):


class Battery(object):
'''Battery info facade.
Returns a status dictionary with supported information.
If any of the fields is not readable, it is set as None.
'''
'''Battery info facade.'''

@property
def status(self):
'''Property that returns a dictionary with following keys:
- connected: Connected to power supply as a boolean
- percentage: Percentage charge remaining in float
'''Property that contains a dict with the following fields:
* **connected** *(bool)*: Whether to power supply
* **percentage** *(float)*: Battery charge remaining
.. warning::
If any of the fields is not readable, it is set as
None.
'''
return self.get_status()

Expand Down
13 changes: 8 additions & 5 deletions plyer/platforms/android/accelerometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
Sensor = autoclass('android.hardware.Sensor')
SensorManager = autoclass('android.hardware.SensorManager')


class AccelerometerSensorListener(PythonJavaClass):
__javainterfaces__ = ['android/hardware/SensorEventListener']

def __init__(self):
super(AccelerometerSensorListener, self).__init__()
self.SensorManager = cast('android.hardware.SensorManager',
self.SensorManager = cast('android.hardware.SensorManager',
activity.getSystemService(Context.SENSOR_SERVICE))
self.sensor = self.SensorManager.getDefaultSensor(
Sensor.TYPE_ACCELEROMETER)

self.values = [0, 0, 0]

def enable(self):
Expand All @@ -40,8 +41,9 @@ def onSensorChanged(self, event):

@java_method('(Landroid/hardware/Sensor;I)V')
def onAccuracyChanged(self, sensor, accuracy):
# Maybe, do something in future?
pass
# Maybe, do something in future?
pass


class AndroidAccelerometer(Accelerometer):
def __init__(self):
Expand All @@ -56,6 +58,7 @@ def _disable(self):

def _get_acceleration(self):
return tuple(self.listener.values)



def instance():
return AndroidAccelerometer()
10 changes: 6 additions & 4 deletions plyer/platforms/android/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
BatteryManager = autoclass('android.os.BatteryManager')
IntentFilter = autoclass('android.content.IntentFilter')


class AndroidBattery(Battery):
def _get_status(self):
status = {"connected": None, "percentage": None}

ifilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)

batteryStatus = cast('android.content.Intent',
batteryStatus = cast('android.content.Intent',
activity.registerReceiver(None, ifilter))

query = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1)
isCharging = (query == BatteryManager.BATTERY_STATUS_CHARGING or \
isCharging = (query == BatteryManager.BATTERY_STATUS_CHARGING or
query == BatteryManager.BATTERY_STATUS_FULL)

level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
Expand All @@ -27,6 +28,7 @@ def _get_status(self):
status['percentage'] = percentage

return status



def instance():
return AndroidBattery()
return AndroidBattery()
2 changes: 1 addition & 1 deletion plyer/platforms/android/camera.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import android
import android.activity
from os import unlink
Expand Down Expand Up @@ -39,5 +38,6 @@ def _unlink(self, fn):
except:
pass


def instance():
return AndroidCamera()
11 changes: 7 additions & 4 deletions plyer/platforms/android/compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
from jnius import PythonJavaClass, java_method, autoclass, cast
from plyer.platforms.android import activity


class MagneticFieldSensorListener(PythonJavaClass):
__javainterfaces__ = ['android/hardware/SensorEventListener']

def __init__(self):
super(MagneticFieldSensorListener, self).__init__()
self.SensorManager = cast('android.hardware.SensorManager',
self.SensorManager = cast('android.hardware.SensorManager',
activity.getSystemService(Context.SENSOR_SERVICE))
self.sensor = self.SensorManager.getDefaultSensor(
Sensor.TYPE_MAGNETIC_FIELD)

self.values = [0, 0, 0]

def enable(self):
Expand All @@ -36,8 +37,9 @@ def onSensorChanged(self, event):

@java_method('(Landroid/hardware/Sensor;I)V')
def onAccuracyChanged(self, sensor, accuracy):
# Maybe, do something in future?
pass
# Maybe, do something in future?
pass


class AndroidCompass(Compass):
def __init__(self):
Expand All @@ -53,5 +55,6 @@ def _disable(self):
def _get_orientation(self):
return tuple(self.listener.values)


def instance():
return AndroidCompass()
7 changes: 4 additions & 3 deletions plyer/platforms/android/gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def onStatusChanged(self, provider, status, extras):
elif status == 0x02:
s_status = 'available'
self.root.on_status('provider-status', '{}: {}'.format(
provider, s_status))
provider, s_status))


class AndroidGPS(GPS):

Expand All @@ -77,8 +78,8 @@ def _start(self):
for provider in providers:
self._location_manager.requestLocationUpdates(
"gps",
1000, # minTime, in milliseconds
1, # minDistance, in meters
1000, # minTime, in milliseconds
1, # minDistance, in meters
self._location_listener,
Looper.getMainLooper())

Expand Down
11 changes: 7 additions & 4 deletions plyer/platforms/android/gyroscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
Sensor = autoclass('android.hardware.Sensor')
SensorManager = autoclass('android.hardware.SensorManager')


class GyroscopeSensorListener(PythonJavaClass):
__javainterfaces__ = ['android/hardware/SensorEventListener']

def __init__(self):
super(GyroscopeSensorListener, self).__init__()
self.SensorManager = cast('android.hardware.SensorManager',
self.SensorManager = cast('android.hardware.SensorManager',
activity.getSystemService(Context.SENSOR_SERVICE))
self.sensor = self.SensorManager.getDefaultSensor(
Sensor.TYPE_GYROSCOPE)

self.values = [0, 0, 0]

def enable(self):
Expand All @@ -40,8 +41,9 @@ def onSensorChanged(self, event):

@java_method('(Landroid/hardware/Sensor;I)V')
def onAccuracyChanged(self, sensor, accuracy):
# Maybe, do something in future?
pass
# Maybe, do something in future?
pass


class AndroidGyroscope(Gyroscope):
def __init__(self):
Expand All @@ -57,5 +59,6 @@ def _disable(self):
def _get_orientation(self):
return tuple(self.listener.values)


def instance():
return AndroidGyroscope()
3 changes: 3 additions & 0 deletions plyer/platforms/android/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from plyer.facades import Sms

SmsManager = autoclass('android.telephony.SmsManager')


class AndroidSms(Sms):

def _send(self, **kwargs):
Expand All @@ -18,5 +20,6 @@ def _send(self, **kwargs):
if sms:
sms.sendTextMessage(recipient, None, message, None, None)


def instance():
return AndroidSms()
Loading

0 comments on commit c8b9632

Please sign in to comment.