Changeset 81019b0


Ignore:
Timestamp:
05/28/11 18:15:50 (4 years ago)
Author:
xkolman2 <xkolman2@…>
Branches:
master
Children:
654689e
Parents:
1e30bc2
git-author:
xkolman2 <xkolman2@…> (05/28/11 18:15:50)
git-committer:
xkolman2 <xkolman2@…> (05/28/11 18:15:50)
Message:

use pango to make text in batch download menu look better :)
show how mach data was transfered during download

git-svn-id: https://nlp.fi.muni.cz/svn/gps_navigace/trunk@406 0858a4d0-ffff-46e5-938e-62b5ecb34222

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/mod_mapData.py

    rc210815 r81019b0  
    558558      self.retryInProgress = 0 
    559559 
    560       self.transfered = 0 
    561560      self.urlCount = len(neededTiles) 
    562561      self.finished = False 
     
    570569      self.downloaded = 0 # counter for downloaded tiles 
    571570      self.failedDownloads = [] 
     571      self.transfered = 0 
    572572 
    573573    def _resetCounts(self): 
     
    577577 
    578578    def getProgress(self): 
    579       return (self.processed, self.urlCount) 
     579      return (self.processed, self.urlCount, self.transfered, self.getFailedDownloadCount()) 
    580580 
    581581    def getFailedDownloads(self): 
     
    693693#            "BOOM"/2 
    694694 
    695           dl = self.saveTileForURL(item) 
     695          dlSize = self.saveTileForURL(item) 
    696696        except Exception, e: 
    697697          failed = True 
     
    704704          if failed: 
    705705            self.failedDownloads.append(item) 
    706           elif dl: 
     706          elif dlSize!=False: 
    707707            self.downloaded+=1 
     708            self.transfered+=dlSize 
    708709 
    709710    def saveTileForURL(self, tile): 
     
    717718        if not m.tileExists(filename, folderPrefix, z, x, y, layerType, fromThread = True): # if the file does not exist 
    718719          request = self.connPool.get_url(url) 
     720          size = int(request.getheaders()['content-length']) 
    719721          content = request.data 
    720722          """ 
     
    734736            # its not ana image, raise exception 
    735737            raise TileNotImageException() 
    736           return True # something was actually downloaded saved 
     738          return size # something was actually downloaded and saved 
    737739        else: 
    738740          return False # nothing was downloaded 
     
    892894      # * display information about download status 
    893895      getFilesText = self.getFilesText(getFilesThread) 
     896      sizeText = self.getSizeText(sizeThread) 
    894897      getFilesTextX = boxX + dx/8 
    895       getFilesTextY = boxY + boxH*1/4 
    896       self.showText(cr, getFilesText, getFilesTextX, getFilesTextY, w-dx/4, 40) 
    897  
    898       # * display information about size of the tiles 
    899       sizeText = self.getSizeText(sizeThread) 
    900       sizeTextX = boxX + dx/8 
    901       sizeTextY = boxY + boxH*2/4 
    902       self.showText(cr, sizeText, sizeTextX, sizeTextY, w-dx/4, 40) 
     898      getFilesTextY = boxY + boxH*1/10 
     899      menus.showText(cr, "%s\n\n%s" % (getFilesText, sizeText), getFilesTextX, getFilesTextY, w-dx/4, 40) 
     900 
     901#      # * display information about size of the tiles 
     902#      sizeTextX = boxX + dx/8 
     903#      sizeTextY = boxY + boxH*2/4 
     904#      menus.showText(cr, sizeText, sizeTextX, sizeTextY, w-dx/4, 40) 
    903905 
    904906      # * display information about free space available (for the filesystem with tilefolder) 
     
    906908      freeSpaceTextX = boxX + dx/8 
    907909      freeSpaceTextY = boxY + boxH * 3/4 
    908       self.showText(cr, freeSpaceText, freeSpaceTextX, freeSpaceTextY, w-dx/4, 40) 
     910      menus.showText(cr, freeSpaceText, freeSpaceTextX, freeSpaceTextY, w-dx/4, 40) 
    909911 
    910912    if menuName == 'chooseRouteForDl': 
     
    952954    if getFilesThread == None: 
    953955      if tileCount: 
    954         text = "Press Start to download ~ %d tiles." % tileCount 
     956        text = "Press <b>Start</b> to download ~ <b>%d</b> tiles." % tileCount 
    955957      else: 
    956958        text = "Download queue empty." 
    957959    else: 
    958       failedCount = getFilesThread.getFailedDownloadCount() 
     960      (currentTileCount, totalTileCount, BTotalTransfered, failedCount) = getFilesThread.getProgress() 
    959961      if getFilesThread.isAlive() == True: 
     962        MBTotalTransfered = BTotalTransfered/float(1048576) 
    960963        totalTileCount = getFilesThread.urlCount 
    961964        currentTileCount = getFilesThread.processed 
     
    965968        else: 
    966969          action = "Downloading" 
    967  
    968         text = "%s: %d of %d tiles done, %d failed" % (action, currentTileCount, totalTileCount, failedCount) 
     970           
     971        text = "<b>%s</b>: <b>%d</b> of <b>%d</b> tiles done\n\n<b>%1.2f MB</b> transfered, %d downloads failed" % (action, currentTileCount, totalTileCount, MBTotalTransfered, failedCount) 
    969972      elif getFilesThread.isAlive() == False: #TODO: send an alert that download is complete 
    970973        if getFilesThread.getDownloadCount(): 
    971974          # some downloads occured 
    972           text = "Download complete." 
     975          text = "<b>Download complete.</b>" 
    973976        else: 
    974977          # no downloads occured 
    975978          if failedCount: 
    976979            # no downloads + failed downloads 
    977             text = "Download of all tiles failed." 
     980            text = "<b>Download of all tiles failed.</b>" 
    978981          else: 
    979982            # no downalods and no failed downloads 
    980             text = "All tiles were locally available." 
     983            text = "<b>All tiles were locally available.</b>" 
    981984    return text 
    982985 
     
    987990      return "" 
    988991    if sizeThread == None: 
    989       return ("Total size of tiles is unknown (click to compute).") 
     992      return ("Total size of tiles is unknown (<i>click to compute</i>).") 
    990993    elif sizeThread.isAlive() == True: 
    991994      totalTileCount = sizeThread.urlCount 
    992995      currentTileCount = sizeThread.processed 
    993996      currentSize = sizeThread.totalSize/(1048576) # = 1024.0*1024.0 
    994       text = "Checking: %d of %d tiles complete(%1.0f MB)" % (currentTileCount, totalTileCount, currentSize) 
     997      text = "Checking: %d of %d tiles complete(<b>%1.0f MB</b>)" % (currentTileCount, totalTileCount, currentSize) 
    995998      return text 
    996999    elif sizeThread.isAlive() == False: 
     
    10081011    return text 
    10091012 
    1010  
    1011   def showText(self,cr,text,x,y,widthLimit=None,fontsize=40): 
    1012     if(text): 
    1013       cr.set_font_size(fontsize) 
    1014       stats = cr.text_extents(text) 
    1015       (textwidth, textheight) = stats[2:4] 
    1016  
    1017       if(widthLimit and textwidth > widthLimit): 
    1018         cr.set_font_size(fontsize * widthLimit / textwidth) 
    1019         stats = cr.text_extents(text) 
    1020         (textwidth, textheight) = stats[2:4] 
    1021  
    1022       cr.move_to(x, y+textheight) 
    1023       cr.show_text(text) 
    1024  
    1025   def sendMessage(self,message): 
    1026     m = self.m.get("messages", None) 
    1027     if(m != None): 
    1028       print "mapData: Sending message: " + message 
    1029       m.routeMessage(message) 
    1030     else: 
    1031       print "mapData: No message handler, cant send message." 
    1032  
    10331013  def stopSizeThreads(self): 
    10341014    if self.sizeThread: 
Note: See TracChangeset for help on using the changeset viewer.