[pygi] add the gtk-demo app along with a couple of demos



commit 03b99692b81631d397ab62dcd263341465bcee88
Author: John (J5) Palmieri <johnp redhat com>
Date:   Fri Jun 4 16:26:54 2010 -0400

    add the gtk-demo app along with a couple of demos
    
    * note there are still a couple of patches in bugzilla that are needed for this
      to run correctly:
        - http://bugzilla-attachments.gnome.org/attachment.cgi?id=162682
        - http://bugzilla-attachments.gnome.org/attachment.cgi?id=162764

 demos/gtk-demo/demos/appwindow.py                |  393 ++++++++++++++++++++++
 demos/gtk-demo/demos/data/alphatest.png          |  Bin 0 -> 26529 bytes
 demos/gtk-demo/demos/data/apple-red.png          |  Bin 0 -> 3545 bytes
 demos/gtk-demo/demos/data/background.jpg         |  Bin 0 -> 22219 bytes
 demos/gtk-demo/demos/data/demo.ui                |  258 ++++++++++++++
 demos/gtk-demo/demos/data/floppybuddy.gif        |  Bin 0 -> 5216 bytes
 demos/gtk-demo/demos/data/gnome-applets.png      |  Bin 0 -> 3090 bytes
 demos/gtk-demo/demos/data/gnome-calendar.png     |  Bin 0 -> 2755 bytes
 demos/gtk-demo/demos/data/gnome-foot.png         |  Bin 0 -> 2916 bytes
 demos/gtk-demo/demos/data/gnome-fs-directory.png |  Bin 0 -> 2044 bytes
 demos/gtk-demo/demos/data/gnome-fs-regular.png   |  Bin 0 -> 1795 bytes
 demos/gtk-demo/demos/data/gnome-gimp.png         |  Bin 0 -> 3410 bytes
 demos/gtk-demo/demos/data/gnome-gmush.png        |  Bin 0 -> 3244 bytes
 demos/gtk-demo/demos/data/gnome-gsame.png        |  Bin 0 -> 4263 bytes
 demos/gtk-demo/demos/data/gnu-keys.png           |  Bin 0 -> 3852 bytes
 demos/gtk-demo/demos/data/gtk-logo-rgb.gif       |  Bin 0 -> 6427 bytes
 demos/gtk-demo/demos/test.py                     |   14 +
 demos/gtk-demo/gtk-demo.py                       |  266 +++++++++++++++
 18 files changed, 931 insertions(+), 0 deletions(-)
---
diff --git a/demos/gtk-demo/demos/__init__.py b/demos/gtk-demo/demos/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/demos/gtk-demo/demos/appwindow.py b/demos/gtk-demo/demos/appwindow.py
new file mode 100644
index 0000000..5116f9f
--- /dev/null
+++ b/demos/gtk-demo/demos/appwindow.py
@@ -0,0 +1,393 @@
+#!/bin/env python
+
+title = "Application main window"
+description = """
+Demonstrates a typical application window with menubar, toolbar, statusbar.
+"""
+
+# See FIXME's
+is_fully_bound = False
+
+from gi.repository import Gtk, GdkPixbuf, Gdk
+import sys, os
+
+global infobar
+global window
+global messagelabel
+
+def widget_destroy(widget, button):
+    widget.destroy()
+
+def activate_action(action):
+    global window
+
+    name = action.get_name()
+    _type = type(action)
+    if name == 'DarkTheme':
+        value = action.get_active()
+        settings = Gtk.Settings.get_default()
+        settings.set_property('gtk-application-prefer-dark-theme', value)
+        return
+
+
+    dialog = Gtk.MessageDialog(message_type=Gtk.MessageType.INFO,
+                               buttons=Gtk.ButtonsType.CLOSE,
+                               text='You activated action: "%s" of type %s' % (name, _type))
+
+    # FIXME: this should be done in the constructor
+    dialog.set_transient_for(window)
+    dialog.connect('response', widget_destroy)
+    dialog.show()
+
+def activate_radio_action(action, current):
+    global infobar
+    global messagelabel
+ 
+    name = current.get_name()
+    _type = type(current)
+    active = current.get_active()
+    value = current.get_current_value()
+    if active:
+        text = 'You activated radio action: "%s" of type %s.\n Current value: %d' % (name, _type, value)
+        messagelabel.set_text(text)
+        infobar.set_message_type(Gtk.MessageType(value))
+        infobar.show()
+
+def update_statusbar(buffer, statusbar):
+    statusbar.pop(0)
+    count = buffer.get_char_count()
+
+    iter = Gtk.TextIter()
+    buffer.get_iter_at_mark(iter, buffer.get_insert())
+    row = iter.get_line()
+    col = iter.get_line_offset()
+    msg = 'Cursor at row %d column %d - %d chars in document' % (row, col, count)
+    
+    statusbar.push(0, msg)
+
+def mark_set_callback(buffer, new_location, mark, data):
+    update_statusbar(buffer, data)
+
+def update_resize_grip(widget, event, statusbar):
+    pass
+    # FIXME: event should be a Gdk.EventWindowState but is only a Gdk.Event
+    if event.changed_mask and (Gdk.WindowState.MAXIMIZED or
+			       Gdk.WindowState.FULLSCREEN):
+
+        maximized = event.new_window_state and (Gdk.WindowState.MAXIMIZED or
+					        Gdk.WindowState.FULLSCREEN)
+        statusbar.set_has_resize_grip(not maximized)
+
+def activate_email(about, link, data):
+    text = 'send mail to %s' % (link,)
+    print text
+
+def activate_url(about, link, data):
+    text = 'show url %s' % (link,)
+    print text
+
+def about_cb(widget):
+    global window
+
+    authors = ['John (J5) Palmieri',
+               'Tomeu Vizoso', 
+               'and many more...']
+
+    documentors =  ['David Malcolm',
+                    'Zack Goldberg',
+                    'and many more...']
+
+    license = """
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the Gnome Library; see the file COPYING.LIB.  If not,
+write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
+"""
+    filename = os.path.join('data', 'gtk-logo-rgb.gif')
+    pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
+    transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff) 
+    Gtk.AboutDialog.set_email_hook(activate_email, None)
+    Gtk.AboutDialog.set_url_hook(activate_url, None)
+    # FIXME: override Gtk.show_about_dialog
+    #        make about dailog constructor take a parent argument
+    about = Gtk.AboutDialog(program_name='GTK+ Code Demos',
+			    version='0.1',
+			    copyright='(C) 2010 The PyGI Team',
+			    license=license,
+			    website='http://live.gnome.org/PyGI',
+			    comments='Program to demonstrate PyGI functions.',
+			    authors=authors,
+			    documenters=documentors,
+			    logo=transparent,
+                            title='About GTK+ Code Demos')
+
+    about.set_transient_for(window)
+    about.connect('response', widget_destroy)
+    about.show()  
+    
+
+action_entries = (
+    ("FileMenu", None, "_File"),                # name, stock id, label
+    ("OpenMenu", None, "_Open"),                # name, stock id, label
+    ("PreferencesMenu", None, "_Preferences"),  # name, stock id, label
+    ("ColorMenu", None, "_Color"),              # name, stock id, label
+    ("ShapeMenu", None, "_Shape"),              # name, stock id, label
+    ("HelpMenu", None, "_Help"),                # name, stock id, label
+    ("New", Gtk.STOCK_NEW,                      # name, stock id
+     "_New", "<control>N",                      # label, accelerator
+     "Create a new file",                       # tooltip
+     activate_action),
+    ("File1", None,                             # name, stock id
+     "File1", None,                             # label, accelerator
+     "Open first file",                         # tooltip
+     activate_action),
+    ("Save", Gtk.STOCK_SAVE,                    # name, stock id
+     "_Save","<control>S",                      # label, accelerator
+     "Save current file",                       # tooltip
+     activate_action),
+    ("SaveAs", Gtk.STOCK_SAVE,                  # name, stock id
+     "Save _As...", None,                       # label, accelerator
+     "Save to a file",                          # tooltip
+     activate_action),
+    ("Quit", Gtk.STOCK_QUIT,                    # name, stock id
+     "_Quit", "<control>Q",                     # label, accelerator
+     "Quit",                                    # tooltip
+     activate_action),
+    ("About", None,                             # name, stock id
+     "_About", "<control>A",                    # label, accelerator
+     "About",                                   # tooltip
+     about_cb),
+    ("Logo", "demo-gtk-logo",                   # name, stock id
+     None, None,                                # label, accelerator
+     "GTK+",                                    # tooltip
+     activate_action),
+)
+
+toggle_action_entries = (
+    ("Bold", Gtk.STOCK_BOLD,                    # name, stock id
+     "_Bold", "<control>B",                     # label, accelerator
+     "Bold",                                    # tooltip
+     activate_action,
+     True),                                     # is_active
+    ("DarkTheme", None,                         # name, stock id
+     "_Prefer Dark Theme", None,                # label, accelerator
+     "Prefer Dark Theme",                       # tooltip
+     activate_action,
+     False),                                    # is_active
+)
+
+(COLOR_RED,
+ COLOR_GREEN,
+ COLOR_BLUE) = range(3)
+
+color_action_entries = (
+    ("Red", None,                               # name, stock id
+     "_Red", "<control>R",                      # label, accelerator
+     "Blood", COLOR_RED),                       # tooltip, value
+    ("Green", None,                             # name, stock id
+     "_Green", "<control>G",                    # label, accelerator
+     "Grass", COLOR_GREEN),                     # tooltip, value
+    ("Blue", None,                              # name, stock id
+     "_Blue", "<control>B",                     # label, accelerator
+     "Sky", COLOR_BLUE),                        # tooltip, value
+)
+
+(SHAPE_SQUARE,
+ SHAPE_RECTANGLE,
+ SHAPE_OVAL) = range(3)
+
+shape_action_entries = (
+    ("Square", None,                            # name, stock id
+     "_Square", "<control>S",                   # label, accelerator
+     "Square",  SHAPE_SQUARE),                  # tooltip, value
+    ("Rectangle", None,                         # name, stock id
+     "_Rectangle", "<control>R",                # label, accelerator
+     "Rectangle", SHAPE_RECTANGLE),             # tooltip, value
+    ("Oval", None,                              # name, stock id
+     "_Oval", "<control>O",                     # label, accelerator
+     "Egg", SHAPE_OVAL ),                       # tooltip, value
+)
+
+ui_info = """
+<ui>
+  <menubar name='MenuBar'>
+    <menu action='FileMenu'>
+      <menuitem action='New'/>
+      <menuitem action='Open'/>
+      <menuitem action='Save'/>
+      <menuitem action='SaveAs'/>
+      <separator/>
+      <menuitem action='Quit'/>
+    </menu>
+    <menu action='PreferencesMenu'>
+      <menuitem action='DarkTheme'/>
+      <menu action='ColorMenu'>
+    <menuitem action='Red'/>
+    <menuitem action='Green'/>
+    <menuitem action='Blue'/>
+      </menu>
+      <menu action='ShapeMenu'>
+        <menuitem action='Square'/>
+        <menuitem action='Rectangle'/>
+        <menuitem action='Oval'/>
+      </menu>
+      <menuitem action='Bold'/>
+    </menu>
+    <menu action='HelpMenu'>
+      <menuitem action='About'/>
+    </menu>
+  </menubar>
+  <toolbar name='ToolBar'>
+    <toolitem action='Open'>
+      <menu action='OpenMenu'>
+        <menuitem action='File1'/>
+      </menu>
+    </toolitem>
+    <toolitem action='Quit'/>
+    <separator action='Sep1'/>
+    <toolitem action='Logo'/>
+  </toolbar>
+</ui>
+"""
+
+def _quit(*args):
+    Gtk.main_quit()
+
+def register_stock_icons():
+    """
+    This function registers our custom toolbar icons, so they can be themed.
+    It's totally optional to do this, you could just manually insert icons
+    and have them not be themeable, especially if you never expect people
+    to theme your app.
+    """
+    '''
+    item = Gtk.StockItem()
+    item.stock_id = 'demo-gtk-logo'
+    item.label = '_GTK!'
+    item.modifier = 0
+    item.keyval = 0
+    item.translation_domain = None
+
+    Gtk.stock_add(item, 1)
+    '''
+
+    factory = Gtk.IconFactory()
+    factory.add_default()
+    filename = os.path.join('data', 'gtk-logo-rgb.gif')
+    pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
+    transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff)
+    icon_set = Gtk.IconSet.new_from_pixbuf(transparent)
+
+    factory.add('demo-gtk-logo', icon_set)
+
+class ToolMenuAction(Gtk.Action):
+    __gtype_name__ = "GtkToolMenuAction"
+    def do_create_tool_item(self):
+        return Gtk.MenuToolButton()
+
+def main():
+    global infobar
+    global window
+    global messagelabel 
+
+    register_stock_icons()
+
+    window = Gtk.Window()
+    window.set_title('Application Window')
+    window.set_icon_name('gtk-open')
+    window.connect_after('destroy', _quit)
+    table = Gtk.Table(n_rows=1,
+                      n_columns=5,
+                      homogeneous=False)
+    window.add(table)
+
+    action_group = Gtk.ActionGroup(name='AppWindowActions')
+    open_action = ToolMenuAction(name = 'Open',
+                             stock_id = Gtk.STOCK_OPEN,
+                             label = '_Open',
+                             tooltip = 'Open a file')
+
+    action_group.add_action(open_action)
+    action_group.add_actions(action_entries)
+    action_group.add_toggle_actions(toggle_action_entries)
+    action_group.add_radio_actions(color_action_entries,
+                                   COLOR_RED,
+                                   activate_radio_action)
+    action_group.add_radio_actions(shape_action_entries,
+                                   SHAPE_SQUARE,
+                                   activate_radio_action)
+
+    merge = Gtk.UIManager()
+    merge.insert_action_group(action_group, 0)
+    window.add_accel_group(merge.get_accel_group())
+
+    merge.add_ui_from_string(ui_info)
+
+    bar = merge.get_widget('/MenuBar')
+    bar.show()
+    table.attach(bar, 0, 1, 0, 1,
+                 Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+                 0, 0, 0)
+
+    bar = merge.get_widget('/ToolBar')
+    bar.show()
+    table.attach(bar, 0, 1, 1, 2,
+                 Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+                 0, 0, 0)
+
+
+    infobar = Gtk.InfoBar();
+    infobar.set_no_show_all(True)
+    messagelabel = Gtk.Label()
+    messagelabel.show()
+    infobar.get_content_area().pack_start(messagelabel, True, True, 0)
+    infobar.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
+    infobar.connect('response', lambda a, b: Gtk.Widget.hide(a))
+
+    table.attach(infobar, 0, 1, 2, 3,
+                 Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+                 0, 0, 0)
+
+    sw = Gtk.ScrolledWindow(hadjustment=None,
+                            vadjustment=None)
+    sw.set_shadow_type(Gtk.ShadowType.IN)
+    table.attach(sw, 0, 1, 3, 4,
+                 Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+                 Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+                 0, 0)
+
+    contents = Gtk.TextView()
+    contents.grab_focus()
+    sw.add(contents)
+
+    # Create statusbar
+    statusbar = Gtk.Statusbar()
+    table.attach(statusbar, 0, 1, 4, 5,
+                 Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL,
+                 0, 0, 0)
+
+    # show text widget info in the statusbar
+    buffer = contents.get_buffer()
+    buffer.connect('changed', update_statusbar, statusbar)
+    buffer.connect('mark_set', mark_set_callback, statusbar)
+
+    window.connect('window_state_event', update_resize_grip, statusbar)
+
+    update_statusbar(buffer, statusbar);
+
+    window.set_default_size(200, 200)
+    window.show_all()
+    Gtk.main()
+
+if __name__ == '__main__':
+    main()
diff --git a/demos/gtk-demo/demos/data/alphatest.png b/demos/gtk-demo/demos/data/alphatest.png
new file mode 100644
index 0000000..eb5885f
Binary files /dev/null and b/demos/gtk-demo/demos/data/alphatest.png differ
diff --git a/demos/gtk-demo/demos/data/apple-red.png b/demos/gtk-demo/demos/data/apple-red.png
new file mode 100644
index 0000000..b0a24e9
Binary files /dev/null and b/demos/gtk-demo/demos/data/apple-red.png differ
diff --git a/demos/gtk-demo/demos/data/background.jpg b/demos/gtk-demo/demos/data/background.jpg
new file mode 100644
index 0000000..86c006a
Binary files /dev/null and b/demos/gtk-demo/demos/data/background.jpg differ
diff --git a/demos/gtk-demo/demos/data/demo.ui b/demos/gtk-demo/demos/data/demo.ui
new file mode 100644
index 0000000..57dd232
--- /dev/null
+++ b/demos/gtk-demo/demos/data/demo.ui
@@ -0,0 +1,258 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<interface domain="gtk20">
+    <object class="GtkListStore" id="liststore1">
+      <columns>
+        <column type="gchararray"/>
+        <column type="gchararray"/>
+        <column type="gint"/>
+        <column type="gchararray"/>
+      </columns>
+      <data>
+        <row>
+          <col id="0" translatable="yes">John</col>
+          <col id="1" translatable="yes">Doe</col>
+          <col id="2">25</col>
+          <col id="3" translatable="yes">This is the John Doe row</col>
+        </row>
+        <row>
+          <col id="0" translatable="yes">Mary</col>
+          <col id="1" translatable="yes">Unknown</col>
+          <col id="2">50</col>
+          <col id="3" translatable="yes">This is the Mary Unknown row</col>
+        </row>
+      </data>
+    </object>
+    <object class="GtkUIManager" id="uimanager">
+        <child>
+            <object class="GtkActionGroup" id="DefaultActions">
+                <child>
+                    <object class="GtkAction" id="Copy">
+                        <property name="name">Copy</property>
+                        <property name="tooltip" translatable="yes">Copy selected object into the clipboard</property>
+                        <property name="stock_id">gtk-copy</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="Cut">
+                        <property name="name">Cut</property>
+                        <property name="tooltip" translatable="yes">Cut selected object into the clipboard</property>
+                        <property name="stock_id">gtk-cut</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="EditMenu">
+                        <property name="name">EditMenu</property>
+                        <property name="label" translatable="yes">_Edit</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="FileMenu">
+                        <property name="name">FileMenu</property>
+                        <property name="label" translatable="yes">_File</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="New">
+                        <property name="name">New</property>
+                        <property name="tooltip" translatable="yes">Create a new file</property>
+                        <property name="stock_id">gtk-new</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="Open">
+                        <property name="name">Open</property>
+                        <property name="tooltip" translatable="yes">Open a file</property>
+                        <property name="stock_id">gtk-open</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="Paste">
+                        <property name="name">Paste</property>
+                        <property name="tooltip" translatable="yes">Paste object from the Clipboard</property>
+                        <property name="stock_id">gtk-paste</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="Quit">
+                        <property name="name">Quit</property>
+                        <property name="tooltip" translatable="yes">Quit the program</property>
+                        <property name="stock_id">gtk-quit</property>
+                        <signal handler="quit_activate" name="activate"/>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="Save">
+                        <property name="name">Save</property>
+                        <property name="is_important">True</property>
+                        <property name="tooltip" translatable="yes">Save a file</property>
+                        <property name="stock_id">gtk-save</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="SaveAs">
+                        <property name="name">SaveAs</property>
+                        <property name="tooltip" translatable="yes">Save with a different name</property>
+                        <property name="stock_id">gtk-save-as</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="HelpMenu">
+                        <property name="name">HelpMenu</property>
+                        <property name="label" translatable="yes">_Help</property>
+                    </object>
+                </child>
+                <child>
+                    <object class="GtkAction" id="About">
+                        <property name="name">About</property>
+                        <property name="stock_id">gtk-about</property>
+                        <signal handler="about_activate" name="activate"/>
+                    </object>
+                    <accelerator key="F1"/>
+                </child>
+            </object>
+        </child>
+        <ui>
+          <menubar name="menubar1">
+            <menu action="FileMenu" name="FileMenu">
+              <menuitem action="New" name="New"/>
+              <menuitem action="Open" name="Open"/>
+              <menuitem action="Save" name="Save"/>
+              <menuitem action="SaveAs" name="SaveAs"/>
+              <separator/>
+              <menuitem action="Quit" name="Quit"/>
+            </menu>
+            <menu action="EditMenu">
+              <menuitem action="Copy" name="Copy"/>
+              <menuitem action="Cut" name="Cut"/>
+              <menuitem action="Paste" name="Paste"/>
+            </menu>
+            <menu action="HelpMenu" name="HelpMenu">
+              <menuitem action="About" name="About"/>
+            </menu>
+          </menubar>
+          <toolbar name="toolbar1">
+            <toolitem action="New" name="New"/>
+            <toolitem action="Open" name="Open"/>
+            <toolitem action="Save" name="Save"/>
+            <separator/>
+            <toolitem action="Copy" name="Copy"/>
+            <toolitem action="Cut" name="Cut"/>
+            <toolitem action="Paste" name="Paste"/>
+          </toolbar>
+        </ui>
+    </object>
+    <object class="GtkAboutDialog" id="aboutdialog1">
+        <property name="program-name" translatable="yes">GtkBuilder demo</property>
+         <accessibility>
+	     <relation target="window1" type="subwindow-of"/>
+	 </accessibility>
+    </object>
+    <object class="GtkWindow" id="window1">
+        <property name="default_height">250</property>
+        <property name="default_width">440</property>
+        <property name="title">GtkBuilder demo</property>
+        <child>
+            <object class="GtkVBox" id="vbox1">
+                <property name="visible">True</property>
+                <child>
+                    <object constructor="uimanager" class="GtkMenuBar" id="menubar1">
+                        <property name="visible">True</property>
+	            	<child internal-child="accessible">
+	            	    <object class="AtkObject" id="a11y-menubar">
+	            	        <property name="AtkObject::accessible-name">The menubar</property>
+	            	    </object>
+	            	</child>
+	            </object>
+                    <packing>
+                        <property name="expand">False</property>
+                    </packing>
+                </child>
+                <child>
+                    <object constructor="uimanager" class="GtkToolbar" id="toolbar1">
+                        <property name="visible">True</property>
+	            	<child internal-child="accessible">
+	            	    <object class="AtkObject" id="a11y-toolbar">
+	            	        <property name="AtkObject::accessible-name">The toolbar</property>
+	            	    </object>
+	            	</child>
+                    </object>
+                    <packing>
+                        <property name="expand">False</property>
+                        <property name="position">1</property>
+                    </packing>
+                </child>
+                <child>
+                    <object class="GtkScrolledWindow" id="scrolledwindow1">
+                      <property name="hscrollbar_policy">automatic</property>
+                      <property name="shadow_type">in</property>
+                      <property name="visible">True</property>
+                      <property name="vscrollbar_policy">automatic</property>
+                      <child>
+                        <object class="GtkTreeView" id="treeview1">
+                          <property name="visible">True</property>
+                          <property name="model">liststore1</property>
+                          <property name="tooltip-column">3</property>
+	            	  <child internal-child="accessible">
+	            	      <object class="AtkObject" id="a11y-treeview">
+	            	          <property name="AtkObject::accessible-name">Name list</property>
+                                  <property name="AtkObject::accessible-description">
+                                    A list of person with name, surname and age columns
+                                  </property>
+	            	      </object>
+	            	  </child>
+                          <child>
+                            <object class="GtkTreeViewColumn" id="column1">
+                              <property name="title">Name</property>
+                              <child>
+                                <object class="GtkCellRendererText" id="renderer1"/>
+                                <attributes>
+                                  <attribute name="text">0</attribute>
+                                </attributes>
+                              </child>
+                            </object>
+                          </child>
+                          <child>
+                            <object class="GtkTreeViewColumn" id="column2">
+                              <property name="title">Surname</property>
+                              <child>
+                                <object class="GtkCellRendererText" id="renderer2"/>
+                                <attributes>
+                                  <attribute name="text">1</attribute>
+                                </attributes>
+                              </child>
+                            </object>
+                          </child>
+                          <child>
+                            <object class="GtkTreeViewColumn" id="column3">
+                              <property name="title">Age</property>
+                              <child>
+                                <object class="GtkCellRendererText" id="renderer3"/>
+                                <attributes>
+                                  <attribute name="text">2</attribute>
+                                </attributes>
+                              </child>
+                            </object>
+                          </child>
+                        </object>
+                      </child>
+		    <accessibility>
+		      	<action action_name="move-cursor" description="Move the cursor to select another person."/>
+		    </accessibility>
+                    </object>
+                    <packing>
+                        <property name="position">2</property>
+                    </packing>
+                </child>
+                <child>
+                    <object class="GtkStatusbar" id="statusbar1">
+                        <property name="visible">True</property>
+                    </object>
+                    <packing>
+                        <property name="expand">False</property>
+                        <property name="position">3</property>
+                    </packing>
+                </child>
+            </object>
+        </child>
+    </object>
+</interface>
diff --git a/demos/gtk-demo/demos/data/floppybuddy.gif b/demos/gtk-demo/demos/data/floppybuddy.gif
new file mode 100644
index 0000000..ac986c8
Binary files /dev/null and b/demos/gtk-demo/demos/data/floppybuddy.gif differ
diff --git a/demos/gtk-demo/demos/data/gnome-applets.png b/demos/gtk-demo/demos/data/gnome-applets.png
new file mode 100644
index 0000000..8d3549e
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnome-applets.png differ
diff --git a/demos/gtk-demo/demos/data/gnome-calendar.png b/demos/gtk-demo/demos/data/gnome-calendar.png
new file mode 100644
index 0000000..889f329
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnome-calendar.png differ
diff --git a/demos/gtk-demo/demos/data/gnome-foot.png b/demos/gtk-demo/demos/data/gnome-foot.png
new file mode 100644
index 0000000..0476658
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnome-foot.png differ
diff --git a/demos/gtk-demo/demos/data/gnome-fs-directory.png b/demos/gtk-demo/demos/data/gnome-fs-directory.png
new file mode 100644
index 0000000..05921a6
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnome-fs-directory.png differ
diff --git a/demos/gtk-demo/demos/data/gnome-fs-regular.png b/demos/gtk-demo/demos/data/gnome-fs-regular.png
new file mode 100644
index 0000000..0f5019c
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnome-fs-regular.png differ
diff --git a/demos/gtk-demo/demos/data/gnome-gimp.png b/demos/gtk-demo/demos/data/gnome-gimp.png
new file mode 100644
index 0000000..f6bbc6d
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnome-gimp.png differ
diff --git a/demos/gtk-demo/demos/data/gnome-gmush.png b/demos/gtk-demo/demos/data/gnome-gmush.png
new file mode 100644
index 0000000..0a4b0d0
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnome-gmush.png differ
diff --git a/demos/gtk-demo/demos/data/gnome-gsame.png b/demos/gtk-demo/demos/data/gnome-gsame.png
new file mode 100644
index 0000000..01c0611
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnome-gsame.png differ
diff --git a/demos/gtk-demo/demos/data/gnu-keys.png b/demos/gtk-demo/demos/data/gnu-keys.png
new file mode 100644
index 0000000..58a3377
Binary files /dev/null and b/demos/gtk-demo/demos/data/gnu-keys.png differ
diff --git a/demos/gtk-demo/demos/data/gtk-logo-rgb.gif b/demos/gtk-demo/demos/data/gtk-logo-rgb.gif
new file mode 100644
index 0000000..63c622b
Binary files /dev/null and b/demos/gtk-demo/demos/data/gtk-logo-rgb.gif differ
diff --git a/demos/gtk-demo/demos/test.py b/demos/gtk-demo/demos/test.py
new file mode 100644
index 0000000..4716ff7
--- /dev/null
+++ b/demos/gtk-demo/demos/test.py
@@ -0,0 +1,14 @@
+title = "Test Demo"
+description = "Dude this is a test"
+is_fully_bound = True
+
+from gi.repository import Gtk
+
+def _quit(*args):
+    Gtk.main_quit()
+
+def main():
+    window = Gtk.Window()
+    window.connect_after('destroy', _quit)
+    window.show_all()
+    Gtk.main()
diff --git a/demos/gtk-demo/gtk-demo.py b/demos/gtk-demo/gtk-demo.py
new file mode 100755
index 0000000..9c164dc
--- /dev/null
+++ b/demos/gtk-demo/gtk-demo.py
@@ -0,0 +1,266 @@
+#!/bin/env python
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# vim: tabstop=4 shiftwidth=4 expandtab
+#
+# Copyright (C) 2010 Red Hat, Inc., John (J5) Palmieri <johnp redhat com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+
+
+
+from gi.repository import Gtk, GLib, GObject, GdkPixbuf, Gio, Pango
+import os
+import glob
+
+_DEMOCODEDIR = os.getcwd()
+
+class Demo(GObject.GObject):
+    __gtype_name__ = 'GtkDemo'
+
+    def __init__(self, title = None, module = None, filename = None, children = None):
+        super(Demo, self).__init__()
+        self.title = title
+        self.module = module
+        self.filename = filename
+        if children is None:
+            children = []
+
+        self.children = children
+
+class GtkDemoApp(object):
+    def _quit(self, *args):
+        Gtk.main_quit()
+
+    def __init__(self):
+        super(GtkDemoApp, self).__init__()
+
+        self._demos = []
+        self.load_demos()
+
+        self.setup_default_icon()
+
+        window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
+        window.set_title('PyGI GTK+ Code Demos')
+
+        window.connect_after('destroy', self._quit)
+
+        hbox = Gtk.HBox(homogeneous = False, spacing = 0)
+        window.add(hbox)
+
+        tree = self.create_tree()
+        hbox.pack_start(tree, False, False, 0)
+
+        notebook = Gtk.Notebook()
+        hbox.pack_start(notebook, True, True, 0)
+
+        (text_widget, info_buffer) = self.create_text(True)
+        notebook.append_page(text_widget, Gtk.Label.new_with_mnemonic('_Info'))
+        self.info_buffer = info_buffer
+
+        tag = info_buffer.create_tag ('title', font = 'Sans 18')
+
+        (text_widget, source_buffer) = self.create_text(True)
+        notebook.append_page(text_widget, Gtk.Label.new_with_mnemonic('_Source'))
+
+        self.source_buffer = source_buffer;
+        tag = source_buffer.create_tag ('comment', foreground = 'DodgerBlue')
+        tag = source_buffer.create_tag ('type', foreground = 'ForestGreen')
+        tag = source_buffer.create_tag ('string',
+                                        foreground = 'RosyBrown',
+                                        weight = Pango.Weight.BOLD)
+        tag = source_buffer.create_tag ('control', foreground = 'purple')
+        tag = source_buffer.create_tag ('preprocessor',
+                                        style = Pango.Style.OBLIQUE,
+                                        foreground = 'burlywood4')
+        tag = source_buffer.create_tag ('function' ,
+                                        weight = Pango.Weight.BOLD,
+                                        foreground = 'DarkGoldenrod4')
+
+        self.source_buffer = source_buffer
+        window.set_default_size (600, 400)
+        window.show_all()
+
+        self.selection_cb(self.tree_view.get_selection(), 
+                          self.tree_view.get_model())
+        Gtk.main()
+
+    def load_demos(self):
+        demo_wildcard = os.path.join('demos', '*.py')
+        demo_file_list = glob.glob(demo_wildcard)
+        for f in demo_file_list:
+            base_name = os.path.basename(f)
+            if base_name == '__init__.py':
+                continue
+
+            module_name = base_name[0:-3]
+            module = getattr(__import__('demos.' + module_name), module_name)
+            try:
+	    	demo = Demo(module.title, module, f)
+            except AttributeError, e:
+                raise AttributeError('(%s): %s' % (f, e.message))
+            self._demos.append(demo)
+	
+
+    def demo_find_file(self, base=''):
+        dir = os.path.join('demos', 'data')
+        logo_file = os.path.join(dir, 'gtk-logo-rgb.gif')
+        base_file = os.path.join(dir, base)
+
+        if (GLib.file_test(logo_file, GLib.FileTest.EXISTS) and
+             GLib.file_test(base_file, GLib.FileTest.EXISTS)):
+            return base_file
+        else:
+            filename = os.path.join(_DEMOCODEDIR, base)
+            if GLib.file_test(filename, GLib.FileTest.EXISTS):
+                return filename
+
+            # can't find the file
+            raise IOError('Cannot find demo data file "%s"' % base)
+
+    def setup_default_icon(self):
+        filename = self.demo_find_file ('gtk-logo-rgb.gif')
+        pixbuf = GdkPixbuf.Pixbuf.new_from_file(filename)
+        transparent = pixbuf.add_alpha(True, 0xff, 0xff, 0xff)
+        list = []
+        list.append(transparent)
+        Gtk.Window.set_default_icon_list(list)
+
+    def selection_cb(self, selection, model):
+        start = Gtk.TextIter()
+        end = Gtk.TextIter()
+        iter = Gtk.TreeIter()
+
+        (success, m) = selection.get_selected(iter)
+        if not success:
+            return
+
+        demo = model.get_value(iter, 1)
+        
+        title = demo.title
+        description = demo.module.description
+        code = GLib.file_get_contents(demo.filename)[1]
+
+        # output and style the title
+        self.info_buffer.get_bounds(start, end)
+        self.info_buffer.delete(start, end)
+        self.source_buffer.get_bounds(start, end)
+        self.source_buffer.delete(start, end)
+
+        self.info_buffer.get_iter_at_offset(start, 0)
+        end = start.copy()
+        self.info_buffer.insert(end, title)
+        start = end.copy()
+        start.backward_chars(len(title))
+        self.info_buffer.apply_tag_by_name('title', start, end)
+        self.info_buffer.insert(end, '\n\n')
+
+        # output the description
+        self.info_buffer.insert(end, description)
+
+        # output the code
+        self.source_buffer.get_iter_at_offset(start, 0)
+        end = start.copy()
+        self.source_buffer.insert(end, code)
+
+    def row_activated_cb(self, view, path, col, store):
+        iter = Gtk.TreeIter()
+        store.get_iter(iter, path)
+        demo = store.get_value(iter, 1)
+        demo.module.main()
+
+    def create_tree(self):
+        tree_store = Gtk.TreeStore(str, Demo, Pango.Style)
+        tree_view = Gtk.TreeView()
+        self.tree_view = tree_view
+        tree_view.set_model(tree_store)
+        selection = tree_view.get_selection()
+        selection.set_mode(Gtk.SelectionMode.BROWSE)
+        tree_view.set_size_request(200, -1)
+
+        for demo in self._demos:
+            children = demo.children
+            parent = tree_store.append(None, 
+                                       (demo.title,
+                                        demo,
+                                        Pango.Style.NORMAL))
+            if children:
+                for child_demo in children:
+                    tree_store.append(parent, 
+                                      (child_demo.title,
+                                       Pango.Style.NORMAL))    
+
+        cell = Gtk.CellRendererText()
+        column = Gtk.TreeViewColumn(title = 'Widget (double click for demo)',
+                                    cell_renderer = cell,
+                                    text = 0,
+                                    style = 2)
+
+        
+        first_iter = Gtk.TreeIter()
+        tree_store.get_iter_first(first_iter)
+        selection.select_iter(first_iter)
+        selection.connect('changed', self.selection_cb, tree_store)
+        tree_view.connect('row_activated', self.row_activated_cb, tree_store)
+
+        tree_view.append_column(column)
+
+        tree_view.collapse_all()
+        tree_view.set_headers_visible(False)
+        scrolled_window = Gtk.ScrolledWindow(hadjustment = None,
+                                             vadjustment = None)
+        scrolled_window.set_policy(Gtk.PolicyType.NEVER,
+                                   Gtk.PolicyType.AUTOMATIC)
+
+        scrolled_window.add(tree_view)
+
+        label = Gtk.Label(label = 'Widget (double click for demo)')
+        
+        box = Gtk.Notebook()
+        box.append_page(scrolled_window, label)
+        
+        tree_view.grab_focus()
+
+	return box
+
+    def create_text(self, is_source):
+        scrolled_window = Gtk.ScrolledWindow(hadjustment = None,
+                                             vadjustment = None)
+        scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
+                                   Gtk.PolicyType.AUTOMATIC)
+        scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
+
+        text_view = Gtk.TextView()
+        buffer = Gtk.TextBuffer()
+
+        text_view.set_buffer(buffer)
+        text_view.set_editable(False)
+        text_view.set_cursor_visible(False)
+
+        scrolled_window.add(text_view)
+
+        if is_source:
+            font_desc = Pango.Font.description_from_string('monospace')
+            text_view.modify_font(font_desc)
+            text_view.set_wrap_mode(Gtk.WrapMode.NONE)
+        else:
+            text_view.set_wrap_mode(Gtk.WrapMode.WORD)
+            text_view.set_pixels_above_lines(2)
+            text_view.set_pixels_below_lines(2)
+
+        return(scrolled_window, buffer)
+
+if __name__ == '__main__':
+    demo = GtkDemoApp()



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