예제 #1
0
 def display(self, data):
   """pushes data into our local cache of infos and also gets the length of the longest torrent info string"""
   if not data:
     return
   self.torrents = {'torrents':[], 'maxLength': 0}
   maxLength = 0
   for x in data:
     ( name, status, progress, peers, seeds, seedsmsg, dist,
       uprate, dnrate, upamt, dnamt, size, t, msg, hash, knownSeeds, knownPeers ) = x
     
     progress = float(progress.replace("%", ""))
     progressMsg = "%.0f" % (progress)
     pathname, filename = os.path.split(name)
     #TODO: do this better (truncate the name)
     if len(filename) > 14:
       filename = filename[:10] + '... '
     dist = "%.3f" % (dist*1000)
     uprate = Format.bytes_per_second(uprate)
     dnrate = Format.bytes_per_second(dnrate)
     upamt = Format.format_bytes(upamt)
     dnamt = Format.format_bytes(dnamt)
     s = '%s-> P: (%s)%s | S: (%s)%s | D: %s (%s) | U: %s (%s) | %s%%'%\
     (filename, peers, knownPeers, seeds, knownSeeds, dnamt, dnrate, upamt, uprate, progress)
     if len(s) > maxLength:
       maxLength = len(s)
     self.torrents['torrents'].append(s)
   self.torrents['maxLength'] = maxLength
   return False
예제 #2
0
    def display(self, data):
        """pushes data into our local cache of infos and also gets the length of the longest torrent info string"""
        if not data:
            return
        self.torrents = {'torrents': [], 'maxLength': 0}
        maxLength = 0
        for x in data:
            (name, status, progress, peers, seeds, seedsmsg, dist, uprate,
             dnrate, upamt, dnamt, size, t, msg, hash, knownSeeds,
             knownPeers) = x

            progress = float(progress.replace("%", ""))
            progressMsg = "%.0f" % (progress)
            pathname, filename = os.path.split(name)
            #TODO: do this better (truncate the name)
            if len(filename) > 14:
                filename = filename[:10] + '... '
            dist = "%.3f" % (dist * 1000)
            uprate = Format.bytes_per_second(uprate)
            dnrate = Format.bytes_per_second(dnrate)
            upamt = Format.format_bytes(upamt)
            dnamt = Format.format_bytes(dnamt)
            s = '%s-> P: (%s)%s | S: (%s)%s | D: %s (%s) | U: %s (%s) | %s%%'%\
            (filename, peers, knownPeers, seeds, knownSeeds, dnamt, dnrate, upamt, uprate, progress)
            if len(s) > maxLength:
                maxLength = len(s)
            self.torrents['torrents'].append(s)
        self.torrents['maxLength'] = maxLength
        return False
예제 #3
0
 def get_app_info(self):
   appInfos = []
   #for all socks applications:
   for app in self.applications.values():
     #ignore those that are not running
     if not app.is_running():
       continue
     #collect the necessary data
     down, up = app.get_instant_bw()
     uprate = Format.bytes_per_second(up)
     dnrate = Format.bytes_per_second(down)
     numHops = app.pathLength
     numCoins = app.coinsSpent
     appInfos.append((app.name, numHops, dnrate, uprate, numCoins))
   return appInfos
예제 #4
0
 def update(self, globalDownRate, globalUpRate, globalDownAmount, globalUpAmount):
   if self.btApp.is_ready():
     try:
       nodes = self.btApp.btInstance.dht.get_dht_peers()
     except:
       nodes = ("unknown", "disabled")
     self.dhtText.set_markup('<span>DHT Nodes:  %s (%s)</span>' % nodes)
   globalDownRate = Format.bytes_per_second(globalDownRate)
   globalDownAmount = Format.format_bytes(globalDownAmount)
   self.downText.set_markup('<span>U:  %s  %s</span>' % (globalDownRate, globalDownAmount))
   globalUpRate = Format.bytes_per_second(globalUpRate)
   globalUpAmount = Format.format_bytes(globalUpAmount)
   self.upText.set_markup('<span>D:  %s  %s</span>' % (globalUpRate, globalUpAmount))
   credits = Bank.get().get_total_asset_value()
   self.creditText.set_markup('<span>Credits:  %s (%s)</span>' % (credits, Format.convert_to_gb(credits)))
예제 #5
0
 def get_app_info(self):
     appInfos = []
     #for all socks applications:
     for app in self.applications.values():
         #ignore those that are not running
         if not app.is_running():
             continue
         #collect the necessary data
         down, up = app.get_instant_bw()
         uprate = Format.bytes_per_second(up)
         dnrate = Format.bytes_per_second(down)
         numHops = app.pathLength
         numCoins = app.coinsSpent
         appInfos.append((app.name, numHops, dnrate, uprate, numCoins))
     return appInfos
