当前位置: 首页>>代码示例>>Python>>正文


Python Scheduler.submit方法代码示例

本文整理汇总了Python中scheduler.Scheduler.submit方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler.submit方法的具体用法?Python Scheduler.submit怎么用?Python Scheduler.submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scheduler.Scheduler的用法示例。


在下文中一共展示了Scheduler.submit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DBPictureBox

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import submit [as 别名]

#.........这里部分代码省略.........

   #===========================================================================
   def free(self):
      ''' Explicitly frees all resources held by this object. '''
      self.__scheduler.shutdown(True) # blocks; safer even if gui locks a little
      self.__unknown_image.Dispose()
      self.__loading_image.Dispose()
      for image in self.__image_cache.values():
         image.Dispose()
      self.__image_cache = {}
      PictureBox.Dispose(self, True)
      

   #===========================================================================
   def set_image_ref(self, ref):
      '''
      Sets the image displayed in this picturebox to whatever image
      corresponds to the given ref (a SeriesRef or IssueRef) in the database.
      If the given value is None, or unavailable, a placeholder image gets used.
      '''
      
      self.__current_image_ref = ref
      if self.Visible:
         self.__update_image()
     
    
   #===========================================================================
   def __copy_transparent(self, image):
      ''' Creates a semi-transparent copy of the given image ''' 
      
      b = Bitmap( image.Width, image.Height )
      g = Graphics.FromImage(b)
      cm = ColorMatrix()
      cm.Matrix33 = 0.3
      ia = ImageAttributes()
      ia.SetColorMatrix(cm)
      g.DrawImage(image, Rectangle(0,0, image.Width, image.Height), 0,0,\
         image.Width, image.Height, GraphicsUnit.Pixel, ia)
      return b

   #===========================================================================
   def __update_image(self):
      '''
      Update the currently displayed image on this picturebox to match
      whatever image __current_image_ref pulls out of the database or cache.
      
      If the image is coming from the database, loading is done on separate
      worker thread, so as not to lock up the UI.
      '''
       
      # simple image setter that uses a blank image if 'image' is None 
      def switchimage( image ):
         if image: self.Image = image
         else: self.Image = self.__unknown_image
             
      ref = self.__current_image_ref
      
      # 1. if the ref is empty, switch to display an empty image
      if not ref and ref != 0:
         switchimage(None)
         
      # 2. if the ref is cached, switch to display the cached image
      elif ref in self.__image_cache:
         switchimage( self.__image_cache[ref] )
         
      # 3. if the ref is unkown, the hard part begins.  create a download "task"
      #    that downloads, caches, and then switches display to the needed 
      #    image.  then invoke this task asyncrhonously on the off-thread.
      else:
         self.Image = self.__loading_image
         def download_task():
            
            # 3a. load the image. 
            new_image = db.query_image(ref) # disposed later
               
            # 3b. now that we've loaded a new image, the following method is
            #     passed back to the gui thread and run to update our gui 
            def update_image():
               
               # if somehow the image we just loaded is already in the cache,
               # take it out and dispose it.  this should be rare.    
               if ref in self.__image_cache:
                  old_image = self.__image_cache[ref]
                  del self.__image_cache[ref]
                  if old_image:
                     old_image.Dispose()
               
               # cache the new image, so we never have to load it again
               if new_image:
                  self.__image_cache[ref] = new_image
               
               # if the __current_image_ref hasn't changed, switch this 
               # PictureBox to display that image.  otherwise, we already 
               # loading a new one, so don't do a pointless visual update.
               if ref == self.__current_image_ref:
                  switchimage(new_image)
                  
            utils.invoke(self, update_image, False) 
         self.__scheduler.submit(download_task)
         
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:103,代码来源:dbpicturebox.py

示例2: IssueCoverPanel

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import submit [as 别名]

#.........这里部分代码省略.........
      self.__setter_scheduler.shutdown(False)
      self.set_ref(None)
      self.__coverpanel.free()
      self.__prevbutton = None
      self.__nextbutton = None
      self.__label = None
      self.Dispose()


   # ==========================================================================
   def set_ref(self, ref):
      '''
      Sets the comic IssueRef or SeriesRef that this panel is displaying.
      'ref'-> the IssueRef or SeriesRef that we are displaying, or None.
      '''

      run_in_background = type(ref) == SeriesRef and self.__issue_num_hint_s       
      if run_in_background:
         # 1a. our ref is a SeriesRef.  use our issue num hint to try to convert
         #     it into an IssueRef.  use a simple cache to avoid requerying
         def maybe_convert_seriesref_to_issue_ref(ref):
            if not ref in self.__series_cache:
               issue_ref = db.query_issue_ref(ref, self.__issue_num_hint_s)
               self.__series_cache[ref] = issue_ref if issue_ref else ref
                  
            # 1b. go back to the application thread to do the actual ref change
            def change_ref():  
               self.__ref = self.__series_cache[ref]
               self.__update()
            utils.invoke(self.__coverpanel, change_ref, True)
            
         def dummy(): # I don't know why this is needed 
            maybe_convert_seriesref_to_issue_ref(ref)
         self.__setter_scheduler.submit(dummy)
         
      else:
         # 2. our ref is an IssueRef
         # we're already on the application thread, so just do the ref change 
         self.__ref = ref
         self.__update()
            

   # ==========================================================================
   def get_alt_issue_cover_choice(self):
      '''
      If the comic cover that this panel was displaying when it was closed was
      an alternate cover image (i.e. anything other than the default image 
      choice for an issue or series) then this method will return a tuple, with 
      the first element being the IssueRef (never a SeriesRef) for the 
      alternate image choice, and the second element being a string URL for 
      the alternate image itself.  
      
      If the chosen image was the default image anyway, or if the panel hasn't 
      been shutdown yet, we return None.
      '''
      return self.__alt_cover_choice

   # ==========================================================================
   def __update(self):
      '''
      Updates all elements of this control's GUI.  Should be called anytime 
      anything has changed that might require us to update the data displayed
      by any of our child controls (text labels, buttons, DBPictureBox, etc).  
      
      Note that this method call may initiate a background thread to update a 
      a ref's _ButtonModel based on a db query.
开发者ID:cbanack,项目名称:comic-vine-scraper,代码行数:70,代码来源:issuecoverpanel.py


注:本文中的scheduler.Scheduler.submit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。