Commit 597bd643 authored by Johan Dahlin's avatar Johan Dahlin

Merge branch 'pygi-merge'

parents ec8d148e fa91dfd3
.libs/
.deps/
/COPYING
Makefile
Makefile.in
/aclocal.m4
/autom4te.cache/
/config.guess
/config.h
/config.h.in
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/m4/
/missing
/py-compile
/pygi-*.tar.gz
/stamp-h1
*.o
*.lo
*.la
*.so
*.pyc
*.gir
*.typelib
.*.swp
*~
*.orig
*.rej
tests/tmp-introspect*
Tests
===
'make check' execute all tests
'make check TEST_NAMES="test_gi"' executes the tests in test_gi.py
'make check TEST_NAMES="test_gi.TestUtf8"' executes the tests in test_gi.TestUtf8
'make check TEST_NAMES="test_gi.TestUtf8.test_utf8_full_return"' executes the test_gi.TestUtf8.test_utf8_full_return test
'make check.gdb' executes all the tests in a gdb session
'make test_gi.TestUtf8.gdb' executes all the tests in test_gi.TestUtf8 in a gdb session
'make check.valgrind' executes all the tests in valgrind
'make test_gi.TestUtf8.valgrind' executes all the tests in test_gi.TestUtf8 in valgrind
Releasing
===
* Bump version in configure.ac
* Commit & Tag
* Make distcheck
* Upload tarball to git servers
* Email PyGTK-announce & gnome-release mailing list
PLATFORM_VERSION = 2.0
pkgincludedir = $(includedir)/pygtk-$(PLATFORM_VERSION)
pkgpyexecdir = $(pyexecdir)/gtk-2.0
SUBDIRS = \
repository \
overrides
AM_CFLAGS = \
$(PYTHON_INCLUDES) \
$(GNOME_CFLAGS) \
$(PYCAIRO_CFLAGS)
pygidir = $(pkgpyexecdir)/gi
pygi_PYTHON = \
types.py \
module.py \
importer.py \
__init__.py
_gi_la_LDFLAGS = \
-module \
-avoid-version \
-export-symbols-regex init_gi
_gi_la_LIBADD = \
$(GNOME_LIBS) \
$(PYCAIRO_LIBS)
_gi_la_SOURCES = \
pygi-repository.c \
pygi-repository.h \
pygi-info.c \
pygi-info.h \
pygi-invoke.c \
pygi-invoke.h \
pygi-foreign.c \
pygi-foreign.h \
pygi-foreign-cairo.c \
pygi-foreign-cairo.h \
pygi-struct.c \
pygi-struct.h \
pygi-argument.c \
pygi-argument.h \
pygi-type.c \
pygi-type.h \
pygi-boxed.c \
pygi-boxed.h \
pygi-closure.c \
pygi-closure.h \
pygi-callbacks.c \
pygi-callbacks.h \
pygi.h \
pygi-private.h \
pygobject-external.h \
gimodule.c
pygi_LTLIBRARIES = _gi.la
# This is to ensure we have a symlink to the .so in the
# build directory, which the Python interpreter can load
# directly without having to know how to parse .la files.
_gi.so: _gi.la
rm -f $@ && $(LN_S) .libs/$@ $@
all-local: _gi.so
clean-local:
rm -f _gi.so
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2005-2009 Johan Dahlin <johan@gnome.org>
#
# 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 __future__ import absolute_import
from ._gi import _API
#!/usr/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
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 = buffer.get_iter_at_mark(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()
#!/usr/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
title = "Assistant"
description = """
Demonstrates a sample multistep assistant. Assistants are used to divide
an operation into several simpler sequential steps, and to guide the user
through these steps.
"""
# See FIXME's
is_fully_bound = True
from gi.repository import Gtk, GdkPixbuf
class AssistantApp:
def __init__(self):
self.assistant = Gtk.Assistant()
self.assistant.set_default_size(-1, 300)
self.create_page1()
self.create_page2()
self.create_page3()
self.assistant.connect('cancel', self.on_close_cancel)
self.assistant.connect('close', self.on_close_cancel)
self.assistant.connect('apply', self.on_apply)
self.assistant.connect('prepare', self.on_prepare)
self.assistant.show()
def on_close_cancel(self, assistant):
assistant.destroy()
Gtk.main_quit()
def on_apply(self, assistant):
# apply changes here; this is a fictional example so just do
# nothing here
pass
def on_prepare(self, assistant, page):
current_page = assistant.get_current_page()
n_pages = assistant.get_n_pages()
title = 'Sample assistant (%d of %d)' % (current_page + 1, n_pages)
assistant.set_title(title)
def on_entry_changed(self, widget):
page_number = self.assistant.get_current_page()
current_page = self.assistant.get_nth_page(page_number)
text = widget.get_text()
if text:
self.assistant.set_page_complete(current_page, True)
else:
self.assistant.set_page_complete(current_page, False)
def create_page1(self):
box = Gtk.HBox(homogeneous=False,
spacing=12)
box.set_border_width(12)
label = Gtk.Label(label='You must fill out this entry to continue:')
box.pack_start(label, False, False, 0)
entry = Gtk.Entry()
box.pack_start(entry, True, True, 0)
entry.connect('changed', self.on_entry_changed)
box.show_all()
self.assistant.append_page(box)
self.assistant.set_page_title(box, 'Page 1')
self.assistant.set_page_type(box, Gtk.AssistantPageType.INTRO)
pixbuf = self.assistant.render_icon(Gtk.STOCK_DIALOG_INFO,
Gtk.IconSize.DIALOG,
None)
self.assistant.set_page_header_image(box, pixbuf)
def create_page2(self):
box = Gtk.VBox(homogeneous=False,
spacing=12)
box.set_border_width(12)
checkbutton = Gtk.CheckButton(label='This is optional data, you may continue even if you do not check this')
box.pack_start(checkbutton, False, False, 0)
box.show_all()
self.assistant.append_page(box)
self.assistant.set_page_complete(box, True)
self.assistant.set_page_title(box, 'Page 2')
pixbuf = self.assistant.render_icon(Gtk.STOCK_DIALOG_INFO,
Gtk.IconSize.DIALOG,
None)
self.assistant.set_page_header_image(box, pixbuf)