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

Plyer style guide update #145

Merged
merged 5 commits into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
improved styles in files
  • Loading branch information
andrzej.grymkowski committed May 14, 2015
commit 7646faad7ea365e90030718ac220bd4df9d8de50
10 changes: 7 additions & 3 deletions examples/accelerometer/basic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from plyer import accelerometer


class AccelerometerTest(BoxLayout):
def __init__(self):
super(AccelerometerTest, self).__init__()
Expand All @@ -30,17 +31,20 @@ def do_toggle(self):
self.sensorEnabled = False
self.ids.toggle_button.text = "Start Accelerometer"
except NotImplementedError:
import traceback; traceback.print_exc()
self.ids.accel_status.text = "Accelerometer is not implemented for your platform"
import traceback
traceback.print_exc()
status = "Accelerometer is not implemented for your platform"
self.ids.accel_status.text = status

def get_acceleration(self, dt):
val = accelerometer.acceleration[:3]

if(not val == (None, None, None)):
if not val == (None, None, None):
self.ids.x_label.text = "X: " + str(val[0])
self.ids.y_label.text = "Y: " + str(val[1])
self.ids.z_label.text = "Z: " + str(val[2])


class AccelerometerTestApp(App):
def build(self):
return AccelerometerTest()
Expand Down
20 changes: 11 additions & 9 deletions examples/compass/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
Compass example.
'''

from kivy.lang import Builder
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock

from plyer import compass

class compassTest(BoxLayout):

class CompassTest(BoxLayout):
def __init__(self):
super(compassTest, self).__init__()
super(CompassTest, self).__init__()
self.sensorEnabled = False

def do_toggle(self):
Expand All @@ -30,8 +29,10 @@ def do_toggle(self):
self.sensorEnabled = False
self.ids.toggle_button.text = "Start compass"
except NotImplementedError:
import traceback; traceback.print_exc()
self.ids.status.text = "Compass is not implemented for your platform"
import traceback
traceback.print_exc()
status = "Compass is not implemented for your platform"
self.ids.status.text = status

def get_readings(self, dt):
val = compass.orientation
Expand All @@ -40,9 +41,10 @@ def get_readings(self, dt):
self.ids.y_label.text = "Y: " + str(val[1])
self.ids.z_label.text = "Z: " + str(val[2])

class compassTestApp(App):

class CompassTestApp(App):
def build(self):
return compassTest()
return CompassTest()

if __name__ == '__main__':
compassTestApp().run()
CompassTestApp().run()
6 changes: 4 additions & 2 deletions examples/gps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

ToggleButton:
text: 'Start' if self.state == 'normal' else 'Stop'
on_state: app.gps.start() if self.state == 'down' else app.gps.stop()
on_state:
app.gps.start() if self.state == 'down' else app.gps.stop()
'''


Expand All @@ -45,7 +46,8 @@ def build(self):
self.gps.configure(on_location=self.on_location,
on_status=self.on_status)
except NotImplementedError:
import traceback; traceback.print_exc()
import traceback
traceback.print_exc()
self.gps_status = 'GPS is not implemented for your platform'

return Builder.load_string(kv)
Expand Down
2 changes: 2 additions & 0 deletions examples/sms/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
class SmsInterface(BoxLayout):
pass


class IntentButton(Button):
sms_recipient = StringProperty()
sms_message = StringProperty()

def send_sms(self, *args):
sms.send(recipient=self.sms_recipient, message=self.sms_message)


class SmsApp(App):
def build(self):
return SmsInterface()
Expand Down
5 changes: 3 additions & 2 deletions examples/text2speech/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
kivy.require('1.8.0')

from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup

from plyer import tts


class Text2SpeechDemo(BoxLayout):
def do_read(self):
try:
Expand All @@ -16,13 +16,14 @@ def do_read(self):
popup = ErrorPopup()
popup.open()


class Text2SpeechDemoApp(App):
def build(self):
return Text2SpeechDemo()


class ErrorPopup(Popup):
pass

if __name__ == '__main__':
Text2SpeechDemoApp().run()

8 changes: 5 additions & 3 deletions plyer/platforms/android/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _take_picture(self, on_complete, filename=None):
parcelable = cast('android.os.Parcelable', uri)
intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
activity.startActivityForResult(intent, 0x123)

def _take_video(self, on_complete, filename=None):
assert(on_complete is not None)
self.on_complete = on_complete
Expand All @@ -35,8 +35,10 @@ def _take_video(self, on_complete, filename=None):
uri = Uri.parse('file://' + filename)
parcelable = cast('android.os.Parcelable', uri)
intent.putExtra(MediaStore.EXTRA_OUTPUT, parcelable)
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1) #0 = low quality, suitable for MMS messages, 1 = high quality
#intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, X) #Optional, allows limiting record time to X seconds.

# 0 = low quality, suitable for MMS messages,
# 1 = high quality
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1)
activity.startActivityForResult(intent, 0x123)

