Rev 1188 |
Rev 1381 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include "cmdmani.h"
#include "cmdutil.h"
PyObject *scribus_loadimage(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
char *Image;
if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Image, "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item == NULL)
return NULL;
if (item->PType != FRAME_IMAGE)
{
PyErr_SetString(WrongFrameTypeError, QObject::tr("Target is not an image frame.","python error"));
return NULL;
}
Carrier->view->LoadPict(QString::fromUtf8(Image), item->ItemNr);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_scaleimage(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
double x, y;
if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item == NULL)
return NULL;
if (item->PType != FRAME_IMAGE)
{
PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame","python error"));
return NULL;
}
item->LocalScX = x;
item->LocalScY = y;
Carrier->view->ChLocalSc(x, y);
Carrier->view->UpdatePic();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_moveobjrel(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
double x, y;
if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item==NULL)
return NULL;
if (Carrier->view->GroupSel)
Carrier->view->moveGroup(ValueToPoint(x), ValueToPoint(y));
else
Carrier->view->MoveItem(ValueToPoint(x), ValueToPoint(y), item);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_moveobjabs(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
double x, y;
if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item == NULL)
return NULL;
if (Carrier->view->GroupSel)
{
if (Carrier->view->GroupSel)
{
double x2, y2, w, h;
Carrier->view->getGroupRect(&x2, &y2, &w, &h);
Carrier->view->moveGroup(pageUnitXToDocX(x) - x2, pageUnitYToDocY(y) - y2);
}
else
Carrier->view->MoveItem(pageUnitXToDocX(x) - item->Xpos, pageUnitYToDocY(y) - item->Ypos, item);
}
else
Carrier->view->MoveItem(pageUnitXToDocX(x) - item->Xpos, pageUnitYToDocY(y) - item->Ypos, item);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_rotobjrel(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
double x;
if (!PyArg_ParseTuple(args, "d|es", &x, "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item == NULL)
return NULL;
Carrier->view->RotateItem(item->Rot - x, item->ItemNr);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_rotobjabs(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
double x;
if (!PyArg_ParseTuple(args, "d|es", &x, "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item == NULL)
return NULL;
Carrier->view->RotateItem(x * -1.0, item->ItemNr);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_sizeobjabs(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
double x, y;
if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item == NULL)
return NULL;
Carrier->view->SizeItem(pageUnitXToDocX(x) - item->Xpos, pageUnitYToDocY(y) - item->Ypos, item->ItemNr);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_groupobj(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
PyObject *il = 0;
if (!PyArg_ParseTuple(args, "|O", &il))
return NULL;
if(!checkHaveDocument())
return NULL;
uint ap = Carrier->doc->currentPage->PageNr;
if (il != 0)
{
int len = PyList_Size(il);
if (len == 0)
{
Py_INCREF(Py_None);
return Py_None;
}
for (int i = 0; i < len; i++)
{
// FIXME: We might need to explicitly get this string as utf8
// but as sysdefaultencoding is utf8 it should be a no-op to do
// so anyway.
Name = PyString_AsString(PyList_GetItem(il, i));
PageItem *ic = GetUniqueItem(QString::fromUtf8(Name));
if (ic == NULL)
return NULL;
Carrier->view->SelectItemNr(ic->ItemNr);
}
}
if (Carrier->view->SelItem.count() != 0)
{
Carrier->GroupObj();
Carrier->view->Deselect();
Carrier->view->GotoPage(ap);
}
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_ungroupobj(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
if (i == NULL)
return NULL;
Carrier->UnGroupObj();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_scalegroup(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
double sc;
if (!PyArg_ParseTuple(args, "d|es", &sc, "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
if (sc == 0.0)
{
PyErr_SetString(PyExc_ValueError, QObject::tr("Can't scale by 0%","python error"));
return NULL;
}
PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
if (i == NULL)
return NULL;
Carrier->view->Deselect();
Carrier->view->SelectItemNr(i->ItemNr);
int h = Carrier->view->HowTo;
Carrier->view->HowTo = 1;
Carrier->view->scaleGroup(sc, sc);
Carrier->view->HowTo = h;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_getselobjnam(PyObject */*self*/, PyObject* args)
{
int i = 0;
if (!PyArg_ParseTuple(args, "|i", &i))
return NULL;
if(!checkHaveDocument())
return NULL;
if ((i < static_cast<int>(Carrier->view->SelItem.count())) && (i > -1))
return PyString_FromString(Carrier->view->SelItem.at(i)->AnName.utf8());
else
// FIXME: Should probably return None if no selection?
return PyString_FromString("");
}
PyObject *scribus_selcount(PyObject */*self*/)
{
if(!checkHaveDocument())
return NULL;
return PyInt_FromLong(static_cast<long>(Carrier->view->SelItem.count()));
}
PyObject *scribus_selectobj(PyObject */*self*/, PyObject* args)
{
char *Name = const_cast<char*>("");
if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
if (i == NULL)
return NULL;
Carrier->view->SelectItemNr(i->ItemNr);
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_deselect(PyObject */*self*/)
{
if(!checkHaveDocument())
return NULL;
Carrier->view->Deselect();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *scribus_lockobject(PyObject */*self*/, PyObject* args)
{
char *name = const_cast<char*>("");
if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
return NULL;
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(name));
if (item == NULL)
return NULL;
item->Locked = !item->Locked;
if (item->Locked)
return PyInt_FromLong(1);
return PyInt_FromLong(0);
}
PyObject *scribus_islocked(PyObject */*self*/, PyObject* args)
{
char *name = const_cast<char*>("");
if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
return NULL;
// FIXME: Rather than toggling the lock, we should probably let the user set the lock state
// and instead provide a different function like toggleLock()
if(!checkHaveDocument())
return NULL;
PageItem *item = GetUniqueItem(QString::fromUtf8(name));
if (item == NULL)
return NULL;
if (item->Locked)
return PyBool_FromLong(1);
return PyBool_FromLong(0);
}