Subversion Repositories Scribus

Rev

Rev 5781 | Rev 5890 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
792 subik 7
#include "objprinter.h"
8
#include "cmdutil.h"
2834 cbradney 9
#include "prefsmanager.h"
792 subik 10
 
413 Franz 11
#include <structmember.h>
420 Franz 12
#include <qfileinfo.h>
2921 fschmid 13
#include <qdir.h>
413 Franz 14
#include <vector>
3136 fschmid 15
#include "pslib.h"
4506 cbradney 16
#include "gsutil.h"
5781 cbradney 17
#include "scribuscore.h"
4194 fschmid 18
#include "util.h"
413 Franz 19
 
20
#ifdef HAVE_CUPS
21
#include <cups/cups.h>
22
#endif
23
// these functions are located at utils.cpp
3819 subik 24
bool SCRIBUS_API loadText(QString nam, QString *Buffer);
25
void SCRIBUS_API ReOrderText(ScribusDoc *doc, ScribusView *view);
413 Franz 26
// end of utils.cpp
27
 
1745 subik 28
 
733 subik 29
typedef struct
413 Franz 30
{
1745 subik 31
        PyObject_HEAD
32
        PyObject *allPrinters; // list of strings - names of installed printers
33
        PyObject *printer;  // string - selected printer
34
        PyObject *file;  // string - name of file to print into (eg. output.ps)
35
        PyObject *cmd; // string - if "" use standard command else use this as command (eg. "kprinter", "xpp" ...)
36
        PyObject *pages; // list of integers - pages to be printed
37
        int copies; // numer of printed copies
38
        PyObject *separation; // string - No; All; Cyan; Magenta; Yellow; Black
39
        int color; // bool - do we print in color=1 or greyscale=0
40
        int useICC; // bool - do we use ICC Profiles 0 = No 1 = Yes
41
        int pslevel; // integer - 1, 2 or 3 level of used postscript
42
        int mph; // bool - mirror pages horizontally
43
        int mpv; // bool - mirror pages vertically
44
        int ucr; // bool - Under Color Removal
413 Franz 45
} Printer;
46
 
47
 
48
static void Printer_dealloc(Printer* self)
49
{
1745 subik 50
        Py_XDECREF(self->allPrinters);
51
        Py_XDECREF(self->printer);
52
        Py_XDECREF(self->file);
53
        Py_XDECREF(self->cmd);
54
        Py_XDECREF(self->pages);
55
        Py_XDECREF(self->separation);
56
        self->ob_type->tp_free((PyObject *)self);
413 Franz 57
}
58
 
1745 subik 59
static PyObject * Printer_new(PyTypeObject *type, PyObject */*args*/, PyObject */*kwds*/)
413 Franz 60
{
61
// do not create new object if there is no opened document
5781 cbradney 62
        if (!ScCore->primaryMainWindow()->HaveDoc) {
1745 subik 63
                PyErr_SetString(PyExc_SystemError, "Need to open document first");
64
                return NULL;
65
        }
413 Franz 66
 
1745 subik 67
        Printer *self;
68
        self = (Printer *)type->tp_alloc(type, 0);
69
        if (self != NULL) {
413 Franz 70
// set allPrinters attribute
1745 subik 71
                self->allPrinters = PyList_New(0);
72
                if (self->allPrinters == NULL){
73
                        Py_DECREF(self);
74
                        return NULL;
75
                }
413 Franz 76
// set printer attribute
1745 subik 77
                self->printer = PyString_FromString("");
78
                if (self->printer == NULL){
79
                        Py_DECREF(self);
80
                        return NULL;
81
                }
413 Franz 82
// set file attribute
1745 subik 83
                self->file = PyString_FromString("");
84
                if (self->file == NULL){
85
                        Py_DECREF(self);
86
                        return NULL;
87
                }
413 Franz 88
// set cmd attribute
1745 subik 89
                self->cmd = PyString_FromString("");
90
                if (self->cmd == NULL){
91
                        Py_DECREF(self);
92
                        return NULL;
93
                }
413 Franz 94
// set pages attribute
1745 subik 95
                self->pages = PyList_New(0);
96
                if (self->pages == NULL){
97
                        Py_DECREF(self);
98
                        return NULL;
99
                }
413 Franz 100
// set separation attribute
1745 subik 101
                self->separation = PyString_FromString("No");
102
                if (self->separation == NULL){
103
                        Py_DECREF(self);
104
                        return NULL;
105
                }
413 Franz 106
// set color attribute
1745 subik 107
                self->color = 1;
413 Franz 108
// set useICC attribute
1745 subik 109
                self->useICC = 0;
413 Franz 110
// set pslevel attribute
1745 subik 111
                self->pslevel = 3;
413 Franz 112
// set mph attribute
1745 subik 113
                self->mph = 0;
413 Franz 114
// set mpv attribute
1745 subik 115
                self->mpv = 0;
413 Franz 116
// set ucr attribute
1745 subik 117
                self->ucr = 1;
413 Franz 118
// set copies attribute
1745 subik 119
                self->copies = 1;
120
        }
121
        return (PyObject *) self;
413 Franz 122
}
123
 
1745 subik 124
static int Printer_init(Printer *self, PyObject */*args*/, PyObject */*kwds*/)
413 Franz 125
{
126
// pool system for installed printers
127
// most code is stolen and little adopted from druck.cpp
1745 subik 128
        PyObject *allPrinters = PyList_New(0);
129
        if (allPrinters){
130
                Py_DECREF(self->allPrinters);
131
                self->allPrinters = allPrinters;
132
        }
413 Franz 133
#ifdef HAVE_CUPS
1745 subik 134
        cups_dest_t *dests;
135
        int num_dests = cupsGetDests(&dests);
136
        for (int i = 0; i < num_dests; ++i) {
137
                if (dests[i].name != NULL) {
138
                        PyObject *tmp = PyString_FromString(dests[i].name);
139
                        if (tmp) {
140
                                PyList_Append(self->allPrinters, tmp);
141
                                Py_DECREF(tmp);
142
                        }
143
                }
144
        }
145
        cupsFreeDests(num_dests, dests);
413 Franz 146
#else
1745 subik 147
        QString Pcap;
148
        // loadText is defined in utils.cpp
149
        if (loadText("/etc/printcap", &Pcap))
150
        {
151
                QTextStream ts(&Pcap, IO_ReadOnly);
152
                while(!ts.atEnd())
153
                {
154
                        QStringList wt;
155
                        QString tmp = ts.readLine();
156
                        if (tmp.isEmpty())
157
                                continue;
158
                        if ((tmp[0] != '#') && (tmp[0] != ' ') && (tmp[0] != '\n') && (tmp[0] != '\t'))
159
                        {
160
                                tmp = tmp.stripWhiteSpace();
161
                                tmp = tmp.left(tmp.length() - (tmp.right(2) == ":\\" ? 2 : 1));
162
                                wt = QStringList::split("|", tmp);
163
                                PyObject *tmppr = PyString_FromString(wt[0]);
164
                                if (tmppr){
165
                                        PyList_Append(self->allPrinters, tmppr);
166
                                        Py_DECREF(tmppr);
167
                                }
168
                        }
169
                }
170
        }
413 Franz 171
#endif
1745 subik 172
        PyObject *tmp2 = PyString_FromString("File");
173
        PyList_Append(self->allPrinters, tmp2);
174
        Py_DECREF(tmp2);
413 Franz 175
// as defaut set to print into file
1745 subik 176
        PyObject *printer = NULL;
177
        printer = PyString_FromString("File");
178
        if (printer){
179
                Py_DECREF(self->printer);
180
                self->printer = printer;
181
        }
413 Franz 182
// set defaul name of file to print into
5781 cbradney 183
        QString tf = ScCore->primaryMainWindow()->doc->PDF_Options.Datei;
2877 cbradney 184
        if (tf.isEmpty()) {
5781 cbradney 185
                QFileInfo fi = QFileInfo(ScCore->primaryMainWindow()->doc->DocName);
1745 subik 186
                tf = fi.dirPath()+"/"+fi.baseName()+".pdf";
187
        }
188
        PyObject *file = NULL;
189
        file = PyString_FromString(tf.ascii());
190
        if (file){
191
                Py_DECREF(self->file);
192
                self->file = file;
193
        } else {
194
                PyErr_SetString(PyExc_SystemError, "Can not initialize 'file' attribute");
195
                return -1;
196
        }
413 Franz 197
// alternative printer commands default to ""
1745 subik 198
        PyObject *cmd = NULL;
199
        cmd = PyString_FromString("");
200
        if (cmd){
201
                Py_DECREF(self->cmd);
202
                self->cmd = cmd;
203
        }
413 Franz 204
// if document exist when created Printer instance
205
// set to print all pages
1745 subik 206
        PyObject *pages = NULL;
207
        int num = 0;
5781 cbradney 208
        if (ScCore->primaryMainWindow()->HaveDoc)
1745 subik 209
                // which one should I use ???
5781 cbradney 210
                // new = ScCore->primaryMainWindow()->view->Pages.count()
211
                num = ScCore->primaryMainWindow()->doc->Pages->count();
1745 subik 212
        pages = PyList_New(num);
213
        if (pages){
214
                Py_DECREF(self->pages);
215
                self->pages = pages;
216
        }
217
        for (int i = 0; i<num; i++) {
218
                PyObject *tmp=NULL;
219
                tmp = PyInt_FromLong((long)i+1L); // instead of 1 put here first page number
220
                if (tmp)
221
                        PyList_SetItem(self->pages, i, tmp);
222
        }
413 Franz 223
// do not print separation
1745 subik 224
        PyObject *separation = NULL;
225
        separation = PyString_FromString("No");
226
        if (separation){
227
                Py_DECREF(self->separation);
228
                self->separation = separation;
229
        }
413 Franz 230
// print in color
1745 subik 231
        self->color = 1;
413 Franz 232
// do not use ICC Profile
1745 subik 233
        self->useICC = 0;
413 Franz 234
// use PostScrip level 3
1745 subik 235
        self->pslevel = 3;
413 Franz 236
// do not mirror pages
1745 subik 237
        self->mph = 0;
413 Franz 238
// do not mirror pages
1745 subik 239
        self->mpv = 0;
413 Franz 240
// apply Under Color Removal as default
1745 subik 241
        self->ucr = 1;
413 Franz 242
// number of copies
1745 subik 243
        self->copies = 1;
244
        return 0;
413 Franz 245
}
246
 
