[Py2to3] Passes libfuturize.fixes.fix_division_safe

This commit is contained in:
Calum Lind 2016-04-26 22:00:11 +01:00
parent 81334389a9
commit 9fab98a6ce
23 changed files with 142 additions and 99 deletions

View File

@ -8,7 +8,7 @@
#
"""Common functions for various parts of Deluge to use."""
from __future__ import print_function
from __future__ import division, print_function
import base64
import functools
@ -321,16 +321,16 @@ def fsize(fsize_b, precision=1, shortform=False):
# Bigger than 1 TiB
if fsize_b >= 1099511627776:
return "%.*f %s" % (precision, fsize_b / 1099511627776.0, tib_txt_short if shortform else tib_txt)
return "%.*f %s" % (precision, fsize_b / 1099511627776, tib_txt_short if shortform else tib_txt)
# Bigger than 1 GiB
elif fsize_b >= 1073741824:
return "%.*f %s" % (precision, fsize_b / 1073741824.0, gib_txt_short if shortform else gib_txt)
return "%.*f %s" % (precision, fsize_b / 1073741824, gib_txt_short if shortform else gib_txt)
# Bigger than 1 MiB
elif fsize_b >= 1048576:
return "%.*f %s" % (precision, fsize_b / 1048576.0, mib_txt_short if shortform else mib_txt)
return "%.*f %s" % (precision, fsize_b / 1048576, mib_txt_short if shortform else mib_txt)
# Bigger than 1 KiB
elif fsize_b >= 1024:
return "%.*f %s" % (precision, fsize_b / 1024.0, kib_txt_short if shortform else kib_txt)
return "%.*f %s" % (precision, fsize_b / 1024, kib_txt_short if shortform else kib_txt)
else:
return "%d %s" % (fsize_b, byte_txt)
@ -376,16 +376,16 @@ def fspeed(bps, precision=1, shortform=False):
"""
fspeed_kb = bps / 1024.0
fspeed_kb = bps / 1024
if fspeed_kb < 1024:
return "%.*f %s" % (precision, fspeed_kb, _("K/s") if shortform else _("KiB/s"))
fspeed_mb = fspeed_kb / 1024.0
fspeed_mb = fspeed_kb / 1024
if fspeed_mb < 1024:
return "%.*f %s" % (precision, fspeed_mb, _("M/s") if shortform else _("MiB/s"))
fspeed_gb = fspeed_mb / 1024.0
fspeed_gb = fspeed_mb / 1024
if fspeed_gb < 1024:
return "%.*f %s" % (precision, fspeed_gb, _("G/s") if shortform else _("GiB/s"))
fspeed_tb = fspeed_gb / 1024.0
fspeed_tb = fspeed_gb / 1024
return "%.*f %s" % (precision, fspeed_tb, _("T/s") if shortform else _("TiB/s"))
@ -433,23 +433,23 @@ def ftime(seconds):
return ""
if seconds < 60:
return '%ds' % (seconds)
minutes = seconds / 60
minutes = seconds // 60
if minutes < 60:
seconds = seconds % 60
return '%dm %ds' % (minutes, seconds)
hours = minutes / 60
hours = minutes // 60
if hours < 24:
minutes = minutes % 60
return '%dh %dm' % (hours, minutes)
days = hours / 24
days = hours // 24
if days < 7:
hours = hours % 24
return '%dd %dh' % (days, hours)
weeks = days / 7
weeks = days // 7
if weeks < 52:
days = days % 7
return '%dw %dd' % (weeks, days)
years = weeks / 52
years = weeks // 52
weeks = weeks % 52
return '%dy %dw' % (years, weeks)

View File

@ -8,6 +8,8 @@
# See LICENSE for more details.
#
from __future__ import division
import base64
import glob
import logging
@ -413,13 +415,12 @@ class Core(component.Component):
# Add in a couple ratios
try:
cache["write_hit_ratio"] = float((cache["blocks_written"] -
cache["writes"])) / float(cache["blocks_written"])
cache["write_hit_ratio"] = (cache["blocks_written"] - cache["writes"]) / cache["blocks_written"]
except ZeroDivisionError:
cache["write_hit_ratio"] = 0.0
try:
cache["read_hit_ratio"] = float(cache["blocks_read_hit"]) / float(cache["blocks_read"])
cache["read_hit_ratio"] = cache["blocks_read_hit"] / cache["blocks_read"]
except ZeroDivisionError:
cache["read_hit_ratio"] = 0.0

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import os
import sys
from hashlib import sha1 as sha
@ -102,11 +104,11 @@ class TorrentMetadata(object):
else:
# We need to calculate a piece size
piece_size = 16384
while (datasize / piece_size) > 1024 and piece_size < (8192 * 1024):
while (datasize // piece_size) > 1024 and piece_size < (8192 * 1024):
piece_size *= 2
# Calculate the number of pieces we will require for the data
num_pieces = datasize / piece_size
num_pieces = datasize // piece_size
if datasize % piece_size:
num_pieces += 1

View File

@ -11,6 +11,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
import os.path
import sys
@ -169,7 +171,7 @@ def makeinfo(path, piece_length, progress, name=None, content_type=None, private
totalsize += os.path.getsize(f)
if totalsize >= piece_length:
import math
num_pieces = math.ceil(float(totalsize) / float(piece_length))
num_pieces = math.ceil(totalsize / piece_length)
else:
num_pieces = 1
@ -216,7 +218,7 @@ def makeinfo(path, piece_length, progress, name=None, content_type=None, private
else:
size = os.path.getsize(path)
if size >= piece_length:
num_pieces = size / piece_length
num_pieces = size // piece_length
else:
num_pieces = 1

View File

@ -8,6 +8,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
import os
import shutil
@ -288,7 +290,7 @@ class Core(CorePluginBase):
"""
def on_retrieve_data(data, current_length, total_length):
if total_length:
fp = float(current_length) / total_length
fp = current_length / total_length
if fp > 1.0:
fp = 1.0
else:

