Python console.hud_alert() Examples
The following are 30
code examples of console.hud_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: ptinstaller.py From pythonista-scripts with MIT License | 6 votes |
def load(self): self.app.activity_indicator.start() try: self.categories_dict = self.app.repo.get_categories() categories_listdatasource = ui.ListDataSource( {'title': category_name, 'accessory_type': 'disclosure_indicator'} for category_name in sorted(self.categories_dict.keys()) ) categories_listdatasource.action = self.category_item_tapped categories_listdatasource.delete_enabled = False self.view.data_source = categories_listdatasource self.view.delegate = categories_listdatasource self.view.reload() except Exception as e: console.hud_alert('Failed to load Categories', 'error', 1.0) finally: self.app.activity_indicator.stop()
Example #3
Source File: CloudJump2.py From pythonista-scripts with MIT License | 6 votes |
def end_game(self): self.game_state = GAME_DEAD self.player.velocity = Point(0, 0) death_loc = self.player.frame.center() death_loc.y = max(death_loc.y, 80) self.player.die() del self.player self.player = None score = int(self.climb / 10) if self.high_scores.is_high_score(player_name, score): self.smoke_special.frame.center(death_loc) self.smoke_special.configure(frame_count=0, is_done=False) #console.hud_alert('New high score!') # for debugging purposes run_in_thread(high_score_sounds) fmt = 'Congratulations {}:\nYou have a new high score!' self.high_score_msg = fmt.format(player_name) else: self.smoke_normal.frame.center(death_loc) self.smoke_normal.configure(frame_count=0, is_done=False)
Example #4
Source File: gitui.py From pythonista-scripts with MIT License | 6 votes |
def did_select_repo(self,sender): self.g=self._get_repo() try: self.g.head except KeyError: def fixHEAD(sender): self._repo().refs.set_symbolic_ref('HEAD', 'refs/heads/'+branch) self.confirm(fixHEAD,'No HEAD found. set to master?') if self.g: r.view['branch'].text=self.g.active_branch author,author_email=self._get_last_committer() self.view['user'].text=author self.view['email'].text=author_email remote, remote_branch=self.remote_for_head() if not remote: remote=self.remotes_iterator().next() self.view['remote'].text=remote self.view['remotebranch'].text=remote_branch else: console.hud_alert('No repo found at {}. create new repo, or clone'.format(self.view['repo'].text)) r.view['branch'].text='' self.g=None self.refresh()
Example #5
Source File: futurize.py From blackmamba with MIT License | 6 votes |
def main(mock): import libfuturize.main path = editor.get_path() if not path or not path.endswith('.py'): console.hud_alert('Not a Python file', 'error') return tab.save() args = ['-1', '-n', '-w', '--all-imports', '--add-suffix', _SUFFIX, path] result = libfuturize.main.main(args) if result == 0 and _replace_file_content(path): console.hud_alert('Futurized') else: console.hud_alert('Failed to futurize', 'error')
Example #6
Source File: filebrowser.py From pythonista-scripts with MIT License | 6 votes |
def tableview_did_select(self, tableview, section, row): try: if os.path.isdir(self.files[row]): self.prev_path = os.path.abspath('.') os.chdir(self.files[row]) self.files= [] self.files.append('..') for file in os.listdir('.'): if self.filetypes == '*' or self.is_correct_file_type(file) or os.path.isdir(file): self.files.append(file) tableview.reload() else: self.cb(path=self.files[row]) except OSError : console.hud_alert('Not Allowed') os.chdir(self.prev_path) self.files= [] self.files.append('..') for file in os.listdir('.'): if self.filetypes == '*' or self.is_correct_file_type(file) or os.path.isdir(file): self.files.append(file) tableview.reload()
Example #7
Source File: importfinder.py From pythonista-scripts with MIT License | 6 votes |
def main(args): if args: name = args[0] else: sel = editor.get_selection() or "" seltxt = preformat(editor.get_text()[sel[0]:sel[1]]) if sel and sel[0] != sel[1] and is_valid_name(seltxt): name = seltxt else: name = console.input_alert("Find Module") try: loc = find_path(name) except ValueError: console.hud_alert(name + " is not a valid module name", "error") return if loc == "<built-in>": console.hud_alert(name + " is a built-in module", "error") elif loc == "<string>": console.hud_alert("Could not find module " + name, "error") else: editor.open_file(os.path.relpath(loc, DOCS))
Example #8
Source File: run_unit_tests.py From blackmamba with MIT License | 6 votes |
def _show_results(attrib, all_passed=True): x = { 'errors': 'errored', 'failures': 'failed', 'skips': 'skipped' } tests = int(attrib.get('tests', 0)) time = attrib.get('time', '?') messages = [] for k, v in x.items(): c = int(attrib.get(k, 0)) if c > 0: tests -= c messages.append('{} {}'.format(c, v)) messages.append('{} passed'.format(tests)) console.hud_alert( ', '.join(messages) + ' in {} seconds'.format(time), 'success' if all_passed else 'error', _hud_alert_delay())
Example #9
Source File: uidir.py From pythonista-scripts with MIT License | 6 votes |
def tableview_did_select(self, tableview, section, row): '@type tableview: ui.TableView' if section == 0: dir = os.path.normpath(os.path.join(self.dir, self.data[section][row])) if os.path.exists(dir): try: def setme(value): # set and bubble up setters self.sel[0]=value if self.setter is not None: self.setter(value) newv = FileViewer(setter=setme,base_dir=dir) nav = tableview.superview.navigation_view nav.push_view(newv) except StopIteration: console.hud_alert('Folder not accessible','error') else: # print self.dir, self.data[section][row] self.sel[0] = os.path.join(self.dir, self.data[section][row]) tableview.superview.navigation_view.close() if self.setter is not None: self.setter(self.sel[0])
Example #10
Source File: importfinder.py From pythonista-scripts with MIT License | 6 votes |
def main(args): if args: name = args[0] else: sel = editor.get_selection() or "" seltxt = preformat(editor.get_text()[sel[0]:sel[1]]) if sel and sel[0] != sel[1] and is_valid_name(seltxt): name = seltxt else: name = console.input_alert("Find Module") try: loc = find_path(name) except ValueError: console.hud_alert(name + " is not a valid module name", "error") return if loc == "<built-in>": console.hud_alert(name + " is a built-in module", "error") elif loc == "<string>": console.hud_alert("Could not find module " + name, "error") else: editor.open_file(os.path.relpath(loc, DOCS))
Example #11
Source File: gitui.py From pythonista-scripts with MIT License | 6 votes |
def pull(self): repo = self._get_repo() remote=self.view['remote'].text if remote in self.remotes_iterator(): uri=repo.remotes.get(remote,'') else: print remote, 'adding' uri=remote #Set the origin config = repo.repo.get_config() config.set(('remote','origin'),'url',uri) config.write_to_path() repo.pull(origin_uri=uri) console.hud_alert('pulled from ',remote) self.refresh()
Example #12
Source File: ptinstaller.py From pythonista-tools-installer with MIT License | 6 votes |
def load(self): self.app.activity_indicator.start() try: self.categories_dict = self.app.repo.get_categories() categories_listdatasource = ui.ListDataSource( {'title': category_name, 'accessory_type': 'disclosure_indicator'} for category_name in sorted(self.categories_dict.keys()) ) categories_listdatasource.action = self.category_item_tapped categories_listdatasource.delete_enabled = False self.view.data_source = categories_listdatasource self.view.delegate = categories_listdatasource self.view.reload() except Exception as e: console.hud_alert('Failed to load Categories', 'error', 1.0) finally: self.app.activity_indicator.stop()
Example #13
Source File: gitui.py From pythonista-scripts with MIT License | 5 votes |
def commit(self,sender): if list(itertools.chain(*porcelain.status(self.g.path).staged.itervalues())): self.g=self._get_repo() user=self.view['user'].text email=self.view['email'].text message=self.view['message'].text author = "{0} <{1}>".format(user, email) porcelain.commit(self.g.path,message,author,author) console.hud_alert('committed') self.view['message'].text='' self.refresh() else: console.hud_alert('nothing to commit!',icon='error')
Example #14
Source File: keyboard_example.py From pythonista-scripts with MIT License | 5 votes |
def notimplemented(sender): import console console.hud_alert('key action not implemented')
Example #15
Source File: uidir.py From pythonista-scripts with MIT License | 5 votes |
def tableview_accessory_button_tapped(self, tableview, section, row): full = os.path.join(self.dir,self.data[section][row]) stats = os.stat(full) console.hud_alert('Size: {0} KB'.format(stats.st_size//1024))
Example #16
Source File: TicTacToe.py From pythonista-scripts with MIT License | 5 votes |
def square_tapped(self, sender): sender.image = self.image_o if sender.image == self.image_x else self.image_x winner = self.winner_check() if winner: console.hud_alert('The winner is {}'.format(winner)) ui.delay(self.clear_all_squares, 1) self.computer_pick() winner = self.winner_check() if winner: console.hud_alert('The winner is {}'.format(winner)) ui.delay(self.clear_all_squares, 1)
Example #17
Source File: AreYouEnabledView.py From pythonista-scripts with MIT License | 5 votes |
def console_hud_alert(self, msg): console.hud_alert(msg)
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: gitui.py From pythonista-scripts with MIT License | 5 votes |
def init_repo_if_empty(self,repo_name): repopath=os.path.join(self.view['repo'].base,repo_name) self.g= Gittle.init(repopath,bare=False ) self.g.commit('name','email','initial commit') self.view['repo'].text=repo_name console.hud_alert('Repo {} created'.format(repo_name)) self.did_select_repo(self.view['repo'])
Example #20
Source File: ptinstaller.py From pythonista-scripts with MIT License | 5 votes |
def uninstall(self, btn, sender): target_folder = PythonistaToolsInstaller.get_target_folder(btn.category_name, btn.tool_name) if os.path.exists(target_folder): shutil.rmtree(target_folder) btn.set_state_install() console.hud_alert('%s uninstalled' % btn.tool_name, 'success', 1.0)
Example #21
Source File: gitui.py From pythonista-scripts with MIT License | 5 votes |
def unstage(self,repo,paths=None): from dulwich import porcelain from dulwich.index import index_entry_from_stat # if tree_entry does not exist, this was an add, so remove index entry to undo # if index_ entry does not exist, this was a remove.. add back in if paths: for path in paths: #print path full_path = os.path.join(repo.path, path) index=repo.open_index() tree_id=repo.object_store[repo.head()]._tree try: tree_entry=repo.object_store[tree_id]._entries[path] except KeyError: try: del(index[path]) index.write() except KeyError: console.hud_alert('file not in index...') return try: index_entry=list(index[path]) except KeyError: if os.path.exists(full_path): index_entry=list(index_entry_from_stat(posix.lstat(full_path),tree_entry[1] ,0 )) else: index_entry=[[0]*11,tree_entry[1],0] index_entry[4]=tree_entry[0] #mode index_entry[7]=len(repo.object_store [tree_entry[1]].data) #size index_entry[8]=tree_entry[1] #sha index_entry[0]=repo.object_store[repo.head()].commit_time #ctime index_entry[1]=repo.object_store[repo.head()].commit_time #mtime index[path]=index_entry index.write()
Example #22
Source File: gitui.py From pythonista-scripts with MIT License | 5 votes |
def branch_did_change(self,sender): # set head to branch repo=self._get_repo() branch=self.view['branch'].text if branch==repo.active_branch: return if branch in self.branch_iterator(): def switch_branch(): self._repo().refs.set_symbolic_ref('HEAD', 'refs/heads/'+branch) self.unstage_all() self.refresh() console.hud_alert('branch') if self.has_uncommitted_changes(): self.confirm(switch_branch,'WARNING: there are uncommitted changes. \ncontinue anyway?',self.revert_to_active_branch) elif branch in self._repo(): #sha indexfile = repo.repo.index_path() tree = repo.repo[str(branch)].tree def checkout_sha(sender): build_index_from_tree(repo.repo.path, indexfile, repo.repo.object_store, tree) self.refresh() console.hud_alert('SHA has been checked out into working tree. ') self.confirm(checkout_sha,'WARNING: this will \nerase all unstaged/untracked changes?',self.revert_to_active_branch) else: self.confirm(self.create_branch,'do you want to create a new branch? \n you will lose all unstaged/untracked files!!!!!',self.revert_to_active_branch)
Example #23
Source File: gitui.py From pythonista-scripts with MIT License | 5 votes |
def create_branch(self,dummy): #TODO: Add tracking as a parameter repo=self._get_repo() branch=self.view['branch'].text console.hud_alert( "Creating branch {0}".format(branch)) repo.create_branch(repo.active_branch, branch, tracking=None) #Recursive call to checkout the branch we just created self.checkout(self)
Example #24
Source File: gitui.py From pythonista-scripts with MIT License | 5 votes |
def clone(self,clonedict): remote=clonedict['remote url'] local=clonedict['local path'] repo_name= os.path.join(self.view['repo'].base, local) if not local: console.hud_alert('you must define a local path','error') return if remote and not remote=='https://github.com/': #for github urls, force it to end in .git if remote.find('github') and not remote.endswith('.git'): remote=remote+'.git' try: console.show_activity() repo = Gittle.clone(remote, repo_name, bare=False) console.hide_activity() #Set the origin config = repo.repo.get_config() config.set(('remote','origin'),'url',remote) config.write_to_path() self.view['repo'].text=local self.did_select_repo(self.view['repo']) console.hud_alert('clone successful') except urllib2.URLError: console.hud_alert('invalid remote url. check url and try again','error') except OSError: def overwrite(items): import shutil shutil.rmtree(os.path.join(repo_name,'.git')) self.clone(clonedict) def cancel(items): console.hud_alert('clone cancelled!','error') self.confirm(overwrite,'{} already has a .git folder. Overwrite?'.format(local),cancel) except: console.hud_alert('failed to clone. check traceback','error') raise else: console.hud_alert('You must specify a valid repo to clone','error')
Example #25
Source File: gitui.py From pythonista-scripts with MIT License | 5 votes |
def new_action(self,sender): def ok(somedict): reponame=somedict['repo name'] if reponame: self.init_repo(reponame) else: console.hud_alert('No repo created, name was blank!','error') d=UIDialog(root=self.view,title='Clone repo',items={'repo name':''},ok_action=ok)
Example #26
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 #27
Source File: save-text.py From pythonista-scripts with MIT License | 5 votes |
def main(): # get text from app share or clipboard if appex.is_running_extension(): text = appex.get_text() else: text = clipboard.get() # get file save info save_dir_name = get_save_dir() file_name = 'txt-{:%Y%m%d-%H%M%S}.txt'.format(datetime.datetime.now()) save_dir = os.path.join(BASE_DIR, save_dir_name) file_path = os.path.join(save_dir, file_name) # check dirs and save if not os.path.exists(save_dir ): os.makedirs(save_dir) with open(file_path, 'w') as f: f.write(text) f.close() # wrapup console.hud_alert('Saved to: ' + os.path.join(save_dir_name, file_name)) if appex.is_running_extension(): appex.finish() ###########################################
Example #28
Source File: md2html.py From pythonista-scripts with MIT License | 5 votes |
def main(): text = None label = 'Shared text' if appex.is_running_extension(): text = appex.get_text() if not text: try: import editor editor_file = editor.get_path() if editor_file: sel = console.alert('Editor or clipboard?', button1='Editor', button2='Clipboard') if sel == 1: editor_text = editor.get_text() sel_st, sel_end = editor.get_selection() label = os.path.basename(editor_file) if sel_end != sel_st: text = editor_text[sel_st:sel_end] elif editor_text: text = editor_text except ImportError: pass if not text: label = 'Clipboard' text = clipboard.get().strip() if text: converted = markdown(text) html = TEMPLATE.replace('{{CONTENT}}', converted) clip = console.alert('Replace clipboard?', button1='Yes', button2='No', hide_cancel_button=True) if clip ==1: clipboard.set(html) console.hud_alert('HTML copied to clipboard.') wv = MyWebView(name='Markdown - %s' % label) wv.load_html(html) wv.present('full_screen') else: console.hud_alert('No text found.') appex.finish()
Example #29
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 #30
Source File: find_usages.py From blackmamba with MIT License | 5 votes |
def main(): if not get_config_value('general.jedi', False): log.warn('find_usages disabled, you can enable it by setting general.jedi to True') return path = editor.get_path() if path is None: return if not path.endswith('.py'): return tab.save() text = editor.get_text() if not text: return line = source.get_line_number() column = source.get_column_index() if line is None or column is None: return script = jedi.api.Script(text, line, column, path) definitions = [ d for d in script.usages() if d.module_path and d.line ] if not definitions: console.hud_alert('Definition not found', 'error') return _select_location(definitions)