예제 #6
0
  def __init__(self, controller):
    buttons = (gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO, gtk.RESPONSE_NO)
    dia = gtk.Dialog("Credits Low", None, 0, buttons)
    self.controller = controller
    
    vbox = gtk.VBox()
    
    title = gtk.Label()
    markup = "<span size='large' weight='bold'>You Are Running out of Credits</span>"
    title.set_markup(markup)
    title.set_justify(gtk.JUSTIFY_CENTER)
    vbox.pack_start(title, True, False, 0)
    
    #A text entry telling the user what to do:
    balance = Bank.get().get_expected_balance()
    balanceGB = Format.convert_to_gb(balance)
    label = gtk.Label()
    text = "You only have %s (%s) credits remaining.  You must set up a relay to gain more credits.  \
This will allow other users to send traffic via your computer.\n\nWould you like to set up a relay now?" % (balance, balanceGB)
    label.set_markup(text)
    label.set_line_wrap(True)
    vbox.pack_start(label, True, True, 5)
    
    #if we should always check:
    self.askAboutRelay = gtk.CheckButton("Always ask about help setting up relay")
    vbox.pack_start(self.askAboutRelay, True, True, 10)
    #initialize the checkbox:
    self.askAboutRelay.set_active(CoreSettings.get().askAboutRelay)

    vbox = GTKUtils.add_padding(vbox, 5)
    dia.vbox.pack_start(vbox, True, True, 0)
    dia.connect("response", self.on_response)
    self.dia = dia
    #start the dialog
    dia.show_all()
예제 #7
0
 def update(self, globalDownRate, globalUpRate, globalDownAmount,
            globalUpAmount):
     if self.btApp.is_ready():
         try:
             nodes = self.btApp.btInstance.dht.get_dht_peers()
         except:
             nodes = ("unknown", "disabled")
         self.dhtText.set_markup('<span>DHT Nodes:  %s (%s)</span>' % nodes)
     globalDownRate = Format.bytes_per_second(globalDownRate)
     globalDownAmount = Format.format_bytes(globalDownAmount)
     self.downText.set_markup('<span>U:  %s  %s</span>' %
                              (globalDownRate, globalDownAmount))
     globalUpRate = Format.bytes_per_second(globalUpRate)
     globalUpAmount = Format.format_bytes(globalUpAmount)
     self.upText.set_markup('<span>D:  %s  %s</span>' %
                            (globalUpRate, globalUpAmount))
     credits = Bank.get().get_total_asset_value()
     self.creditText.set_markup('<span>Credits:  %s (%s)</span>' %
                                (credits, Format.convert_to_gb(credits)))
예제 #8
0
    def on_update(self):
        """updates the gui via pulling infos out of tor and the bank-
    slow, stupid, and easy"""
        # don't do updates if we arent visible
        if not GTKUtils.is_visible(self.container):
            return

        configuredAsRelay = self.torApp.is_server()
        if configuredAsRelay:
            self.relayRow.update_row_image(True)
        else:
            self.relayRow.reset_row_image()

        relayStatus, relayStateString = self.torApp.get_relay_status()
        if self.torApp.is_server():
            self.statusRow.update_row_image(relayStatus)
        else:
            self.statusRow.reset_row_image()
        self.statusRow.widget.set_markup('<span size="large">%s</span>' % (relayStateString))

        # update as appropriate for rows when we are trying to be a relay
        if configuredAsRelay:
            boolToStringMapping = {True: "is reachable", False: "is unreachable", None: "testing..."}
            # do updates where we have the info
            relayPortsState = self.torApp.get_all_port_status()
            for row in self.statusRows:
                updateForGUIPort = row.rowName in relayPortsState
                if updateForGUIPort:
                    port = relayPortsState[row.rowName]
                    row.update_row_image(port[0])
                    statusText = boolToStringMapping[port[0]]
                    row.widget.set_markup('<span size="large">%s %s</span>' % (port[1], statusText))
        # else, null  everything out
        else:
            for row in [self.udpRelayPortRow, self.tcpRelayPortRow, self.dirPortRow, self.statusRow]:
                row.reset_row_image()
                row.widget.set_markup('<span size="large">offline</span>')

        # update the balance
        bank = Bank.get()
        if not bank:
            return
        credits = bank.get_expected_balance()
        if not credits:
            return
        self.creditsRow.widget.set_markup(
            '<span size="large">%s  (%s)</span>' % (credits, Format.convert_to_gb(credits))
        )
        if credits > 200:
            creditState = True
        elif credits > 100:
            creditState = None
        else:
            creditState = False
        self.creditsRow.update_row_image(creditState)
