def getFile(setter=None, base_dir='.'): fv = FileViewer(setter, base_dir) fv.height = 700 nv = ui.NavigationView(fv) def openDocuments(sender, path): def setme(fv, value): # set and bubble up setters fv.src.sel[0] = value if fv.src.setter is not None: fv.src.setter(value) newfv = FileViewer(setter=lambda value: setme(fv, value), base_dir=path) nv.push_view(newfv) nv.right_button_items = [ ui.ButtonItem(title='Documents', action=lambda sender: openDocuments( sender, os.path.expanduser('~/Documents'))), ui.ButtonItem( title='Library', action=lambda sender: openDocuments(sender, os.path.split(os.__file__)[0])) ] nv.height = 800 nv.width = 500 nv.name = 'File Selector' nv.present('popover') ui.in_background(nv.wait_modal) nv.wait_modal() return fv.src.sel[0]
def getFile(setter): fv = FileViewer(setter) nv = ui.NavigationView(fv) nv.name = 'File Selector' nv.present('popover') ui.in_background(nv.wait_modal) nv.wait_modal()
def textview_should_change(self, textview, range, replacement): keys = {u"÷": "insert_comment", u"π": "preview"} print replacement #print keys[replacement] if replacement in keys: ui.in_background(console.hud_alert(keys[replacement])) if replacement == u"π": preview(textview) if replacement == u"÷": self.insert_comment = True return False else: #print replacement text = textview.text bracket_open = "( { [ <".split() bracket_close = ") } ] >".split() #print bracket_open, bracket_close if range[0] > 0: last = text[range[0] - 1] #print "%r" % last if last in bracket_open: pass elif replacement == "\n": self.get_tabs_for_line(textview.text, textview.selected_range) return True
def textview_should_change(self, textview, range, replacement): keys = {u"÷": "insert_comment", u"π": "preview"} logger.debug(replacement) # print keys[replacement] if replacement in keys: ui.in_background(console.hud_alert(keys[replacement])) if replacement == u"π": preview(textview) if replacement == u"÷": self.insert_comment = True return False else: # print replacement text = textview.text bracket_open = "( { [ <".split() bracket_close = ") } ] >".split() # print bracket_open, bracket_close if range[0] > 0: last = text[range[0] - 1] # print "%r" % last if last in bracket_open: pass elif replacement == "\n": self.get_tabs_for_line(textview.text, textview.selected_range) return True
def getFile(setter=None,base_dir='.'): fv = FileViewer(setter,base_dir) fv.height=700 nv = ui.NavigationView(fv) def openDocuments(sender,path): def setme(fv,value): # set and bubble up setters fv.src.sel[0]=value if fv.src.setter is not None: fv.src.setter(value) newfv = FileViewer(setter=lambda value:setme(fv,value),base_dir=path) nv.push_view(newfv) nv.right_button_items=[ ui.ButtonItem(title='Documents', action=lambda sender:openDocuments(sender,os.path.expanduser('~/Documents'))), ui.ButtonItem(title='Library', action=lambda sender:openDocuments(sender,os.path.split(os.__file__)[0]))] nv.height=800 nv.width=500 nv.name = 'File Selector' nv.present('popover') ui.in_background(nv.wait_modal) nv.wait_modal() return fv.src.sel[0]
def getFile(setter=None, base_dir='.'): fv = FileViewer(setter, base_dir) fv.height = 700 nv = ui.NavigationView(fv) nv.height = 800 nv.name = 'File Selector' nv.present('popover') ui.in_background(nv.wait_modal) #nv.wait_modal() return fv.selection
def walkftp(ftp_inst, dirname): global ftp_files ftp_inst.cwd(dirname) for name in ftp_inst.nlst(ftp_inst.pwd()): path = os.path.join(ftp_inst.pwd(), name) try: ftp_inst.cwd(path) ftp_inst.cwd('..') ui.in_background(walkftp(ftp_inst, path)) except ftplib.error_perm: ftp_files.append(path)
def foreground(func): ui.in_background(func)()
textfield.text = self.username = username or self.read_username() self.add_subview(textfield) self.hidden = True self.width = self.height = min(ui.get_screen_size()) self.present('sheet') # somtimes it is good to be self-centered textfield.center = self.center self.hidden = False @classmethod def read_username(cls, filename=filename): username = None try: with open(filename) as in_file: for line in in_file.readlines(): username = line.strip() or username except IOError: pass return username or 'Player 1' def will_close(self): self.username = self['namefield'].text.strip() or self.username if self.username: with open(filename, 'w') as out_file: out_file.write(self.username) root_view = GetUsernameView() ui.in_background(root_view.wait_modal()) print(root_view.username)
textfield.text = self.username = username or self.read_username() self.add_subview(textfield) self.hidden = True self.present('sheet') # somtimes it is good to be self-centered textfield.center = self.center self.hidden = False @classmethod def read_username(cls, filename=filename): username = None try: with open(filename) as in_file: for line in in_file.readlines(): username = line.strip() or username except IOError: pass return username or 'Player 1' def will_close(self): self.username = self['namefield'].text.strip() or self.username if self.username: with open(filename, 'w') as out_file: out_file.write(self.username) root_view = GetUsernameView() ui.in_background(root_view.wait_modal()) print(root_view.username)
def fn(): self.worker_stack.append(threading.currentThread()) try: if type(input_) is list: lines = input_ elif input_ == self.stash.io: lines = self.stash.io.readline_no_block() else: lines = input_.splitlines() for line in lines: # Ignore empty lines if line.strip() == '': continue # Parse and expand the line (note this function returns a generator object) expanded = self.expander.expand(line) # The first member is the history expanded form and number of pipe_sequence newline, n_pipe_sequences = expanded.next() # Only add history entry if: # 1. It is explicitly required # 2. It is the first layer thread directly spawned by the main thread # and not explicitly required to not add if (add_to_history is None and len(self.worker_stack) == 1) or add_to_history: self.add_history(newline) # Subsequent members are actual commands for _ in range(n_pipe_sequences): self.save_state() # State needs to be saved before expansion happens try: pipe_sequence = expanded.next() if code_validation_func is None or code_validation_func(pipe_sequence): if pipe_sequence.in_background: ui.in_background(self.run_pipe_sequence)(pipe_sequence, final_ins=final_ins, final_outs=final_outs, final_errs=final_errs) else: self.run_pipe_sequence(pipe_sequence, final_ins=final_ins, final_outs=final_outs, final_errs=final_errs) finally: self.restore_state(persist_envars=persist_envars, persist_aliases=persist_aliases, persist_cwd=persist_cwd) except pp.ParseException as e: if self.debug: self.logger.debug('ParseException: %s\n' % repr(e)) self.stash.write_message('syntax error: at char %d: %s\n' % (e.loc, e.pstr)) except ShEventNotFound as e: if self.debug: self.logger.debug('%s\n' % repr(e)) self.stash.write_message('%s: event not found\n' % e.message) except ShBadSubstitution as e: if self.debug: self.logger.debug('%s\n' % repr(e)) self.stash.write_message('%s\n' % e.message) except ShInternalError as e: if self.debug: self.logger.debug('%s\n' % repr(e)) self.stash.write_message('%s\n' % e.message) except IOError as e: if self.debug: self.logger.debug('IOError: %s\n' % repr(e)) self.stash.write_message('%s: %s\n' % (e.filename, e.strerror)) except KeyboardInterrupt as e: self.stash.write_message('^C\nKeyboardInterrupt: %s\n' % e.message) # This catch all exception handler is to handle errors outside of # run_pipe_sequence. The traceback print is mainly for debugging # the shell itself as opposed to the running script (handled inside # exec_py_file) except Exception as e: etype, evalue, tb = sys.exc_info() if self.debug: self.logger.debug('Exception: %s\n' % repr(e)) self.stash.write_message('%s\n' % repr(e)) if self.py_traceback or self.py_pdb: import traceback traceback.print_exception(etype, evalue, tb) finally: if add_new_inp_line or (len(self.worker_stack) == 1 and add_new_inp_line is not False): self.script_will_end() self.worker_stack.pop() # remove itself from the stack