summaryrefslogtreecommitdiffstats
path: root/src/objects/window-object.c
blob: 7684379960d101a8e2d38d9c979693c7b699f154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/* 
    irssi-python

    Copyright (C) 2006 Christopher Davis

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <Python.h>
#include "pyirssi_irc.h"
#include "pymodule.h"
#include "window-object.h"
#include "factory.h"
#include "pycore.h"
#include "pyutils.h"

/* monitor "window destroyed" signal */
static void window_cleanup(WINDOW_REC *win)
{
    PyWindow *pywindow = signal_get_user_data();

    if (win == pywindow->data)
    {
        pywindow->data = NULL;
        pywindow->cleanup_installed = 0;
        signal_remove_data("window destroyed", window_cleanup, pywindow);
    }
}

static void PyWindow_dealloc(PyWindow *self)
{
    if (self->cleanup_installed)
        signal_remove_data("window destroyed", window_cleanup, self); 

    self->ob_type->tp_free((PyObject*)self);
}

static PyObject *PyWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    PyWindow *self;

    self = (PyWindow *)type->tp_alloc(type, 0);
    if (!self)
        return NULL;

    return (PyObject *)self;
}

/* Getters */
PyDoc_STRVAR(PyWindow_refnum_doc,
    "Reference number"
);
static PyObject *PyWindow_refnum_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return PyInt_FromLong(self->data->refnum);
}

PyDoc_STRVAR(PyWindow_name_doc,
    "Name"
);
static PyObject *PyWindow_name_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    RET_AS_STRING_OR_NONE(self->data->name);
}

PyDoc_STRVAR(PyWindow_width_doc,
    "Width"
);
static PyObject *PyWindow_width_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return PyInt_FromLong(self->data->width);
}

PyDoc_STRVAR(PyWindow_height_doc,
    "Height"
);
static PyObject *PyWindow_height_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return PyInt_FromLong(self->data->height);
}

PyDoc_STRVAR(PyWindow_history_name_doc,
    "Name of named historylist for this window"
);
static PyObject *PyWindow_history_name_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    RET_AS_STRING_OR_NONE(self->data->history_name);
}

PyDoc_STRVAR(PyWindow_active_doc,
    "Active window item"
);
static PyObject *PyWindow_active_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return py_irssi_chat_new(self->data->active, 1);
}

PyDoc_STRVAR(PyWindow_active_server_doc,
    "Active server"
);
static PyObject *PyWindow_active_server_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return py_irssi_chat_new(self->data->active_server, 1);
}

PyDoc_STRVAR(PyWindow_servertag_doc,
    "active_server must be either None or have this same tag"
    "(unless there's items in this window). This is used by"
	"/WINDOW SERVER -sticky"
);
static PyObject *PyWindow_servertag_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    RET_AS_STRING_OR_NONE(self->data->servertag);
}

PyDoc_STRVAR(PyWindow_level_doc,
    "Current window level"
);
static PyObject *PyWindow_level_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return PyInt_FromLong(self->data->level);
}

PyDoc_STRVAR(PyWindow_sticky_refnum_doc,
    "True if reference number is sticky"
);
static PyObject *PyWindow_sticky_refnum_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return PyBool_FromLong(self->data->sticky_refnum);
}

PyDoc_STRVAR(PyWindow_data_level_doc,
    "Current data level"
);
static PyObject *PyWindow_data_level_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return PyInt_FromLong(self->data->data_level);
}

PyDoc_STRVAR(PyWindow_hilight_color_doc,
    "Current activity hilight color"
);
static PyObject *PyWindow_hilight_color_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    RET_AS_STRING_OR_NONE(self->data->hilight_color);
}

PyDoc_STRVAR(PyWindow_last_timestamp_doc,
    "Last time timestamp was written in window"
);
static PyObject *PyWindow_last_timestamp_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return PyLong_FromUnsignedLong(self->data->last_timestamp);
}

PyDoc_STRVAR(PyWindow_last_line_doc,
    "Last time text was written in window"
);
static PyObject *PyWindow_last_line_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    return PyLong_FromUnsignedLong(self->data->last_line);
}

PyDoc_STRVAR(PyWindow_theme_name_doc,
    "Active theme in window, None = default"
);
static PyObject *PyWindow_theme_name_get(PyWindow *self, void *closure)
{
    RET_NULL_IF_INVALID(self->data);
    RET_AS_STRING_OR_NONE(self->data->theme_name);
}

/* specialized getters/setters */
static PyGetSetDef PyWindow_getseters[] = {
    {"refnum", (getter)PyWindow_refnum_get, NULL,
        PyWindow_refnum_doc, NULL},
    {"name", (getter)PyWindow_name_get, NULL,
        PyWindow_name_doc, NULL},
    {"width", (getter)PyWindow_width_get, NULL,
        PyWindow_width_doc, NULL},
    {"height", (getter)PyWindow_height_get, NULL,
        PyWindow_height_doc, NULL},
    {"history_name", (getter)PyWindow_history_name_get, NULL,
        PyWindow_history_name_doc, NULL},
    {"active", (getter)PyWindow_active_get, NULL,
        PyWindow_active_doc, NULL},
    {"active_server", (getter)PyWindow_active_server_get, NULL,
        PyWindow_active_server_doc, NULL},
    {"servertag", (getter)PyWindow_servertag_get, NULL,
        PyWindow_servertag_doc, NULL},
    {"level", (getter)PyWindow_level_get, NULL,
        PyWindow_level_doc, NULL},
    {"sticky_refnum", (getter)PyWindow_sticky_refnum_get, NULL,
        PyWindow_sticky_refnum_doc, NULL},
    {"data_level", (getter)PyWindow_data_level_get, NULL,
        PyWindow_data_level_doc, NULL},
    {"hilight_color", (getter)PyWindow_hilight_color_get, NULL,
        PyWindow_hilight_color_doc, NULL},
    {"last_timestamp", (getter)PyWindow_last_timestamp_get, NULL,
        PyWindow_last_timestamp_doc, NULL},
    {"last_line", (getter)PyWindow_last_line_get, NULL,
        PyWindow_last_line_doc, NULL},
    {"theme_name", (getter)PyWindow_theme_name_get, NULL,
        PyWindow_theme_name_doc, NULL},
    {NULL}
};

/* Methods */
PyDoc_STRVAR(PyWindow_items_doc,
    "items() -> list of WindowItem objects\n"
    "\n"
    "Return a list of items in window.\n"
);
static PyObject *PyWindow_items(PyWindow *self, PyObject *args)
{
    RET_NULL_IF_INVALID(self->data);
    return py_irssi_chatlist_new(self->data->items, 1);
}