예제 #9
0
 def __init__(self, btApp, maggicPadding):
   gtk.Frame.__init__(self)
   #bottom row
   self.btApp = btApp
   row = gtk.HBox()
   self.dhtText = gtk.Label('')
   self.dhtText.set_markup('<span size="large">DHT Nodes:  0 (0)</span>')
   self.upText = gtk.Label('')
   initialInfos = (Format.bytes_per_second(0), Format.format_bytes(0))
   self.upText.set_markup('<span size="large">D: %s  %s</span>' % initialInfos)
   self.downText = gtk.Label('')
   self.downText.set_markup('<span size="large">U: %s  %s</span>' % initialInfos)
   self.creditText = gtk.Label('')
   self.creditText.set_markup('<span size="large">Credits: Unknown</span>')
   for item in [self.dhtText, self.upText, self.downText]:
     row.pack_start(item, True, True, 0)
     row.pack_start(gtk.VSeparator(), False, False, 0)
   row.pack_start(self.creditText, True, True, 0)
   self.set_shadow_type(gtk.SHADOW_IN)
   self.add(row)
예제 #10
0
 def on_update(self):
   """updates the gui via pulling infos out of tor and the bank-
   slow, stupid, and easy"""
   #don't do updates if we arent visible
   if not GTKUtils.is_visible(self.container):
     return
   
   configuredAsRelay = self.torApp.is_server()
   if configuredAsRelay:
     self.relayRow.update_row_image(True)
   else:
     self.relayRow.reset_row_image()
   
   relayStatus, relayStateString = self.torApp.get_relay_status()
   if self.torApp.is_server():
     self.statusRow.update_row_image(relayStatus)
   else:
     self.statusRow.reset_row_image()
   self.statusRow.widget.set_markup('<span size="large">%s</span>' % (relayStateString))
   
   #update as appropriate for rows when we are trying to be a relay
   if configuredAsRelay:
     boolToStringMapping = {True: 'is reachable', False: 'is unreachable', None: 'testing...'}
     #do updates where we have the info
     relayPortsState = self.torApp.get_all_port_status()
     for row in self.statusRows:
       updateForGUIPort = row.rowName in relayPortsState
       if updateForGUIPort:
         port = relayPortsState[row.rowName]
         row.update_row_image(port[0])
         statusText = boolToStringMapping[port[0]]
         row.widget.set_markup('<span size="large">%s %s</span>' % (port[1], statusText))
   #else, null  everything out
   else:
     for row in [self.udpRelayPortRow, self.tcpRelayPortRow, self.dirPortRow, self.statusRow]:
       row.reset_row_image()
       row.widget.set_markup('<span size="large">offline</span>')
   
   #update the balance
   bank = Bank.get()
   if not bank:
     return
   credits = bank.get_expected_balance()
   if not credits:
     return
   self.creditsRow.widget.set_markup('<span size="large">%s  (%s)</span>'%\
                      (credits, Format.convert_to_gb(credits)))
   if credits > 200:
     creditState = True
   elif credits > 100:
     creditState = None
   else:
     creditState = False
   self.creditsRow.update_row_image(creditState)
예제 #11
0
 def __init__(self, btApp, maggicPadding):
     gtk.Frame.__init__(self)
     #bottom row
     self.btApp = btApp
     row = gtk.HBox()
     self.dhtText = gtk.Label('')
     self.dhtText.set_markup('<span size="large">DHT Nodes:  0 (0)</span>')
     self.upText = gtk.Label('')
     initialInfos = (Format.bytes_per_second(0), Format.format_bytes(0))
     self.upText.set_markup('<span size="large">D: %s  %s</span>' %
                            initialInfos)
     self.downText = gtk.Label('')
     self.downText.set_markup('<span size="large">U: %s  %s</span>' %
                              initialInfos)
     self.creditText = gtk.Label('')
     self.creditText.set_markup(
         '<span size="large">Credits: Unknown</span>')
     for item in [self.dhtText, self.upText, self.downText]:
         row.pack_start(item, True, True, 0)
         row.pack_start(gtk.VSeparator(), False, False, 0)
     row.pack_start(self.creditText, True, True, 0)
     self.set_shadow_type(gtk.SHADOW_IN)
     self.add(row)
