[Sugar-devel] [PATCH] Free space displayed for Journal Button in Volumes Toolbar. (Ticket #2318)

Tomeu Vizoso tomeu at sugarlabs.org
Tue Oct 5 04:32:26 EDT 2010


On Mon, Sep 27, 2010 at 20:21, Ishan Bansal <ishan at seeta.in> wrote:
> Pallete added to calculate and display free journal space when we write click.

Thanks for the patch, we should see how we can avoid duplicating code.

Maybe we could split palettes.BaseJournalPalette from
palettes.JournalPalette and make JournalButtonPalette inherit from it?

Regards,

Tomeu

> ---
>  src/jarabe/journal/volumestoolbar.py |   34 +++++++++++++++++++++++++++++++++-
>  1 files changed, 33 insertions(+), 1 deletions(-)
>
> diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py
> index 4208c17..749f2cb 100644
> --- a/src/jarabe/journal/volumestoolbar.py
> +++ b/src/jarabe/journal/volumestoolbar.py
> @@ -16,6 +16,7 @@
>
>  import logging
>  import os
> +import statvfs
>  from gettext import gettext as _
>
>  import gobject
> @@ -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()
> @@ -206,4 +207,35 @@ class JournalButton(BaseButton):
>         client = gconf.client_get_default()
>         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
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>


More information about the Sugar-devel mailing list