PyDoc_STRVAR(PyWindow_prnt_doc,
    "prnt(str, level=MSGLEVEL_CLIENTNOTICE) -> None\n"
    "\n"
    "Print to window\n"
);
static PyObject *PyWindow_prnt(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"str", "level", NULL};
    char *str = "";
    int level = MSGLEVEL_CLIENTNOTICE;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwlist, 
           &str, &level))
        return NULL;

    printtext_string_window(self->data, level, str);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_command_doc,
    "command(cmd) -> None\n"
    "\n"
    "Send command to window\n"
);
static PyObject *PyWindow_command(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"cmd", NULL};
    char *cmd = "";
    WINDOW_REC *old;
    
    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, 
           &cmd))
        return NULL;

    old = active_win;
    active_win = self->data;
    py_command(cmd, active_win->active_server, active_win->active);
    if (g_slist_find(windows, old) != NULL)
        active_win = old;

    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_item_add_doc,
    "item_add(item, automatic=False) -> None\n"
    "\n"
    "Add window item\n"
);
static PyObject *PyWindow_item_add(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"item", "automatic", NULL};
    PyObject *item = NULL;
    int automatic = 0;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, 
           &item, &automatic))
        return NULL;

    if (!pywindow_item_check(item))
        return PyErr_Format(PyExc_TypeError, "item must be window item");
    
    window_item_add(self->data, ((PyWindowItem*)item)->data, automatic);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_item_remove_doc,
    "item_remove(item) -> None\n"
    "\n"
    "Remove window item\n"
);
static PyObject *PyWindow_item_remove(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"item", NULL};
    PyObject *item = NULL;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, 
           &item))
        return NULL;

    if (!pywindow_item_check(item))
        return PyErr_Format(PyExc_TypeError, "item must be window item");

    window_item_remove(((PyWindowItem*)item)->data);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_item_destroy_doc,
    "item_destroy(item) -> None\n"
    "\n"
    "Destroy window item\n"
);
static PyObject *PyWindow_item_destroy(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"item", NULL};
    PyObject *item = NULL;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, 
           &item))
        return NULL;

    if (!pywindow_item_check(item))
        return PyErr_Format(PyExc_TypeError, "item must be window item");

    window_item_destroy(((PyWindowItem*)item)->data);

    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_item_prev_doc,
    "item_prev() -> None\n"
    "\n"
    "Change to previous window item\n"
);
static PyObject *PyWindow_item_prev(PyWindow *self, PyObject *args)
{
    RET_NULL_IF_INVALID(self->data);

    window_item_prev(self->data);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_item_next_doc,
    "item_next() -> None\n"
    "\n"
    "Change to next window item\n"
);
static PyObject *PyWindow_item_next(PyWindow *self, PyObject *args)
{
    RET_NULL_IF_INVALID(self->data);

    window_item_next(self->data);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_destroy_doc,
    "destroy() -> None\n"
    "\n"
    "Destroy the window.\n"
);
static PyObject *PyWindow_destroy(PyWindow *self, PyObject *args)
{
    RET_NULL_IF_INVALID(self->data);

    window_destroy(self->data);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_set_active_doc,
    "set_active() -> None\n"
    "\n"
    "Set window active.\n"
);
static PyObject *PyWindow_set_active(PyWindow *self, PyObject *args)
{
    RET_NULL_IF_INVALID(self->data);

    window_set_active(self->data);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_change_server_doc,
    "change_server(server) -> None\n"
    "\n"
    "Change server in window\n"
);
static PyObject *PyWindow_change_server(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"server", NULL};
    PyObject *server = NULL;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, 
           &server))
        return NULL;

    if (!pyserver_check(server))
        return PyErr_Format(PyExc_TypeError, "arg must be server");
   
    window_change_server(self->data, ((PyServer*)server)->data);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_set_refnum_doc,
    "set_refnum(refnum) -> None\n"
    "\n"
    "Set window refnum\n"
);
static PyObject *PyWindow_set_refnum(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"refnum", NULL};
    int refnum = 0;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, 
           &refnum))
        return NULL;

    window_set_refnum(self->data, refnum);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_set_name_doc,
    "set_name(name) -> None\n"
    "\n"
    "Set window name\n"
);
static PyObject *PyWindow_set_name(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"name", NULL};
    char *name = "";

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, 
           &name))
        return NULL;

    window_set_name(self->data, name);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_set_history_doc,
    "set_history(history) -> None\n"
    "\n"
    "Set window history\n"
);
static PyObject *PyWindow_set_history(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"history", NULL};
    char *history = "";

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, 
           &history))
        return NULL;

    window_set_history(self->data, history);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_set_level_doc,
    "set_level(level) -> None\n"
    "\n"
    "Set window level\n"
);
static PyObject *PyWindow_set_level(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"level", NULL};
    int level = 0;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, 
           &level))
        return NULL;

    window_set_level(self->data, level);

    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_activity_doc,
    "activity(data_level, hilight_color) -> None\n"
    "\n"
);
static PyObject *PyWindow_activity(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"data_level", "hilight_color", NULL};
    int data_level = 0;
    char *hilight_color = NULL;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|s", kwlist, 
           &data_level, &hilight_color))
        return NULL;

    window_activity(self->data, data_level, hilight_color);
    
    Py_RETURN_NONE;
}

PyDoc_STRVAR(PyWindow_get_active_name_doc,
    "get_active_name() -> str or None\n"
    "\n"
    "Return active item's name, or if none is active, window's name.\n"
);
static PyObject *PyWindow_get_active_name(PyWindow *self, PyObject *args)
{
    RET_NULL_IF_INVALID(self->data);
    RET_AS_STRING_OR_NONE(window_get_active_name(self->data));
}

PyDoc_STRVAR(PyWindow_item_find_doc,
    "item_find(server, name) -> WindowItem or None\n"
    "\n"
    "Find window item that matches best to given arguments\n"
);
static PyObject *PyWindow_item_find(PyWindow *self, PyObject *args, PyObject *kwds)
{
    static char *kwlist[] = {"server", "name", NULL};
    PyObject *server = NULL;
    char *name = "";
    WI_ITEM_REC *witem;

    RET_NULL_IF_INVALID(self->data);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "Os", kwlist, 
           &server, &name))
        return NULL;

    if (!pyserver_check(server))
        return PyErr_Format(PyExc_TypeError, "arg 1 must be server");

    witem = window_item_find_window(self->data, ((PyServer*)server)->data, name);
    return py_irssi_chat_new(witem, 1);
}