예제 #12
0
    def __init__(self, controller):
        buttons = (gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO,
                   gtk.RESPONSE_NO)
        dia = gtk.Dialog("Credits Low", None, 0, buttons)
        self.controller = controller

        vbox = gtk.VBox()

        title = gtk.Label()
        markup = "<span size='large' weight='bold'>You Are Running out of Credits</span>"
        title.set_markup(markup)
        title.set_justify(gtk.JUSTIFY_CENTER)
        vbox.pack_start(title, True, False, 0)

        #A text entry telling the user what to do:
        balance = Bank.get().get_expected_balance()
        balanceGB = Format.convert_to_gb(balance)
        label = gtk.Label()
        text = "You only have %s (%s) credits remaining.  You must set up a relay to gain more credits.  \
This will allow other users to send traffic via your computer.\n\nWould you like to set up a relay now?" % (
            balance, balanceGB)
        label.set_markup(text)
        label.set_line_wrap(True)
        vbox.pack_start(label, True, True, 5)

        #if we should always check:
        self.askAboutRelay = gtk.CheckButton(
            "Always ask about help setting up relay")
        vbox.pack_start(self.askAboutRelay, True, True, 10)
        #initialize the checkbox:
        self.askAboutRelay.set_active(CoreSettings.get().askAboutRelay)

        vbox = GTKUtils.add_padding(vbox, 5)
        dia.vbox.pack_start(vbox, True, True, 0)
        dia.connect("response", self.on_response)
        self.dia = dia
        #start the dialog
        dia.show_all()