247
static PyMemberDef Printer_members[] = {
1745 subik 248
        {const_cast<char*>("copies"), T_INT, offsetof(Printer, copies), 0, const_cast<char*>("Number of copies")},
249
        {const_cast<char*>("color"), T_INT, offsetof(Printer, color), 0, const_cast<char*>("Print in color.\n\t True - color  --  Default\n\t False - greyscale")},
250
        {const_cast<char*>("useICC"), T_INT, offsetof(Printer, useICC), 0, const_cast<char*>("Use ICC Profile\n\tTrue\n\tFalse  --  Default")},
251
        {const_cast<char*>("pslevel"), T_INT, offsetof(Printer, pslevel), 0, const_cast<char*>("PostScript Level\nCan be 1 or 2 or 3    -- Default is 3.")},
252
        {const_cast<char*>("mph"), T_INT, offsetof(Printer, mph), 0, const_cast<char*>("Mirror Pages Horizontal\n\tTrue\n\tFalse  --  Default")},
253
        {const_cast<char*>("mpv"), T_INT, offsetof(Printer, mpv), 0, const_cast<char*>("Mirror Pages Vertical\n\t True\n\tFalse  --  Default")},
254
        {const_cast<char*>("ucr"), T_INT, offsetof(Printer, ucr), 0, const_cast<char*>("Apply Under Color Removal\n\tTrue  --  Default\n\tFalse")},
255
        {NULL, 0, 0, 0, NULL} // sentinel
413 Franz 256
};
257
 
258
/* Here begins Getter & Setter functions */
259
 
1745 subik 260
static PyObject *Printer_getallPrinters(Printer *self, void */*closure*/)
413 Franz 261
{
1745 subik 262
        Py_INCREF(self->allPrinters);
263
        return self->allPrinters;
413 Franz 264
}
265
 
1745 subik 266
static int Printer_setallPrinters(Printer */*self*/, PyObject */*value*/, void */*closure*/)
413 Franz 267
{
1745 subik 268
        PyErr_SetString(PyExc_ValueError, "'allPrinters' attribute is READ-ONLY");
269
        return -1;
413 Franz 270
}
271
 
1745 subik 272
static PyObject *Printer_getprinter(Printer *self, void */*closure*/)
413 Franz 273
{
1745 subik 274
        Py_INCREF(self->printer);
275
        return self->printer;
413 Franz 276
}
277
 
1745 subik 278
static int Printer_setprinter(Printer *self, PyObject *value, void */*closure*/)
413 Franz 279
{
1745 subik 280
        if (value == NULL) {
281
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'printer' attribute.");
282
                return -1;
283
        }
284
        if (!PyString_Check(value)) {
285
                PyErr_SetString(PyExc_TypeError, "The 'printer' attribute value must be string.");
286
                return -1;
287
        }
288
        int n = PyList_Size(self->allPrinters);
289
        bool same = 0;
290
        for (int i = 0; i<n; i++)
291
                if (PyObject_RichCompareBool(value, PyList_GetItem(self->allPrinters, i), Py_EQ) == 1)
292
                        same = true;
293
        if (!same) {
294
                PyErr_SetString(PyExc_ValueError, "'printer' value can be only one of string in 'allPrinters' attribute ");
295
                return -1;
296
        }
297
        Py_DECREF(self->printer);
298
        Py_INCREF(value);
299
        self->printer = value;
300
        return 0;
413 Franz 301
}
302
 
1745 subik 303
static PyObject *Printer_getfile(Printer *self, void */*closure*/)
413 Franz 304
{
1745 subik 305
        Py_INCREF(self->file);
306
        return self->file;
413 Franz 307
}
308
 
1745 subik 309
static int Printer_setfile(Printer *self, PyObject *value, void */*closure*/)
413 Franz 310
{
1745 subik 311
        if (value == NULL) {
312
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'file' attribute.");
313
                return -1;
314
        }
315
        if (!PyString_Check(value)) {
316
                PyErr_SetString(PyExc_TypeError, "The 'file' attribute value must be string.");
317
                return -1;
318
        }
319
        Py_DECREF(self->file);
320
        Py_INCREF(value);
321
        self->file = value;
322
        return 0;
413 Franz 323
}
324
 
1745 subik 325
static PyObject *Printer_getcmd(Printer *self, void */*closure*/)
413 Franz 326
{
1745 subik 327
        Py_INCREF(self->cmd);
328
        return self->cmd;
413 Franz 329
}
330
 
1745 subik 331
static int Printer_setcmd(Printer *self, PyObject *value, void */*closure*/)
413 Franz 332
{
1745 subik 333
        if (value == NULL) {
334
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'cmd' attribute.");
335
                return -1;
336
        }
337
        if (!PyString_Check(value)) {
338
                PyErr_SetString(PyExc_TypeError, "The 'cmd' attribute value must be string.");
339
                return -1;
340
        }
341
        Py_DECREF(self->cmd);
342
        Py_INCREF(value);
343
        self->cmd = value;
344
        return 0;
413 Franz 345
}
346
 
1745 subik 347
static PyObject *Printer_getpages(Printer *self, void */*closure*/)
413 Franz 348
{
1745 subik 349
        Py_INCREF(self->pages);
350
        return self->pages;
413 Franz 351
}
352
 
1745 subik 353
static int Printer_setpages(Printer *self, PyObject *value, void */*closure*/)
413 Franz 354
{
1745 subik 355
        if (value == NULL) {
356
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'pages' attribute.");
357
                return -1;
358
        }
359
        if (!PyList_Check(value)) {
360
                PyErr_SetString(PyExc_TypeError, "'pages' attribute value must be list of integers.");
361
                return -1;
362
        }
363
        int len = PyList_Size(value);
364
        for (int i = 0; i<len; i++){
365
                PyObject *tmp = PyList_GetItem(value, i);
366
                if (!PyInt_Check(tmp)){
367
                        PyErr_SetString(PyExc_TypeError, "'pages' attribute must be list containing only integers.");
368
                        return -1;
369
                }
5781 cbradney 370
                if (PyInt_AsLong(tmp) > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count()) || PyInt_AsLong(tmp) < 1) {
1745 subik 371
                        PyErr_SetString(PyExc_ValueError, "'pages' value out of range.");
372
                        return -1;
373
                }
374
        }
