Added an entry that can have icons inside: IconEntry. From libsexy.
This commit is contained in:
@@ -22,8 +22,25 @@
|
||||
(gtype-id "SUGAR_TYPE_MENU")
|
||||
)
|
||||
|
||||
(define-object IconEntry
|
||||
(in-module "Sexy")
|
||||
(parent "GtkEntry")
|
||||
(c-name "SexyIconEntry")
|
||||
(gtype-id "SEXY_TYPE_ICON_ENTRY")
|
||||
)
|
||||
|
||||
;; Enumerations and flags ...
|
||||
|
||||
(define-enum IconEntryPosition
|
||||
(in-module "Sexy")
|
||||
(c-name "SexyIconEntryPosition")
|
||||
(gtype-id "SEXY_TYPE_ICON_ENTRY_POSITION")
|
||||
(values
|
||||
'("primary" "SEXY_ICON_ENTRY_PRIMARY")
|
||||
'("secondary" "SEXY_ICON_ENTRY_SECONDARY")
|
||||
)
|
||||
)
|
||||
|
||||
;; From sugar-menu.h
|
||||
|
||||
(define-method set_active
|
||||
@@ -94,3 +111,61 @@
|
||||
'("const-char*" "property")
|
||||
)
|
||||
)
|
||||
|
||||
;; From sexy-icon-entry.h
|
||||
|
||||
(define-function sexy_icon_entry_get_type
|
||||
(c-name "sexy_icon_entry_get_type")
|
||||
(return-type "GType")
|
||||
)
|
||||
|
||||
(define-function sexy_icon_entry_new
|
||||
(c-name "sexy_icon_entry_new")
|
||||
(is-constructor-of "SexyIconEntry")
|
||||
(return-type "GtkWidget*")
|
||||
)
|
||||
|
||||
(define-method set_icon
|
||||
(of-object "SexyIconEntry")
|
||||
(c-name "sexy_icon_entry_set_icon")
|
||||
(return-type "none")
|
||||
(parameters
|
||||
'("SexyIconEntryPosition" "position")
|
||||
'("GtkImage*" "icon")
|
||||
)
|
||||
)
|
||||
|
||||
(define-method set_icon_highlight
|
||||
(of-object "SexyIconEntry")
|
||||
(c-name "sexy_icon_entry_set_icon_highlight")
|
||||
(return-type "none")
|
||||
(parameters
|
||||
'("SexyIconEntryPosition" "position")
|
||||
'("gboolean" "highlight")
|
||||
)
|
||||
)
|
||||
|
||||
(define-method get_icon
|
||||
(of-object "SexyIconEntry")
|
||||
(c-name "sexy_icon_entry_get_icon")
|
||||
(return-type "GtkImage*")
|
||||
(parameters
|
||||
'("SexyIconEntryPosition" "position")
|
||||
)
|
||||
)
|
||||
|
||||
(define-method get_icon_highlight
|
||||
(of-object "SexyIconEntry")
|
||||
(c-name "sexy_icon_entry_get_icon_highlight")
|
||||
(return-type "gboolean")
|
||||
(parameters
|
||||
'("SexyIconEntryPosition" "position")
|
||||
)
|
||||
)
|
||||
|
||||
(define-method add_clear_button
|
||||
(of-object "SexyIconEntry")
|
||||
(c-name "sexy_icon_entry_add_clear_button")
|
||||
(return-type "none")
|
||||
)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ headers
|
||||
#include "sugar-key-grabber.h"
|
||||
#include "sugar-menu.h"
|
||||
#include "sugar-x11-util.h"
|
||||
#include "sexy-icon-entry.h"
|
||||
|
||||
#include <pygtk/pygtk.h>
|
||||
#include <glib.h>
|
||||
@@ -20,6 +21,7 @@ import gtk.Entry as PyGtkEntry_Type
|
||||
import gtk.Menu as PyGtkMenu_Type
|
||||
import gtk.Container as PyGtkContainer_Type
|
||||
import gtk.gdk.Window as PyGdkWindow_Type
|
||||
import gtk.Image as PyGtkImage_Type
|
||||
%%
|
||||
ignore-glob
|
||||
*_get_type
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
extern PyMethodDef py_sugaruiext_functions[];
|
||||
|
||||
void py_sugaruiext_register_classes (PyObject *d);
|
||||
void py_sugaruiext_add_constants (PyObject *module, const gchar *strip_prefix);
|
||||
|
||||
DL_EXPORT(void)
|
||||
init_sugaruiext(void)
|
||||
@@ -39,6 +40,7 @@ init_sugaruiext(void)
|
||||
d = PyModule_GetDict (m);
|
||||
|
||||
py_sugaruiext_register_classes (d);
|
||||
py_sugaruiext_add_constants(m, "SEXY_");
|
||||
|
||||
if (PyErr_Occurred ()) {
|
||||
Py_FatalError ("can't initialise module _sugaruiext");
|
||||
|
||||
@@ -9,7 +9,7 @@ sugar_PYTHON = \
|
||||
combobox.py \
|
||||
icon.py \
|
||||
iconbutton.py \
|
||||
menuitem.py \
|
||||
iconentry.py \
|
||||
notebook.py \
|
||||
objectchooser.py \
|
||||
radiotoolbutton.py \
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# Copyright (C) 2007, One Laptop Per Child
|
||||
#
|
||||
# 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 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., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
import gtk
|
||||
|
||||
from sugar import _sugaruiext
|
||||
|
||||
ICON_ENTRY_PRIMARY = _sugaruiext.ICON_ENTRY_PRIMARY
|
||||
ICON_ENTRY_SECONDARY = _sugaruiext.ICON_ENTRY_SECONDARY
|
||||
|
||||
class IconEntry(_sugaruiext.IconEntry):
|
||||
def set_icon_from_name(self, position, name):
|
||||
icon_theme = gtk.icon_theme_get_default()
|
||||
icon_info = icon_theme.lookup_icon(name,
|
||||
gtk.ICON_SIZE_SMALL_TOOLBAR,
|
||||
0)
|
||||
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file(icon_info.get_filename())
|
||||
|
||||
image = gtk.Image()
|
||||
image.set_from_pixbuf(pixbuf)
|
||||
image.show()
|
||||
|
||||
self.set_icon(position, image)
|
||||
|
||||
def set_icon(self, position, image):
|
||||
if image.get_storage_type() not in [gtk.IMAGE_PIXBUF, gtk.IMAGE_STOCK]:
|
||||
raise ValueError('Image must have a storage type of pixbuf or ' +
|
||||
'stock, not %r.' % image.get_storage_type())
|
||||
_sugaruiext.IconEntry.set_icon(self, position, image)
|
||||
|
||||
Reference in New Issue
Block a user