Skip to content

Instantly share code, notes, and snippets.

@alessaba
Forked from jwt2d/gist:6120070
Last active December 20, 2015 18:08
Show Gist options
  • Save alessaba/6173177 to your computer and use it in GitHub Desktop.
Save alessaba/6173177 to your computer and use it in GitHub Desktop.
# Launcher
#
# A Simple Launcher in Notification Center
from scene import *
import webbrowser,console,notification
#----------Launcher Settings---------------
key_names = [[['GChrome','googlechrome:'],
['Keeper','keeper:']],
[['Calculator','calculatorinfinity:']],
[['Anote','awesomenote:'],
['Any.do','anydo:']],
[['Calendars+','calendars:'],
['Any.cal','cal:']],
[['Reeder','reeder:'],
['Yahoo','fb187737851251557:']],
[['','']]]
#----------Notification Settings-----------
delay=7
Nsound='Coin_5'
favourite_skype=['123456789','Josh'] #insert your favourite Skype friend number and name
favourite_whatsapp=['+39221333566','Jane'] #insert your favourite WhatsApp friend number and name
favourite_phone=['+393332244566','John'] #insert your favourite phone number and name
#-----------------------------
class Key (object):
def __init__(self, frame):
self.frame = frame
self.names = []
self.select = 0
self.touch = None
self.color = Color(1, 1, 1)
self.highlight_color = Color(0.9, 0.9, 0.9)
def hit_test(self, touch):
return touch.location in self.frame
class Launcher (Scene):
def setup(self):
self.open_default = True
self.keys = []
positions = range(6)
key_w = self.size.w
key_h = self.size.h / 6
for i in range(len(key_names)):
pos = positions[i]
key = Key(Rect(0, pos * key_h, key_w, key_h))
key.names = key_names[i]
Key.select = 0
self.keys.append(key)
self.delay(3,self.defaultopen)
def pause(self):
self.open_default = False
def defaultopen(self):
if self.open_default:
webbrowser.open('pythonista://')
return
def draw(self):
stroke_weight(1)
stroke(0.5, 0.5, 0.5)
for key in self.keys:
if len(key.names) == 1:
tint(0,0,0,1)
else:
tint(1,0,0,1)
fill(*key.color.as_tuple())
rect(*key.frame.as_tuple())
if len(key.names) == 1:
text(key.names[key.select][0],'Helvetica',30.0,key.frame.center().x,key.frame.center().y,5)
else:
text(key.names[0][0],'Helvetica',30.0,key.frame.left(),key.frame.center().y,6)
text(key.names[1][0],'Helvetica',30.0,key.frame.right(),key.frame.center().y,4)
def any_touch(self, touch):
for key in self.keys:
if key.hit_test(touch):
if touch.location.x > key.frame.center().x and len(key.names) > 1:
webbrowser.open(key.names[1][1])
else:
webbrowser.open(key.names[0][1])
return
def touch_began(self, touch):
self.any_touch(touch)
return
def touch_moved(self, touch):
self.any_touch(touch)
return
def touch_ended(self, touch):
self.any_touch(touch)
return
notification.cancel_all()
notification.schedule('Launch Phone',delay,Nsound,'tel://')
notification.schedule('Launch Whatsapp',delay,Nsound,'whatsapp://')
notification.schedule('Launch Skype',delay,Nsound,'skype://')
notification.schedule('Launch Reeder',delay,Nsound,'reeder:')
notification.schedule('Launch GMaps',delay,Nsound,'comgooglemaps:')
notification.schedule('Launch Twitter',delay,Nsound,'twitter:')
notification.schedule('Call '+favourite_phone[1],delay,Nsound,'tel://'+favourite_phone[0])
notification.schedule('Skype '+favourite_skype[1],delay,Nsound,'skype://'+favourite_skype[0])
notification.schedule('WhatsApp '+favourite_whatsapp[1],delay,Nsound,'whatsapp://'+favourite_whatsapp[0])
notification.schedule('Run Launcher',delay,Nsound,'pythonista://Launcher?action=run')
run(Launcher(), PORTRAIT,7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment