Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Functions
cmddoc.cpp File Reference
#include "cmddoc.h"
#include "cmdutil.h"
#include "units.h"
#include "documentinformation.h"
#include "scribuscore.h"

Go to the source code of this file.

Functions

PyObject * scribus_newdocument (PyObject *, PyObject *args)
 Creates a new document e.g.
PyObject * scribus_newdoc (PyObject *, PyObject *args)
 Creates a new document e.g.
PyObject * scribus_setmargins (PyObject *, PyObject *args)
 Sets document margins - left, right, top and bottom.
PyObject * scribus_closedoc (PyObject *)
 Closes active doc.
PyObject * scribus_havedoc (PyObject *)
 Checks if is a document opened.
PyObject * scribus_opendoc (PyObject *, PyObject *args)
 Opens a document with given name.
PyObject * scribus_savedoc (PyObject *)
PyObject * scribus_savedocas (PyObject *, PyObject *args)
 Saves active document with given name.
PyObject * scribus_setinfo (PyObject *, PyObject *args)
 Sets document infos - author, title and description.
PyObject * scribus_setunit (PyObject *, PyObject *args)
 Changes unit scale.
PyObject * scribus_getunit (PyObject *)
 Returns actual unit scale.
PyObject * scribus_loadstylesfromfile (PyObject *, PyObject *args)
 Loads styles from another .sla file (craig r.)
PyObject * scribus_setdoctype (PyObject *, PyObject *args)
PyObject * scribus_closemasterpage (PyObject *)
PyObject * scribus_masterpagenames (PyObject *)
PyObject * scribus_editmasterpage (PyObject *, PyObject *args)
PyObject * scribus_createmasterpage (PyObject *, PyObject *args)
PyObject * scribus_deletemasterpage (PyObject *, PyObject *args)
void cmddocdocwarnings ()
 HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV.

Function Documentation

HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV.

Definition at line 360 of file cmddoc.cpp.

{
    QStringList s;
    s << scribus_newdocument__doc__ << scribus_newdoc__doc__ <<  scribus_closedoc__doc__ << scribus_havedoc__doc__ << scribus_opendoc__doc__ << scribus_savedoc__doc__ << scribus_savedocas__doc__ << scribus_setinfo__doc__ <<scribus_setmargins__doc__ <<scribus_setunit__doc__ <<scribus_getunit__doc__ <<scribus_loadstylesfromfile__doc__ <<scribus_setdoctype__doc__ <<scribus_closemasterpage__doc__ <<scribus_masterpagenames__doc__ <<scribus_editmasterpage__doc__ <<scribus_createmasterpage__doc__ <<scribus_deletemasterpage__doc__;
}
PyObject* scribus_closedoc ( PyObject *  )

Closes active doc.

No params

Definition at line 129 of file cmddoc.cpp.

{
       if(!checkHaveDocument())
              return NULL;
       ScCore->primaryMainWindow()->doc->setModified(false);
       bool ret = ScCore->primaryMainWindow()->slotFileClose();
       qApp->processEvents();
       return PyInt_FromLong(static_cast<long>(ret));
}

Here is the call graph for this function:

PyObject* scribus_closemasterpage ( PyObject *  )

Definition at line 265 of file cmddoc.cpp.

{
       if(!checkHaveDocument())
              return NULL;
       ScCore->primaryMainWindow()->view->hideMasterPage();
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_createmasterpage ( PyObject *  ,
PyObject *  args 
)

Definition at line 311 of file cmddoc.cpp.

{
       char* name = 0;
       if (!PyArg_ParseTuple(args, "es", const_cast<char*>("utf-8"), &name))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       const QString masterPageName(name);
       if (ScCore->primaryMainWindow()->doc->MasterNames.contains(masterPageName))
       {
              PyErr_SetString(PyExc_ValueError, "Master page already exists");
              return NULL;
       }
       ScCore->primaryMainWindow()->doc->addMasterPage(ScCore->primaryMainWindow()->doc->MasterPages.count(), masterPageName);
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_deletemasterpage ( PyObject *  ,
PyObject *  args 
)

Definition at line 330 of file cmddoc.cpp.

{
       char* name = 0;
       if (!PyArg_ParseTuple(args, "es", const_cast<char*>("utf-8"), &name))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       const QString masterPageName(name);
       if (!ScCore->primaryMainWindow()->doc->MasterNames.contains(masterPageName))
       {
              PyErr_SetString(PyExc_ValueError, "Master page does not exist");
              return NULL;
       }
       if (masterPageName == "Normal")
       {
              PyErr_SetString(PyExc_ValueError, "Can not delete the Normal master page");
              return NULL;
       }
       bool oldMode = ScCore->primaryMainWindow()->doc->masterPageMode();
       ScCore->primaryMainWindow()->doc->setMasterPageMode(true);
       ScCore->primaryMainWindow()->DeletePage2(ScCore->primaryMainWindow()->doc->MasterNames[masterPageName]);
       ScCore->primaryMainWindow()->doc->setMasterPageMode(oldMode);
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_editmasterpage ( PyObject *  ,
PyObject *  args 
)

Definition at line 290 of file cmddoc.cpp.

{
       char* name = 0;
       if (!PyArg_ParseTuple(args, "es", const_cast<char*>("utf-8"), &name))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       const QString masterPageName(name);
       const QMap<QString,int>& masterNames(ScCore->primaryMainWindow()->doc->MasterNames);
       const QMap<QString,int>::const_iterator it(masterNames.find(masterPageName));
       if ( it == masterNames.constEnd() )
       {
              PyErr_SetString(PyExc_ValueError, "Master page not found");
              return NULL;
       }
       ScCore->primaryMainWindow()->view->showMasterPage(*it);
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_getunit ( PyObject *  )

Returns actual unit scale.

Definition at line 226 of file cmddoc.cpp.

{
       if(!checkHaveDocument())
              return NULL;
       return PyInt_FromLong(static_cast<long>(ScCore->primaryMainWindow()->doc->unitIndex()));
}

Here is the call graph for this function:

PyObject* scribus_havedoc ( PyObject *  )

Checks if is a document opened.

Definition at line 139 of file cmddoc.cpp.

{
       return PyInt_FromLong(static_cast<long>(ScCore->primaryMainWindow()->HaveDoc));
}

Here is the call graph for this function:

PyObject* scribus_loadstylesfromfile ( PyObject *  ,
PyObject *  args 
)

Loads styles from another .sla file (craig r.)

Definition at line 233 of file cmddoc.cpp.

{
       char *fileName;
       if (!PyArg_ParseTuple(args, "es", "utf-8", &fileName))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       ScCore->primaryMainWindow()->doc->loadStylesFromFile(QString::fromUtf8(fileName));
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_masterpagenames ( PyObject *  )

Definition at line 275 of file cmddoc.cpp.

{
       if(!checkHaveDocument())
              return NULL;
       PyObject* names = PyList_New(ScCore->primaryMainWindow()->doc->MasterPages.count());
       QMap<QString,int>::const_iterator it(ScCore->primaryMainWindow()->doc->MasterNames.constBegin());
       QMap<QString,int>::const_iterator itEnd(ScCore->primaryMainWindow()->doc->MasterNames.constEnd());
       int n = 0;
       for ( ; it != itEnd; ++it )
       {
              PyList_SET_ITEM(names, n++, PyString_FromString(it.key().utf8().data()) );
       }
       return names;
}

Here is the call graph for this function:

PyObject* scribus_newdoc ( PyObject *  ,
PyObject *  args 
)

Creates a new document e.g.

(Paper_A4, Margins, 1, 1, 1, NoFacingPages, FirstPageLeft) first 2 args are lists (tuples)

Todo:
Obsolete! In the case of no facing pages use only firstpageleft scripter is not new-page-size ready. What is it: don't allow to use wrong FSL constant in the case of onesided document.

Definition at line 74 of file cmddoc.cpp.

{
       qDebug("WARNING: newDoc() procedure is obsolete, it will be removed in a forthcoming release. Use newDocument() instead.");
       double b, h, lr, tpr, btr, rr, ebr;
       int unit, ds, fsl, fNr, ori;
       PyObject *p, *m;
       if ((!PyArg_ParseTuple(args, "OOiiiii", &p, &m, &ori, &fNr, &unit, &ds, &fsl)) ||
               (!PyArg_ParseTuple(p, "dd", &b, &h)) ||
               (!PyArg_ParseTuple(m, "dddd", &lr, &rr, &tpr, &btr)))
              return NULL;
       b = value2pts(b, unit);
       h = value2pts(h, unit);
       if (ori == 1)
       {
              ebr = b;
              b = h;
              h = ebr;
       }
       if (ds!=1 && fsl>0)
              fsl = 0;
       // end of hack
       tpr = value2pts(tpr, unit);
       lr = value2pts(lr, unit);
       rr = value2pts(rr, unit);
       btr = value2pts(btr, unit);
       bool ret = ScCore->primaryMainWindow()->doFileNew(b, h, tpr, lr, rr, btr, 0, 1, false, ds, unit, fsl, ori, fNr, "Custom", true);
       //     qApp->processEvents();
       return PyInt_FromLong(static_cast<long>(ret));
}

Here is the call graph for this function:

PyObject* scribus_newdocument ( PyObject *  ,
PyObject *  args 
)

Creates a new document e.g.

(Paper_A4, Margins, 1, 1, 1, NoFacingPages, FirstPageLeft) first 2 args are lists (tuples)

Definition at line 16 of file cmddoc.cpp.

{
       double topMargin, bottomMargin, leftMargin, rightMargin;
       double pageWidth, pageHeight;
       int orientation, firstPageNr, unit, pagesType, facingPages, firstPageOrder, numPages;

       PyObject *p, *m;

       if ((!PyArg_ParseTuple(args, "OOiiiiii", &p, &m, &orientation,
                                                                             &firstPageNr, &unit,
                                                                             &pagesType,
                                                                             &firstPageOrder,
                                                                             &numPages)) ||
                                          (!PyArg_ParseTuple(p, "dd", &pageWidth, &pageHeight)) ||
                                          (!PyArg_ParseTuple(m, "dddd", &leftMargin, &rightMargin,
                                                                                    &topMargin, &bottomMargin)))
              return NULL;
       if (numPages <= 0)
              numPages = 1;
       if (pagesType == 0)
       {
              facingPages = 0;
              firstPageOrder = 0;
       }
       else
              facingPages = 1;
       // checking the bounds
       if (pagesType < firstPageOrder)
       {
              PyErr_SetString(ScribusException, QObject::tr("firstPageOrder is bigger than allowed.","python error"));
              return NULL;
       }

       pageWidth = value2pts(pageWidth, unit);
       pageHeight = value2pts(pageHeight, unit);
       if (orientation == 1)
       {
              double x = pageWidth;
              pageWidth = pageHeight;
              pageHeight = x;
       }
       leftMargin = value2pts(leftMargin, unit);
       rightMargin = value2pts(rightMargin, unit);
       topMargin = value2pts(topMargin, unit);
       bottomMargin = value2pts(bottomMargin, unit);

       bool ret = ScCore->primaryMainWindow()->doFileNew(pageWidth, pageHeight,
                                                        topMargin, leftMargin, rightMargin, bottomMargin,
                                                        // autoframes. It's disabled in python
                                                        // columnDistance, numberCols, autoframes,
                                                        0, 1, false,
                                                        pagesType, unit, firstPageOrder,
                                                        orientation, firstPageNr, "Custom", true, numPages);
       ScCore->primaryMainWindow()->doc->pageSets[pagesType].FirstPage = firstPageOrder;

       return PyInt_FromLong(static_cast<long>(ret));
}

Here is the call graph for this function:

PyObject* scribus_opendoc ( PyObject *  ,
PyObject *  args 
)

Opens a document with given name.

Definition at line 144 of file cmddoc.cpp.

{
       char *Name;
       if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
              return NULL;
       bool ret = ScCore->primaryMainWindow()->loadDoc(QString::fromUtf8(Name));
       if (!ret)
       {
              PyErr_SetString(ScribusException, QObject::tr("Failed to open document.","python error"));
              return NULL;
       }
//     Py_INCREF(Py_True); // compatibility: return true, not none, on success
//     return Py_True;
       Py_RETURN_TRUE;
}

Here is the call graph for this function:

PyObject* scribus_savedoc ( PyObject *  )

Definition at line 160 of file cmddoc.cpp.

{
       if(!checkHaveDocument())
              return NULL;
       ScCore->primaryMainWindow()->slotFileSave();
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_savedocas ( PyObject *  ,
PyObject *  args 
)

Saves active document with given name.

Definition at line 170 of file cmddoc.cpp.

{
       char *Name;
       if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       bool ret = ScCore->primaryMainWindow()->DoFileSave(QString::fromUtf8(Name));
       if (!ret)
       {
              PyErr_SetString(ScribusException, QObject::tr("Failed to save document.","python error"));
              return NULL;
       }
//     Py_INCREF(Py_True); // compatibility: return true, not none, on success
//     return Py_True;
       Py_RETURN_TRUE;
}

Here is the call graph for this function:

PyObject* scribus_setdoctype ( PyObject *  ,
PyObject *  args 
)

Definition at line 246 of file cmddoc.cpp.

{
       int fp, fsl;
       if (!PyArg_ParseTuple(args, "ii", &fp, &fsl))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       if (ScCore->primaryMainWindow()->doc->currentPageLayout == fp)
              ScCore->primaryMainWindow()->doc->pageSets[ScCore->primaryMainWindow()->doc->currentPageLayout].FirstPage = fsl;
       ScCore->primaryMainWindow()->view->reformPages();
       ScCore->primaryMainWindow()->view->GotoPage(ScCore->primaryMainWindow()->doc->currentPageNumber()); // is this needed?
       ScCore->primaryMainWindow()->view->DrawNew();   // is this needed?
       //CB TODO ScCore->primaryMainWindow()->pagePalette->RebuildPage(); // is this needed?
       ScCore->primaryMainWindow()->slotDocCh();
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_setinfo ( PyObject *  ,
PyObject *  args 
)

Sets document infos - author, title and description.

Definition at line 188 of file cmddoc.cpp.

{
       char *Author;
       char *Title;
       char *Desc;
       // z means string, but None becomes a NULL value. QString()
       // will correctly handle NULL.
       if (!PyArg_ParseTuple(args, "zzz", &Author, &Title, &Desc))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       ScCore->primaryMainWindow()->doc->documentInfo.setAuthor(QString::fromUtf8(Author));
       ScCore->primaryMainWindow()->doc->documentInfo.setTitle(QString::fromUtf8(Title));
       ScCore->primaryMainWindow()->doc->documentInfo.setComments(QString::fromUtf8(Desc));
       ScCore->primaryMainWindow()->slotDocCh();
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_setmargins ( PyObject *  ,
PyObject *  args 
)

Sets document margins - left, right, top and bottom.

Definition at line 108 of file cmddoc.cpp.

{
       double lr, tpr, btr, rr;
       if (!PyArg_ParseTuple(args, "dddd", &lr, &rr, &tpr, &btr))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       tpr = ValueToPoint(tpr);
       lr = ValueToPoint(lr);
       rr = ValueToPoint(rr);
       btr = ValueToPoint(btr);
       ScCore->primaryMainWindow()->doc->resetPage(tpr, lr, rr, btr, ScCore->primaryMainWindow()->doc->currentPageLayout);
       ScCore->primaryMainWindow()->view->reformPages();
       ScCore->primaryMainWindow()->doc->setModified(true);
       ScCore->primaryMainWindow()->view->GotoPage(ScCore->primaryMainWindow()->doc->currentPageNumber());
       ScCore->primaryMainWindow()->view->DrawNew();
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function:

PyObject* scribus_setunit ( PyObject *  ,
PyObject *  args 
)

Changes unit scale.

Definition at line 208 of file cmddoc.cpp.

{
       int e;
       if (!PyArg_ParseTuple(args, "i", &e))
              return NULL;
       if(!checkHaveDocument())
              return NULL;
       if ((e < 0) || (e > 3))
       {
              PyErr_SetString(PyExc_ValueError, QObject::tr("Unit out of range. Use one of the scribus.UNIT_* constants.","python error"));
              return NULL;
       }
       ScCore->primaryMainWindow()->slotChangeUnit(e);
//     Py_INCREF(Py_None);
//     return Py_None;
       Py_RETURN_NONE;
}

Here is the call graph for this function: