[gnome-clocks/clutter] Initial implementation of Clutter toolbar



commit eda75d1c13c1366d685e480891c724aacc3bb112
Author: Seif Lotfy <seif lotfy com>
Date:   Fri Aug 24 12:46:08 2012 +0200

    Initial implementation of Clutter toolbar

 gnomeclocks/app.py     |    8 ++-
 gnomeclocks/widgets.py |  120 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 124 insertions(+), 4 deletions(-)
---
diff --git a/gnomeclocks/app.py b/gnomeclocks/app.py
index 34deca1..47045b0 100644
--- a/gnomeclocks/app.py
+++ b/gnomeclocks/app.py
@@ -17,12 +17,15 @@
 # Author: Seif Lotfy <seif lotfy collabora co uk>
 
 import os
+import sys
 from gettext import ngettext
-from gi.repository import Gtk, Gdk, GObject, GLib, Gio
+from gi.repository import Gtk, Gdk, GObject, GLib, Gio, GtkClutter
 from clocks import Clock, World, Alarm, Timer, Stopwatch
+from widgets import Embed
 from utils import Dirs
 from gnomeclocks import __version__, AUTHORS, COPYRIGHTS
 
+GtkClutter.init(sys.argv)
 
 class Window(Gtk.ApplicationWindow):
     def __init__(self, app):
@@ -49,7 +52,8 @@ class Window(Gtk.ApplicationWindow):
 
         self.set_size_request(640, 480)
         self.vbox = vbox = Gtk.VBox()
-        self.add(vbox)
+        embed = Embed(vbox)
+        self.add(embed)
         self.notebook = Gtk.Notebook()
         self.notebook.set_show_tabs(False)
         self.notebook.set_show_border(False)
diff --git a/gnomeclocks/widgets.py b/gnomeclocks/widgets.py
index 4a9a85f..56bd75a 100644
--- a/gnomeclocks/widgets.py
+++ b/gnomeclocks/widgets.py
@@ -17,7 +17,7 @@
 # Author: Seif Lotfy <seif lotfy collabora co uk>
 
 from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Gio, Pango, PangoCairo
-from gi.repository import GWeather
+from gi.repository import GWeather, Clutter, GtkClutter
 
 from storage import Location
 from alarm import AlarmItem
@@ -27,6 +27,7 @@ import os
 import cairo
 import time
 
+SELECTION_TOOLBAR_DEFAULT_WIDTH = 500;
 
 # FIXME: Use real sunrise/sunset time in the future
 def get_is_day(hour):
@@ -672,5 +673,120 @@ class SelectableIconView(Gtk.IconView):
                     self.emit("selection-changed")
             else:
                 self.emit("item-activated", path)
-
         return False
+
+
+class SelectionToolbar():
+    def __init__(self, parent_actor):
+        self._parent_actor = parent_actor
+        self.widget = Gtk.Toolbar()
+        self.widget.set_show_arrow(False)
+        self.widget.set_icon_size(Gtk.IconSize.LARGE_TOOLBAR)
+        self.widget.get_style_context().add_class('osd');
+        self.widget.set_size_request(SELECTION_TOOLBAR_DEFAULT_WIDTH, -1);
+        self.actor = GtkClutter.Actor.new_with_contents(self.widget)
+        #self.actor.set_show_on_set_parent(False)
+        self.actor.set_opacity(0)
+        #Utils.alphaGtkWidget(self.actor.get_widget());
+        constraint = Clutter.AlignConstraint()
+        constraint.set_source(self._parent_actor)
+        constraint.set_align_axis(Clutter.AlignAxis.X_AXIS)
+        constraint.set_factor(0.50)
+        constraint = Clutter.AlignConstraint()
+        constraint.set_source(self._parent_actor)
+        constraint.set_align_axis(Clutter.AlignAxis.Y_AXIS)
+        constraint.set_factor(0.50)
+        self._leftBox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
+        self._leftGroup = Gtk.ToolItem()
+        self._leftGroup.add(self._leftBox)
+        self.widget.insert(self._leftGroup, -1);
+        self._toolbarDelete = Gtk.Button("Delete") #FIXME: Make translatable
+        self._leftBox.add(self._toolbarDelete);
+        self._toolbarDelete.connect('clicked', self._on_toolbar_delete)
+        self.widget.show_all()
+
+    def _on_toolbar_delete(self, widget, event):
+        pass
+
+    def change_select_mode(self, mode):
+        if mode:
+            self._fade_in() #TODO implement fading in
+        else:
+            self._fade_out()
+
+    def _fade_in(self):
+        if self.actor.opacity != 0:
+            return
+        else:
+            self.actor.opacity = 0
+            self.actor.show()
+            # FIXME: add tween
+            #Tweener.addTween(self.actor,
+            #    { opacity: 255,
+            #      time: 0.30,
+            #      transition: 'easeOutQuad' });
+            self.actor.opacity = 255
+
+    def _fade_out(self):
+        # FIXME: add tween
+        #Tweener.addTween(self.actor,
+        #{ opacity: 0,
+        #  time: 0.30,
+        #  transition: 'easeOutQuad',
+        #  onComplete: function() {
+        #      self.actor.hide();
+        #  },
+        #  onCompleteScope: this });
+        self.actor.opacity = 0
+
+
+class Embed (GtkClutter.Embed):
+    def __init__(self, notebook):
+        GtkClutter.Embed.__init__(self)
+        self.set_use_layout_size(True)
+
+        self.stage = self.get_stage()
+
+        self._overlayLayout = Clutter.BinLayout()
+        self.actor = Clutter.Box()
+        self.actor.set_layout_manager(self._overlayLayout)
+        constraint = Clutter.BindConstraint()
+        constraint.set_source(self.stage)
+        constraint.set_coordinate(Clutter.BindCoordinate.SIZE)
+        self.actor.add_constraint(constraint)
+
+        self._contentsLayout = Clutter.BoxLayout()
+        self._contentsLayout.set_vertical(True)
+        self._contentsActor = Clutter.Box()
+        self._contentsActor.set_layout_manager(self._contentsLayout)
+        self._overlayLayout.add(self._contentsActor,
+            Clutter.BinAlignment.FILL, Clutter.BinAlignment.FILL)
+
+        self._viewLayout = Clutter.BinLayout()
+        self._viewActor = Clutter.Box()
+        self._viewActor.set_layout_manager(self._viewLayout)
+        self._contentsLayout.set_expand(self._viewActor, True)
+        self._contentsLayout.set_fill(self._viewActor, True, True)
+        self._contentsActor.add_actor(self._viewActor)
+
+        self._notebook = notebook
+        self._notebookActor = GtkClutter.Actor.new_with_contents(self._notebook)
+        self._overlayLayout.add(self._notebookActor, Clutter.BinAlignment.FILL, Clutter.BinAlignment.FILL)
+        self.show_all()
+        self._notebook.show_all()
+
+################################################################################
+# Main
+################################################################################
+def main():
+    import sys
+    Clutter.init(sys.argv)
+    sec = SelectionToolbar(None)
+    sec.actor.opacity = 0
+    sec._fade_in()
+    sec._fade_out()
+    sec._fade_in()
+    embed = Embed(Gtk.Label("Hi"))
+
+if __name__ == "__main__":
+    main ()



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