Python源码示例:ui.in_background()

示例1
def show(self):
        """shows the view and starts a thread."""
        self.present(orientations=ORIENTATIONS)
        # launch a background thread
        # we can not use ui.in_background here
        # because some dialogs would not open anymoe
        thr = threading.Thread(target=self.show_messages)
        thr.daemon = True
        thr.start() 
示例2
def printLog():
   ### Pull the contents back into a string and close the stream
   global log_capture_string
   log_contents = log_capture_string.getvalue()
   log_capture_string.close()
   log_capture_string = StringIO()
   logger.handlers[0].stream=log_capture_string
   print(log_contents.lower())


## run a runction in an async thread.  better than ui.in_background for this application, because it is not queued up 
示例3
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]