summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog27
-rw-r--r--Makefile.am1
-rw-r--r--README5
-rw-r--r--description.py6
-rwxr-xr-xexamples/testgtk/testgtk.py94
-rw-r--r--gtk.py54
-rw-r--r--gtkmodule.c31
-rw-r--r--pygtk.spec2
8 files changed, 183 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index 55a16081..91af11ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+1999-02-23 James Henstridge <james@daa.com.au>
+
+ * README, Makefile.am, pygtk.spec: added references to the MAPPING
+ file.
+
+ * MAPPING: new file describing the mapping of GTK+ onto python as
+ pygtk does it.
+
+1999-02-22 James Henstridge <james@daa.com.au>
+
+ * description.py (GdkCursor): added information about this type.
+
+ * gtk.py: commented out the __getattr__, __setattr__ and __delattr__
+ methods of GtkObject. There were too many things that broke because
+ of these changes. If I can get these to work correctly in the
+ future, I will consider re-enabling it, but not till then.
+
+ * examples/testgtk/testgtk.py (create_cursor_test): added a cursor
+ test to the python testgtk. It is adapted from the translation sent
+ in by Osamu Tanimoto.
+
+ * gtkmodule.c: fixed a bit of bad copy'n'paste in the GC part of the
+ style wrapper code. Thanks go to Osamu Tanimoto <tanimoto@rios.co.jp>.
+ (PyGdkCursor_GetAttr): now GdkCursor objects have a type attribute
+ that returns the type number for the object, and a name attribute
+ that gives a string representation of that type number.
+
1999-02-20 James Henstridge <james@daa.com.au>
* gtk.py (GtkTooltips.set_tip): made tip_private argument optional.
diff --git a/Makefile.am b/Makefile.am
index eca25614..75e432ee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -33,6 +33,7 @@ gtkmodule.o: gtkmodule_defs.c gtkmodule_impl.c
EXTRA_DIST = \
pygtk.spec \
+ MAPPING \
examples/imlib/view.py \
examples/ide/gtkcons.py \
examples/ide/gtkdb.py \
diff --git a/README b/README
index 0a12f49d..a0e10cc4 100644
--- a/README
+++ b/README
@@ -192,7 +192,10 @@ The function mainloop() is basically just the function gtk_main(), and
the function mainquit is equivalent to gtk_main_quit().
For further information on the interface, please see the source file
-Gtkinter.py.
+gtk.py.
+
+For a more in depth look at the mapping of the C GTK functions to
+python, read the file MAPPING that is distributed with this package.
Should I Use _gtkmodule or gtk.py?
diff --git a/description.py b/description.py
index 8a494964..38e98966 100644
--- a/description.py
+++ b/description.py
@@ -129,6 +129,12 @@ class GdkColormap:
that has been allocated in the colormap"""
pass
+class GdkCursor:
+ """the type number of this cursor, or -1 for a pixmap cursor"""
+ type = _
+ """the string name for this type of cursor"""
+ name = _
+
class GdkDragContext:
"""This event holds the context of a DND drag"""
diff --git a/examples/testgtk/testgtk.py b/examples/testgtk/testgtk.py
index 7cdd1086..aa0d5373 100755
--- a/examples/testgtk/testgtk.py
+++ b/examples/testgtk/testgtk.py
@@ -1442,6 +1442,99 @@ def create_idle_test(_button):
button.show()
wins["idle_test"].show()
+def create_cursor_test(_button):
+ if not wins.has_key("cursor_test"):
+ def expose_event(darea, event):
+ drawable = darea.get_window()
+ white_gc = darea.get_style().white_gc
+ grey_gc = darea.get_style().bg_gc[STATE_NORMAL]
+ black_gc = darea.get_style().black_gc
+ max_width = drawable.width
+ max_height = drawable.height
+ draw_rectangle(drawable, white_gc, TRUE, 0, 0,
+ max_width, max_height / 2)
+ draw_rectangle(drawable, black_gc, TRUE, 0,
+ max_height/2, max_width, max_height / 2)
+ draw_rectangle(drawable, grey_gc, TRUE,
+ max_width / 3, max_height / 3,
+ max_width / 3, max_height / 3)
+
+ def button_press(widget, event, spinner):
+ if event.type == GDK.BUTTON_PRESS:
+ if event.button == 1:
+ spinner.spin(SPIN_STEP_FORWARD, 0)
+ elif event.button == 3:
+ spinner.spin(SPIN_STEP_BACKWARD, 0)
+ def set_cursor(spinner, widget, cur_name):
+ c = spinner.get_value_as_int()
+ c = c & 0xfe
+ cursor = cursor_new(c)
+ widget.get_window().set_cursor(cursor)
+ cur_name.set_text(cursor.name)
+
+ win = GtkWindow()
+ wins["cursor_test"] = win
+ win.connect("delete_event", lambda _w, _e, win=win: win.hide())
+ win.set_title("Cursor Test")
+
+ main_vbox = GtkVBox(FALSE, 5)
+ main_vbox.set_border_width(0)
+ win.add(main_vbox)
+ main_vbox.show()
+
+ vbox = GtkVBox(FALSE, 5)
+ vbox.set_border_width(10)
+ main_vbox.pack_start(vbox)
+ vbox.show()
+
+ hbox = GtkHBox(FALSE, 5)
+ vbox.pack_start(hbox, expand=FALSE)
+ hbox.show()
+
+ label = GtkLabel('Cursor value: ')
+ label.set_alignment(0, 0.5)
+ hbox.pack_start(label, expand=FALSE)
+ label.show()
+
+ spinner = GtkSpinButton(GtkAdjustment(0,0,152,2,10,0), 0, 0)
+ hbox.pack_start(spinner)
+ spinner.show()
+
+ frame = GtkFrame("Cursor Area")
+ frame.set_border_width(10)
+ frame.set_label_align(0.5, 0)
+ vbox.pack_start(frame)
+ frame.show()
+
+ darea = GtkDrawingArea()
+ darea.set_usize(80, 80)
+ frame.add(darea)
+ darea.show()
+
+ cur_name = GtkLabel("")
+ vbox.pack_start(cur_name, expand=FALSE)
+ cur_name.show()
+
+ darea.connect("expose_event", expose_event)
+ darea.add_events(GDK.EXPOSURE_MASK | GDK.BUTTON_PRESS_MASK)
+ darea.connect("button_press_event", button_press, spinner)
+ spinner.connect("changed", set_cursor, darea, cur_name)
+
+ hsep = GtkHSeparator()
+ main_vbox.pack_start(hsep, expand=FALSE)
+ hsep.show()
+
+ hbox = GtkHBox(FALSE, 5)
+ hbox.set_border_width(10)
+ main_vbox.pack_start(hbox, expand=FALSE)
+ hbox.show()
+
+ button = GtkButton("Close")
+ button.connect("clicked", win.hide)
+ hbox.pack_start(button)
+ button.show()
+ wins["cursor_test"].show()
+
def do_exit(button):
mainquit()
@@ -1484,6 +1577,7 @@ def create_main_window():
"test idle": create_idle_test,
"test": None, #create_test
"status bar": create_statusbar_test,
+ "cursor": create_cursor_test,
}
win = GtkWindow()
win.set_name("main window")
diff --git a/gtk.py b/gtk.py
index 50d8b6e2..57f49b6f 100644
--- a/gtk.py
+++ b/gtk.py
@@ -58,34 +58,34 @@ class GtkObject:
# they will always be available with the object. Due to
# reference counting problems, we can't always pass the
# same GtkObject instance to a callback.
- if attr[0] == '_' or not self.__dict__.has_key('_o'):
- raise AttributeError, attr
- dict = self.get_data('Python-Attributes')
- if dict and dict.has_key(attr):
- return dict[attr]
+ #if attr[0] == '_' or not self.__dict__.has_key('_o'):
+ # raise AttributeError, attr
+ #dict = self.get_data('Python-Attributes')
+ #if dict and dict.has_key(attr):
+ # return dict[attr]
raise AttributeError, attr
- def __setattr__(self, attr, value):
- if attr[0] == '_' or self.__dict__.has_key(attr) or \
- not self.__dict__.has_key('_o'):
- self.__dict__[attr] = value
- dict = self.get_data('Python-Attributes')
- if not dict:
- dict = {}
- self.set_data('Python-Attributes', dict)
- dict[attr] = value
- def __delattr__(self, attr):
- if self.__dict__.has_key(attr):
- del self.__dict__[attr]
- return
- if not self.__dict__.has_key('_o'):
- raise AttributeError, \
- 'delete non-existing instance attribute'
- dict = self.get_data('Python-Attributes')
- if dict and dict.has_key(attr):
- del dict[attr]
- else:
- raise AttributeError, \
- 'delete non-existing instance attribute'
+ #def __setattr__(self, attr, value):
+ # if attr[0] == '_' or self.__dict__.has_key(attr) or \
+ # not self.__dict__.has_key('_o'):
+ # self.__dict__[attr] = value
+ # dict = self.get_data('Python-Attributes')
+ # if not dict:
+ # dict = {}
+ # self.set_data('Python-Attributes', dict)
+ # dict[attr] = value
+ #def __delattr__(self, attr):
+ # if self.__dict__.has_key(attr):
+ # del self.__dict__[attr]
+ # return
+ # if not self.__dict__.has_key('_o'):
+ # raise AttributeError, \
+ # 'delete non-existing instance attribute'
+ # dict = self.get_data('Python-Attributes')
+ # if dict and dict.has_key(attr):
+ # del dict[attr]
+ # else:
+ # raise AttributeError, \
+ # 'delete non-existing instance attribute'
def flags(self, mask=None):
if mask:
diff --git a/gtkmodule.c b/gtkmodule.c
index 181ef747..bab922eb 100644
--- a/gtkmodule.c
+++ b/gtkmodule.c
@@ -651,17 +651,17 @@ static PyObject *PyGtkStyle_GetAttr(PyGtkStyle_Object *self, char *attr) {
if (!strcmp(attr, "fg_gc"))
return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->fg_gc);
if (!strcmp(attr, "bg_gc"))
- return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->fg_gc);
+ return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->bg_gc);
if (!strcmp(attr, "light_gc"))
- return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->fg_gc);
+ return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->light_gc);
if (!strcmp(attr, "dark_gc"))
- return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->fg_gc);
+ return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->dark_gc);
if (!strcmp(attr, "mid_gc"))
- return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->fg_gc);
+ return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->mid_gc);
if (!strcmp(attr, "text_gc"))
- return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->fg_gc);
+ return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->text_gc);
if (!strcmp(attr, "base_gc"))
- return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->fg_gc);
+ return PyGtkStyleHelper_New(style, STYLE_GC_ARRAY, style->base_gc);
if (!strcmp(attr, "black_gc"))
return PyGdkGC_New(style->black_gc);
if (!strcmp(attr, "white_gc"))
@@ -2013,13 +2013,28 @@ PyGdkCursor_Repr(PyGdkCursor_Object *self) {
while (vals->value_name != NULL && vals->value != self->obj->type)
vals++;
if (vals->value_nick) cname = vals->value_nick;
- else cname = "*unknown";
+ else cname = "*unknown*";
}
g_snprintf(buf, 256, "<GdkCursor '%s'>", cname);
return PyString_FromString(buf);
}
+static PyObject *PyGdkCursor_GetAttr(PyGdkCursor_Object *self, char *attr) {
+ if (!strcmp(attr, "type"))
+ return PyInt_FromLong(self->obj->type);
+ else if (!strcmp(attr, "name")) {
+ GtkEnumValue *vals = gtk_type_enum_get_values(GTK_TYPE_GDK_CURSOR_TYPE);
+
+ while (vals->value_name != NULL && vals->value != self->obj->type)
+ vals++;
+ if (vals->value_nick) return PyString_FromString(vals->value_nick);
+ return PyString_FromString("*unknown*");
+ }
+ PyErr_SetString(PyExc_AttributeError, attr);
+ return NULL;
+}
+
static PyTypeObject PyGdkCursor_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -2028,7 +2043,7 @@ static PyTypeObject PyGdkCursor_Type = {
0,
(destructor)PyGdkCursor_Dealloc,
(printfunc)0,
- (getattrfunc)0,
+ (getattrfunc)PyGdkCursor_GetAttr,
(setattrfunc)0,
(cmpfunc)PyGdkCursor_Compare,
(reprfunc)PyGdkCursor_Repr,
diff --git a/pygtk.spec b/pygtk.spec
index 5b876bca..44490ec2 100644
--- a/pygtk.spec
+++ b/pygtk.spec
@@ -42,6 +42,6 @@ make DESTDIR=$RPM_BUILD_ROOT install
%{py_prefix}/lib/python%{py_ver}/site-packages/_gtkmodule.so
%{py_prefix}/lib/python%{py_ver}/site-packages/_gdkimlibmodule.so
-%doc AUTHORS NEWS README ChangeLog description.py
+%doc AUTHORS NEWS README MAPPING ChangeLog description.py
%doc examples