예제 #13
0
  def do_expose_event(self, event):
    #schedule the draw event if this is the first time we've ever been exposed
    if not self.shouldDraw:
      self.shouldDraw = True
      Scheduler.schedule_repeat(1.0, self.draw)
    self.visible_cb()
    #Create the cairo context
    self.cr = self.window.cairo_create()
    #Restrict Cairo to the exposed area; avoid extra work
    self.cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
    self.cr.clip()
    width, height = self.window.get_size()
    cr = self.cr

    cr.set_source_rgb(*self.cFill)
    cr.rectangle(0, 0, width, height)
    cr.fill()
    
    #figure out the scale mapping between values and pixels:
    maxYVal = self.maxVal
    maxValueText, maxValueUnits = Format.bytes_per_second(maxYVal).split(" ")
    x_bearing, y_bearing, w, h = cr.text_extents(maxValueText)[:4]
    xStart = w + self.PADDING_LEFT + self.PADDING_AXIS
    xEnd = width - self.PADDING_RIGHT 
    xStepSize = float(xEnd - xStart) / float(self.NUM_VALUES)
    x_bearing, y_bearing, w, h = cr.text_extents("100MB/s")[:4]
    bottomY = height - (self.PADDING_BOTTOM + h + self.PADDING_AXIS)
    yScale = float(bottomY - self.PADDING_TOP) / float(maxYVal)
    
    #shade enclosed rectangle white
    cr.set_source_rgb(self.cInnerShade[0], self.cInnerShade[1], self.cInnerShade[2])
    cr.rectangle(xStart, self.PADDING_TOP, width-self.PADDING_RIGHT-xStart, bottomY-self.PADDING_TOP)
    cr.fill()
    
    #labels
    cr.set_line_width(0.6)
    cr.set_font_size(self.FONT_SIZE)
    
    #vertical lines:
    numLines = self.NUM_VERT_LINES
    cr.set_source_rgb(self.cLines[0], self.cLines[1], self.cLines[2])
    if self.xMiddleTics:
      numLines = (numLines * (self.xMiddleTics+1))
    for i in range(0, numLines + 1):
      if self.xMiddleTics:
        if i % (1+self.xMiddleTics) == 0:
          cr.set_line_width(0.6)
        else:
          cr.set_line_width(0.2)
      s = (self.NUM_VALUES / numLines) * i
      #should be a dark color...
      x = xStart + int(xStepSize * s)
      cr.move_to(x, self.PADDING_TOP)
      cr.line_to(x, bottomY)
      cr.stroke()

    x_bearing, y_bearing, w, h = cr.text_extents("Time (1 second step)")[:4]
    yPos = bottomY + self.PADDING_AXIS + h - self.lineWidth
    #make left label:
    cr.move_to(xStart, yPos)
    cr.show_text("Time (1 second step)")
        
    #middle label:
    x_bearing, y_bearing, w, h = cr.text_extents("Grid: 10 seconds")[:4]
    cr.move_to((xStart+xEnd)/2 - w/2, yPos)
    cr.show_text("Grid: 10 seconds")
    
    #make right label:
    x_bearing, y_bearing, w, h = cr.text_extents("Now")[:4]
    cr.move_to(xEnd-w, yPos)
    cr.show_text("Now")

    #horizontal lines:
    cr.set_source_rgb(self.cLines[0], self.cLines[1], self.cLines[2])
    numLines = self.NUM_HORIZ_LINES
    if self.yMiddleTics:
      numLines = (numLines * (self.yMiddleTics+1))
    j = 0
    for i in range(0,maxYVal+1,maxYVal/numLines):
      if self.yMiddleTics:
        if j % (1+self.yMiddleTics) == 0:
          cr.set_line_width(0.6)
        else:
          cr.set_line_width(0.2)
        j += 1
      #should be a dark color...
      y = bottomY - int(yScale * i)
      cr.move_to(xEnd, y)
      cr.line_to(xStart, y)
      cr.stroke()
        
    #make top label:
    x_bearing, y_bearing, w, h = cr.text_extents("0")[:4]
    cr.move_to(self.PADDING_LEFT, self.PADDING_TOP+h)
    cr.show_text(maxValueText)
        
    #middle label:
    self.cr.rotate(-1*math.pi / 2.0)
    x_bearing, y_bearing, w, h = cr.text_extents(maxValueUnits)[:4]
    cr.move_to(-1 * height / 2.0 - w/2 + self.PADDING_TOP, self.PADDING_LEFT + h + 2)
    cr.show_text(maxValueUnits)
    self.cr.rotate(math.pi / 2.0)
    
    #make bottom label:
    x_bearing, y_bearing, w, h = cr.text_extents("0")[:4]
    cr.move_to(xStart-self.PADDING_AXIS-w, bottomY)
    cr.show_text("0")

    #draw the data lines on the graph:
    for sourceVals in (self.dataSource.bytesRead, self.dataSource.bytesWritten):
      # Set properties for the line (different colors for read and written)
      if sourceVals == self.dataSource.bytesWritten:
        cr.set_source_rgb(self.cWritten[0], self.cWritten[1], self.cWritten[2])
      else:
        cr.set_source_rgb(self.cRead[0], self.cRead[1], self.cRead[2])
      cr.set_line_width(self.lineWidth)
      #for every bw value,
      vals = sourceVals[len(sourceVals)-self.NUM_VALUES:]
      for i in range(0, len(vals)-1):
        #draw a line segment:
        startX = xStart + int(xStepSize * i)
        endX = xStart + int(xStepSize * (i+1))
        y1 = bottomY - (vals[i] * yScale)
        y2 = bottomY - (vals[i+1] * yScale)
        cr.move_to(startX, y1)
        cr.line_to(endX, y2)
      #Apply the ink
      cr.stroke()
      #update the maximum y value and scale for next time:
      newMax = 0
      for v in vals:
        if v > newMax:
          newMax = v
      #double the scale until we contain the max value:
      while newMax > self.maxVal:
        self.maxVal *= 2
      else:
        if newMax < self.maxVal / 2:
          self.scale_too_big += 1
        else:
          self.scale_too_big = 0
      #if the scale has been too big for more than 5 ticks, make it smaller
      if self.scale_too_big > 5:
        #dont go below the original axis value:
        if self.maxVal > 32 * 1024:
          self.maxVal /= 2
