def main(): v = appex.get_widget_view() global view view = ui.View(frame=(0, 0, 320, 64), name='StudyTimerWidget') sender = True viewHistory(sender) ''' label = ui.Label(frame=(0, 0, 320-44, 64), flex='wh', font=('HelveticaNeue-Light', 64), alignment=ui.ALIGN_CENTER, text='') label.name = 'timerLabel' view.add_subview(label) global studyButton studyButton = ui.Button(name='studyButton', image=ui.Image('iow:ios7_heart_outline_256'), flex='hl', tint_color='#ff2765', action=button_tapped) studyButton.frame = (320-100, 0, 64, 64) view.add_subview(studyButton) reset_btn = ui.Button(name='viewHistory', image=ui.Image('iow:ios7_heart_32'), flex='h', tint_color='#ff2765', action=refreshHistory) reset_btn.frame = (320-40, 0, 64, 64) view.add_subview(reset_btn) ''' appex.set_widget_view(view)
def main(): if not appex.is_widget(): print('This script must be run in the Pythonista Today widget (in Notification Center). You can configure the widget script in the settings.') return console.clear() v = appex.get_widget_view() # If the shortcuts change, change the view name as well, # so it is reloaded. view_name = 'Launcher_' + str(shortcuts) # Check if the launcher view already exists, if not, # create it, and set it as the widget's view. if not v or v.name != view_name: h = math.ceil(len(shortcuts) / 3) * 44 v = ui.View(frame=(0, 0, 300, h)) # Create a button for each shortcut for i, s in enumerate(shortcuts): btn = ui.Button(title=s['title']) btn.image = ui.Image.named(s['icon']) btn.frame = ((i % 3) * 100, (i // 3) * 44, 100, 44) btn.flex = 'LRWH' btn.tint_color = 'white' # Just store the shortcut URL in the button's name attribute. # This makes it easy to retrieve it in the button_tapped action. btn.name = s['url'] btn.action = button_tapped v.add_subview(btn) v.name = view_name appex.set_widget_view(v)
def main(): widget_name = __file__ + str(os.stat(__file__).st_mtime) v = appex.get_widget_view() # Optimization: Don't create a new view if the widget already shows the launcher. if v is None or v.name != widget_name: v = LauncherView(SHORTCUTS) v.name = widget_name appex.set_widget_view(v)
def main(): # Optimization: Don't create a new view if the widget already shows the calculator. widget_name = __file__ + str(os.stat(__file__).st_mtime) widget_view = appex.get_widget_view() if widget_view is None or widget_view.name != widget_name: widget_view = CalcView() widget_view.name = widget_name appex.set_widget_view(widget_view)
def main(): widget_name = __file__ + str(os.stat(__file__).st_mtime) v = appex.get_widget_view() if v is None or v.name != widget_name: NOTICES = crawling_notice() v = LauncherView(NOTICES) v.name = widget_name appex.set_widget_view(v)
def main(): # Get the current widget widget_name = __file__ + str(os.stat(__file__).st_mtime) v = appex.get_widget_view() # Only update the widget if the widget isn't displaying if v is None or v.name != widget_name: v = TimerView(COLS) v.name = widget_name appex.set_widget_view(v)
def main(): widget_name = __file__ + str(os.stat(__file__).st_mtime) widget_view = appex.get_widget_view() if widget_view is None or widget_view.name != widget_name: widget_view = ClockView() widget_view.name = widget_name appex.set_widget_view(widget_view) while True: widget_view.reload() time.sleep(1)
def main(): tl = todo_list() tv = ui.TextView(font=('Menlo', 16), alignment=ui.ALIGN_CENTER, editable=False, selectable=False) tv.text = '\n'.join(tl) tv.background_color = (0.85, 0.85, 0.85, 0.6) appex.set_widget_view(tv)
def view(self): view = ui.View() for i in range(len(self.data)): view.add_subview( ui.Label(font=('Menlo', 14), alignment=ui.ALIGN_CENTER, text=self.data[i], width=385, y=(15 * i))) appex.set_widget_view(view)
def main(): v = ui.View(frame=(0, 0, 320, 220)) label = ui.Label(frame=(8, 0, 320 - 44 - 8, 220), flex='wh') label.name = 'text_label' label.font = ('Menlo', 12) label.number_of_lines = 0 v.add_subview(label) clear_btn = ui.Button(frame=(320 - 44, 0, 44, 220), flex='hl') clear_btn.image = ui.Image.named('iow:ios7_trash_32') clear_btn.action = clear_button_tapped v.add_subview(clear_btn) appex.set_widget_view(v) text = clipboard.get() label.text = 'Clipboard:\n' + text
def main(): if appex.is_widget(): console.clear() v = appex.get_widget_view() # Check if the counter view already exists, if not, create it, # and set it as the widget's view. if not v or v.name != 'TallyCounter': v = make_widget_view() appex.set_widget_view(v) else: v = make_widget_view() v.name = 'Widget Preview' v.background_color = '#333' v.present('sheet')
def nansu(): url = 'https://ameblo.jp/natsukawashiinablog/' try: response = requests.get(url) response.encoding = 'UTF-8' html = BeautifulSoup(response.text, 'html5lib') new_title_html = html.find("a", {"class": "skinArticleTitle"}) new_title = re.sub(' |\n', '', str(new_title_html.string)) print(new_title) label = ui.Label(font=('Menlo', 20), alignment=ui.ALIGN_CENTER) label.text = '最新記事: ' + new_title appex.set_widget_view(label) except: pass
def main(): if appex.is_widget(): console.clear() v = appex.get_widget_view() # Check if the clipboard view already exists, if not, create it, # and set it as the widget's view. if not v or v.name != 'Clipboard': v = make_widget_view() appex.set_widget_view(v) else: v = make_widget_view() v.background_color = '#333' v.name = 'Widget Preview' v.present('sheet') v['text_label'].text = 'Clipboard: ' + (clipboard.get() or '(Empty)')
def main(): widget_name = __file__ + str(os.stat(__file__).st_mtime) v = appex.get_widget_view() # Optimization: Don't create a new view if the widget already shows the launcher. if v is None or v.name != widget_name: from utils import py_utils from core.ui2.ui_widget import LauncherView # load global configs MAIN_CONFIG = py_utils.load_config() # getter index page buttons v = LauncherView(MAIN_CONFIG) v.name = widget_name appex.set_widget_view(v)
def main(text): v = ui.View(frame=(0, 0, 320, 120)) label = ui.Label(frame=(20, 0, 320 - 44 - 30, 120), flex='wh') label.name = 'text_label' label.font = ('Menlo', 13) label.number_of_lines = 0 v.add_subview(label) clear_btn = ui.Button(frame=(320 - 44 - 10, 0, 44, 120), flex='hl') clear_btn.name = "clear_button" clear_btn.image = ui.Image.named('iow:clipboard_32') clear_btn.tint_color = "#000000" clear_btn.action = toClipButton v.add_subview(clear_btn) appex.set_widget_view(v) label.text = "正在生成分享链接…" label.text = 'Base 62: ' + text + "\n数字 ID: " + str( index(text)) + "\n微博国际版 URL: " + clearURL
def main(): kb = Keyboard() if appex.is_widget(): appex.set_widget_view(kb.root) else: kb.root.present("sheet") def read(self, size=-1): return kb.read(size) def readline(self): return kb.read() sys.stdin.__class__.read = read sys.stdin.__class__.readline = readline code.interact()
def main(): if appex.is_widget(): console.clear() label = appex.get_widget_view() # Check if the label already exists, if not, create it, # and set it as the widget's view. if not label or label.name != 'Dice': label = make_widget_view() appex.set_widget_view(label) else: label = make_widget_view() label.background_color = '#333' label.name = 'Widget Preview' label.present('sheet') # Roll two dice. a, b = randint(1, 6), randint(1, 6) # Update the label's text label.text = faces[a] + ' ' + faces[b]
def main(): # Optimization: Don't create a new view if the widget already shows the tally counter. widget_name = __file__ + str(os.stat(__file__).st_mtime) v = appex.get_widget_view() if v is not None and v.name == widget_name: return v = ui.View(frame=(0, 0, 320, 64), name=widget_name) label = ui.Label(frame=(0, 0, 320-44, 64), flex='wh', font=('HelveticaNeue-Light', 64), alignment=ui.ALIGN_CENTER, text=str(counter)) label.name = 'text_label' v.add_subview(label) minus_btn = ui.Button(name='-', image=ui.Image('iow:ios7_minus_outline_32'), flex='hl', tint_color='#666', action=button_tapped) minus_btn.frame = (320-128, 0, 64, 64) v.add_subview(minus_btn) plus_btn = ui.Button(name='+', image=ui.Image('iow:ios7_plus_outline_32'), flex='hl', tint_color='#666', action=button_tapped) plus_btn.frame = (320-64, 0, 64, 64) v.add_subview(plus_btn) reset_btn = ui.Button(name='reset', image=ui.Image('iow:ios7_skipbackward_outline_32'), flex='h', tint_color='#666', action=button_tapped) reset_btn.frame = (0, 0, 64, 64) v.add_subview(reset_btn) appex.set_widget_view(v)
def main(): # Optimization: Don't create a new view if the widget already shows the tally dataset. widget_name = __file__ + str(os.stat(__file__).st_mtime) v = appex.get_widget_view() if v is not None and v.name == widget_name: return v = ui.View(frame=(0, 0, 320, 96), name=widget_name) label = ui.Label(frame=(0, 32, 320, 64), flex='wh', font=('HelveticaNeue-Light', 24), alignment=ui.ALIGN_CENTER, text='Median: ' + str(calc_median()), line_break_mode=ui.LB_WORD_WRAP) label.name = 'text_label' v.add_subview(label) logout_btn = ui.Button(name='start', image=ui.Image('iow:log_out_32'), flex='hl', tint_color='#666', action=button_tapped) logout_btn.frame = (-32, 0, 32, 32) v.add_subview(logout_btn) home_btn = ui.Button(name='end', image=ui.Image('iow:log_in_32'), flex='hl', tint_color='#666', action=button_tapped) home_btn.frame = (320 - 64, 0, 32, 32) v.add_subview(home_btn) refresh_btn = ui.Button(name='refresh', image=ui.Image('iow:ios7_refresh_outline_32'), flex='hl', tint_color='#666', action=button_tapped) refresh_btn.frame = (320 - 112, 0, 32, 32) v.add_subview(refresh_btn) appex.set_widget_view(v)
def main(): v = Info() appex.set_widget_view(v)
This widget script shows a single button and a label. Tapping the button simulates a dice roll and shows the result in the label. ''' import appex, ui import random def roll_action(sender): symbols = ['\u2680', '\u2681', '\u2682', '\u2683', '\u2684', '\u2685'] dice = [random.randint(1, 6) for i in range(2)] dice_str = ''.join(symbols[i - 1] for i in dice) sender.superview['result_label'].text = dice_str v = ui.View(frame=(0, 0, 300, 110)) label = ui.Label(frame=(150, 0, 150, 110), flex='lwh', font=('<System>', 64), alignment=ui.ALIGN_CENTER, name='result_label') v.add_subview(label) button = ui.Button(title='Roll Dice!', font=('<System>', 24), flex='rwh', action=roll_action) button.frame = (0, 0, 150, 110) v.add_subview(button) appex.set_widget_view(v)
def main(): label = ui.View(frame=(0, 0, 320, 64)) helv_15 = ('HelveticaNeue-Light', 15) # TEMPERATURE label.add_subview( ui.Label(frame=(1, 0, 100, 0), flex='wh', font=helv_15, text_color='white', alignment=ui.ALIGN_LEFT, text='Temperature:' + str(info)[3:7] + '°')) # HUMIDITY label.add_subview( ui.Label(frame=(1, 0, 150, 32), flex='wh', font=helv_15, text_color='white', alignment=ui.ALIGN_LEFT, text='Humidity:' + str(info)[11:13] + '%')) # LIVING ROOM LIGHTS monla_15 = ('Monla', 15) living_title = ui.Label(frame=(320 - 135, 0, 130, -20), flex='wh', font=monla_15, alignment=ui.ALIGN_RIGHT, text_color='white', text='Living Room Lights') # GREETING (WIP) greet = 'hi' # LIVING ROOM BUTTONS plus_btn = ui.Button(name='+', image=ui.Image('iow:ios7_plus_outline_32'), flex='hl', tint_color='#666', action=button_tapped) plus_btn.frame = (320 - 64, 0, 64, 64) minus_btn = ui.Button(name='-', image=ui.Image('iow:ios7_minus_outline_32'), flex='hl', tint_color='#666', action=button_tapped) minus_btn.frame = (320 - 64, 0, -64, 64) if tem != ' -- ': label.add_subview(minus_btn) label.add_subview(plus_btn) label.add_subview(living_title) else: # GREETING label.add_subview( ui.Label(frame=(320 - 135, 0, 130, -20), flex='wh', text_color='white', font=monla_15, alignment=ui.ALIGN_RIGHT, text=greet)) # BATTERY if battery_percent >= 85: img = 'full' elif battery_percent >= 50: img = 'half' elif battery_percent >= 30: img = 'low' else: img = 'empty' bat = ui.Button(name='batteryl', flex='hl', tint_color='#00d500', image=ui.Image('iow:battery_{}_24'.format(img)), action=button_tapped) bat.frame = (320 - 30, 64, 32, 32) label.add_subview(bat) # BACKGROUND COLOR label.background_color = '#1a1a1a' # SETS WIDGET appex.set_widget_view(label)
self.statusText = '販売状況:' + self.status self.content = ui.Label() # self.content_status = ui.Label() self.btn = ui.Button(title=' RaktenMobile製品ページへ', name=URL, action=self.button_action, bg_color='#73c239', tint_color='#fff', corner_radius=7, font=('Arial Hebrew', 15)) self.bounds = (0, 0, 300, 100) self.add_subview(self.content) self.add_subview(self.btn) def button_action(self, sender): webbrowser.open(sender.name) def layout(self): self.bounds = (0, 0, 300, 150) self.content.font = ('Arial Hebrew', 18) self.content.text = self.productText self.content.bounds = (0, 0, 300, 90) self.content.center = (150, 45) self.btn.bounds = (0, 0, 300, 45) self.btn.center = (150, 100) if __name__ == '__main__': appex.set_widget_view(getProductInfo())
def main(): v = appex.get_widget_view() if v is not None and v.name == widget_name: return appex.set_widget_view(init_view())
import appex, ui import os import requests from datetime import datetime # Replace <addressHere> with your base58 or xpub address address = "<addressHere>" # Request blockchain.com API response = requests.get("https://blockchain.info/multiaddr?active=" + address) # Get transaction data data = response.json() final_balance = str(data['wallet']['final_balance'] * 10**-8) txTimeUnix = data['txs'][0]['time'] txTime = datetime.utcfromtimestamp(txTime).strftime('%Y-%m-%d %H:%M:%S') amount = str(data['txs'][0]['out'][0]['value']) # Create text label = ui.Label(font=('Menlo', 15), alignment=ui.ALIGN_NATURAL) label.number_of_lines = 0 label.text = 'Final balance: ' + final_balance + ' btc' + '\n' + 'Last transaction: ' + txTime + '\n' + 'Amount: ' + amount + ' sat' appex.set_widget_view(label)
self.jpy = 'JPY : ' + str(data['rates']['JPY']) return len(data['rates']) def __init__(self): self.desc = '' self.jpy = '' self.content = ui.Label() self.bounds = (0, 0, 300, 430) num = self.getExchangeRates() self.content.number_of_lines = num self.add_subview(self.content) def layout(self): if self.height >= 200: self.content.font = ('Arial Hebrew', 12) self.content.text = self.desc self.bounds = (0, 0, 300, 430) self.content.bounds = (0, 0, 300, 430) self.content.center = (150, 215) else: self.content.font = ('Arial Hebrew', 24) self.content.text = '為替レート\n\n' + self.jpy self.bounds = (0, 0, 300, 180) self.content.bounds = (0, 0, 300, 180) self.content.center = (150, 90) appex.set_widget_view(ExchangeRates())
import ui import os import xkcd import appex os.chdir(os.path.dirname(__file__)) width = 304 i = xkcd.get_comic(xkcd.get_info(xkcd.lat())['img']) v = ui.ImageView() v.flex = 'WH' v.height = width/(i.size[0]/i.size[1]) v.content_mode = ui.CONTENT_SCALE_ASPECT_FIT v.image = i appex.set_widget_view(v)
This widget script shows thumbnails of photos that were recently added to the photo library. Tapping the widget opens the Photos app. ''' import appex import ui import photos def widget_tapped(sender): import webbrowser webbrowser.open('photos-redirect://') album = photos.get_recently_added_album() if album: assets = album.assets[-6:] v = ui.View(frame=(0, 0, 300, 110)) for i, a in enumerate(reversed(assets)): img_view = ui.ImageView(frame=(8 + i * 90, 15, 80, 80), flex='tb') img_view.content_mode = ui.CONTENT_SCALE_ASPECT_FILL img_view.image = a.get_ui_image(size=(120, 120), crop=True) v.add_subview(img_view) tap_button = ui.Button(frame=v.bounds, flex='wh', action=widget_tapped) v.add_subview(tap_button) appex.set_widget_view(v) else: appex.set_widget_view(None) print('Cannot access photos')
def main(): pt = Pomotodo() hab = Habitica() if sys.platform != "ios": action = sys.argv[1] if action == "htp": habitica_to_pomotodo(hab, pt) elif action == "pth": pomotodo_to_habitica(pt, hab) else: print("action '%s" % action, "' not supported") exit() else: ''' A widget script that shows two buttons. One for syncing Habitica tasks to Pomotodo, the other for the reversed action. ''' import appex import ui def htp_btn_pressed(sender): sender.superview["status"].text = "Syncing…" habitica_to_pomotodo(hab, pt) sender.superview["status"].text = "Done" def pth_btn_pressed(sender): sender.superview["status"].text = "Syncing…" pomotodo_to_habitica(pt, hab) sender.superview["status"].text = "Done" v = ui.View(frame=(0, 0, 320, 220)) label_status = ui.Label(frame=(200, 50, 100, 150),flex='h') label_status.name = 'status' label_status.font = ('Menlo', 12) label_status.number_of_lines = 0 v.add_subview(label_status) label_status.text = "" htp_btn = ui.Button(frame=(10, 50, 150, 150),flex="hr") htp_btn.title = "Habitica ->" htp_btn.font = ('Menlo', 18) htp_btn.border_color = "slategray" htp_btn.border_width = 2 htp_btn.corner_radius = 6 htp_btn.action = htp_btn_pressed v.add_subview(htp_btn) pth_btn = ui.Button(frame=(160, 50, 150, 150),flex="hl") pth_btn.title = "<- Pomotodo" pth_btn.font = ('Menlo', 18) pth_btn.border_color = "slategray" pth_btn.border_width = 2 pth_btn.corner_radius = 6 pth_btn.action = pth_btn_pressed v.add_subview(pth_btn) appex.set_widget_view(v)
def switchDay(self, sender): # Get the SwitchView's currently selected index selectedIndex = sender.selected_index # Store a copy of the current week currentWeek = self.day[1] # Update the day variable with the new day and current week self.day = [self.dayList[selectedIndex], currentWeek] # Request for a new timetable to be generated with the new day parameters self.generateTimetable(self.timetable, self.day) def switchWeek(self, sender): # Get the SwitchView's currently selected index selectedIndex = sender.selected_index # Store a copy of the current week currentDay = self.day[0] # Update the day variable with the new day and current week self.day = [currentDay, self.weekList[selectedIndex]] # Request for a new timetable to be generated with the new day parameters self.generateTimetable(self.timetable, self.day) TT = timetableOutput(timetable, timings, 'Wednesday', "#ffffff", "#000000") # Set all of the UI element's actions to the class TT.view['btn_switch'].action = TT.switchText TT.view['seg_day'].action = TT.switchDay TT.view['seg_week'].action = TT.switchWeek appex.set_widget_view(TT.view)