static PyMethodDef PyWindow_methods[] = {
    {"items", (PyCFunction)PyWindow_items, METH_NOARGS,
        PyWindow_items_doc},
    {"prnt", (PyCFunction)PyWindow_prnt, METH_VARARGS | METH_KEYWORDS,
        PyWindow_prnt_doc},
    {"command", (PyCFunction)PyWindow_command, METH_VARARGS | METH_KEYWORDS,
        PyWindow_command_doc},
    {"item_add", (PyCFunction)PyWindow_item_add, METH_VARARGS | METH_KEYWORDS,
        PyWindow_item_add_doc},
    {"item_remove", (PyCFunction)PyWindow_item_remove, METH_VARARGS | METH_KEYWORDS,
        PyWindow_item_remove_doc},
    {"item_destroy", (PyCFunction)PyWindow_item_destroy, METH_VARARGS | METH_KEYWORDS,
        PyWindow_item_destroy_doc},
    {"item_prev", (PyCFunction)PyWindow_item_prev, METH_NOARGS,
        PyWindow_item_prev_doc},
    {"item_next", (PyCFunction)PyWindow_item_next, METH_NOARGS,
        PyWindow_item_next_doc},
    {"destroy", (PyCFunction)PyWindow_destroy, METH_NOARGS,
        PyWindow_destroy_doc},
    {"set_active", (PyCFunction)PyWindow_set_active, METH_NOARGS,
        PyWindow_set_active_doc},
    {"change_server", (PyCFunction)PyWindow_change_server, METH_VARARGS | METH_KEYWORDS,
        PyWindow_change_server_doc},
    {"set_refnum", (PyCFunction)PyWindow_set_refnum, METH_VARARGS | METH_KEYWORDS,
        PyWindow_set_refnum_doc},
    {"set_name", (PyCFunction)PyWindow_set_name, METH_VARARGS | METH_KEYWORDS,
        PyWindow_set_name_doc},
    {"set_history", (PyCFunction)PyWindow_set_history, METH_VARARGS | METH_KEYWORDS,
        PyWindow_set_history_doc},
    {"set_level", (PyCFunction)PyWindow_set_level, METH_VARARGS | METH_KEYWORDS,
        PyWindow_set_level_doc},
    {"activity", (PyCFunction)PyWindow_activity, METH_VARARGS | METH_KEYWORDS,
        PyWindow_activity_doc},
    {"get_active_name", (PyCFunction)PyWindow_get_active_name, METH_NOARGS,
        PyWindow_get_active_name_doc},
    {"item_find", (PyCFunction)PyWindow_item_find, METH_VARARGS | METH_KEYWORDS,
        PyWindow_item_find_doc},
    {NULL}  /* Sentinel */
};

PyTypeObject PyWindowType = {
    PyObject_HEAD_INIT(NULL)
    0,                         /*ob_size*/
    "irssi.Window",            /*tp_name*/
    sizeof(PyWindow),             /*tp_basicsize*/
    0,                         /*tp_itemsize*/
    (destructor)PyWindow_dealloc, /*tp_dealloc*/
    0,                         /*tp_print*/
    0,                         /*tp_getattr*/
    0,                         /*tp_setattr*/
    0,                         /*tp_compare*/
    0,                         /*tp_repr*/
    0,                         /*tp_as_number*/
    0,                         /*tp_as_sequence*/
    0,                         /*tp_as_mapping*/
    0,                         /*tp_hash */
    0,                         /*tp_call*/
    0,                         /*tp_str*/
    0,                         /*tp_getattro*/
    0,                         /*tp_setattro*/
    0,                         /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
    "PyWindow objects",           /* tp_doc */
    0,		               /* tp_traverse */
    0,		               /* tp_clear */
    0,		               /* tp_richcompare */
    0,		               /* tp_weaklistoffset */
    0,		               /* tp_iter */
    0,		               /* tp_iternext */
    PyWindow_methods,             /* tp_methods */
    0,                      /* tp_members */
    PyWindow_getseters,        /* tp_getset */
    0,          /* tp_base */
    0,                         /* tp_dict */
    0,                         /* tp_descr_get */
    0,                         /* tp_descr_set */
    0,                         /* tp_dictoffset */
    0,      /* tp_init */
    0,                         /* tp_alloc */
    PyWindow_new,                 /* tp_new */
};


/* window item wrapper factory function */
PyObject *pywindow_new(void *win)
{
    PyWindow *pywindow;

    pywindow = py_inst(PyWindow, PyWindowType);
    if (!pywindow)
        return NULL;

    pywindow->data = win;
    pywindow->cleanup_installed = 1;
    signal_add_last_data("window destroyed", window_cleanup, pywindow);

    return (PyObject *)pywindow;
}

int window_object_init(void) 
{
    g_return_val_if_fail(py_module != NULL, 0);

    if (PyType_Ready(&PyWindowType) < 0)
        return 0;
    
    Py_INCREF(&PyWindowType);
    PyModule_AddObject(py_module, "Window", (PyObject *)&PyWindowType);

    return 1;
}