[Sugar-devel] [PATCH sugar] Add empty messages for empty devices and empty DOCUMENTS folders
Currently the message will be the same for an empty Journal or an empty external device or an empty documents folder. This patch does distinguish between the different cases. In order to get the path of the documents folder as well from the listview the function has been moved to the model. @design team: because I could not figure out an easy way to get the volume's label in the listview I did change the text for an empty device to: 'The device is empty' This patch depends on the previous patch: "Only show DOCUMENTS folder when it is not $HOME" Signed-off-by: Simon Schampijer --- src/jarabe/journal/listview.py | 16 ++-- src/jarabe/journal/model.py | 23 +++ src/jarabe/journal/volumestoolbar.py | 26 +- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py index a9f5a53..c642617 100644 --- a/src/jarabe/journal/listview.py +++ b/src/jarabe/journal/listview.py @@ -38,7 +38,9 @@ from jarabe.journal import misc UPDATE_INTERVAL = 300 MESSAGE_EMPTY_JOURNAL = 0 -MESSAGE_NO_MATCH = 1 +MESSAGE_EMPTY_DOCUMENTS_FOLDER = 1 +MESSAGE_EMPTY_DEVICE = 2 +MESSAGE_NO_MATCH = 3 class TreeView(gtk.TreeView): @@ -315,7 +317,13 @@ class BaseListView(gtk.Bin): if len(tree_model) == 0: if self._is_query_empty(): -self._show_message(MESSAGE_EMPTY_JOURNAL) +if self._query['mountpoints'] == ['/']: +self._show_message(MESSAGE_EMPTY_JOURNAL) +elif self._query['mountpoints'] == \ +[model.get_documents_path()]: +self._show_message(MESSAGE_EMPTY_DOCUMENTS_FOLDER) +else: +self._show_message(MESSAGE_EMPTY_DEVICE) else: self._show_message(MESSAGE_NO_MATCH) else: @@ -385,6 +393,10 @@ class BaseListView(gtk.Bin): if message == MESSAGE_EMPTY_JOURNAL: text = _('Your Journal is empty') +elif message == MESSAGE_EMPTY_DOCUMENTS_FOLDER: +text = _('Your documents folder is empty') +elif message == MESSAGE_EMPTY_DEVICE: +text = _('The device is empty') elif message == MESSAGE_NO_MATCH: text = _('No matching entries') else: diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py index 1242787..c57dfc4 100644 --- a/src/jarabe/journal/model.py +++ b/src/jarabe/journal/model.py @@ -17,6 +17,7 @@ import logging import os import errno +import subprocess from datetime import datetime import time import shutil @@ -794,3 +795,25 @@ def is_editable(metadata): return True else: return os.access(metadata['mountpoint'], os.W_OK) + + +def get_documents_path(): +"""Gets the path of the DOCUMENTS folder + +If xdg-user-dir can not find the DOCUMENTS folder it will +return the user directory instead. It also handles +localization (i.e. translation) of the filenames. + +Returns: Path to $HOME/DOCUMENTS or None if an error occurs +""" +try: +pipe = subprocess.Popen(['xdg-user-dir', 'DOCUMENTS'], +stdout=subprocess.PIPE) +documents_path = os.path.normpath(pipe.communicate()[0].strip()) +if os.path.exists(documents_path) and \ +os.environ.get('HOME') != documents_path: +return documents_path +except OSError, exception: +if exception.errno != errno.ENOENT: +logging.exception('Could not run xdg-user-dir') +return None diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py index 1cc764f..77bb955 100644 --- a/src/jarabe/journal/volumestoolbar.py +++ b/src/jarabe/journal/volumestoolbar.py @@ -16,8 +16,6 @@ import logging import os -import subprocess -import errno import statvfs from gettext import gettext as _ @@ -55,28 +53,6 @@ def _get_id(document): return None -def _get_documents_path(): -"""Gets the path of the DOCUMENTS folder - -If xdg-user-dir can not find the DOCUMENTS folder it will -return the user directory instead. It also handles -localization (i.e. translation) of the filenames. - -Returns: Path to $HOME/DOCUMENTS or None if an error occurs -""" -try: -pipe = subprocess.Popen(['xdg-user-dir', 'DOCUMENTS'], -stdout=subprocess.PIPE) -documents_path = os.path.normpath(pipe.communicate()[0].strip()) -if os.path.exists(documents_path) and \ -os.environ.get('HOME') != documents_path: -return documents_path -except OSError, exception: -if exception.errno != errno.ENOENT: -logging.exception('Could not run xdg-user-dir') -return None - - def _convert_entries(root): """Convert entries written by the datastore version 0. @@ -225,7
[Sugar-devel] [PATCH sugar] Add empty messages for empty devices and empty DOCUMENTS folders
Currently the message will be the same for an empty Journal or an empty external device or an empty documents folder. This patch does distinguish between the different cases. In order to get the path of the documents folder as well from the listview the function has been moved to the model. @design team: because I could not figure out an easy way to get the volume's label in the listview I did change the text for an empty device to: 'The device is empty' This patch depends on the previous patch: "Only show DOCUMENTS folder when it is not $HOME" Signed-off-by: Simon Schampijer --- src/jarabe/journal/listview.py | 27 --- src/jarabe/journal/model.py | 23 +++ src/jarabe/journal/volumestoolbar.py | 26 +- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py index a9f5a53..0d7e112 100644 --- a/src/jarabe/journal/listview.py +++ b/src/jarabe/journal/listview.py @@ -37,9 +37,6 @@ from jarabe.journal import misc UPDATE_INTERVAL = 300 -MESSAGE_EMPTY_JOURNAL = 0 -MESSAGE_NO_MATCH = 1 - class TreeView(gtk.TreeView): __gtype_name__ = 'JournalTreeView' @@ -315,9 +312,16 @@ class BaseListView(gtk.Bin): if len(tree_model) == 0: if self._is_query_empty(): -self._show_message(MESSAGE_EMPTY_JOURNAL) +if self._query['mountpoints'] == ['/']: +self._show_message(_('Your Journal is empty')) +elif self._query['mountpoints'] == \ +[model.get_documents_path()]: +self._show_message(_('Your documents folder is empty')) +else: +self._show_message(_('The device is empty')) else: -self._show_message(MESSAGE_NO_MATCH) +self._show_message(_('No matching entries'), + show_clear_query=True) else: self._clear_message() @@ -364,7 +368,7 @@ class BaseListView(gtk.Bin): self.add(self._scrolled_window) self._progress_bar = None -def _show_message(self, message): +def _show_message(self, message, show_clear_query=False): canvas = hippo.Canvas() self.remove(self.child) self.add(canvas) @@ -383,20 +387,13 @@ class BaseListView(gtk.Bin): fill_color=style.COLOR_TRANSPARENT.get_svg()) box.append(icon) -if message == MESSAGE_EMPTY_JOURNAL: -text = _('Your Journal is empty') -elif message == MESSAGE_NO_MATCH: -text = _('No matching entries') -else: -raise ValueError('Invalid message') - -text = hippo.CanvasText(text=text, +text = hippo.CanvasText(text=message, xalign=hippo.ALIGNMENT_CENTER, font_desc=style.FONT_BOLD.get_pango_desc(), color=style.COLOR_BUTTON_GREY.get_int()) box.append(text) -if message == MESSAGE_NO_MATCH: +if show_clear_query: button = gtk.Button(label=_('Clear search')) button.connect('clicked', self.__clear_button_clicked_cb) button.props.image = Icon(icon_name='dialog-cancel', diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py index 1242787..c57dfc4 100644 --- a/src/jarabe/journal/model.py +++ b/src/jarabe/journal/model.py @@ -17,6 +17,7 @@ import logging import os import errno +import subprocess from datetime import datetime import time import shutil @@ -794,3 +795,25 @@ def is_editable(metadata): return True else: return os.access(metadata['mountpoint'], os.W_OK) + + +def get_documents_path(): +"""Gets the path of the DOCUMENTS folder + +If xdg-user-dir can not find the DOCUMENTS folder it will +return the user directory instead. It also handles +localization (i.e. translation) of the filenames. + +Returns: Path to $HOME/DOCUMENTS or None if an error occurs +""" +try: +pipe = subprocess.Popen(['xdg-user-dir', 'DOCUMENTS'], +stdout=subprocess.PIPE) +documents_path = os.path.normpath(pipe.communicate()[0].strip()) +if os.path.exists(documents_path) and \ +os.environ.get('HOME') != documents_path: +return documents_path +except OSError, exception: +if exception.errno != errno.ENOENT: +logging.exception('Could not run xdg-user-dir') +return None diff --git a/src/jarabe/journal/volumestoolbar.py b/src/jarabe/journal/volumestoolbar.py index 1cc764f..77bb955 100644 --- a/src/jarabe/journal/volumestoolbar.py +++ b/src/jarabe/journal/volumestoolbar.py @@ -16,8 +16,6 @@ import logging import os -import subprocess -import errno import statvfs from gettext import gettext as _ @@ -55,28 +53,6 @@ def _get_id(document):
Re: [Sugar-devel] [PATCH sugar] Add empty messages for empty devices and empty DOCUMENTS folders
Tested and works ok. IMHO, sending the constants had more sense when we only had two messages, now should be more clear if we do: if len(tree_model) == 0: > if self._is_query_empty(): > -self._show_message(MESSAGE_EMPTY_JOURNAL) > +if self._query['mountpoints'] == ['/']: > +self._show_message(_('Your Journal is empty')) > +elif self._query['mountpoints'] == \ > +[model.get_documents_path()]: > +self._show_message(_('Your documents folder is > empty')) > +else: > +self._show_message(_('The device is empty')) > else: > self._show_message(_('No matching > entries'),show_clear_query=True) > else: > @@ -385,6 +393,10 @@ class BaseListView(gtk.Bin): > > def _show_message(self, message, show_clear_query=False): . if show_clear_query: button = gtk.Button(label=_('Clear search')) button.connect('clicked', self.__clear_button_clicked_cb) button.props.image = Icon(icon_name='dialog-cancel', icon_size=gtk.ICON_SIZE_BUTTON) canvas_button = hippo.CanvasWidget(widget=button, xalign=hippo.ALIGNMENT_CENTER) box.append(canvas_button) ... but is only me. Regards, Gonzalo ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel
Re: [Sugar-devel] [PATCH sugar] Add empty messages for empty devices and empty DOCUMENTS folders
On 09/06/2011 08:59 PM, Gonzalo Odiard wrote: Tested and works ok. IMHO, sending the constants had more sense when we only had two messages, now should be more clear if we do: if len(tree_model) == 0: if self._is_query_empty(): -self._show_message(MESSAGE_EMPTY_JOURNAL) +if self._query['mountpoints'] == ['/']: +self._show_message(_('Your Journal is empty')) +elif self._query['mountpoints'] == \ +[model.get_documents_path()]: +self._show_message(_('Your documents folder is empty')) +else: +self._show_message(_('The device is empty')) else: self._show_message(_('No matching entries'),show_clear_query=True) else: @@ -385,6 +393,10 @@ class BaseListView(gtk.Bin): def _show_message(self, message, show_clear_query=False): . if show_clear_query: button = gtk.Button(label=_('Clear search')) button.connect('clicked', self.__clear_button_clicked_cb) button.props.image = Icon(icon_name='dialog-cancel', icon_size=gtk.ICON_SIZE_BUTTON) canvas_button = hippo.CanvasWidget(widget=button, xalign=hippo.ALIGNMENT_CENTER) box.append(canvas_button) ... but is only me. Regards, Gonzalo Thanks Gonzalo for the feedback. Addressed your suggestion in the follow-up patch. Can you retest before I push? Regards, Simon ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel
Re: [Sugar-devel] [PATCH sugar] Add empty messages for empty devices and empty DOCUMENTS folders
Retested! Please push. Gonzalo On Wed, Sep 7, 2011 at 3:07 AM, Simon Schampijer wrote: > On 09/06/2011 08:59 PM, Gonzalo Odiard wrote: > >> Tested and works ok. >> IMHO, sending the constants had more sense when we only had two messages, >> now should be more clear if we do: >> >> if len(tree_model) == 0: >> >> if self._is_query_empty(): >>> -self._show_message(MESSAGE_**EMPTY_JOURNAL) >>> +if self._query['mountpoints'] == ['/']: >>> +self._show_message(_('Your Journal is empty')) >>> +elif self._query['mountpoints'] == \ >>> +[model.get_documents_path()]: >>> +self._show_message(_('Your documents folder is >>> empty')) >>> +else: >>> +self._show_message(_('The device is empty')) >>> else: >>> self._show_message(_('No matching >>> entries'),show_clear_query=**True) >>> else: >>> @@ -385,6 +393,10 @@ class BaseListView(gtk.Bin): >>> >>> >>> >>def _show_message(self, message, show_clear_query=False): >> >> . >> >> if show_clear_query: >> button = gtk.Button(label=_('Clear search')) >> button.connect('clicked', self.__clear_button_clicked_**cb) >> button.props.image = Icon(icon_name='dialog-cancel'**, >> icon_size=gtk.ICON_SIZE_**BUTTON) >> canvas_button = hippo.CanvasWidget(widget=**button, >> >> xalign=hippo.ALIGNMENT_CENTER) >> box.append(canvas_button) >> >> >> ... but is only me. >> Regards, >> >> Gonzalo >> > > Thanks Gonzalo for the feedback. Addressed your suggestion in the follow-up > patch. Can you retest before I push? > > Regards, > Simon > > > > ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel
Re: [Sugar-devel] [PATCH sugar] Add empty messages for empty devices and empty DOCUMENTS folders
On 09/07/2011 03:20 PM, Gonzalo Odiard wrote: Retested! Please push. Gonzalo Pushed as: http://git.sugarlabs.org/sugar/mainline/commit/b644c5e097b14810336da85c9669559d55fd7f60 Regards, Simon ___ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel