[gnome-news/wip/gbsneto/improvements] window: load widgets from resource
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-news/wip/gbsneto/improvements] window: load widgets from resource
- Date: Sat, 5 Mar 2016 17:19:00 +0000 (UTC)
commit 0f842cca12b184f79dc10856ff0143d24a221ff6
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sat Mar 5 14:12:57 2016 -0300
window: load widgets from resource
Time already proved us that crafting UI in
source code is a very bad idea. This commit
adds a new window.ui resource, and loads the
window widgets from this resource.
data/gnome-news.gresource.xml | 1 +
data/ui/window.ui | 149 +++++++++++++++++++++++++++++++++++++++++
gnomenews/window.py | 35 ++++++----
3 files changed, 171 insertions(+), 14 deletions(-)
---
diff --git a/data/gnome-news.gresource.xml b/data/gnome-news.gresource.xml
index 277e4c7..5856cf6 100644
--- a/data/gnome-news.gresource.xml
+++ b/data/gnome-news.gresource.xml
@@ -6,6 +6,7 @@
<file compressed="true" alias="AUTHORS">../AUTHORS</file>
<file compressed="true" preprocess="xml-stripblanks">gtk/menus.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>
<file compressed="true">theme/reader.css</file>
</gresource>
diff --git a/data/ui/window.ui b/data/ui/window.ui
new file mode 100644
index 0000000..6630c18
--- /dev/null
+++ b/data/ui/window.ui
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.19.0 -->
+<interface>
+ <requires lib="gtk+" version="3.16"/>
+ <object class="GtkBox" id="box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkSearchBar" id="search_bar">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <property name="show_close_button">True</property>
+ <child>
+ <object class="GtkSearchEntry" id="search_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="width_chars">40</property>
+ <property name="primary_icon_name">edit-find-symbolic</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">False</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkOverlay" id="overlay">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <child>
+ <object class="GtkStack" id="stack">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <child>
+ <placeholder/>
+ </child>
+ <style>
+ <class name="background"/>
+ </style>
+ </object>
+ <packing>
+ <property name="index">-1</property>
+ </packing>
+ </child>
+ <child type="overlay">
+ <object class="GtkRevealer" id="notification">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">center</property>
+ <property name="valign">start</property>
+ <property name="transition_type">none</property>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="notification_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="secondary_action_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="close_notification_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="relief">none</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">window-close-symbolic</property>
+ </object>
+ </child>
+ <style>
+ <class name="image-button"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child type="label_item">
+ <placeholder/>
+ </child>
+ <style>
+ <class name="osd"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkActionBar" id="action_bar">
+ <property name="can_focus">False</property>
+ </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/window.py b/gnomenews/window.py
index 9e2d026..bbc4f4d 100644
--- a/gnomenews/window.py
+++ b/gnomenews/window.py
@@ -40,8 +40,11 @@ class Window(Gtk.ApplicationWindow):
self.tracker = Tracker()
self.restore_saved_size()
- # Start drawing UI
- self._setup_view()
+
+ # Setup UI widgets
+ self._setup_widgets()
+
+ self.show()
@log
def restore_saved_size(self):
@@ -79,24 +82,28 @@ class Window(Gtk.ApplicationWindow):
self.settings.set_value('window-position', GLib.Variant('ai', [position[0], position[1]]))
@log
- def _setup_view(self):
- self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ def _setup_widgets(self):
+ self._ui = Gtk.Builder()
+ self._ui.add_from_resource('/org/gnome/News/ui/window.ui')
+
+ self._box = self._ui.get_object('box')
+ self.add(self._box)
+
+ # Views
self.views = []
- self.toolbar = Toolbar(self)
- self._stack = Gtk.Stack(
- transition_type=Gtk.StackTransitionType.CROSSFADE,
- transition_duration=100,
- visible=True,
- can_focus=False)
+ self._stack = self._ui.get_object('stack')
+ self._overlay = self._ui.get_object('overlay')
self._stack.connect("notify::visible-child", self.view_changed)
- self._overlay = Gtk.Overlay(child=self._stack)
+
+ # Action bar
+ self.action_bar = self._ui.get_object('action_bar')
+
+ # Header bar
+ self.toolbar = Toolbar(self)
self.set_titlebar(self.toolbar.header_bar)
- self._box.pack_start(self._overlay, True, True, 0)
- self.add(self._box)
self._add_views()
- self.show_all()
self.toolbar._back_button.set_visible(False)
@log
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]