Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
103 Franz 1
#include "cmdobj.h"
2
#include "cmdutil.h"
82 Franz 3
 
2529 craig 4
#include "util.h"
740 fschmid 5
 
2790 craig 6
PyObject *scribus_newrect(PyObject* /* self */, PyObject* args)
82 Franz 7
{
8
        double x, y, b, h;
934 subik 9
        char *Name = const_cast<char*>("");
900 cbradney 10
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 11
                return NULL;
649 fschmid 12
        if(!checkHaveDocument())
13
                return NULL;
900 cbradney 14
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 15
        {
1525 cbradney 16
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 17
                return NULL;
18
        }
3207 craig 19
        int i = ScApp->view->PaintRect(pageUnitXToDocX(x), pageUnitYToDocY(y),
2086 craig 20
                                                                         ValueToPoint(b), ValueToPoint(h),
3207 craig 21
                                                                         ScApp->doc->toolSettings.dWidth,
22
                                                                         ScApp->doc->toolSettings.dBrush,
23
                                                                         ScApp->doc->toolSettings.dPen);
3242 cbradney 24
        ScApp->doc->Items.at(i)->SetRectFrame();
25
        ScApp->view->setRedrawBounding(ScApp->doc->Items.at(i));
2879 cbradney 26
        if (Name != "")
3207 craig 27
                ScApp->doc->Items.at(i)->setItemName(QString::fromUtf8(Name));
28
        return PyString_FromString(ScApp->doc->Items.at(i)->itemName().utf8());
82 Franz 29
}
30
 
243 Franz 31
 
2790 craig 32
PyObject *scribus_newellipse(PyObject* /* self */, PyObject* args)
82 Franz 33
{
34
        double x, y, b, h;
934 subik 35
        char *Name = const_cast<char*>("");
900 cbradney 36
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 37
                return NULL;
649 fschmid 38
        if(!checkHaveDocument())
39
                return NULL;
3207 craig 40
        int i = ScApp->view->PaintEllipse(pageUnitXToDocX(x), pageUnitYToDocY(y), b, h,
41
                                                                                ScApp->doc->toolSettings.dWidth,
42
                                                                                ScApp->doc->toolSettings.dBrush,
43
                                                                                ScApp->doc->toolSettings.dPen);
900 cbradney 44
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 45
        {
1525 cbradney 46
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 47
                return NULL;
48
        }
3242 cbradney 49
        ScApp->doc->Items.at(i)->SetOvalFrame();
50
        ScApp->view->setRedrawBounding(ScApp->doc->Items.at(i));
2879 cbradney 51
        if (Name != "")
3207 craig 52
                ScApp->doc->Items.at(i)->setItemName(QString::fromUtf8(Name));
53
        return PyString_FromString(ScApp->doc->Items.at(i)->itemName().utf8());
82 Franz 54
}
55
 
243 Franz 56
 
2790 craig 57
PyObject *scribus_newimage(PyObject* /* self */, PyObject* args)
82 Franz 58
{
59
        double x, y, b, h;
934 subik 60
        char *Name = const_cast<char*>("");
900 cbradney 61
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 62
                return NULL;
649 fschmid 63
        if(!checkHaveDocument())
64
                return NULL;
3207 craig 65
        int i = ScApp->view->PaintPict(pageUnitXToDocX(x), pageUnitYToDocY(y), b, h);
900 cbradney 66
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 67
        {
1525 cbradney 68
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 69
                return NULL;
70
        }
3242 cbradney 71
        ScApp->doc->Items.at(i)->SetRectFrame();
72
        ScApp->view->setRedrawBounding(ScApp->doc->Items.at(i));
2879 cbradney 73
        if (Name != "")
3207 craig 74
                ScApp->doc->Items.at(i)->setItemName(QString::fromUtf8(Name));
75
        return PyString_FromString(ScApp->doc->Items.at(i)->itemName().utf8());
82 Franz 76
}
77
 
243 Franz 78
 
