Hello, Gerrit!
On Thu, 2007-11-01 at 16:21 +0100, Gerrit Sangel wrote:
> So in summary (in my opinion) the way would be:
> default: leave the way it is now, but change KB, MB and so on to KiB,
> MiB, GiB
> optional: offer SI units with kB as 10^3, MB as 10^6 and so on.
Your idea sounds reasonable. I've created a patch on top of the latest
SVN version (use "svn up" in your working copy before applying that
patch) that adds support for a "use_si_units" configuration setting that
will enable display of SI units.
By default, binary prefixes will be used now.
Please try the patch and if everything works as expected, I'll commit
the patch after your reply.
Thomas
Index: src/gpodder/config.py
===================================================================
--- src/gpodder/config.py (revision 447)
+++ src/gpodder/config.py (working copy)
@@ -65,6 +65,7 @@
# Special settings (not in preferences)
'default_new': ( int, 1 ),
+ 'use_si_units': ( bool, False ),
# Window and paned positions
'main_window_x': ( int, 100 ),
Index: src/gpodder/download.py
===================================================================
--- src/gpodder/download.py (revision 447)
+++ src/gpodder/download.py (working copy)
@@ -122,7 +122,7 @@
self.start_time = now
passed = now - self.start_time
speed = count*blockSize
- self.speed = '%s/s' % util.format_filesize( speed)
+ self.speed = '%s/s' % libgpodder.gPodderLib().format_filesize( speed)
if self.limit_rate and speed > self.limit_rate_value:
# calculate the time that should have passed to reach
Index: src/gpodder/libpodcasts.py
===================================================================
--- src/gpodder/libpodcasts.py (revision 447)
+++ src/gpodder/libpodcasts.py (working copy)
@@ -403,7 +403,7 @@
new_episodes = self.get_new_episodes()
for item in self.get_all_episodes():
- new_iter = new_model.append( ( item.url, item.title, util.format_filesize( item.length), True, None, item.cute_pubdate(), item.one_line_description(), item.description, item.local_filename() ))
+ new_iter = new_model.append( ( item.url, item.title, libgpodder.gPodderLib().format_filesize( item.length), True, None, item.cute_pubdate(), item.one_line_description(), item.description, item.local_filename() ))
self.iter_set_downloading_columns( new_model, new_iter, new_episodes)
return new_model
Index: src/gpodder/libgpodder.py
===================================================================
--- src/gpodder/libgpodder.py (revision 447)
+++ src/gpodder/libgpodder.py (working copy)
@@ -78,6 +78,9 @@
log( 'Warning: Called get_device_name() when no device was selected.', sender = self)
return '(unknown device)'
+ def format_filesize( self, bytesize):
+ return util.format_filesize( bytesize, self.config.use_si_units)
+
def clean_up_downloads( self, delete_partial = False):
# Clean up temporary files left behind by old gPodder versions
if delete_partial:
Index: src/gpodder/util.py
===================================================================
--- src/gpodder/util.py (revision 447)
+++ src/gpodder/util.py (working copy)
@@ -135,22 +135,25 @@
return 0L
-def format_filesize( bytesize, method = None):
+def format_filesize( bytesize, use_si_units = False):
"""
Formats the given size in bytes to be human-readable,
- either the most appropriate form (B, KB, MB, GB) or
- a form specified as optional second parameter (e.g. "MB").
Returns a localized "(unknown)" string when the bytesize
has a negative value.
"""
- methods = {
- 'GB': 1024.0 * 1024.0 * 1024.0,
- 'MB': 1024.0 * 1024.0,
- 'KB': 1024.0,
- 'B': 1.0
- }
+ si_units = (
+ ( 'kB', 10**3 ),
+ ( 'MB', 10**6 ),
+ ( 'GB', 10**9 ),
+ )
+ binary_units = (
+ ( 'KiB', 2**10 ),
+ ( 'MiB', 2**20 ),
+ ( 'GiB', 2**30 ),
+ )
+
try:
bytesize = float( bytesize)
except:
@@ -159,15 +162,21 @@
if bytesize < 0:
return _('(unknown)')
- if method not in methods:
- method = 'B'
- for trying in ( 'KB', 'MB', 'GB' ):
- if bytesize >= methods[trying]:
- method = trying
+ if use_si_units:
+ units = si_units
+ else:
+ units = binary_units
- return '%.2f %s' % ( bytesize / methods[method], method, )
+ ( used_unit, used_value ) = ( 'B', bytesize )
+ for ( unit, value ) in units:
+ if bytesize >= value:
+ used_value = bytesize / float(value)
+ used_unit = unit
+ return '%.2f %s' % ( used_value, used_unit )
+
+
def delete_file( path):
"""
Tries to delete the given filename and silently
Index: src/gpodder/gui.py
===================================================================
--- src/gpodder/gui.py (revision 447)
+++ src/gpodder/gui.py (working copy)
@@ -1487,7 +1487,7 @@
if gl.downloaddir != self.chooserDownloadTo.get_filename():
new_download_dir = self.chooserDownloadTo.get_filename()
download_dir_size = util.calculate_size( gl.downloaddir)
- download_dir_size_string = util.format_filesize( download_dir_size, 'MB')
+ download_dir_size_string = gl.format_filesize( download_dir_size)
event = Event()
dlg = gtk.Dialog( _('Moving downloads folder'), self.gPodderProperties)
@@ -1523,7 +1523,7 @@
else:
fract = 0.0
if fract < 0.99:
- myprogressbar.set_text( _('%s of %s') % ( util.format_filesize( new_download_dir_size, 'MB'), download_dir_size_string, ))
+ myprogressbar.set_text( _('%s of %s') % ( gl.format_filesize( new_download_dir_size), download_dir_size_string, ))
else:
myprogressbar.set_text( _('Finishing... please wait.'))
myprogressbar.set_fraction( fract)
_______________________________________________
gpodder-devel mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/gpodder-devel