[gnome-music/wip/merge: 8/343] write toolbar.py



commit 116fff467ce7b706ed8c1811ea26056040ebc4bd
Author: Eslam Mostafa <cseslam gmail com>
Date:   Fri Jul 12 23:20:06 2013 +0200

    write toolbar.py

 gnome-music/toolbar.py |   86 +++++++++++++++++++++++++++++++++++++++++++++--
 gnome-music/window.py  |    4 ++-
 2 files changed, 85 insertions(+), 5 deletions(-)
---
diff --git a/gnome-music/toolbar.py b/gnome-music/toolbar.py
index 5ab5f96..d6c3a8b 100644
--- a/gnome-music/toolbar.py
+++ b/gnome-music/toolbar.py
@@ -1,4 +1,4 @@
-from gi.repository import Gtk
+from gi.repository import Gtk, Gd
 
 class Toolbar():
     def __init__(self):
@@ -14,7 +14,85 @@ class Toolbar():
         self._selectionMenu = self._ui.get_object("selection-menu")
         self._selectionMenuButton = self._ui.get_object("selection-menu-button")
         self._selectionMenuButton.set_relief(Gtk.ReliefStyle.NONE);
-        self.header_bar.custom_title = this._stack_switcher;
-        self._searchButton = this._ui.get_object("search-button")
-        self._backButton.connect('clicked',self._setState)
+        self.headerBar.custom_title = self._stackSwitcher;
+        self._searchButton = self._ui.get_object("search-button")
+        self._backButton.connect('clicked',self.setState)
         self._closeButton.connect('clicked', self._closeButtonClicked)
+
+    def _closeButtonClicked(self, btn):
+        self._closeButton.get_toplevel().close()
+
+    def set_stack(self, stack)
+        self._stackSwitcher.set_stack(stack)
+
+    def get_stack(self):
+        return self._stackSwitcher.get_stack()
+
+    def setSelectionMode(self, selectionMode):
+        self._selectionMode = selectionMode
+        if (selectionMode):
+            self._selectButton.hide()
+            self._cancelButton.show()
+            self.headerBar.get_style_context().add_class('selection-mode')
+            self._cancelButton.get_style_context().remove_class('selection-mode')
+        else:
+            self.headerBar.get_style_context().remove_class('selection-mode')
+            self._selectButton.set_active(false)
+            self._selectButton.show()
+            self._cancelButton.hide()
+        self._update()
+
+    def setState(self, state, *btn=None):
+        self._state = state
+        self._update()
+        self.emit('state-changed')
+
+    def _update(self):
+        if (self._state == ToolbarState.SINGLE or self._selectionMode):
+            self.headerBar.custom_title = None
+        else:
+            self.title = ""
+            self.headerBar.custom_title = self._stackSwitcher
+
+        if (self._state == ToolbarState.SINGLE and !self._selectionMode):
+            self._backButton.show()
+        else:
+            self._backButton.hide()
+
+        if (self._selectionMode):
+            self.headerBar.custom_title = self._selectionMenuButton
+            self._closeSeparator.hide()
+            self._closeButton.hide();
+        else:
+            self._closeSeparator.show()
+            self._closeButton.show()
+
+    def _addBackButton(self):
+        iconName = (self.get_direction() == Gtk.TextDirection.RTL) ?
+            'go-previous-rtl-symbolic' : 'go-previous-symbolic'
+        self._backButton = Gd.HeaderSimpleButton(symbolic_icon_name=iconName,
+                                                     label=_("Back"))
+        self._backButton.connect('clicked', self.setState);
+        self.pack_start(self._backButton, False, False, 0);
+
+    def _addSearchButton(self):
+        self._searchButton = Gd.HeaderSimpleButton(symbolic_icon_name='folder-saved-search-symbolic',
+                                                        label=_("Search"))
+        self.pack_end(self._searchButton)
+        self._searchButton.show()
+
+    def _addSelectButton(self):
+        self._selectButton = Gd.HeaderToggleButton(symbolic_icon_name='object-select-symbolic',
+                                                        label= _("Select"))
+        self.pack_end(self._selectButton)
+        self._selectButton.show()
+
+    def _addCloseButton(self):
+        self._closeSeparator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
+        self.pack_end(self._closeSeparator)
+
+        self._closeButton = Gd.HeaderSimpleButton(symbolic_icon_name='window-close-symbolic')
+        self._closeButton.set_relief(Gtk.ReliefStyle.NONE)
+        self._closeButton.connect('clicked', self._closeButtonClicked)
+        self.pack_end(self._closeButton);
+
diff --git a/gnome-music/window.py b/gnome-music/window.py
index ebacd81..0bb828f 100644
--- a/gnome-music/window.py
+++ b/gnome-music/window.py
@@ -17,4 +17,6 @@ class Window(Gtk.ApplicationWindow):
             transition_type=Gtk.StackTransitionType.CROSSFADE,
             transition_duration=100,
             visible=true)
-        
+        self._box.pack_start(self._stack, True, True, 0)
+        this.add(self._box)
+        count = 1


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