2790 craig 79
PyObject *scribus_newtext(PyObject* /* self */, PyObject* args)
82 Franz 80
{
81
        double x, y, b, h;
934 subik 82
        char *Name = const_cast<char*>("");
900 cbradney 83
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 84
                return NULL;
649 fschmid 85
        if(!checkHaveDocument())
86
                return NULL;
3207 craig 87
        int i = ScApp->view->PaintText(pageUnitXToDocX(x), pageUnitYToDocY(y), b, h,
88
                                                                         ScApp->doc->toolSettings.dWidth,
89
                                                                         ScApp->doc->toolSettings.dPenText);
900 cbradney 90
        if (ItemExists(QString::fromUtf8(Name)))
332 Franz 91
        {
1525 cbradney 92
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 93
                return NULL;
332 Franz 94
        }
3242 cbradney 95
        ScApp->doc->Items.at(i)->SetRectFrame();
96
        ScApp->view->setRedrawBounding(ScApp->doc->Items.at(i));
2879 cbradney 97
        if (Name != "")
3207 craig 98
                ScApp->doc->Items.at(i)->setItemName(QString::fromUtf8(Name));
99
        return PyString_FromString(ScApp->doc->Items.at(i)->itemName().utf8());
82 Franz 100
}
101
 
243 Franz 102
 
2790 craig 103
PyObject *scribus_newline(PyObject* /* self */, PyObject* args)
82 Franz 104
{
105
        double x, y, b, h;
934 subik 106
        char *Name = const_cast<char*>("");
900 cbradney 107
        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
82 Franz 108
                return NULL;
649 fschmid 109
        if(!checkHaveDocument())
110
                return NULL;
2029 craig 111
        x = pageUnitXToDocX(x);
1283 subik 112
        y = pageUnitYToDocY(y);
113
        b = pageUnitXToDocX(b);
114
        h = pageUnitYToDocY(h);
900 cbradney 115
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 116
        {
1525 cbradney 117
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 118
                return NULL;
119
        }
3207 craig 120
        int i = ScApp->view->PaintPolyLine(x, y, 1, 1,  ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen);
121
        PageItem *it = ScApp->doc->Items.at(i);
82 Franz 122
        it->PoLine.resize(4);
123
        it->PoLine.setPoint(0, 0, 0);
124
        it->PoLine.setPoint(1, 0, 0);
125
        it->PoLine.setPoint(2, b-x, h-y);
126
        it->PoLine.setPoint(3, b-x, h-y);
1065 cbradney 127
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 128
        if (np2.x() < 0)
647 fschmid 129
        {
82 Franz 130
                it->PoLine.translate(-np2.x(), 0);
3207 craig 131
                ScApp->view->MoveItem(np2.x(), 0, it);
647 fschmid 132
        }
82 Franz 133
        if (np2.y() < 0)
647 fschmid 134
        {
82 Franz 135
                it->PoLine.translate(0, -np2.y());
3207 craig 136
                ScApp->view->MoveItem(0, np2.y(), it);
647 fschmid 137
        }
3207 craig 138
        ScApp->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), i, false, false);
139
        ScApp->view->AdjustItemSize(it);
2879 cbradney 140
        if (Name != "")
1361 tsoots 141
                it->setItemName(QString::fromUtf8(Name));
142
        return PyString_FromString(it->itemName().utf8());
82 Franz 143
}
144
 
243 Franz 145
 
2790 craig 146
PyObject *scribus_polyline(PyObject* /* self */, PyObject* args)
82 Franz 147
{
934 subik 148
        char *Name = const_cast<char*>("");
82 Franz 149
        PyObject *il;
900 cbradney 150
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
151
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 152
                return NULL;
649 fschmid 153
        if(!checkHaveDocument())
154
                return NULL;
87 Franz 155
        int len = PyList_Size(il);
720 subik 156
        if (len < 4)
157
        {
1525 cbradney 158
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least two points (four values).","python error"));
720 subik 159
                return NULL;
160
        }
161
        if ((len % 2) != 0)
162
        {
1525 cbradney 163
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error"));
720 subik 164
                return NULL;
165
        }
900 cbradney 166
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 167
        {
1525 cbradney 168
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 169
                return NULL;
170
        }
87 Franz 171
        double x, y, b, h;
237 Franz 172
        int i = 0;
1283 subik 173
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 174
        i++;
1283 subik 175
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 176
        i++;
3207 craig 177
        int ic = ScApp->view->PaintPolyLine(x, y, 1, 1, ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen);
178
        PageItem *it = ScApp->doc->Items.at(ic);
82 Franz 179
        it->PoLine.resize(2);
180
        it->PoLine.setPoint(0, 0, 0);
181
        it->PoLine.setPoint(1, 0, 0);
87 Franz 182
        int pp = 6;
82 Franz 183
        for (i = 2; i < len - 2; i += 2)
647 fschmid 184
        {
1283 subik 185
                b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
186
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
82 Franz 187
                it->PoLine.resize(pp);
188
                it->PoLine.setPoint(pp-4, b-x, h-y);
189
                it->PoLine.setPoint(pp-3, b-x, h-y);
190
                it->PoLine.setPoint(pp-2, b-x, h-y);
191
                it->PoLine.setPoint(pp-1, b-x, h-y);
192
                pp += 4;
647 fschmid 193
        }
82 Franz 194
        pp -= 2;
1283 subik 195
        b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
196
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
82 Franz 197
        it->PoLine.resize(pp);
198
        it->PoLine.setPoint(pp-2, b-x, h-y);
199
        it->PoLine.setPoint(pp-1, b-x, h-y);
1065 cbradney 200
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 201
        if (np2.x() < 0)
647 fschmid 202
        {
82 Franz 203
                it->PoLine.translate(-np2.x(), 0);
3207 craig 204
                ScApp->view->MoveItem(np2.x(), 0, it);
647 fschmid 205
        }
82 Franz 206
        if (np2.y() < 0)
647 fschmid 207
        {
82 Franz 208
                it->PoLine.translate(0, -np2.y());
3207 craig 209
                ScApp->view->MoveItem(0, np2.y(), it);
647 fschmid 210
        }
3207 craig 211
        ScApp->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
212
        ScApp->view->AdjustItemSize(it);
2879 cbradney 213
        if (Name != "")
720 subik 214
        {
1361 tsoots 215
                it->setItemName(QString::fromUtf8(Name));
720 subik 216
        }
1361 tsoots 217
        return PyString_FromString(it->itemName().utf8());
82 Franz 218
}
219
 
243 Franz 220
 
2790 craig 221
PyObject *scribus_polygon(PyObject* /* self */, PyObject* args)
82 Franz 222
{
934 subik 223
        char *Name = const_cast<char*>("");
82 Franz 224
        PyObject *il;
900 cbradney 225
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
226
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 227
                return NULL;
649 fschmid 228
        if(!checkHaveDocument())
229
                return NULL;
87 Franz 230
        int len = PyList_Size(il);
720 subik 231
        if (len < 6)
232
        {
1525 cbradney 233
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least three points (six values).","python error"));
720 subik 234
                return NULL;
235
        }
236
        if ((len % 2) != 0)
237
        {
1525 cbradney 238
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error"));
720 subik 239
                return NULL;
240
        }
900 cbradney 241
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 242
        {
1525 cbradney 243
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 244
                return NULL;
245
        }
87 Franz 246
        double x, y, b, h;
237 Franz 247
        int i = 0;
1283 subik 248
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 249
        i++;
1283 subik 250
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 251
        i++;
3207 craig 252
        int ic = ScApp->view->PaintPoly(x, y, 1, 1,     ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen);
253
        PageItem *it = ScApp->doc->Items.at(ic);
82 Franz 254
        it->PoLine.resize(2);
255
        it->PoLine.setPoint(0, 0, 0);
256
        it->PoLine.setPoint(1, 0, 0);
87 Franz 257
        int pp = 6;
82 Franz 258
        for (i = 2; i < len - 2; i += 2)
647 fschmid 259
        {
1283 subik 260
                b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
261
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
82 Franz 262
                it->PoLine.resize(pp);
263
                it->PoLine.setPoint(pp-4, b-x, h-y);
264
                it->PoLine.setPoint(pp-3, b-x, h-y);
265
                it->PoLine.setPoint(pp-2, b-x, h-y);
266
                it->PoLine.setPoint(pp-1, b-x, h-y);
267
                pp += 4;
647 fschmid 268
        }
1283 subik 269
        b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
270
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
82 Franz 271
        it->PoLine.resize(pp);
272
        it->PoLine.setPoint(pp-4, b-x, h-y);
273
        it->PoLine.setPoint(pp-3, b-x, h-y);
274
        it->PoLine.setPoint(pp-2, b-x, h-y);
275
        it->PoLine.setPoint(pp-1, b-x, h-y);
276
        pp += 2;
277
        it->PoLine.resize(pp);
278
        it->PoLine.setPoint(pp-2, 0, 0);
279
        it->PoLine.setPoint(pp-1, 0, 0);
1065 cbradney 280
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 281
        if (np2.x() < 0)
647 fschmid 282
        {
82 Franz 283
                it->PoLine.translate(-np2.x(), 0);
3207 craig 284
                ScApp->view->MoveItem(np2.x(), 0, it);
647 fschmid 285
        }
82 Franz 286
        if (np2.y() < 0)
647 fschmid 287
        {
82 Franz 288
                it->PoLine.translate(0, -np2.y());
3207 craig 289
                ScApp->view->MoveItem(0, np2.y(), it);
647 fschmid 290
        }
3207 craig 291
        ScApp->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
292
        ScApp->view->AdjustItemSize(it);
2879 cbradney 293
        if (Name != "")
1361 tsoots 294
                it->setItemName(QString::fromUtf8(Name));
295
        return PyString_FromString(it->itemName().utf8());
82 Franz 296
}
297
 