예제 #14
0
    def do_expose_event(self, event):
        #schedule the draw event if this is the first time we've ever been exposed
        if not self.shouldDraw:
            self.shouldDraw = True
            Scheduler.schedule_repeat(1.0, self.draw)
        self.visible_cb()
        #Create the cairo context
        self.cr = self.window.cairo_create()
        #Restrict Cairo to the exposed area; avoid extra work
        self.cr.rectangle(event.area.x, event.area.y, event.area.width,
                          event.area.height)
        self.cr.clip()
        width, height = self.window.get_size()
        cr = self.cr

        cr.set_source_rgb(*self.cFill)
        cr.rectangle(0, 0, width, height)
        cr.fill()

        #figure out the scale mapping between values and pixels:
        maxYVal = self.maxVal
        maxValueText, maxValueUnits = Format.bytes_per_second(maxYVal).split(
            " ")
        x_bearing, y_bearing, w, h = cr.text_extents(maxValueText)[:4]
        xStart = w + self.PADDING_LEFT + self.PADDING_AXIS
        xEnd = width - self.PADDING_RIGHT
        xStepSize = float(xEnd - xStart) / float(self.NUM_VALUES)
        x_bearing, y_bearing, w, h = cr.text_extents("100MB/s")[:4]
        bottomY = height - (self.PADDING_BOTTOM + h + self.PADDING_AXIS)
        yScale = float(bottomY - self.PADDING_TOP) / float(maxYVal)

        #shade enclosed rectangle white
        cr.set_source_rgb(self.cInnerShade[0], self.cInnerShade[1],
                          self.cInnerShade[2])
        cr.rectangle(xStart, self.PADDING_TOP,
                     width - self.PADDING_RIGHT - xStart,
                     bottomY - self.PADDING_TOP)
        cr.fill()

        #labels
        cr.set_line_width(0.6)
        cr.set_font_size(self.FONT_SIZE)

        #vertical lines:
        numLines = self.NUM_VERT_LINES
        cr.set_source_rgb(self.cLines[0], self.cLines[1], self.cLines[2])
        if self.xMiddleTics:
            numLines = (numLines * (self.xMiddleTics + 1))
        for i in range(0, numLines + 1):
            if self.xMiddleTics:
                if i % (1 + self.xMiddleTics) == 0:
                    cr.set_line_width(0.6)
                else:
                    cr.set_line_width(0.2)
            s = (self.NUM_VALUES / numLines) * i
            #should be a dark color...
            x = xStart + int(xStepSize * s)
            cr.move_to(x, self.PADDING_TOP)
            cr.line_to(x, bottomY)
            cr.stroke()

        x_bearing, y_bearing, w, h = cr.text_extents(
            "Time (1 second step)")[:4]
        yPos = bottomY + self.PADDING_AXIS + h - self.lineWidth
        #make left label:
        cr.move_to(xStart, yPos)
        cr.show_text("Time (1 second step)")

        #middle label:
        x_bearing, y_bearing, w, h = cr.text_extents("Grid: 10 seconds")[:4]
        cr.move_to((xStart + xEnd) / 2 - w / 2, yPos)
        cr.show_text("Grid: 10 seconds")

        #make right label:
        x_bearing, y_bearing, w, h = cr.text_extents("Now")[:4]
        cr.move_to(xEnd - w, yPos)
        cr.show_text("Now")

        #horizontal lines:
        cr.set_source_rgb(self.cLines[0], self.cLines[1], self.cLines[2])
        numLines = self.NUM_HORIZ_LINES
        if self.yMiddleTics:
            numLines = (numLines * (self.yMiddleTics + 1))
        j = 0
        for i in range(0, maxYVal + 1, maxYVal / numLines):
            if self.yMiddleTics:
                if j % (1 + self.yMiddleTics) == 0:
                    cr.set_line_width(0.6)
                else:
                    cr.set_line_width(0.2)
                j += 1
            #should be a dark color...
            y = bottomY - int(yScale * i)
            cr.move_to(xEnd, y)
            cr.line_to(xStart, y)
            cr.stroke()

        #make top label:
        x_bearing, y_bearing, w, h = cr.text_extents("0")[:4]
        cr.move_to(self.PADDING_LEFT, self.PADDING_TOP + h)
        cr.show_text(maxValueText)

        #middle label:
        self.cr.rotate(-1 * math.pi / 2.0)
        x_bearing, y_bearing, w, h = cr.text_extents(maxValueUnits)[:4]
        cr.move_to(-1 * height / 2.0 - w / 2 + self.PADDING_TOP,
                   self.PADDING_LEFT + h + 2)
        cr.show_text(maxValueUnits)
        self.cr.rotate(math.pi / 2.0)

        #make bottom label:
        x_bearing, y_bearing, w, h = cr.text_extents("0")[:4]
        cr.move_to(xStart - self.PADDING_AXIS - w, bottomY)
        cr.show_text("0")

        #draw the data lines on the graph:
        for sourceVals in (self.dataSource.bytesRead,
                           self.dataSource.bytesWritten):
            # Set properties for the line (different colors for read and written)
            if sourceVals == self.dataSource.bytesWritten:
                cr.set_source_rgb(self.cWritten[0], self.cWritten[1],
                                  self.cWritten[2])
            else:
                cr.set_source_rgb(self.cRead[0], self.cRead[1], self.cRead[2])
            cr.set_line_width(self.lineWidth)
            #for every bw value,
            vals = sourceVals[len(sourceVals) - self.NUM_VALUES:]
            for i in range(0, len(vals) - 1):
                #draw a line segment:
                startX = xStart + int(xStepSize * i)
                endX = xStart + int(xStepSize * (i + 1))
                y1 = bottomY - (vals[i] * yScale)
                y2 = bottomY - (vals[i + 1] * yScale)
                cr.move_to(startX, y1)
                cr.line_to(endX, y2)
            #Apply the ink
            cr.stroke()
            #update the maximum y value and scale for next time:
            newMax = 0
            for v in vals:
                if v > newMax:
                    newMax = v
            #double the scale until we contain the max value:
            while newMax > self.maxVal:
                self.maxVal *= 2
            else:
                if newMax < self.maxVal / 2:
                    self.scale_too_big += 1
                else:
                    self.scale_too_big = 0
            #if the scale has been too big for more than 5 ticks, make it smaller
            if self.scale_too_big > 5:
                #dont go below the original axis value:
                if self.maxVal > 32 * 1024:
                    self.maxVal /= 2