View File

@ -11,6 +11,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
import gtk
@ -38,9 +40,9 @@ class SchedulerSelectWidget(gtk.DrawingArea):
self.connect("motion_notify_event", self.mouse_hover)
self.connect("leave_notify_event", self.mouse_leave)
self.colors = [[115.0 / 255, 210.0 / 255, 22.0 / 255],
[237.0 / 255, 212.0 / 255, 0.0 / 255],
[204.0 / 255, 0.0 / 255, 0.0 / 255]]
self.colors = [[115 / 255, 210 / 255, 22 / 255],
[237 / 255, 212 / 255, 0 / 255],
[204 / 255, 0 / 255, 0 / 255]]
self.button_state = [[0] * 7 for dummy in xrange(24)]
self.start_point = [0, 0]
@ -70,8 +72,8 @@ class SchedulerSelectWidget(gtk.DrawingArea):
context.set_source_rgba(self.colors[self.button_state[x][y]][0],
self.colors[self.button_state[x][y]][1],
self.colors[self.button_state[x][y]][2], 0.7)
context.rectangle(width * (6 * x / 145.0 + 1 / 145.0), height * (6 * y / 43.0 + 1 / 43.0),
5 * width / 145.0, 5 * height / 43.0)
context.rectangle(width * (6 * x / 145 + 1 / 145), height * (6 * y / 43 + 1 / 43),
5 * width / 145, 5 * height / 43)
context.fill_preserve()
context.set_source_rgba(0.5, 0.5, 0.5, 0.5)
context.stroke()
@ -79,8 +81,8 @@ class SchedulerSelectWidget(gtk.DrawingArea):
# coordinates --> which box
def get_point(self, event):
size = self.window.get_size()
x = int((event.x - size[0] * 0.5 / 145.0) / (6 * size[0] / 145.0))
y = int((event.y - size[1] * 0.5 / 43.0) / (6 * size[1] / 43.0))
x = int((event.x - size[0] * 0.5 / 145) / (6 * size[0] / 145))
y = int((event.y - size[1] * 0.5 / 43) / (6 * size[1] / 43))
if x > 23:
x = 23

View File

