Python console.alert() Examples
The following are 30
code examples of console.alert().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
console
, or try the search function
.
Example #1
Source File: drag_and_drop.py From blackmamba with MIT License | 7 votes |
def _drop_file(data_ptr, path): try: if os.path.exists(path): console.alert( '{} exists'.format(os.path.basename(path)), 'Do you want to replace existing file?', 'Replace' ) data = ObjCInstance(data_ptr) if not data.writeToFile_atomically_(ns(path), True): console.hud_alert('Failed to write file', 'error') return console.hud_alert('{} dropped'.format(os.path.basename(path))) except KeyboardInterrupt: pass
Example #2
Source File: OpenLocationinGoogleMaps.py From pythonista-scripts with MIT License | 6 votes |
def run(self, input=''): mapmodeparam = self.get_param_by_name('mapmode') viewsparam = self.get_param_by_name('viewmode') zoomparam = self.get_param_by_name('zoom') queryparam = self.get_param_by_name('query') url = 'comgooglemaps://?center={latitude},{longitude}'.format(**input.value) if mapmodeparam.value: url += '&mapmode='+ mapmodeparam.value if viewsparam.value: url += '&views=' + viewsparam.value if zoomparam.value: url += '&zoom=' + zoomparam.value if queryparam.value: url += '&q=' + queryparam.value uia = ObjCClass('UIApplication').sharedApplication() if not uia.openURL_(nsurl(url)): console.alert(title='Error oppening App',message='Is Google Maps app installed?',button1='Ok',hide_cancel_button=True) self.status = 'complete'
Example #3
Source File: PackUI.py From pythonista-scripts with MIT License | 6 votes |
def main(): import sys if len(sys.argv) > 1: # pack files specified via argv arg = ' '.join(sys.argv[1:]) try: pack(arg) except IOError as err: print("Failed to pack program: " + err.message) else: # display prompt for file import console msg = "Enter path (relative to current directory) of the application to be packaged, without .py or .pyui suffixes." arg = console.input_alert("Package UI Application", msg) try: pack(arg) except IOError as err: console.alert("Failed to pack", err.message) return msg = "Application was successfully packaged into {}.uipack.py!".format(arg) console.alert("Packaging Successful", msg, "OK", hide_cancel_button=True)
Example #4
Source File: AppendtoVariable.py From pythonista-scripts with MIT License | 6 votes |
def run(self, input=''): np = self.get_param_by_name('VariableName') name = np.value or console.input_alert('Please enter Variable name') rv = self.get_param_by_name('fm:runtime_variables') if not name in rv.value: rv.value[name] = None if rv.value[name] == None: rv.value[name] = copy.deepcopy(input) else: if input.type == rv.value[name].type: if not isinstance(rv.value[name].value,list): t = copy.deepcopy(rv.value[name].value) rv.value[name].value = [] rv.value[name].value.append(copy.deepcopy(t)) if input.isList: for i in input.value: rv.value[name].value.append(copy.deepcopy(i)) else: rv.value[name].value.append(copy.deepcopy(input.value)) else: console.alert('Error','Incorrect type to append to variable',button1='Ok',hide_cancel_button=True) self.status = 'complete'
Example #5
Source File: install.py From blackmamba with MIT License | 6 votes |
def _install(prerelease=False): release = _get_latest_release(prerelease) if not release: _error('Unable to find latest release') return _local_installation_exists(release) path = _download_release_zip(release) extracted_zip_dir = _extract_release(release, path) _move_to_site_packages(extracted_zip_dir) _save_release_info(release) _cleanup() _info('Black Mamba {} installed'.format(_get_version(release))) console.alert( 'Black Mamba {} Installed'.format(_get_version(release)), 'Pythonista RESTART is required for changes to take effect.', 'Got it!', hide_cancel_button=True )
Example #6
Source File: more.py From stash with MIT License | 6 votes |
def more(filenames, pagesize=10, clear=False, fmt='{line}'): '''Display content of filenames pagesize lines at a time (cleared if specified) with format fmt for each output line''' fileinput.close() # in case still open try: pageno = 1 if clear: clear_screen() for line in fileinput.input(filenames, openhook=fileinput.hook_encoded("utf-8")): lineno, filename, filelineno = fileinput.lineno(), fileinput.filename(), fileinput.filelineno() print(fmt.format(**locals()), end='') if pagesize and lineno % pagesize == 0: console.alert('Abort or continue', filename, 'Next page') # TODO: use less intrusive mechanism than alert pageno += 1 if clear: clear_screen() finally: fileinput.close() # --- main
Example #7
Source File: easy_config.py From stash with MIT License | 6 votes |
def tableview_did_select(self, tv, section, row): # deselect row tv.selected_row = (-1, -1) sn = SECTIONS[section] info = OPTIONS[sn][row] otype = info["type"] if otype == TYPE_LABEL: # show content console.alert(info.get("display_name", ""), info.get("value", ""), "Ok", hide_cancel_button=True) else: # show description console.alert( info.get("display_name", ""), info.get("description", "No description available."), "Ok", hide_cancel_button=True )
Example #8
Source File: easy_config.py From stash with MIT License | 6 votes |
def show_messages(self): """shows some warnings and tips.""" console.alert( "Info", "If StaSh does not launch anymore after you changed the config, run the 'launch_stash.py' script with \n'--no-cfgfile'.", "Ok", hide_cancel_button=True, ) while True: self.wait_modal() if not self.subview_open: break console.alert( "Info", "Some changes may only be visible after restarting StaSh and/or Pythonista.", "Ok", hide_cancel_button=True, ) # data source and delegate functions. see docs
Example #9
Source File: PackUI.py From pythonista-scripts with MIT License | 6 votes |
def main(): import sys if len(sys.argv) > 1: # pack files specified via argv arg = ' '.join(sys.argv[1:]) try: pack(arg) except IOError as err: print("Failed to pack program: " + err.message) else: # display prompt for file import console msg = "Enter path (relative to current directory) of the application to be packaged, without .py or .pyui suffixes." arg = console.input_alert("Package UI Application", msg) try: pack(arg) except IOError as err: console.alert("Failed to pack", err.message) return msg = "Application was successfully packaged into {}.uipack.py!".format(arg) console.alert("Packaging Successful", msg, "OK", hide_cancel_button=True)
Example #10
Source File: KeyboardControl.uipack.py From pythonista-scripts with MIT License | 6 votes |
def main(): if os.path.exists(NAME + ".py"): console.alert("Failed to Extract", NAME + ".py already exists.") return if os.path.exists(NAME + ".pyui"): console.alert("Failed to Extract", NAME + ".pyui already exists.") return with open(NAME + ".py", "w") as f: f.write(fix_quotes_out(PYFILE)) with open(NAME + ".pyui", "w") as f: f.write(fix_quotes_out(PYUIFILE)) msg = NAME + ".py and " + NAME + ".pyui were successfully extracted!" console.alert("Extraction Successful", msg, "OK", hide_cancel_button=True)
Example #11
Source File: Youtube-dl downloader.py From pythonista-youtubedl-downloader with Apache License 2.0 | 6 votes |
def update_youtubedl(sender): if os.path.exists(youtubedl_location+youtubedl_dir): msg = 'Are you sure you want to update youtubedl exists in site-packages and will be overwritten' if not console.alert('Continue',msg,'OK'): return console.show_activity('Downloading') file = downloadfile(youtubedl_downloadurl) console.show_activity('Extracting') process_file(file) console.show_activity('Moving') if os.path.exists(youtubedl_location+youtubedl_dir): shutil.rmtree(youtubedl_location+youtubedl_dir) shutil.move(youtubedl_unarchive_location+youtubedl_dir, youtubedl_location+youtubedl_dir) console.show_activity('Cleaning Up Download Files') shutil.rmtree(youtubedl_unarchive_location) os.remove(file) console.show_activity('Making youtube-dl friendly') process_youtubedl_for_pythonista() console.hide_activity()
Example #12
Source File: save-attachment.py From pythonista-scripts with MIT License | 5 votes |
def main(): if appex.is_running_extension(): content = None attachments = appex.get_attachments() filepaths = appex.get_file_path() if attachments and attachments[0].rstrip() and appex.get_file_path(): with open(attachments[0], 'r') as f: content = f.read() attachment_name = filepaths.split(os.sep)[-1] else: print('No attachment found.') sys.exit(1) sel = console.alert('Save: %s' % attachment_name, button1='File', button2='Clipboard') if sel == 1: file_name = '{:%Y%m%d-%H%M%S}_{}'.format(datetime.datetime.now(), attachment_name) save_dir_name = get_save_dir() save_dir_path = os.path.join(BASE_DIR, save_dir_name) save_file_rel_path = os.path.join(save_dir_name, file_name) save_file_path = os.path.join(BASE_DIR, save_file_rel_path) try: # check dirs and save if not os.path.exists(save_dir_path): os.makedirs(save_dir_path) with open(save_file_path, 'w') as f: f.write(content) # wrapup msg = 'Saved: %s' % save_file_rel_path except Exception as e: msg = str(e) console.alert(msg, button1='OK', hide_cancel_button=True) elif sel == 2: clipboard.set(content) if appex.is_running_extension(): appex.finish() ###########################################
Example #13
Source File: speak.py From pythonista-scripts with MIT License | 5 votes |
def main(): speech.stop() if not appex.is_running_extension(): console.hud_alert('Reading clipboard') text = clipboard.get() url = None else: text = appex.get_text() url = appex.get_url() if url == None: try: url = [ mgroups[0] for mgroups in GRUBER_URLINTEXT_PAT.findall(text) ][0] except: pass if url != None: console.hud_alert('Reading: ' + url) h = html2text.HTML2Text() try: r = requests.get( url=url, headers={"User-agent": "Mozilla/5.0{0:06}".format(random.randrange(999999))}) except requests.ConnectionError as e: console.alert('Unable to connect to url.') return True html_content = r.text.decode('utf-8') text = html2text.html2text(html_content) else: console.hud_alert('Reading text: ' + str(text)) if text: speech.say(text) stop = console.alert('Done?', hide_cancel_button=True, button1='OK') speech.stop() else: console.hud_alert('No text found.')
Example #14
Source File: main.py From pythonista-scripts with MIT License | 5 votes |
def get_info(sender): index = sender.tapped_accessory_row console.alert('How to Play', names[index]['info'], button1='Cool', hide_cancel_button=True)
Example #15
Source File: Youtube-dl downloader.py From pythonista-youtubedl-downloader with Apache License 2.0 | 5 votes |
def restore_youtubedl_backup(sender): if not os.path.isdir(backup_location) or not os.listdir(backup_location): console.alert('Nothing to do', 'No backups found to restore') else: folders = os.listdir(backup_location) folder = folders[len(folders)-1] shutil.move(backup_location+folder,youtubedl_location+youtubedl_dir) console.alert('Success','Successfully restored '+folder)
Example #16
Source File: ShowTableView.py From pythonista-scripts with MIT License | 5 votes |
def tv1_action(self, sender): info = sender.items[sender.selected_row] console.alert('info', '\n'.join(['{} = {}'.format(i, info[i]) for i in info]))
Example #17
Source File: AreYouEnabledView.py From pythonista-scripts with MIT License | 5 votes |
def console_alert(self, msg): console.alert(msg, 'console.alert')
Example #18
Source File: AreYouEnabledView.py From pythonista-scripts with MIT License | 5 votes |
def button_pressed(self, sender): user_text = self['user text'].text assert user_text # buttons will not be enabled if there is no text # method 4: using sender.name to decide how to respond if sender.name == 'alert': self.console_alert(user_text) elif sender.name == 'hud_alert': self.console_hud_alert(user_text) elif sender.name == 'popover': self.popover(user_text) elif sender.name == 'print': print(user_text) elif sender.name == 'say': speech.say(user_text) else: # this should never happen! print('button_pressed({})'.format(sender.name)) assert False # panic
Example #19
Source File: AreYouEnabledView.py From pythonista-scripts with MIT License | 5 votes |
def did_load(self): self['user text'].begin_editing() # place the focus on the field self.textfield_sensitive_buttons = 'alert hud_alert popover print say'.split() self.enable_buttons(False) self.set_actions()
Example #20
Source File: TexttoURL.py From pythonista-scripts with MIT License | 5 votes |
def run(self, input=''): stringUrl = input.value protoParam = self.get_param_by_name('protocol').value if not stringUrl: console.alert(title='Error',message='No url was given',button1='Ok',hide_cancel_button=True) return None if stringUrl[:len(protoParam)].find(protoParam) == -1: if not '//' in stringUrl: stringUrl = protoParam + stringUrl else: console.alert(title='Information',message='Url passed with incorrect protocol given',button1='Ok',hide_cancel_button=True) return ElementValue(type='url',value=stringUrl)
Example #21
Source File: url2md.py From pythonista-scripts with MIT License | 5 votes |
def main(): if appex.is_running_extension(): url = appex.get_url() if url == None: text = appex.get_text() url = [ mgroups[0] for mgroups in GRUBER_URLINTEXT_PAT.findall(text) ][0] else: text = clipboard.get().strip() url = [ mgroups[0] for mgroups in GRUBER_URLINTEXT_PAT.findall(text) ][0] if not "http" in url: url = "http://" try: url = console.input_alert("URL", "", url) except: return True console.hud_alert('URL: %s' % url) h = html2text.HTML2Text() try: r = requests.get( url=url, headers={"User-agent": "Mozilla/5.0{0:06}".format(random.randrange(999999))} ) except Exception as e: raise(e.message) return True html_content = r.text.decode('utf-8') rendered_content = html2text.html2text(html_content) clipboard.set(rendered_content) launch_e = console.alert('Markdown copied to clipboard. Launch Evernote?', button1='Yes', button2='No', hide_cancel_button=True) if launch_e ==1: _eurl = "evernote://x-callback-url/new-note?type=clipboard&title=DRAFT&text=" app=UIApplication.sharedApplication() eurl=nsurl(_eurl) app.openURL_(eurl) appex.finish()
Example #22
Source File: GetImagesfromAppextension.py From pythonista-scripts with MIT License | 5 votes |
def run(self, input=''): console.alert(title='Not complete', message='Does not work',button1='Ok',hide_cancel_button=True) if not appex.is_running_extension(): console.alert(title='Error', message='Not running from app extension',button1='Ok',hide_cancel_button=True) else: try: allowMultiple = self.get_param_by_name('allowMultiple').value if allowMultiple: images = appex.get_images() else: images = appex.get_image() ev = ElementValue(type='image',value=images) return ev except error: console.alert(title='Error', message='error: {}'.format(error),button1='Ok',hide_cancel_button=True)
Example #23
Source File: GetURLContents.py From pythonista-scripts with MIT License | 5 votes |
def run(self, input=''): verbParam = self.get_param_by_name('verb') paramsParam = self.get_param_by_name('params') if verbParam.value == 'GET': if paramsParam.value == None: r = requests.get(input.value) else: r = requests.get(input.value, params=paramsParam.value) elif verbParam.value == 'POST': if paramsParam.value == None: r = requests.post(input.value) else: r = requests.get(input.value, data=paramsParam.value) elif verbParam.value == 'PUT': r = requests.put(input.value) elif verbParam.value == 'DELETE': r = requests.delete(input.value) self.status = 'complete' if r.status_code == 200: type = r.headers['content-type'].split('/')[0] value = Image.open(StringIO(r.content)) if type == 'image' else r.text return ElementValue(type=type, value=value) else: console.alert(title='Error',message=r.status_code,button1='Ok',hide_cancel_button=True) return ElementValue(type=None, value=None)
Example #24
Source File: SaveImagetoCameraRoll.py From pythonista-scripts with MIT License | 5 votes |
def run(self, input): try: if not photos.save_image(input.value): console.alert("didn't work") except error: console.alert('error: {}'.format(error)) self.status = 'complete'
Example #25
Source File: ShowAlert.py From pythonista-scripts with MIT License | 5 votes |
def run(self, input): self.status = 'complete' input = str(input.value) title = __file__.rpartition('/')[2].partition('.')[0] or 'Message' console.alert(title=title, message=input, button1='Ok', hide_cancel_button=True)
Example #26
Source File: ShowAlert.py From pythonista-scripts with MIT License | 5 votes |
def get_description(self): return "This show an alert from the string that is in the input parameter"
Example #27
Source File: istaflow.py From pythonista-scripts with MIT License | 5 votes |
def runflow(self,sender): try: self.flow_creation_view.reload() ret, message= self.flow_manager.run_flow(self.selectedElements,self.navigation_view, self.selectedFlowType) if ret: console.alert(title='Complete',message=message,button1='Ok',hide_cancel_button=True) else: console.alert(title='Error',message=message,button1='Ok',hide_cancel_button=True) except ValueError, e: console.alert(str(e))
Example #28
Source File: istaflow.py From pythonista-scripts with MIT License | 5 votes |
def saveflow(self,sender): if self.flow_creation_view.data_source.title == '': console.alert(title='Error',message='Please enter a title',button1='Ok',hide_cancel_button=True) else: self.selectedFlowType = self.flow_creation_view.data_source.flowType self.flow_manager.save_flow(self.flow_creation_view.data_source.title, self.selectedElements, self.selectedFlowType) console.alert(title='Success',message='Flow has been saved',button1='Ok',hide_cancel_button=True) self.get_flows(appex.is_running_extension()) self.flow_view.data_source.flows = self.flows self.flow_view.reload_data()
Example #29
Source File: install.py From blackmamba with MIT License | 5 votes |
def _local_installation_exists(release): _info('Checking Black Mamba installation...') if os.path.islink(_TARGET_DIR): _terminate('Skipping, Black Mamba symlinked to site-packages-3') local_version = None try: import blackmamba local_version = blackmamba.__version__ _info('Black Mamba {} installed'.format(local_version)) except ImportError: _info('Black Mamba not installed') if local_version is not None: remote_version = _get_version(release) try: if remote_version == local_version: console.alert( 'Black Mamba Installer', 'Black Mamba {} installed. Do you want to replace it with {}?'.format(local_version, remote_version), 'Replace' ) else: console.alert( 'Black Mamba Installer', 'Black Mamba {} installed. Do you want to update it to {}?'.format(local_version, remote_version), 'Update' ) except KeyboardInterrupt: _terminate('Cancelling installation on user request')
Example #30
Source File: drag_and_drop.py From blackmamba with MIT License | 5 votes |
def _drop_folder(data_ptr, path): try: if os.path.exists(path): console.alert( '{} exists'.format(os.path.basename(path)), 'Do you want to replace existing {}?'.format( 'folder' if os.path.isdir(path) else 'file' ), 'Replace' ) if os.path.isfile(path): os.remove(path) else: shutil.rmtree(path) data = ObjCInstance(data_ptr) zip_data = io.BytesIO(ctypes.string_at(data.bytes(), data.length())) zf = zipfile.ZipFile(zip_data) corrupted_file = zf.testzip() if corrupted_file: console.hud_alert('Corrupted ZIP file', 'error') zf.extractall(os.path.dirname(path)) _datasource.reload_path(os.path.dirname(path)) console.hud_alert('{} dropped'.format(os.path.basename(path))) except KeyboardInterrupt: pass