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

James Cameron quozl at laptop.org
Mon Oct 18 02:24:25 EDT 2010


On Mon, Oct 18, 2010 at 12:14:59AM +0530, Ishan Bansal wrote:
> Pallete added to calculate and display free journal space when we write click.

Two errors.

s/Pallete/Palette
s/write click/right click

> --- a/src/jarabe/journal/volumestoolbar.py
> +++ b/src/jarabe/journal/volumestoolbar.py
> [...]
> @@ -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)}

An os.statvfs against get_profile_path ... this looks very familiar.  It
is very similar to code in src/jarabe/journal/journalactivity.py and
src/jarabe/view/palettes.py

The use of the gtk.ProgressBar also appears in a similar form in
src/jarabe/view/palettes.py

Perhaps it is time to factor rather than duplicate code.

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list