예제 #15
0
  def on_update(self):
    globalDownRate = 0
    globalUpRate = 0
    globalDownAmount = 0
    globalUpAmount = 0
    torrentInfo = None
    if self.app.is_ready():
      torrentInfo = self.app.btInstance.stats(False)
    if not torrentInfo:
      #generate it from the pending downloads:
      torrentInfo = []
      for torrentHash, data in self.app.pendingDownloads.iteritems():
        name = data[0]['metainfo']['info']['name']
        torrentInfo.append([name, "Waiting for Tor...", "0%", 0, 0, "", 0,
        0, 0, 0, 0, 0, "0 seconds", "", torrentHash, 0, 0])
    #log_msg("update: %s" % (len(self.lastData)))
    #mark everything as invisible unless it was in this update:
    visible = {}
    for ref in self.rows.values():
      visible[ref] = False
    #update each of the active torrents:
    for torrent in torrentInfo:
      ( name, status, progress, peers, seeds, seedsmsg, numCopies,
        dnrate, uprate, dnamt, upamt, size, timeLeft, msg, torrentHash, knownSeeds, knownPeers ) = torrent
      globalDownRate += dnrate
      globalUpRate += uprate
      globalDownAmount += dnamt
      globalUpAmount += upamt
      progress = float(progress.replace("%", ""))
      pathname, filename = os.path.split(name)
      #status = status+"|"+seedsmsg+"|"+msg
      progressMsg = "%.0f" % (progress)
      uprate = Format.bytes_per_second(uprate)
      dnrate = Format.bytes_per_second(dnrate)
      upamt = Format.format_bytes(upamt)
      dnamt = Format.format_bytes(dnamt)
      
#      if progress >= 100:
#        status = "Seeding"
        
      try:
        if self.app.btInstance and self.app.btInstance.downloads.has_key(torrentHash):
          if not self.app.btInstance.downloads[torrentHash].unpauseflag.isSet():
            status = "Paused"
        if self.app.forcedStatus:
          status = self.app.forcedStatus
      except Exception, error:
        log_ex(error, "Could not find torrent")
      
      peers = "%s (%s)" % (peers, knownPeers)
      seeds = "%s (%s)" % (seeds, knownSeeds)
      
      if not self.rows.has_key(torrentHash):
        rowIter = self.liststore.append([filename, progress, progressMsg, status, peers, seeds, uprate, dnrate, upamt, dnamt, numCopies, torrentHash.encode("hex"), True])
        self.rows[torrentHash] = gtk.TreeRowReference(self.liststore, self.liststore.get_string_from_iter(rowIter))
      else:
        rowIter = self.liststore[self.rows[torrentHash].get_path()].iter
        self.liststore.set_value(rowIter, self.attrIdx["name"], filename)
        self.liststore.set_value(rowIter, self.attrIdx["progress"], progress)
        self.liststore.set_value(rowIter, self.attrIdx["progressMsg"], progressMsg)
        self.liststore.set_value(rowIter, self.attrIdx["status"], status)
        self.liststore.set_value(rowIter, self.attrIdx["peers"], peers)
        self.liststore.set_value(rowIter, self.attrIdx["seeds"], seeds)
        self.liststore.set_value(rowIter, self.attrIdx["rateUp"], uprate)
        self.liststore.set_value(rowIter, self.attrIdx["rateDown"], dnrate)
        self.liststore.set_value(rowIter, self.attrIdx["amountUp"], upamt)
        self.liststore.set_value(rowIter, self.attrIdx["amountDown"], dnamt)
        self.liststore.set_value(rowIter, self.attrIdx["copies"], numCopies)
        if not self.liststore.get_value(rowIter, self.attrIdx["visibility"]):
          self.liststore.set_value(rowIter, self.attrIdx["visibility"], True)
      visible[self.rows[torrentHash]] = True
예제 #16
0
 def make_pretty(self):
   """Note, pretty is set here!"""
   self.pretty = Format.convert_to_gb(self.value)
   return self.pretty