def _on_activity_result(self, requestCode, resultCode, intent):
Expand Down
1 change: 1 addition & 0 deletions plyer/platforms/android/irblaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
else:
ir_manager = None


class AndroidIrBlaster(IrBlaster):
def _exists(self):
if ir_manager and ir_manager.hasIrEmitter():
Expand Down
2 changes: 1 addition & 1 deletion plyer/platforms/ios/gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _configure(self):

def _start(self):
self._location_manager.delegate = self

self._location_manager.requestWhenInUseAuthorization()
# NSLocationWhenInUseUsageDescription key must exist in Info.plist
# file. When the authorization prompt is displayed your app goes
Expand Down
102 changes: 57 additions & 45 deletions plyer/platforms/win/filechooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from plyer.facades import FileChooser
from win32com.shell import shell, shellcon
import os
import win32gui, win32con, pywintypes
import win32gui
import win32con
import pywintypes


class Win32FileChooser(object):
Expand Down Expand Up @@ -42,58 +44,68 @@ def __init__(self, **kwargs):

def run(self):
try:
if mode != "dir":
args = {}

if self.path:
args["InitialDir"] = os.path.dirname(self.path)
args["File"] = os.path.splitext(os.path.dirname(self.path))[0]
args["DefExt"] = os.path.splitext(os.path.dirname(self.path))[1]
args["Title"] = self.title if self.title else "Pick a file..."
args["CustomFilter"] = 'Other file types\x00*.*\x00'
args["FilterIndex"] = 1

filters = ""
for f in self.filters:
if type(f) == str:
filters += (f + "\x00") * 2
else:
filters += f[0] + "\x00" + ";".join(f[1:]) + "\x00"
args["Filter"] = filters

flags = win32con.OFN_EXTENSIONDIFFERENT | win32con.OFN_OVERWRITEPROMPT
return self._run()
except (RuntimeError, pywintypes.error):
return None

def _run(self):
if mode != "dir":
args = {}

if self.path:
args["InitialDir"] = os.path.dirname(self.path)
path = os.path.splitext(os.path.dirname(self.path))
args["File"] = path[0]
args["DefExt"] = path[1]
args["Title"] = self.title if self.title else "Pick a file..."
args["CustomFilter"] = 'Other file types\x00*.*\x00'
args["FilterIndex"] = 1

filters = ""
for f in self.filters:
if type(f) == str:
filters += (f + "\x00") * 2
else:
filters += f[0] + "\x00" + ";".join(f[1:]) + "\x00"
args["Filter"] = filters

flag_extension = win32con.OFN_EXTENSIONDIFFERENT
flag_overwriteprompt = win32con.OFN_OVERWRITEPROMPT
flags = flag_extension | flag_overwriteprompt
if self.multiple:
flags |= win32con.OFN_ALLOWmultiple | win32con.OFN_EXPLORER
if self.show_hidden:
flags |= win32con.OFN_FORCESHOWHIDDEN
args["Flags"] = flags

if self.mode == "open":
self.fname, _, _ = win32gui.GetOpenFileNameW(**args)
elif self.mode == "save":
self.fname, _, _ = win32gui.GetSaveFileNameW(**args)

if self.fname:
if self.multiple:
flags |= win32con.OFN_ALLOWmultiple | win32con.OFN_EXPLORER
if self.show_hidden:
flags |= win32con.OFN_FORCESHOWHIDDEN
args["Flags"] = flags

if self.mode == "open":
self.fname, self.customfilter, self.flags = win32gui.GetOpenFileNameW(**args)
elif self.mode == "save":
self.fname, self.customfilter, self.flags = win32gui.GetSaveFileNameW(**args)

if self.fname:
if self.multiple:
seq = str(self.fname).split("\x00")
dir_n, base_n = seq[0], seq[1:]
self.selection = [os.path.join(dir_n, i) for i in base_n]
else:
self.selection = str(self.fname).split("\x00")
else:
# From http://timgolden.me.uk/python/win32_how_do_i/browse-for-a-folder.html
pidl, display_name, image_list = shell.SHBrowseForFolder(
seq = str(self.fname).split("\x00")
dir_n, base_n = seq[0], seq[1:]
self.selection = [
os.path.join(dir_n, i) for i in base_n]
else:
self.selection = str(self.fname).split("\x00")
else:
# From
# http://goo.gl/UDqCqo
pidl, display_name, image_list = shell.SHBrowseForFolder(
win32gui.GetDesktopWindow(), None,
self.title if self.title else "Pick a folder...", 0, None, None)
self.selection = [str(shell.SHGetPathFromIDList (pidl))]
self.selection = [str(shell.SHGetPathFromIDList(pidl))]

return self.selection

return self.selection
except (RuntimeError, pywintypes.error):
return None

class WinFileChooser(FileChooser):
"""FileChooser implementation for Windows, using win3all.
"""

def _file_selection_dialog(self, **kwargs):
return Win32FileChooser(**kwargs).run()

Expand Down