2790 craig 298
PyObject *scribus_bezierline(PyObject* /* self */, PyObject* args)
82 Franz 299
{
934 subik 300
        char *Name = const_cast<char*>("");
82 Franz 301
        PyObject *il;
900 cbradney 302
        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
303
        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
82 Franz 304
                return NULL;
649 fschmid 305
        if(!checkHaveDocument())
306
                return NULL;
87 Franz 307
        int len = PyList_Size(il);
720 subik 308
        if (len < 8)
309
        {
1525 cbradney 310
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least four points (eight values).","python error"));
720 subik 311
                return NULL;
312
        }
313
        if ((len % 6) != 0)
314
        {
1525 cbradney 315
                PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values.","python error"));
720 subik 316
                return NULL;
317
        }
900 cbradney 318
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 319
        {
1525 cbradney 320
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 321
                return NULL;
322
        }
87 Franz 323
        double x, y, b, h, kx, ky, kx2, ky2;
237 Franz 324
        int i = 0;
1283 subik 325
        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 326
        i++;
1283 subik 327
        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 328
        i++;
1283 subik 329
        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 330
        i++;
1283 subik 331
        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 332
        i++;
1283 subik 333
        kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 334
        i++;
1283 subik 335
        ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
82 Franz 336
        i++;
3207 craig 337
        int ic = ScApp->view->PaintPolyLine(x, y, 1, 1, ScApp->doc->toolSettings.dWidth, ScApp->doc->toolSettings.dBrush, ScApp->doc->toolSettings.dPen);
338
        PageItem *it = ScApp->doc->Items.at(ic);
82 Franz 339
        it->PoLine.resize(2);
340
        it->PoLine.setPoint(0, 0, 0);
341
        it->PoLine.setPoint(1, kx-x, ky-y);
87 Franz 342
        int pp = 6;
82 Franz 343
        for (i = 6; i < len - 6; i += 6)
647 fschmid 344
        {
1283 subik 345
                b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
346
                h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
347
                kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+2))));
348
                ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+3))));
349
                kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+4))));
350
                ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+5))));
82 Franz 351
                it->PoLine.resize(pp);
352
                it->PoLine.setPoint(pp-4, b-x, h-y);
353
                it->PoLine.setPoint(pp-3, kx-x, ky-y);
354
                it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4));
355
                it->PoLine.setPoint(pp-1, kx2-x, ky2-y);
356
                pp += 4;
647 fschmid 357
        }
82 Franz 358
        pp -= 2;
1283 subik 359
        b = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-6))));
360
        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-5))));
361
        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-4))));
362
        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-3))));
82 Franz 363
        it->PoLine.resize(pp);
364
        it->PoLine.setPoint(pp-2, b-x, h-y);
365
        it->PoLine.setPoint(pp-1, kx-x, ky-y);
1065 cbradney 366
        FPoint np2 = getMinClipF(&it->PoLine);
82 Franz 367
        if (np2.x() < 0)
647 fschmid 368
        {
82 Franz 369
                it->PoLine.translate(-np2.x(), 0);
3207 craig 370
                ScApp->view->MoveItem(np2.x(), 0, it);
647 fschmid 371
        }
82 Franz 372
        if (np2.y() < 0)
647 fschmid 373
        {
82 Franz 374
                it->PoLine.translate(0, -np2.y());
3207 craig 375
                ScApp->view->MoveItem(0, np2.y(), it);
647 fschmid 376
        }
3207 craig 377
        ScApp->view->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
378
        ScApp->view->AdjustItemSize(it);
2879 cbradney 379
        if (Name != "")
1361 tsoots 380
                it->setItemName(QString::fromUtf8(Name));
381
        return PyString_FromString(it->itemName().utf8());
82 Franz 382
}
383
 
243 Franz 384
 
385
/* 03/31/2004 - xception handling
386
 */
2790 craig 387
PyObject *scribus_pathtext(PyObject* /* self */, PyObject* args)
82 Franz 388
{
389
        double x, y;
934 subik 390
        char *Name = const_cast<char*>("");
391
        char *TextB = const_cast<char*>("");
392
        char *PolyB = const_cast<char*>("");
900 cbradney 393
        if (!PyArg_ParseTuple(args, "ddeses|es", &x, &y, "utf-8", &TextB, "utf-8", &PolyB, "utf-8", &Name))
82 Franz 394
                return NULL;
649 fschmid 395
        if(!checkHaveDocument())
396
                return NULL;
900 cbradney 397
        if (ItemExists(QString::fromUtf8(Name)))
720 subik 398
        {
1525 cbradney 399
                PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
720 subik 400
                return NULL;
401
        }
402
        //FIXME: Why use GetItem not GetUniqueItem? Maybe use GetUniqueItem and use the exceptions
403
        // its sets for us?
900 cbradney 404
        int i = GetItem(QString::fromUtf8(TextB));
405
        int ii = GetItem(QString::fromUtf8(PolyB));
82 Franz 406
        if ((i == -1) || (ii == -1))
243 Franz 407
        {
1525 cbradney 408
                PyErr_SetString(NotFoundError, QObject::tr("Object not found.","python error"));
243 Franz 409
                return NULL;
410
        }
3207 craig 411
        ScApp->view->SelItem.clear();
412
        ScApp->view->SelItem.append(ScApp->doc->Items.at(i));
413
        ScApp->view->SelItem.append(ScApp->doc->Items.at(ii));
414
        PageItem *it = ScApp->doc->Items.at(i);
415
        ScApp->view->ToPathText();
416
        ScApp->view->MoveItem(pageUnitXToDocX(x) - it->Xpos, pageUnitYToDocY(y) - it->Ypos, it);
2879 cbradney 417
        if (Name != "")
1361 tsoots 418
                it->setItemName(QString::fromUtf8(Name));
419
        return PyString_FromString(it->itemName().utf8());
82 Franz 420
}
421
 
243 Franz 422
 
237 Franz 423
/* 03/21/2004 - exception raised when Name doesn't exists. Doesn't crash then. (subik)
424
 */
2790 craig 425
PyObject *scribus_deleteobj(PyObject* /* self */, PyObject* args)
82 Franz 426
{
934 subik 427
        char *Name = const_cast<char*>("");
900 cbradney 428
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
82 Franz 429
                return NULL;
649 fschmid 430
        if(!checkHaveDocument())
431
                return NULL;
900 cbradney 432
        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
720 subik 433
        if (i == NULL)
332 Franz 434
                return NULL;
3207 craig 435
        ScApp->view->SelItem.clear();
436
        ScApp->view->SelItem.append(i);
437
        ScApp->view->DeleteItem();
647 fschmid 438
        Py_INCREF(Py_None);
82 Franz 439
        return Py_None;
440
}
441
 
243 Franz 442
 
237 Franz 443
/* 03/21/2004 - exception raises by non existent name (subik)
444
 */
2790 craig 445
PyObject *scribus_textflow(PyObject* /* self */, PyObject* args)
214 Franz 446
{
934 subik 447
        char *name = const_cast<char*>("");
332 Franz 448
        int state = -1;
214 Franz 449
 
900 cbradney 450
        if (!PyArg_ParseTuple(args, "es|i", "utf-8", &name, &state))
214 Franz 451
                return NULL;
649 fschmid 452
        if(!checkHaveDocument())
453
                return NULL;
900 cbradney 454
        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
332 Franz 455
        if (i == NULL)
237 Franz 456
                return NULL;
214 Franz 457
        if (state == -1)
1653 craig 458
                i->setTextFlowsAroundFrame(!i->textFlowsAroundFrame());
214 Franz 459
        else
1653 craig 460
                i->setTextFlowsAroundFrame( state ? true : false);
3207 craig 461
        ScApp->view->DrawNew();
462
        ScApp->slotDocCh(true);
647 fschmid 463
        Py_INCREF(Py_None);
214 Franz 464
        return Py_None;
465
}
243 Franz 466
 
467
 
2790 craig 468
PyObject *scribus_objectexists(PyObject* /* self */, PyObject* args)
243 Franz 469
{
934 subik 470
        char* name = const_cast<char*>("");
900 cbradney 471
        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
243 Franz 472
                return NULL;
649 fschmid 473
        if(!checkHaveDocument())
474
                return NULL;
900 cbradney 475
        if (ItemExists(QString::fromUtf8(name)))
720 subik 476
                return PyBool_FromLong(static_cast<long>(true));
477
        return PyBool_FromLong(static_cast<long>(false));
243 Franz 478
}
479
 
411 Franz 480
/*
481
 * Craig Ringer, 2004-09-09
482
 * Apply the named style to the currently selected object.
483
 * pv, 2004-09-13, optionaly param objectName + "check the page" stuff
484
 */
2790 craig 485
PyObject *scribus_setstyle(PyObject* /* self */, PyObject* args)
411 Franz 486
{
934 subik 487
        char *style = const_cast<char*>("");
488
        char *name = const_cast<char*>("");
900 cbradney 489
        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name))
411 Franz 490
                return NULL;
649 fschmid 491
        if(!checkHaveDocument())
492
                return NULL;
900 cbradney 493
        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
720 subik 494
        if (item == NULL)
495
                return NULL;
1460 cbradney 496
        if ((item->itemType() == PageItem::TextFrame) || (item->itemType() == PageItem::PathText))
411 Franz 497
        {
498
                /*
499
                 * First, find the style number associated with the requested style
500
                 * by scanning through the styles looking for the name. If
501
                 * we can't find it, raise PyExc_Exception.
502
                 * FIXME: Should use a more specific exception.
503
                 */
504
                bool found = false;
505
                uint styleid = 0;
506
                // We start at zero here because it's OK to match an internal name
3207 craig 507
                for (uint i=0; i < ScApp->doc->docParagraphStyles.count(); ++i)
411 Franz 508
                {
3207 craig 509
                        if (ScApp->doc->docParagraphStyles[i].Vname == QString::fromUtf8(style)) {
411 Franz 510
                                found = true;
511
                                styleid = i;
512
                                break;
513
                        }
514
                }
515
                if (!found) {
516
                        // whoops, the user specified an invalid style, complain loudly.
1525 cbradney 517
                        PyErr_SetString(NotFoundError, QObject::tr("Style not found.","python error"));
411 Franz 518
                        return NULL;
519
                }
520
                // quick hack to always apply on the right frame - pv
3207 craig 521
                ScApp->view->Deselect(true);
522
                ScApp->view->SelectItemNr(item->ItemNr);
411 Franz 523
                // Now apply the style.
3207 craig 524
                ScApp->setNewAbStyle(styleid);
411 Franz 525
        }
720 subik 526
        else
527
        {
1525 cbradney 528
                PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set style on a non-text frame.","python error"));
720 subik 529
                return NULL;
530
        }
411 Franz 531
        Py_INCREF(Py_None);
532
        return Py_None;
533
}
534
 
535
/*
536
 * Craig Ringer, 2004-09-09
537
 * Enumerate all known paragraph styles
538
 */
2790 craig 539
PyObject *scribus_getstylenames(PyObject* /* self */)
411 Franz 540
{
541
        PyObject *styleList;
649 fschmid 542
        if(!checkHaveDocument())
543
                return NULL;
411 Franz 544
        styleList = PyList_New(0);
545
        /*
421 Franz 546
        We start at 5 because the lower styles are internal names.
547
        pv - changet to get all (with system) objects
649 fschmid 548
        FIXME: this should be a constant defined by the scribus core
421 Franz 549
        */
3207 craig 550
        for (uint i=0; i < ScApp->doc->docParagraphStyles.count(); ++i)
411 Franz 551
        {
3207 craig 552
                if (PyList_Append(styleList, PyString_FromString(ScApp->doc->docParagraphStyles[i].Vname.utf8())))
411 Franz 553
                {
554
                        // An exception will have already been set by PyList_Append apparently.
555
                        return NULL;
556
                }
557
        }
558
        return styleList;
559
}