[Sugar-devel] [PATCH v2] Free space displayed for Journal Button in Volumes Toolbar. (Ticket #2318)
Ishan Bansal
ishan at seeta.in
Sun Oct 17 14:44:59 EDT 2010
Pallete added to calculate and display free journal space when we write click.
---
src/jarabe/journal/volumestoolbar.py | 36 +++++++++++++++++++++++++++++++++-
1 files changed, 35 insertions(+), 1 deletions(-)
v1->v2: pep8 errors corrected
diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
index 4208c17..76bf607 100644
--- a/src/jarabe/journal/volumestoolbar.py
+++ b/src/jarabe/journal/volumestoolbar.py
@@ -17,6 +17,7 @@
import logging
import os
from gettext import gettext as _
+import statvfs
import gobject
import gio
@@ -26,6 +27,7 @@ import gconf
from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.graphics.palette import Palette
from sugar.graphics.xocolor import XoColor
+from sugar import env
from jarabe.journal import model
from jarabe.view.palettes import VolumePalette
@@ -48,7 +50,6 @@ class VolumesToolbar(gtk.Toolbar):
self._mount_removed_hid = None
button = JournalButton()
- button.set_palette(Palette(_('Journal')))
button.connect('toggled', self._button_toggled_cb)
self.insert(button, 0)
button.show()
@@ -207,3 +208,36 @@ class JournalButton(BaseButton):
color = XoColor(client.get_string('/desktop/sugar/user/color'))
self.props.xo_color = color
+ def create_palette(self):
+ palette = JournalButtonPalette(self)
+ return palette
+
+class JournalButtonPalette(Palette):
+ def __init__(self, mount):
+ label = _('Journal')
+ Palette.__init__(self, label)
+
+ vbox = gtk.VBox()
+ self.set_content(vbox)
+ vbox.show()
+
+ self._progress_bar = gtk.ProgressBar()
+ vbox.add(self._progress_bar)
+ self._progress_bar.show()
+
+ self._free_space_label = gtk.Label()
+ self._free_space_label.set_alignment(0.5, 0.5)
+ vbox.add(self._free_space_label)
+ self._free_space_label.show()
+
+ self.connect('popup', self.__popup_cb)
+
+ def __popup_cb(self, palette):
+ stat = os.statvfs(env.get_profile_path())
+ free_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
+ total_space = stat[statvfs.F_BSIZE] * stat[statvfs.F_BLOCKS]
+
+ fraction = (total_space - free_space) / float(total_space)
+ self._progress_bar.props.fraction = fraction
+ self._free_space_label.props.label = _('%(free_space)d MB Free') % \
+ {'free_space': free_space / (1024 * 1024)}
--
1.7.0.4
More information about the Sugar-devel
mailing list