예제 #17
0
 def make_pretty(self):
     """Note, pretty is set here!"""
     self.pretty = Format.convert_to_gb(self.value)
     return self.pretty
예제 #18
0
 def _cell_data_amount(self, column, cell, model, row):
   value = model.get_value(row, column.valueNum)
   text = Format.format_bytes(value)
   cell.set_property("text", text)
예제 #19
0
 def _cell_data_rate(self, column, cell, model, row):
   value = model.get_value(row, column.valueNum)
   text = Format.bytes_per_second(value)
   cell.set_property("text", text)
예제 #20
0
    def on_update(self):
        globalDownRate = 0
        globalUpRate = 0
        globalDownAmount = 0
        globalUpAmount = 0
        torrentInfo = None
        if self.app.is_ready():
            torrentInfo = self.app.btInstance.stats(False)
        if not torrentInfo:
            #generate it from the pending downloads:
            torrentInfo = []
            for torrentHash, data in self.app.pendingDownloads.iteritems():
                name = data[0]['metainfo']['info']['name']
                torrentInfo.append([
                    name, "Waiting for Tor...", "0%", 0, 0, "", 0, 0, 0, 0, 0,
                    0, "0 seconds", "", torrentHash, 0, 0
                ])
        #log_msg("update: %s" % (len(self.lastData)))
        #mark everything as invisible unless it was in this update:
        visible = {}
        for ref in self.rows.values():
            visible[ref] = False
        #update each of the active torrents:
        for torrent in torrentInfo:
            (name, status, progress, peers, seeds, seedsmsg, numCopies, dnrate,
             uprate, dnamt, upamt, size, timeLeft, msg, torrentHash,
             knownSeeds, knownPeers) = torrent
            globalDownRate += dnrate
            globalUpRate += uprate
            globalDownAmount += dnamt
            globalUpAmount += upamt
            progress = float(progress.replace("%", ""))
            pathname, filename = os.path.split(name)
            #status = status+"|"+seedsmsg+"|"+msg
            progressMsg = "%.0f" % (progress)
            uprate = Format.bytes_per_second(uprate)
            dnrate = Format.bytes_per_second(dnrate)
            upamt = Format.format_bytes(upamt)
            dnamt = Format.format_bytes(dnamt)

            #      if progress >= 100:
            #        status = "Seeding"

            try:
                if self.app.btInstance and self.app.btInstance.downloads.has_key(
                        torrentHash):
                    if not self.app.btInstance.downloads[
                            torrentHash].unpauseflag.isSet():
                        status = "Paused"
                if self.app.forcedStatus:
                    status = self.app.forcedStatus
            except Exception, error:
                log_ex(error, "Could not find torrent")

            peers = "%s (%s)" % (peers, knownPeers)
            seeds = "%s (%s)" % (seeds, knownSeeds)

            if not self.rows.has_key(torrentHash):
                rowIter = self.liststore.append([
                    filename, progress, progressMsg, status, peers, seeds,
                    uprate, dnrate, upamt, dnamt, numCopies,
                    torrentHash.encode("hex"), True
                ])
                self.rows[torrentHash] = gtk.TreeRowReference(
                    self.liststore,
                    self.liststore.get_string_from_iter(rowIter))
            else:
                rowIter = self.liststore[
                    self.rows[torrentHash].get_path()].iter
                self.liststore.set_value(rowIter, self.attrIdx["name"],
                                         filename)
                self.liststore.set_value(rowIter, self.attrIdx["progress"],
                                         progress)
                self.liststore.set_value(rowIter, self.attrIdx["progressMsg"],
                                         progressMsg)
                self.liststore.set_value(rowIter, self.attrIdx["status"],
                                         status)
                self.liststore.set_value(rowIter, self.attrIdx["peers"], peers)
                self.liststore.set_value(rowIter, self.attrIdx["seeds"], seeds)
                self.liststore.set_value(rowIter, self.attrIdx["rateUp"],
                                         uprate)
                self.liststore.set_value(rowIter, self.attrIdx["rateDown"],
                                         dnrate)
                self.liststore.set_value(rowIter, self.attrIdx["amountUp"],
                                         upamt)
                self.liststore.set_value(rowIter, self.attrIdx["amountDown"],
                                         dnamt)
                self.liststore.set_value(rowIter, self.attrIdx["copies"],
                                         numCopies)
                if not self.liststore.get_value(rowIter,
                                                self.attrIdx["visibility"]):
                    self.liststore.set_value(rowIter,
                                             self.attrIdx["visibility"], True)
            visible[self.rows[torrentHash]] = True