[gnome-news/wip/gbsneto/improvements: 1/6] views: add empty state



commit 90ee0d3894399a7eda1e427b051e08118422b18e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Mar 5 18:44:53 2016 -0300

    views: add empty state

 data/gnome-news.gresource.xml |    1 +
 data/ui/empty-view.ui         |  176 +++++++++++++++++++++++++++++++++++++++++
 gnomenews/view.py             |   40 +++++++++-
 3 files changed, 215 insertions(+), 2 deletions(-)
---
diff --git a/data/gnome-news.gresource.xml b/data/gnome-news.gresource.xml
index 5856cf6..7b5ea75 100644
--- a/data/gnome-news.gresource.xml
+++ b/data/gnome-news.gresource.xml
@@ -5,6 +5,7 @@
     <file compressed="true" alias="ARTISTS">../ARTISTS</file>
     <file compressed="true" alias="AUTHORS">../AUTHORS</file>
     <file compressed="true" preprocess="xml-stripblanks">gtk/menus.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">ui/empty-view.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/headerbar.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">ui/window.ui</file>
     <file compressed="true">theme/Adwaita.css</file>
diff --git a/data/ui/empty-view.ui b/data/ui/empty-view.ui
new file mode 100644
index 0000000..f70d741
--- /dev/null
+++ b/data/ui/empty-view.ui
@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.19.0 -->
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <object class="GtkBox" id="empty-search-view">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="halign">center</property>
+    <property name="valign">center</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">12</property>
+    <child>
+      <object class="GtkImage">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="pixel_size">128</property>
+        <property name="icon_name">edit-find-symbolic</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">No Results Found</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+          <attribute name="scale" value="1.4399999999999999"/>
+        </attributes>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Try a different search</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">2</property>
+      </packing>
+    </child>
+  </object>
+  <object class="GtkBox" id="empty-starred-view">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="halign">center</property>
+    <property name="valign">center</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">12</property>
+    <child>
+      <object class="GtkImage">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="pixel_size">128</property>
+        <property name="icon_name">starred-symbolic</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">No Starred Articles Found</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+          <attribute name="scale" value="1.4399999999999999"/>
+        </attributes>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">You can see your starred articles after marking 
them</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">2</property>
+      </packing>
+    </child>
+  </object>
+  <object class="GtkBox" id="empty-view">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="halign">center</property>
+    <property name="valign">center</property>
+    <property name="hexpand">True</property>
+    <property name="vexpand">True</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">12</property>
+    <child>
+      <object class="GtkImage">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="pixel_size">128</property>
+        <property name="icon_name">application-rss+xml-symbolic</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">No Feed Subscription Sound</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+          <attribute name="scale" value="1.4399999999999999"/>
+        </attributes>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">You can subscribe to feeds using the "+" button</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">2</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/gnomenews/view.py b/gnomenews/view.py
index 89d2594..cfface6 100644
--- a/gnomenews/view.py
+++ b/gnomenews/view.py
@@ -36,6 +36,9 @@ class GenericFeedsView(Gtk.Stack):
         self.name = name
         self.title = title
 
+        self._ui = Gtk.Builder()
+        self._ui.add_from_resource('/org/gnome/News/ui/empty-view.ui')
+
         self.flowbox = Gtk.FlowBox(
             min_children_per_line=2,
             activate_on_single_click=True,
@@ -46,12 +49,24 @@ class GenericFeedsView(Gtk.Stack):
         self.flowbox.get_style_context().add_class('feeds-list')
         self.flowbox.connect('child-activated', self._post_activated)
 
+        # Setup the layout
         self.setup_layout()
 
+        # Setup the Empty state view
+        self._empty_view = self._ui.get_object('empty-view')
+        self.add_named(self._empty_view, 'empty')
+
         self.tracker = tracker
         self.show_all()
 
     @log
+    def show_empty_view(self, show):
+        if show:
+            self.set_visible_child_name('empty')
+        else:
+            self.set_visible_child_name('view')
+
+    @log
     def _add_a_new_preview(self, cursor, child=None):
         p = Post(cursor)
         if child:
@@ -84,7 +99,8 @@ class GenericFeedsView(Gtk.Stack):
         self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
         self._box.pack_end(self.flowbox, True, True, 0)
         scrolledWindow.add(self._box)
-        self.add(scrolledWindow)
+
+        self.add_named(scrolledWindow, 'view')
 
     @log
     def update(self):
@@ -167,6 +183,8 @@ class NewView(GenericFeedsView):
         [self._add_a_new_preview(post) for post in posts]
         self.show_all()
 
+        self.show_empty_view(len(posts) is 0)
+
 
 class FeedsView(GenericFeedsView):
     def __init__(self, tracker):
@@ -200,6 +218,8 @@ class FeedsView(GenericFeedsView):
                 logger.info("Adding channel %s" % new_feed['url'])
                 self._add_new_feed(new_feed)
 
+        self.show_empty_view(len(new_feeds) is 0)
+
     @log
     def _add_new_feed(self, feed):
         # Check if we're not adding an already added feed
@@ -268,7 +288,7 @@ class FeedsView(GenericFeedsView):
         self._box.add(Gtk.Separator.new(Gtk.Orientation.VERTICAL))
         self._box.add(feedstackScrolledWindow)
 
-        self.add(self._box)
+        self.add_named(self._box, 'view')
 
         self._box.show_all()
 
@@ -317,6 +337,12 @@ class StarredView(GenericFeedsView):
     def __init__(self, tracker):
         GenericFeedsView.__init__(self, tracker, 'starred', _("Starred"))
 
+        # Setup a custom empty view
+        self.remove(self._empty_view)
+
+        self._empty_view = self._ui.get_object('empty-starred-view')
+        self.add_named(self._empty_view, 'empty')
+
         self.tracker.connect('items-updated', self.update)
 
     @log
@@ -327,6 +353,8 @@ class StarredView(GenericFeedsView):
         [self._add_a_new_preview(post) for post in posts]
         self.show_all()
 
+        self.show_empty_view(len(posts) is 0)
+
 
 class SearchView(GenericFeedsView):
 
@@ -339,6 +367,12 @@ class SearchView(GenericFeedsView):
 
         self.search_query = ""
 
+        # Setup a custom empty view
+        self.remove(self._empty_view)
+
+        self._empty_view = self._ui.get_object('empty-search-view')
+        self.add_named(self._empty_view, 'empty')
+
     @log
     def do_get_property(self, prop):
         if prop.name == 'search-query':
@@ -364,3 +398,5 @@ class SearchView(GenericFeedsView):
         posts = self.tracker.get_text_matches(self.search_query, 10)
         [self._add_a_new_preview(post) for post in posts]
         self.show_all()
+
+        self.show_empty_view(len(posts) is 0)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]