1/* -*- Mode: C; c-basic-offset: 4 -*- 2 * pygtk- Python bindings for the GTK toolkit. 3 * Copyright (C) 1998-2003 James Henstridge 4 * 5 * gdkgc.override: gtk.gdk.GC override 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 20 * USA 21 */ 22%% 23override gdk_gc_new kwargs 24static int 25_wrap_gdk_gc_new(PyGObject *self, PyObject *args, PyObject *kwargs) 26{ 27 static char *kwlist[] = { "drawable", "foreground", "background", "font", 28 "function", "fill", "tile", "stipple", 29 "clip_mask", "subwindow_mode", "ts_x_origin", 30 "ts_y_origin", "clip_x_origin", "clip_y_origin", 31 "graphics_exposures", "line_width", "line_style", 32 "cap_style", "join_style", NULL }; 33 PyGObject *drawable; 34 PyObject *foreground = Py_None, *background = Py_None; 35 PyObject *font = Py_None; 36 PyObject *tile = Py_None, *stipple = Py_None, *clip_mask = Py_None; 37 gint function = -1, fill = -1; 38 gint subwindow_mode = -1, ts_x_origin = -1, ts_y_origin = -1; 39 gint clip_x_origin = -1, clip_y_origin = -1, graphics_exposures = -1; 40 gint line_width = -1, line_style = -1, cap_style = -1, join_style = -1; 41 GdkGCValues values; 42 GdkGCValuesMask mask = 0; 43 44 if (!PyArg_ParseTupleAndKeywords(args, kwargs, 45 "O!|OOOiiOOOiiiiiiiiii:GdkGC.__init__", 46 kwlist, &PyGdkDrawable_Type, &drawable, 47 &foreground, &background, &font, 48 &function, &fill, &tile, &stipple, 49 &clip_mask, &subwindow_mode, 50 &ts_x_origin, &ts_y_origin, 51 &clip_x_origin, &clip_y_origin, 52 &graphics_exposures, &line_width, 53 &line_style, &cap_style, &join_style)) 54 return -1; 55 if (pyg_boxed_check(foreground, GDK_TYPE_COLOR)) { 56 mask |= GDK_GC_FOREGROUND; 57 values.foreground = *pyg_boxed_get(foreground, GdkColor); 58 } else if (foreground != Py_None) { 59 PyErr_SetString(PyExc_TypeError, "foreground must be a GdkColor"); 60 return -1; 61 } 62 if (pyg_boxed_check(background, GDK_TYPE_COLOR)) { 63 mask |= GDK_GC_BACKGROUND; 64 values.background = *pyg_boxed_get(background, GdkColor); 65 } else if (background != Py_None) { 66 PyErr_SetString(PyExc_TypeError, "background must be a GdkColor"); 67 return -1; 68 } 69 if (pyg_boxed_check(font, GDK_TYPE_FONT)) { 70 mask |= GDK_GC_FONT; 71 values.font = pyg_boxed_get(font, GdkFont); 72 } else if (font != Py_None) { 73 PyErr_SetString(PyExc_TypeError, "font must be a GdkFont"); 74 return -1; 75 } 76 if (function != -1) { 77 mask |= GDK_GC_FUNCTION; 78 values.function = function; 79 } 80 if (fill != -1) { 81 mask |= GDK_GC_FILL; 82 values.fill = fill; 83 } 84 if (pygobject_check(tile, &PyGdkPixmap_Type)) { 85 mask |= GDK_GC_TILE; 86 values.tile = GDK_PIXMAP(pygobject_get(tile)); 87 } else if (tile != Py_None) { 88 PyErr_SetString(PyExc_TypeError, "tile must be a GdkPixmap"); 89 return -1; 90 } 91 if (pygobject_check(stipple, &PyGdkPixmap_Type)) { 92 mask |= GDK_GC_STIPPLE; 93 values.stipple = GDK_PIXMAP(pygobject_get(stipple)); 94 } else if (stipple != Py_None) { 95 PyErr_SetString(PyExc_TypeError, "stipple must be a GdkPixmap"); 96 return -1; 97 } 98 if (pygobject_check(clip_mask, &PyGdkPixmap_Type)) { 99 mask |= GDK_GC_CLIP_MASK; 100 values.clip_mask = GDK_PIXMAP(pygobject_get(clip_mask)); 101 } else if (clip_mask != Py_None) { 102 PyErr_SetString(PyExc_TypeError, "clip_mask must be a GdkPixmap"); 103 return -1; 104 } 105 if (subwindow_mode != -1) { 106 mask |= GDK_GC_SUBWINDOW; 107 values.subwindow_mode = subwindow_mode; 108 } 109 if (ts_x_origin != -1) { 110 mask |= GDK_GC_TS_X_ORIGIN; 111 values.ts_x_origin = ts_x_origin; 112 } 113 if (ts_y_origin != -1) { 114 mask |= GDK_GC_TS_Y_ORIGIN; 115 values.ts_y_origin = ts_y_origin; 116 } 117 if (clip_x_origin != -1) { 118 mask |= GDK_GC_CLIP_X_ORIGIN; 119 values.clip_x_origin = clip_x_origin; 120 } 121 if (clip_y_origin != -1) { 122 mask |= GDK_GC_CLIP_Y_ORIGIN; 123 values.clip_y_origin = clip_y_origin; 124 } 125 if (graphics_exposures != -1) { 126 mask |= GDK_GC_EXPOSURES; 127 values.graphics_exposures = graphics_exposures; 128 } 129 if (line_width != -1) { 130 mask |= GDK_GC_LINE_WIDTH; 131 values.line_width = line_width; 132 } 133 if (line_style != -1) { 134 mask |= GDK_GC_LINE_STYLE; 135 values.line_style = line_style; 136 } 137 if (cap_style != -1) { 138 mask |= GDK_GC_CAP_STYLE; 139 values.cap_style = cap_style; 140 } 141 if (join_style != -1) { 142 mask |= GDK_GC_JOIN_STYLE; 143 values.join_style = join_style; 144 } 145 self->obj = (GObject *)gdk_gc_new_with_values(GDK_DRAWABLE(drawable->obj), 146 &values, mask); 147 148 if (!self->obj) { 149 PyErr_SetString(PyExc_RuntimeError, "could not create GdkGC object"); 150 return -1; 151 } 152 pygobject_register_wrapper((PyObject *)self); 153 return 0; 154} 155%% 156override gdk_gc_new_with_values kwargs 157static PyObject * 158_wrap_gdk_gc_new_with_values(PyGObject *self, PyObject *args, PyObject *kwargs) 159{ 160 static char *kwlist[] = { "foreground", "background", "font", "function", 161 "fill", "tile", "stipple", "clip_mask", 162 "subwindow_mode", "ts_x_origin", "ts_y_origin", 163 "clip_x_origin", "clip_y_origin", 164 "graphics_exposures", "line_width", "line_style", 165 "cap_style", "join_style", NULL }; 166 PyObject *foreground = Py_None, *background = Py_None; 167 PyObject *font = Py_None; 168 gint function = -1, fill = -1; 169 PyObject *tile = Py_None, *stipple = Py_None, *clip_mask = Py_None; 170 gint subwindow_mode = -1, ts_x_origin = -1, ts_y_origin = -1; 171 gint clip_x_origin = -1, clip_y_origin = -1, graphics_exposures = -1; 172 gint line_width = -1, line_style = -1, cap_style = -1, join_style = -1; 173 GdkGCValues values; 174 GdkGCValuesMask mask = 0; 175 GdkGC *gc; 176 PyObject *pygc; 177 178 if (!PyArg_ParseTupleAndKeywords(args, kwargs, 179 "|OOOiiOOOiiiiiiiiii:GdkDrawable.new_gc", 180 kwlist, &foreground, &background, &font, 181 &function, &fill, &tile, &stipple, 182 &clip_mask, &subwindow_mode, 183 &ts_x_origin, &ts_y_origin, 184 &clip_x_origin, &clip_y_origin, 185 &graphics_exposures, &line_width, 186 &line_style, &cap_style, &join_style)) 187 return NULL; 188 if (pyg_boxed_check(foreground, GDK_TYPE_COLOR)) { 189 mask |= GDK_GC_FOREGROUND; 190 values.foreground = *pyg_boxed_get(foreground, GdkColor); 191 } else if (foreground != Py_None) { 192 PyErr_SetString(PyExc_TypeError, "foreground must be a GdkColor"); 193 return NULL; 194 } 195 if (pyg_boxed_check(background, GDK_TYPE_COLOR)) { 196 mask |= GDK_GC_BACKGROUND; 197 values.background = *pyg_boxed_get(background, GdkColor); 198 } else if (background != Py_None) { 199 PyErr_SetString(PyExc_TypeError, "background must be a GdkColor"); 200 return NULL; 201 } 202 if (pyg_boxed_check(font, GDK_TYPE_FONT)) { 203 mask |= GDK_GC_FONT; 204 values.font = pyg_boxed_get(font, GdkFont); 205 } else if (font != Py_None) { 206 PyErr_SetString(PyExc_TypeError, "font must be a GdkFont"); 207 return NULL; 208 } 209 if (function != -1) { 210 mask |= GDK_GC_FUNCTION; 211 values.function = function; 212 } 213 if (fill != -1) { 214 mask |= GDK_GC_FILL; 215 values.fill = fill; 216 } 217 if (pygobject_check(tile, &PyGdkPixmap_Type)) { 218 mask |= GDK_GC_TILE; 219 values.tile = GDK_PIXMAP(pygobject_get(tile)); 220 } else if (tile != Py_None) { 221 PyErr_SetString(PyExc_TypeError, "tile must be a GdkPixmap"); 222 return NULL; 223 } 224 if (pygobject_check(stipple, &PyGdkPixmap_Type)) { 225 mask |= GDK_GC_STIPPLE; 226 values.stipple = GDK_PIXMAP(pygobject_get(stipple)); 227 } else if (stipple != Py_None) { 228 PyErr_SetString(PyExc_TypeError, "stipple must be a GdkPixmap"); 229 return NULL; 230 } 231 if (pygobject_check(clip_mask, &PyGdkPixmap_Type)) { 232 mask |= GDK_GC_CLIP_MASK; 233 values.clip_mask = GDK_PIXMAP(pygobject_get(clip_mask)); 234 } else if (clip_mask != Py_None) { 235 PyErr_SetString(PyExc_TypeError, "clip_mask must be a GdkPixmap"); 236 return NULL; 237 } 238 if (subwindow_mode != -1) { 239 mask |= GDK_GC_SUBWINDOW; 240 values.subwindow_mode = subwindow_mode; 241 } 242 if (ts_x_origin != -1) { 243 mask |= GDK_GC_TS_X_ORIGIN; 244 values.ts_x_origin = ts_x_origin; 245 } 246 if (ts_y_origin != -1) { 247 mask |= GDK_GC_TS_Y_ORIGIN; 248 values.ts_y_origin = ts_y_origin; 249 } 250 if (clip_x_origin != -1) { 251 mask |= GDK_GC_CLIP_X_ORIGIN; 252 values.clip_x_origin = clip_x_origin; 253 } 254 if (clip_y_origin != -1) { 255 mask |= GDK_GC_CLIP_Y_ORIGIN; 256 values.clip_y_origin = clip_y_origin; 257 } 258 if (graphics_exposures != -1) { 259 mask |= GDK_GC_EXPOSURES; 260 values.graphics_exposures = graphics_exposures; 261 } 262 if (line_width != -1) { 263 mask |= GDK_GC_LINE_WIDTH; 264 values.line_width = line_width; 265 } 266 if (line_style != -1) { 267 mask |= GDK_GC_LINE_STYLE; 268 values.line_style = line_style; 269 } 270 if (cap_style != -1) { 271 mask |= GDK_GC_CAP_STYLE; 272 values.cap_style = cap_style; 273 } 274 if (join_style != -1) { 275 mask |= GDK_GC_JOIN_STYLE; 276 values.join_style = join_style; 277 } 278 gc = gdk_gc_new_with_values(GDK_DRAWABLE(self->obj), &values, mask); 279 pygc = pygobject_new((GObject *)gc); 280 g_object_unref(gc); 281 return pygc; 282} 283%% 284override gdk_gc_new2 kwargs 285static PyObject * 286_wrap_gdk_gc_new2(PyObject *self, PyObject *args, PyObject *kwargs) 287{ 288 static char *kwlist[] = { "drawable", NULL }; 289 PyGObject *drawable; 290 GdkGC *ret; 291 292 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!:gc_new", kwlist, &PyGdkDrawable_Type, &drawable)) 293 return NULL; 294 if (PyErr_Warn(PyExc_DeprecationWarning, "use gdk.GC or drawable.new_gc") < 0) 295 return NULL; 296 ret = gdk_gc_new(GDK_DRAWABLE(drawable->obj)); 297 /* pygobject_new handles NULL checking */ 298 return pygobject_new((GObject *)ret); 299} 300%% 301override gdk_gc_set_values kwargs 302static PyObject * 303_wrap_gdk_gc_set_values(PyGObject *self, PyObject *args, PyObject *kwargs) 304{ 305 static char *kwlist[] = { "foreground", "background", "font", "function", 306 "fill", "tile", "stipple", "clip_mask", 307 "subwindow_mode", "ts_x_origin", "ts_y_origin", 308 "clip_x_origin", "clip_y_origin", 309 "graphics_exposures", "line_width", "line_style", 310 "cap_style", "join_style", NULL }; 311 PyObject *foreground = Py_None, *background = Py_None; 312 PyObject *font = Py_None; 313 gint function = -1, fill = -1; 314 PyObject *tile = Py_None, *stipple = Py_None, *clip_mask = Py_None; 315 gint subwindow_mode = -1, ts_x_origin = -1, ts_y_origin = -1; 316 gint clip_x_origin = -1, clip_y_origin = -1, graphics_exposures = -1; 317 gint line_width = -1, line_style = -1, cap_style = -1, join_style = -1; 318 GdkGCValues values; 319 GdkGCValuesMask mask = 0; 320 321 if (!PyArg_ParseTupleAndKeywords(args, kwargs, 322 "|OOOiiOOOiiiiiiiiii:GdkGC.set_values", 323 kwlist, &foreground, &background, &font, 324 &function, &fill, &tile, &stipple, 325 &clip_mask, &subwindow_mode, 326 &ts_x_origin, &ts_y_origin, 327 &clip_x_origin, &clip_y_origin, 328 &graphics_exposures, &line_width, 329 &line_style, &cap_style, &join_style)) 330 return NULL; 331 if (pyg_boxed_check(foreground, GDK_TYPE_COLOR)) { 332 mask |= GDK_GC_FOREGROUND; 333 values.foreground = *pyg_boxed_get(foreground, GdkColor); 334 } else if (foreground != Py_None) { 335 PyErr_SetString(PyExc_TypeError, "foreground must be a GdkColor"); 336 return NULL; 337 } 338 if (pyg_boxed_check(background, GDK_TYPE_COLOR)) { 339 mask |= GDK_GC_BACKGROUND; 340 values.background = *pyg_boxed_get(background, GdkColor); 341 } else if (background != Py_None) { 342 PyErr_SetString(PyExc_TypeError, "background must be a GdkColor"); 343 return NULL; 344 } 345 if (pyg_boxed_check(font, GDK_TYPE_FONT)) { 346 mask |= GDK_GC_FONT; 347 values.font = pyg_boxed_get(font, GdkFont); 348 } else if (font != Py_None) { 349 PyErr_SetString(PyExc_TypeError, "font must be a GdkFont"); 350 return NULL; 351 } 352 if (function != -1) { 353 mask |= GDK_GC_FUNCTION; 354 values.function = function; 355 } 356 if (fill != -1) { 357 mask |= GDK_GC_FILL; 358 values.fill = fill; 359 } 360 if (pygobject_check(tile, &PyGdkPixmap_Type)) { 361 mask |= GDK_GC_TILE; 362 values.tile = GDK_PIXMAP(pygobject_get(tile)); 363 } else if (tile != Py_None) { 364 PyErr_SetString(PyExc_TypeError, "tile must be a GdkPixmap"); 365 return NULL; 366 } 367 if (pygobject_check(stipple, &PyGdkPixmap_Type)) { 368 mask |= GDK_GC_STIPPLE; 369 values.stipple = GDK_PIXMAP(pygobject_get(stipple)); 370 } else if (stipple != Py_None) { 371 PyErr_SetString(PyExc_TypeError, "stipple must be a GdkPixmap"); 372 return NULL; 373 } 374 if (pygobject_check(clip_mask, &PyGdkPixmap_Type)) { 375 mask |= GDK_GC_CLIP_MASK; 376 values.clip_mask = GDK_PIXMAP(pygobject_get(clip_mask)); 377 } else if (clip_mask != Py_None) { 378 PyErr_SetString(PyExc_TypeError, "clip_mask must be a GdkPixmap"); 379 return NULL; 380 } 381 if (subwindow_mode != -1) { 382 mask |= GDK_GC_SUBWINDOW; 383 values.subwindow_mode = subwindow_mode; 384 } 385 if (ts_x_origin != -1) { 386 mask |= GDK_GC_TS_X_ORIGIN; 387 values.ts_x_origin = ts_x_origin; 388 } 389 if (ts_y_origin != -1) { 390 mask |= GDK_GC_TS_Y_ORIGIN; 391 values.ts_y_origin = ts_y_origin; 392 } 393 if (clip_x_origin != -1) { 394 mask |= GDK_GC_CLIP_X_ORIGIN; 395 values.clip_x_origin = clip_x_origin; 396 } 397 if (clip_y_origin != -1) { 398 mask |= GDK_GC_CLIP_Y_ORIGIN; 399 values.clip_y_origin = clip_y_origin; 400 } 401 if (graphics_exposures != -1) { 402 mask |= GDK_GC_EXPOSURES; 403 values.graphics_exposures = graphics_exposures; 404 } 405 if (line_width != -1) { 406 mask |= GDK_GC_LINE_WIDTH; 407 values.line_width = line_width; 408 } 409 if (line_style != -1) { 410 mask |= GDK_GC_LINE_STYLE; 411 values.line_style = line_style; 412 } 413 if (cap_style != -1) { 414 mask |= GDK_GC_CAP_STYLE; 415 values.cap_style = cap_style; 416 } 417 if (join_style != -1) { 418 mask |= GDK_GC_JOIN_STYLE; 419 values.join_style = join_style; 420 } 421 gdk_gc_set_values(GDK_GC(self->obj), &values, mask); 422 423 Py_INCREF(Py_None); 424 return Py_None; 425} 426%% 427override-slot GdkGC.tp_getattro 428static PyObject * 429_wrap_gdk_gc_tp_getattro(PyGObject *self, PyObject *py_attr) 430{ 431 GdkGCValues gc; 432 char *attr; 433 434 if (PyString_Check(py_attr)) 435 attr = PyString_AsString(py_attr); 436 else 437 return PyObject_GenericGetAttr((PyObject *)self, py_attr); 438 439 if (!strcmp(attr, "__members__")) 440 return Py_BuildValue("[ssssssssssssssssss]", "background", "cap_style", 441 "clip_mask", "clip_x_origin", "clip_y_origin", 442 "fill", "font", "foreground", "function", 443 "graphics_exposures", "join_style", "line_style", 444 "line_width", "stipple", "sub_window", "tile", 445 "ts_x_origin", "ts_y_origin"); 446 gdk_gc_get_values(GDK_GC(self->obj), &gc); 447 if (!strcmp(attr, "foreground")) 448 return pyg_boxed_new(GDK_TYPE_COLOR, &(gc.foreground), TRUE, TRUE); 449 if (!strcmp(attr, "background")) 450 return pyg_boxed_new(GDK_TYPE_COLOR, &(gc.background), TRUE, TRUE); 451 if (!strcmp(attr, "font")) 452 return pyg_boxed_new(GDK_TYPE_FONT, gc.font, TRUE, TRUE); 453 if (!strcmp(attr, "function")) 454 return PyInt_FromLong(gc.function); 455 if (!strcmp(attr, "fill")) 456 return PyInt_FromLong(gc.fill); 457 if (!strcmp(attr, "tile")) 458 return pygobject_new((GObject *)gc.tile); 459 if (!strcmp(attr, "stipple")) 460 return pygobject_new((GObject *)gc.stipple); 461 if (!strcmp(attr, "clip_mask")) 462 return pygobject_new((GObject *)gc.clip_mask); 463 if (!strcmp(attr, "subwindow_mode")) 464 return pyg_enum_from_gtype(GDK_TYPE_SUBWINDOW_MODE, gc.subwindow_mode); 465 if (!strcmp(attr, "ts_x_origin")) 466 return PyInt_FromLong(gc.ts_x_origin); 467 if (!strcmp(attr, "ts_y_origin")) 468 return PyInt_FromLong(gc.ts_y_origin); 469 if (!strcmp(attr, "clip_x_origin")) 470 return PyInt_FromLong(gc.clip_x_origin); 471 if (!strcmp(attr, "clip_y_origin")) 472 return PyInt_FromLong(gc.clip_y_origin); 473 if (!strcmp(attr, "graphics_exposures")) 474 return PyInt_FromLong(gc.graphics_exposures); 475 if (!strcmp(attr, "line_width")) 476 return PyInt_FromLong(gc.line_width); 477 if (!strcmp(attr, "line_style")) 478 return pyg_enum_from_gtype(GDK_TYPE_LINE_STYLE, gc.line_style); 479 if (!strcmp(attr, "cap_style")) 480 return pyg_enum_from_gtype(GDK_TYPE_CAP_STYLE, gc.cap_style); 481 if (!strcmp(attr, "join_style")) 482 return pyg_enum_from_gtype(GDK_TYPE_JOIN_STYLE, gc.join_style); 483 484 { 485 PyObject *name = PyString_FromString(attr); 486 PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, name); 487 Py_DECREF(name); 488 return ret; 489 } 490} 491%% 492override-slot GdkGC.tp_setattro 493static int 494_wrap_gdk_gc_tp_setattro(PyGObject *self, PyObject *py_attr, PyObject *value) 495{ 496 GdkGC *gc = GDK_GC(self->obj); 497 char *attr; 498 499 if (value == NULL) { 500 PyErr_SetString(PyExc_TypeError, "can't delete attributes"); 501 return -1; 502 } 503 504 if (PyString_Check(py_attr)) 505 attr = PyString_AsString(py_attr); 506 else { 507 PyErr_SetString(PyExc_AttributeError, "could not write attribute"); 508 return -1; 509 } 510 511 if (PyInt_Check(value)) { 512 int i = PyInt_AsLong(value); 513 GdkGCValues v; 514 gdk_gc_get_values(gc, &v); 515 if (!strcmp(attr, "function")) { 516 gdk_gc_set_function(gc, i); 517 return 0; 518 } else if (!strcmp(attr, "fill")) { 519 gdk_gc_set_fill(gc, i); 520 return 0; 521 } else if (!strcmp(attr, "subwindow_mode")) { 522 gdk_gc_set_subwindow(gc, i); 523 return 0; 524 } else if (!strcmp(attr, "ts_x_origin")) { 525 gdk_gc_set_ts_origin(gc, i, v.ts_y_origin); 526 return 0; 527 } else if (!strcmp(attr, "ts_y_origin")) { 528 gdk_gc_set_ts_origin(gc, v.ts_x_origin, i); 529 return 0; 530 } else if (!strcmp(attr, "clip_x_origin")) { 531 gdk_gc_set_clip_origin(gc, i, v.clip_y_origin); 532 return 0; 533 } else if (!strcmp(attr, "clip_y_origin")) { 534 gdk_gc_set_clip_origin(gc, v.clip_x_origin, i); 535 return 0; 536 } else if (!strcmp(attr, "graphics_exposures")) { 537 gdk_gc_set_exposures(gc, i); 538 return 0; 539 } else if (!strcmp(attr, "line_width")) { 540 gdk_gc_set_line_attributes(gc, i, v.line_style, 541 v.cap_style, v.join_style); 542 return 0; 543 } else if (!strcmp(attr, "line_style")) { 544 gdk_gc_set_line_attributes(gc, v.line_width, i, 545 v.cap_style, v.join_style); 546 return 0; 547 } else if (!strcmp(attr, "cap_style")) { 548 gdk_gc_set_line_attributes(gc, v.line_width, v.line_style, 549 i, v.join_style); 550 return 0; 551 } else if (!strcmp(attr, "join_style")) { 552 gdk_gc_set_line_attributes(gc, v.line_width, v.line_style, 553 v.cap_style, i); 554 return 0; 555 } 556 } else if (pyg_boxed_check(value, GDK_TYPE_COLOR)) { 557 GdkColor *c = pyg_boxed_get(value, GdkColor); 558 if (!strcmp(attr, "foreground")) { 559 gdk_gc_set_foreground(gc, c); 560 return 0; 561 } else if (!strcmp(attr, "background")) { 562 gdk_gc_set_background(gc, c); 563 return 0; 564 } 565 } else if (pyg_boxed_check(value, GDK_TYPE_FONT)) { 566 if (!strcmp(attr, "font")) { 567 gdk_gc_set_font(gc, pyg_boxed_get(value, GdkFont)); 568 return 0; 569 } 570 } else if (pygobject_check(value, &PyGdkWindow_Type) || value == Py_None) { 571 PyGObject *window = (PyGObject *)value; 572 GdkWindow *w = (value==Py_None)?NULL:GDK_WINDOW(window->obj); 573 if (!strcmp(attr, "tile")) { 574 gdk_gc_set_tile(gc, w); 575 return 0; 576 } else if (!strcmp(attr, "stipple")) { 577 gdk_gc_set_stipple(gc, w); 578 return 0; 579 } else if (!strcmp(attr, "clip_mask")) { 580 gdk_gc_set_clip_mask(gc, w); 581 return 0; 582 } 583 } 584 585 PyErr_SetString(PyExc_AttributeError, "could not write attribute"); 586 return -1; 587} 588%% 589override gdk_gc_set_dashes 590static PyObject * 591_wrap_gdk_gc_set_dashes(PyGObject *self, PyObject *args) 592{ 593 gint dash_offset, n, i; 594 PyObject *list; 595 gint8 *dash_list; 596 597 if (!PyArg_ParseTuple(args, "iO:GdkGC.set_dashes", &dash_offset, &list)) 598 return NULL; 599 if (!PySequence_Check(list)) { 600 PyErr_SetString(PyExc_TypeError, "second argument must be a sequence"); 601 return NULL; 602 } 603 n = PySequence_Length(list); 604 dash_list = g_new(gint8, n); 605 for (i = 0; i < n; i++) { 606 PyObject *item = PySequence_GetItem(list, i); 607 Py_DECREF(item); 608 609 if (!PyInt_Check(item)) { 610 PyErr_SetString(PyExc_TypeError, "sequence member must be an int"); 611 g_free(dash_list); 612 return NULL; 613 } 614 dash_list[i] = (gint8)PyInt_AsLong(item); 615 if (dash_list[i] == 0) { 616 PyErr_SetString(PyExc_TypeError, "sequence member must not be 0"); 617 g_free(dash_list); 618 return NULL; 619 } 620 } 621 gdk_gc_set_dashes(GDK_GC(self->obj), dash_offset, dash_list, n); 622 g_free(dash_list); 623 Py_INCREF(Py_None); 624 return Py_None; 625} 626