@ -11,6 +11,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
import time
@ -46,7 +48,7 @@ def get_key(config, key):
def mean(items):
try:
return sum(items) / len(items)
return sum(items) // len(items)
except Exception:
return 0

View File

@ -14,6 +14,9 @@
"""
port of old plugin by markybob.
"""
from __future__ import division
import logging
import math
import time
@ -40,7 +43,7 @@ def size_formatter_scale(value):
scale = 1.0
for i in range(0, 3):
scale = scale * 1024.0
if value / scale < 1024:
if value // scale < 1024:
return scale
@ -118,22 +121,22 @@ class Graph(object):
(left, top, right, bottom) = bounds
duration = self.length * self.interval
start = self.last_update - duration
ratio = (right - left) / float(duration)
ratio = (right - left) / duration
if duration < 1800 * 10:
# try rounding to nearest 1min, 5mins, 10mins, 30mins
for step in [60, 300, 600, 1800]:
if duration / step < 10:
if duration // step < 10:
x_step = step
break
else:
# If there wasnt anything useful find a nice fitting hourly divisor
x_step = ((duration / 5) / 3600) * 3600
x_step = ((duration // 5) // 3600) * 3600
# this doesnt allow for dst and timezones...
seconds_to_step = math.ceil(start / float(x_step)) * x_step - start
seconds_to_step = math.ceil(start / x_step) * x_step - start
for i in xrange(0, duration / x_step + 1):
for i in xrange(0, duration // x_step + 1):
text = time.strftime('%H:%M', time.localtime(start + seconds_to_step + i * x_step))
# + 0.5 to allign x to nearest pixel
x = int(ratio * (seconds_to_step + i * x_step) + left) + 0.5
@ -144,10 +147,10 @@ class Graph(object):
def draw_graph(self):
font_extents = self.ctx.font_extents()
x_axis_space = font_extents[2] + 2 + self.line_size / 2.0
x_axis_space = font_extents[2] + 2 + self.line_size / 2
plot_height = self.height - x_axis_space
# lets say we need 2n-1*font height pixels to plot the y ticks
tick_limit = (plot_height / font_extents[3]) # / 2.0
tick_limit = plot_height / font_extents[3]
max_value = 0
for stat in self.stat_info:
@ -171,7 +174,7 @@ class Graph(object):
return math.ceil(te[4] - te[0])
y_tick_width = max((space_required(text) for text in y_tick_text))
top = font_extents[2] / 2.0
top = font_extents[2] / 2
# bounds(left, top, right, bottom)
bounds = (y_tick_width + 4, top + 2, self.width, self.height - x_axis_space)
@ -192,7 +195,7 @@ class Graph(object):
scale = 1
if 'formatter_scale' in self.left_axis:
scale = self.left_axis['formatter_scale'](x)
x = x / float(scale)
x = x / scale
# Find the largest power of 10 less than x
comm_log = math.log10(x)
@ -212,7 +215,7 @@ class Graph(object):
steps = steps * 2
if limit is not None and steps > limit:
multi = steps / float(limit)
multi = steps / limit
if multi > 2:
interval = interval * 5
else:
@ -261,7 +264,7 @@ class Graph(object):
self.ctx.line_to(right, int(bottom - values[0] * ratio))
x = right
step = (right - left) / float(self.length - 1)
step = (right - left) / (self.length - 1)
for i, value in enumerate(values):
if i == self.length - 1:
x = left
@ -290,7 +293,7 @@ class Graph(object):
height = fe[2]
x_bearing = te[0]
width = te[2]
self.ctx.move_to(int(x - width / 2.0 + x_bearing), int(y + height))
self.ctx.move_to(int(x - width / 2 + x_bearing), int(y + height))
self.ctx.set_source_rgba(*self.black)
self.ctx.show_text(text)
@ -302,7 +305,7 @@ class Graph(object):
ascent = fe[0]
x_bearing = te[0]
width = te[4]
self.ctx.move_to(int(x - width - x_bearing - 2), int(y + (ascent - descent) / 2.0))
self.ctx.move_to(int(x - width - x_bearing - 2), int(y + (ascent - descent) / 2))
self.ctx.set_source_rgba(*self.black)
self.ctx.show_text(text)

View File

@ -12,6 +12,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
import gtk
@ -52,7 +54,7 @@ def neat_time(column, cell, model, data):
"""Render seconds as seconds or minutes with label"""
seconds = model.get_value(data, 0)
if seconds > 60:
text = "%d %s" % (seconds / 60, _("minutes"))
text = "%d %s" % (seconds // 60, _("minutes"))
elif seconds == 60:
text = _("1 minute")
elif seconds == 1:
@ -69,11 +71,10 @@ def int_str(number):
def gtk_to_graph_color(color):
"""Turns a gtk.gdk.Color into a tuple with range 0-1 as used by the graph"""
max_val = float(65535)
gtk_color = gtk.gdk.Color(color)
red = gtk_color.red / max_val
green = gtk_color.green / max_val
blue = gtk_color.blue / max_val
red = gtk_color.red / 65535
green = gtk_color.green / 65535
blue = gtk_color.blue / 65535
return (red, green, blue)

View File

@ -44,6 +44,8 @@ Example icon to test with `down.ico`_
.. _down.ico: http://www.axialis.com/tutorials/iw/down.ico
"""
from __future__ import division
import logging
import struct
@ -132,7 +134,7 @@ class Win32IcoFile(object):
log.debug("Loaded image: %s %s %s %s", im.format, im.mode, im.size, im.info)
# change tile dimension to only encompass XOR image
im.size = im.size[0], im.size[1] / 2
im.size = im.size[0], im.size[1] // 2
d, e, o, a = im.tile[0]
im.tile[0] = d, (0, 0) + im.size, o, a
@ -145,7 +147,7 @@ class Win32IcoFile(object):
break
# end for
log.debug("o:%s, w:%s, h:%s, bpp:%s", o, im.size[0], im.size[1], bpp)
and_mask_offset = o + (im.size[0] * im.size[1] * (bpp / 8.0))
and_mask_offset = o + (im.size[0] * im.size[1] * (bpp / 8))
if bpp == 32:
# 32-bit color depth icon image allows semitransparent areas
@ -178,7 +180,7 @@ class Win32IcoFile(object):
# bitmap row data is aligned to word boundaries
w += 32 - (im.size[0] % 32)
# the total mask data is padded row size * height / bits per char
total_bytes = int((w * im.size[1]) / 8)
total_bytes = (w * im.size[1]) // 8
log.debug("tot=%d, off=%d, w=%d, size=%d", len(data), and_mask_offset, w, total_bytes)
self.buf.seek(and_mask_offset)
@ -190,7 +192,7 @@ class Win32IcoFile(object):
im.size, # (w, h)
mask_data, # source chars
'raw', # raw decoder
('1;I', int(w / 8), -1) # 1bpp inverted, padded, reversed
('1;I', w // 8, -1) # 1bpp inverted, padded, reversed
)
# now we have two images, im is XOR image and mask is AND image

View File

@ -8,6 +8,8 @@
# See LICENSE for more details.
#
from __future__ import division
from os.path import sep as dirsep
import deluge.common as common
@ -363,7 +365,7 @@ class Command(BaseCommand):
s += " {!cyan!}%s" % torrent_id
else:
# Shorten the ID
a = int(space_left * 2 / 3.0)
a = space_left * 2 // 3
b = space_left - a
if a < 8:
b = b - (8 - a)

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
from collections import deque
@ -390,14 +392,14 @@ class AllTorrents(BaseMode, component.Component):
self.column_widths = [self.config["%s_width" % c] for c in self.__cols_to_show]
requested_width = sum([width for width in self.column_widths if width >= 0])
if requested_width > self.cols: # can't satisfy requests, just spread out evenly
cw = int(self.cols / len(self.__columns))
cw = self.cols // len(self.__columns)
for i in range(0, len(self.column_widths)):
self.column_widths[i] = cw
else:
rem = self.cols - requested_width
var_cols = len([width for width in self.column_widths if width < 0])
if var_cols > 0:
vw = int(rem / var_cols)
vw = rem // var_cols
for i in range(0, len(self.column_widths)):
if self.column_widths[i] < 0:
self.column_widths[i] = vw
@ -1173,14 +1175,14 @@ class AllTorrents(BaseMode, component.Component):
if not self._scroll_up(1):
effected_lines = [self.cursel - 1, self.cursel]
elif c == curses.KEY_PPAGE:
self._scroll_up(int(self.rows / 2))
self._scroll_up(self.rows // 2)
elif c == curses.KEY_DOWN:
if self.cursel >= self.numtorrents:
return
if not self._scroll_down(1):
effected_lines = [self.cursel - 2, self.cursel - 1]
elif c == curses.KEY_NPAGE:
self._scroll_down(int(self.rows / 2))
self._scroll_down(self.rows // 2)
elif c == curses.KEY_HOME:
self._scroll_up(self.cursel)
elif c == curses.KEY_END:

View File

@ -9,10 +9,7 @@
# See LICENSE for more details.
#
try:
import curses
except ImportError:
pass
from __future__ import division
import logging
import os
@ -21,6 +18,12 @@ import os.path
from deluge.ui.console import colors
from deluge.ui.console.modes.popup import ALIGN, Popup
try:
import curses
except ImportError:
pass
log = logging.getLogger(__name__)
@ -877,7 +880,7 @@ class InputPopup(Popup):
if self.content_height > (self.height - 2):
lts = self.content_height - (self.height - 3)
perc_sc = float(self.lineoff) / lts
perc_sc = self.lineoff / lts
sb_pos = int((self.height - 2) * perc_sc) + 1
if (sb_pos == 1) and (self.lineoff != 0):
sb_pos += 1

View File

@ -7,14 +7,17 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
from deluge.ui.console.modes import format_utils
try:
import curses
except ImportError:
pass
import logging
from deluge.ui.console.modes import format_utils
log = logging.getLogger(__name__)
@ -97,7 +100,7 @@ class Popup(object):
# Height
if hr == 0:
hr = int(self.parent.rows / 2)
hr = self.parent.rows // 2
elif hr == -1:
hr = self.parent.rows - 2
elif hr > self.parent.rows - 2:
@ -105,7 +108,7 @@ class Popup(object):
# Width
if wr == 0:
wr = int(self.parent.cols / 2)
wr = self.parent.cols // 2
elif wr == -1:
wr = self.parent.cols
elif wr >= self.parent.cols:
@ -114,14 +117,14 @@ class Popup(object):
if self.align in [ALIGN.TOP_CENTER, ALIGN.TOP_LEFT, ALIGN.TOP_RIGHT]:
by = 1
elif self.align in [ALIGN.MIDDLE_CENTER, ALIGN.MIDDLE_LEFT, ALIGN.MIDDLE_RIGHT]:
by = (self.parent.rows / 2) - (hr / 2)
by = (self.parent.rows // 2) - (hr // 2)
elif self.align in [ALIGN.BOTTOM_CENTER, ALIGN.BOTTOM_LEFT, ALIGN.BOTTOM_RIGHT]:
by = self.parent.rows - hr - 1
if self.align in [ALIGN.TOP_LEFT, ALIGN.MIDDLE_LEFT, ALIGN.BOTTOM_LEFT]:
bx = 0
elif self.align in [ALIGN.TOP_CENTER, ALIGN.MIDDLE_CENTER, ALIGN.BOTTOM_CENTER]:
bx = (self.parent.cols / 2) - (wr / 2)
bx = (self.parent.cols // 2) - (wr // 2)
elif self.align in [ALIGN.TOP_RIGHT, ALIGN.MIDDLE_RIGHT, ALIGN.BOTTOM_RIGHT]:
bx = self.parent.cols - wr - 1
@ -139,7 +142,7 @@ class Popup(object):
self._refresh_lines()
if len(self._lines) > (self.height - 2):
lts = len(self._lines) - (self.height - 3)
perc_sc = float(self.lineoff) / lts
perc_sc = self.lineoff / lts
sb_pos = int((self.height - 2) * perc_sc) + 1
if (sb_pos == 1) and (self.lineoff != 0):
sb_pos += 1

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
from collections import deque
@ -205,7 +207,7 @@ class TorrentDetail(BaseMode, component.Component):
for f in fs:
if f[3]: # dir, has some children
bd = self.__fill_progress(f[3], progs)
f[5] = format_utils.format_progress((bd / f[2]) * 100)
f[5] = format_utils.format_progress(bd / f[2] * 100)
else: # file, update own prog and add to total
bd = f[2] * progs[f[1]]
f[5] = format_utils.format_progress(progs[f[1]] * 100)
@ -226,13 +228,13 @@ class TorrentDetail(BaseMode, component.Component):
self.column_widths = [-1, 15, 15, 20]
req = sum([col_width for col_width in self.column_widths if col_width >= 0])
if req > self.cols: # can't satisfy requests, just spread out evenly
cw = int(self.cols / len(self.column_names))
cw = self.cols // len(self.column_names)
for i in range(0, len(self.column_widths)):
self.column_widths[i] = cw
else:
rem = self.cols - req
var_cols = len([col_width for col_width in self.column_widths if col_width < 0])
vw = int(rem / var_cols)
vw = rem // var_cols
for i in range(0, len(self.column_widths)):
if self.column_widths[i] < 0:
self.column_widths[i] = vw
@ -404,7 +406,7 @@ class TorrentDetail(BaseMode, component.Component):
if self.popup:
self.popup.handle_resize()
self._listing_start = self.rows / 2
self._listing_start = self.rows // 2
self.refresh()
def render_header(self, off):

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import base64
import logging
import os
@ -620,7 +622,7 @@ class AddTorrentDialog(component.Component):
def on_part(data, current_length, total_length):
if total_length:
percent = float(current_length) / float(total_length)
percent = current_length / total_length
pb.set_fraction(percent)
pb.set_text("%.2f%% (%s / %s)" % (
percent * 100,

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import base64
import logging
import os.path
@ -124,7 +126,7 @@ class CreateTorrentDialog(object):
model = self.builder.get_object("combo_piece_size").get_model()
for index, value in enumerate(model):
psize = self.parse_piece_size_text(value[0])
pieces = size / psize
pieces = size // psize
if pieces < 2048 or (index + 1) == len(model):
self.builder.get_object("combo_piece_size").set_active(index)
break
@ -376,7 +378,7 @@ class CreateTorrentDialog(object):
{"download_location": os.path.split(path)[0]})
def _on_create_torrent_progress(self, value, num_pieces):
percent = float(value) / float(num_pieces)
percent = value / num_pieces
def update_pbar_with_gobject(percent):
pbar = self.builder.get_object("progressbar")

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import cPickle
import logging
import os.path
@ -423,12 +425,12 @@ class FilesTab(Tab):
if self.treestore.iter_children(row):
completed_bytes += get_completed_bytes(self.treestore.iter_children(row))
else:
completed_bytes += self.treestore[row][1] * (float(self.treestore[row][3]) / 100.0)
completed_bytes += self.treestore[row][1] * self.treestore[row][3] / 100
row = self.treestore.iter_next(row)
try:
value = (float(completed_bytes) / float(self.treestore[parent][1])) * 100
value = completed_bytes / self.treestore[parent][1] * 100
except ZeroDivisionError:
# Catch the unusal error found when moving folders around
value = 0

View File

@ -8,7 +8,7 @@
# See LICENSE for more details.
#
from __future__ import print_function
from __future__ import division, print_function
import os
@ -596,7 +596,7 @@ class PathChooserPopup(object):
# Adjust height according to number of list items
if len(self.tree_store) > 0 and self.max_visible_rows > 0:
# The height for one row in the list
self.row_height = self.treeview.size_request()[1] / len(self.tree_store)
self.row_height = self.treeview.size_request()[1] // len(self.tree_store)
# Set height to number of rows
height = len(self.tree_store) * self.row_height + height_extra
# Adjust the height according to the max number of rows

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
from math import pi
@ -104,9 +106,9 @@ class PiecesBar(gtk.DrawingArea):
def __create_roundcorners_subpath(self, ctx, x, y, width, height):
aspect = 1.0
corner_radius = height / 10.0
corner_radius = height / 10
radius = corner_radius / aspect
degrees = pi / 180.0
degrees = pi / 180
ctx.new_sub_path()
ctx.arc(x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees)
ctx.arc(x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees)
@ -125,14 +127,14 @@ class PiecesBar(gtk.DrawingArea):
ctx = cairo.Context(self.__pieces_overlay)
start_pos = 0
num_pieces = self.__num_pieces and self.__num_pieces or len(self.__pieces)
piece_width = self.__width * 1.0 / num_pieces
piece_width = self.__width * 1 / num_pieces
for state in self.__pieces:
color = self.gtkui_config["pieces_color_%s" % COLOR_STATES[state]]
ctx.set_source_rgb(
color[0] / 65535.0,
color[1] / 65535.0,
color[2] / 65535.0,
color[0] / 65535,
color[1] / 65535,
color[2] / 65535,
)
ctx.rectangle(start_pos, 0, piece_width, self.__height)
ctx.fill()
@ -149,15 +151,15 @@ class PiecesBar(gtk.DrawingArea):
cairo.FORMAT_ARGB32, self.__width, self.__height
)
ctx = cairo.Context(self.__pieces_overlay)
piece_width = self.__width * 1.0 / self.__num_pieces
piece_width = self.__width * 1 / self.__num_pieces
start = 0
for _ in range(self.__num_pieces):
# Like this to keep same aspect ratio
color = self.gtkui_config["pieces_color_%s" % COLOR_STATES[3]]
ctx.set_source_rgb(
color[0] / 65535.0,
color[1] / 65535.0,
color[2] / 65535.0,
color[0] / 65535,
color[1] / 65535,
color[2] / 65535,
)
ctx.rectangle(start, 0, piece_width, self.__height)
ctx.fill()
@ -214,11 +216,11 @@ class PiecesBar(gtk.DrawingArea):
log.trace("PiecesBar text %r", text)
pl.set_text(text)
plsize = pl.get_size()
text_width = plsize[0] / pango.SCALE
text_height = plsize[1] / pango.SCALE
text_width = plsize[0] // pango.SCALE
text_height = plsize[1] // pango.SCALE
area_width_without_text = self.__width - text_width
area_height_without_text = self.__height - text_height
ctx.move_to(area_width_without_text / 2, area_height_without_text / 2)
ctx.move_to(area_width_without_text // 2, area_height_without_text // 2)
ctx.set_source_rgb(1.0, 1.0, 1.0)
pg.update_layout(pl)
pg.show_layout(pl)

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
import deluge.component as component

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import logging
import gobject
@ -305,8 +307,8 @@ class StatusBar(component.Component):
def _on_get_session_status(self, status):
self.download_rate = fspeed(status["payload_download_rate"], precision=0, shortform=True)
self.upload_rate = fspeed(status["payload_upload_rate"], precision=0, shortform=True)
self.download_protocol_rate = (status["download_rate"] - status["payload_download_rate"]) / 1024
self.upload_protocol_rate = (status["upload_rate"] - status["payload_upload_rate"]) / 1024
self.download_protocol_rate = (status["download_rate"] - status["payload_download_rate"]) // 1024
self.upload_protocol_rate = (status["upload_rate"] - status["payload_upload_rate"]) // 1024
self.num_connections = status["num_peers"]
self.update_download_label()
self.update_upload_label()

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import division
import base64
import hashlib
import json
@ -590,8 +592,8 @@ class WebApi(JSONComponent):
dirinfo["priority"] = 9
progresses = dirinfo.setdefault("progresses", [])
progresses.append(torrent_file["size"] * (torrent_file["progress"] / 100.0))
dirinfo["progress"] = float(sum(progresses)) / dirinfo["size"] * 100
progresses.append(torrent_file["size"] * torrent_file["progress"] / 100)
dirinfo["progress"] = sum(progresses) / dirinfo["size"] * 100
dirinfo["path"] = dirname
dirname = os.path.dirname(dirname)