375
        Py_DECREF(self->pages);
376
        Py_INCREF(value);
377
        self->pages = value;
378
        return 0;
413 Franz 379
}
380
 
1745 subik 381
static PyObject *Printer_getseparation(Printer *self, void */*closure*/)
413 Franz 382
{
1745 subik 383
        Py_INCREF(self->separation);
384
        return self->separation;
413 Franz 385
}
386
 
1745 subik 387
static int Printer_setseparation(Printer *self, PyObject *value, void */*closure*/)
413 Franz 388
{
1745 subik 389
        if (value == NULL) {
390
                PyErr_SetString(PyExc_TypeError, "Cannot delete 'separation' attribute.");
391
                return -1;
392
        }
393
        if (!PyString_Check(value)) {
394
                PyErr_SetString(PyExc_TypeError, "The 'separation' attribute value must be string.");
395
                return -1;
396
        }
397
        Py_DECREF(self->separation);
398
        Py_INCREF(value);
399
        self->separation = value;
400
        return 0;
413 Franz 401
}
402
 
403
 
404
static PyGetSetDef Printer_getseters [] = {
1745 subik 405
        {const_cast<char*>("allPrinters"), (getter)Printer_getallPrinters, (setter)Printer_setallPrinters, const_cast<char*>("List of installed printers  --  read only"), NULL},
406
        {const_cast<char*>("printer"), (getter)Printer_getprinter, (setter)Printer_setprinter, const_cast<char*>("Name of printer to use.\nDefault is 'File' for printing into file"), NULL},
407
        {const_cast<char*>("file"), (getter)Printer_getfile, (setter)Printer_setfile, const_cast<char*>("Name of file to print into"), NULL},
408
        {const_cast<char*>("cmd"), (getter)Printer_getcmd, (setter)Printer_setcmd, const_cast<char*>("Alternative Printer Command"), NULL},
409
        {const_cast<char*>("pages"), (getter)Printer_getpages, (setter)Printer_setpages, const_cast<char*>("List of pages to be printed"), NULL},
410
        {const_cast<char*>("separation"), (getter)Printer_getseparation, (setter)Printer_setseparation, const_cast<char*>("Print separationl\n\t 'No'  -- Default\n\t 'All'\n\t 'Cyan'\n\t 'Magenta'\n\t 'Yellow'\n\t 'Black'\nBeware of misspelling because check is not performed"), NULL},
411
        {NULL, NULL, NULL, NULL, NULL}  // sentinel
413 Franz 412
};
413
 
