[gnome-news/wip/gbsneto/improvements: 3/4] views: add empty state



commit e65b56b1aa6a755b9c0c1817af1076454f7b7dd2
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         |   61 +++++++++++++++++++++++++++++++++++++++++
 gnomenews/view.py             |   26 ++++++++++++++++-
 3 files changed, 86 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..0430d16
--- /dev/null
+++ b/data/ui/empty-view.ui
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <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 found</property>
+        <attributes>
+          <attribute name="weight" value="bold"/>
+          <attribute name="scale" value="1.44"/>
+        </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..2a6a3a8 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()
 
@@ -327,6 +347,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):
 


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