733 subik 414
// Here we actually print
413 Franz 415
static PyObject *Printer_print(Printer *self)
416
{
5781 cbradney 417
        if (!ScCore->primaryMainWindow()->HaveDoc) {
1745 subik 418
                PyErr_SetString(PyExc_SystemError, "Need to open documetnt first");
419
                return NULL;
420
        }
4026 craig 421
// copied from void ScribusMainWindow::slotFilePrint() in file scribus.cpp
1745 subik 422
        QString fna, prn, cmd, scmd, cc, data, SepName;
423
        QString printcomm;
424
        int Nr, PSLevel;
425
        bool fil, sep, color, PSfile, mirrorH, mirrorV, useICC, DoGCR;
426
        PSfile = false;
413 Franz 427
 
5781 cbradney 428
//    ReOrderText(ScCore->primaryMainWindow()->doc, ScCore->primaryMainWindow()->view);
1745 subik 429
        prn = QString(PyString_AsString(self->printer));
430
        fna = QString(PyString_AsString(self->file));
431
        fil = (QString(PyString_AsString(self->printer)) == QString("File")) ? true : false;
432
        std::vector<int> pageNs;
433
        for (int i = 0; i < PyList_Size(self->pages); ++i) {
434
                pageNs.push_back((int)PyInt_AsLong(PyList_GetItem(self->pages, i)));
435
        }
436
        Nr = (self->copies < 1) ? 1 : self->copies;
437
        SepName = QString(PyString_AsString(self->separation));
438
        sep =(SepName == QString("No")) ?  false : true;
439
//       if (SepName == QString("All"))
440
//               SepName = tr(SepName);
441
        color = self->color;
442
        mirrorH = self->mph;
443
        mirrorV = self->mpv;
444
        useICC = self->useICC;
445
        DoGCR = self->ucr;
446
        int psl = self->pslevel;
447
        if (psl < 1)
448
                psl = 1;
449
        else if (psl > 3)
450
                psl = 3;
451
        PSLevel = psl;
452
        printcomm = QString(PyString_AsString(self->cmd));
5387 avox 453
        QMap<QString, QMap<uint, FPointArray> > ReallyUsed;
1745 subik 454
        ReallyUsed.clear();
5781 cbradney 455
        ScCore->primaryMainWindow()->doc->getUsedFonts(ReallyUsed);
3136 fschmid 456
        PrefsManager *prefsManager=PrefsManager::instance();
5781 cbradney 457
        PSLib *dd = new PSLib(true, prefsManager->appPrefs.AvailFonts, ReallyUsed, ScCore->primaryMainWindow()->doc->PageColors, false, true);
1745 subik 458
        if (dd != NULL)
459
        {
460
                if (!fil)
5781 cbradney 461
                        fna = ScCore->primaryMainWindow()->PrefsPfad+"/tmp.ps";
1745 subik 462
                PSfile = dd->PS_set_file(fna);
2921 fschmid 463
                fna = QDir::convertSeparators(fna);
1745 subik 464
                if (PSfile)
465
                {
3068 fschmid 466
                        QStringList spots;
5781 cbradney 467
                        dd->CreatePS(ScCore->primaryMainWindow()->doc, /*ScCore->primaryMainWindow()->view, */pageNs, sep, SepName, spots, color, mirrorH, mirrorV, useICC, DoGCR, false, false);
1745 subik 468
                        if (PSLevel != 3)
469
                        {
470
                                QString tmp;
4194 fschmid 471
                                QStringList opts;
5781 cbradney 472
                                opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(ScCore->primaryMainWindow()->doc->pageWidth)) );
473
                                opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(ScCore->primaryMainWindow()->doc->pageHeight)) );
4194 fschmid 474
                                convertPS2PS(fna, fna+".tmp", opts, PSLevel);
475
                                moveFile( fna + ".tmp", fna );
1745 subik 476
                        }
418 Franz 477
 
1745 subik 478
                        if (!fil)
479
                        {
2877 cbradney 480
                                if (!printcomm.isEmpty())
1745 subik 481
                                        cmd = printcomm + " "+fna;
482
                                else
483
                                {
484
                                        cmd = "lpr -P" + prn;
485
                                        if (Nr > 1)
486
                                                cmd += " -#" + cc.setNum(Nr);
413 Franz 487
#ifdef HAVE_CUPS
418 Franz 488
// This need yet to be implemented by object Printer
1745 subik 489
//                                      cmd += printer->PrinterOpts;
413 Franz 490
#endif
1745 subik 491
                                        cmd += " "+fna;
492
                                }
493
                                system(cmd);
494
                                unlink(fna);
495
                        }
496
                }
497
                else {
498
                        delete dd;
499
                        PyErr_SetString(PyExc_SystemError, "Printing failed");
500
                        return NULL;
501
                }
502
                delete dd;
503
        }
504
        Py_INCREF(Py_None);
505
        return Py_None;
413 Franz 506
}
507
 
508
static PyMethodDef Printer_methods[] = {
1745 subik 509
        {const_cast<char*>("print"), (PyCFunction)Printer_print, METH_NOARGS, const_cast<char*>("Prints selected pages.")},
510
        {NULL, (PyCFunction)(0), 0, NULL} // sentinel
413 Franz 511
};
512
 
513
PyTypeObject Printer_Type = {
1745 subik 514
        PyObject_HEAD_INIT(NULL)   // PyObject_VAR_HEAD
515
        0,                       //
516
        const_cast<char*>("Printer"), // char *tp_name; /* For printing, in format "<module>.<name>" */
517
        sizeof(Printer),   // int tp_basicsize, /* For allocation */
518
        0,                     // int tp_itemsize; /* For allocation */
413 Franz 519
 
520
        /* Methods to implement standard operations */
521
 
1745 subik 522
        (destructor) Printer_dealloc, //     destructor tp_dealloc;
523
        0, //     printfunc tp_print;
524
        0, //     getattrfunc tp_getattr;
525
        0, //     setattrfunc tp_setattr;
526
        0, //     cmpfunc tp_compare;
527
        0, //     reprfunc tp_repr;
413 Franz 528
 
529
        /* Method suites for standard classes */
530
 
1745 subik 531
        0, //     PyNumberMethods *tp_as_number;
532
        0, //     PySequenceMethods *tp_as_sequence;
533
        0, //     PyMappingMethods *tp_as_mapping;
413 Franz 534
 
535
        /* More standard operations (here for binary compatibility) */
536
 
1745 subik 537
        0, //     hashfunc tp_hash;
538
        0, //     ternaryfunc tp_call;
539
        0, //     reprfunc tp_str;
540
        0, //     getattrofunc tp_getattro;
541
        0, //     setattrofunc tp_setattro;
413 Franz 542
 
543
        /* Functions to access object as input/output buffer */
1745 subik 544
        0, //     PyBufferProcs *tp_as_buffer;
413 Franz 545
 
546
        /* Flags to define presence of optional/expanded features */
1745 subik 547
        Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,    // long tp_flags;
413 Franz 548
 
1745 subik 549
        printer__doc__,      // char *tp_doc; /* Documentation string */
733 subik 550
 
413 Franz 551
        /* Assigned meaning in release 2.0 */
552
        /* call function for all accessible objects */
1745 subik 553
        0, //     traverseproc tp_traverse;
413 Franz 554
 
555
        /* delete references to contained objects */
1745 subik 556
        0, //     inquiry tp_clear;
413 Franz 557
 
558
        /* Assigned meaning in release 2.1 */
559
        /* rich comparisons */
1745 subik 560
        0, //     richcmpfunc tp_richcompare;
413 Franz 561
 
562
        /* weak reference enabler */
1745 subik 563
        0, //     long tp_weaklistoffset;
413 Franz 564
 
565
        /* Added in release 2.2 */
566
        /* Iterators */
1745 subik 567
        0, //     getiterfunc tp_iter;
568
        0, //     iternextfunc tp_iternext;
413 Franz 569
 
570
        /* Attribute descriptor and subclassing stuff */
1745 subik 571
        Printer_methods, //     struct PyMethodDef *tp_methods;
572
        Printer_members, //     struct PyMemberDef *tp_members;
573
        Printer_getseters, //     struct PyGetSetDef *tp_getset;
574
        0, //     struct _typeobject *tp_base;
575
        0, //     PyObject *tp_dict;
576
        0, //     descrgetfunc tp_descr_get;
577
        0, //     descrsetfunc tp_descr_set;
578
        0, //     long tp_dictoffset;
579
        (initproc)Printer_init, //     initproc tp_init;
580
        0, //     allocfunc tp_alloc;
581
        Printer_new, //     newfunc tp_new;
582
        0, //     freefunc tp_free; /* Low-level free-memory routine */
583
        0, //     inquiry tp_is_gc; /* For PyObject_IS_GC */
584
        0, //     PyObject *tp_bases;
585
        0, //     PyObject *tp_mro; /* method resolution order */
586
        0, //     PyObject *tp_cache;
587
        0, //     PyObject *tp_subclasses;
588
        0, //     PyObject *tp_weaklist;
589
        0, //     destructor tp_del;
413 Franz 590
 
591
#ifdef COUNT_ALLOCS
592
        /* these must be last and never explicitly initialized */
1745 subik 593
        //    int tp_allocs;
594
        //    int tp_frees;
595
        //    int tp_maxalloc;
596
        //    struct _typeobject *tp_next;
413 Franz 597
#endif
598
};