Back to index

scribus-ng  1.3.4.dfsg+svn20071115
cmdmisc.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "cmdmisc.h"
00008 #include "cmdutil.h"
00009 
00010 #include "qbuffer.h"
00011 #include "qpixmap.h"
00012 
00013 #include "scribuscore.h"
00014 #include "fonts/scfontmetrics.h"
00015 #include "prefsmanager.h"
00016 
00017 PyObject *scribus_setredraw(PyObject* /* self */, PyObject* args)
00018 {
00019        int e;
00020        if (!PyArg_ParseTuple(args, "i", &e))
00021               return NULL;
00022        if(!checkHaveDocument())
00023               return NULL;
00024        ScCore->primaryMainWindow()->doc->DoDrawing = static_cast<bool>(e);
00025 //     Py_INCREF(Py_None);
00026 //     return Py_None;
00027        Py_RETURN_NONE;
00028 }
00029 
00030 PyObject *scribus_fontnames(PyObject* /* self */)
00031 {
00032        int cc2 = 0;
00033        SCFontsIterator it2(PrefsManager::instance()->appPrefs.AvailFonts);
00034        for ( ; it2.hasNext() ; it2.next())
00035        {
00036               if (it2.current().usable())
00037                      cc2++;
00038        }
00039        PyObject *l = PyList_New(cc2);
00040        SCFontsIterator it(PrefsManager::instance()->appPrefs.AvailFonts);
00041        int cc = 0;
00042        for ( ; it.hasNext() ; it.next())
00043        {
00044               if (it.current().usable())
00045               {
00046                      PyList_SetItem(l, cc, PyString_FromString(it.currentKey().utf8()));
00047                      cc++;
00048               }
00049        }
00050        return l;
00051 }
00052 
00053 PyObject *scribus_xfontnames(PyObject* /* self */)
00054 {
00055        PyObject *l = PyList_New(PrefsManager::instance()->appPrefs.AvailFonts.count());
00056        SCFontsIterator it(PrefsManager::instance()->appPrefs.AvailFonts);
00057        int cc = 0;
00058        PyObject *row;
00059        for ( ; it.hasNext() ; it.next())
00060        {
00061               row = Py_BuildValue((char*)"(sssiis)",
00062                                                  it.currentKey().utf8().data(),
00063                                                  it.current().family().utf8().data(),
00064                                                  it.current().psName().utf8().data(),
00065                                                  it.current().subset(),
00066                                                  it.current().embedPs(),
00067                                                  it.current().fontFilePath().utf8().data()
00068                                           );
00069               PyList_SetItem(l, cc, row);
00070               cc++;
00071        } // for
00072        return l;
00073 }
00074 
00075 // This function is fairly complex because it can either save its output to a
00076 // file, or return it as a Python string.
00077 PyObject *scribus_renderfont(PyObject* /*self*/, PyObject* args, PyObject* kw)
00078 {
00079        char *Name = const_cast<char*>("");
00080        char *FileName = const_cast<char*>("");
00081        char *Sample = const_cast<char*>("");
00082        char *format = NULL;
00083        int Size;
00084        bool ret = false;
00085        char *kwargs[] = {const_cast<char*>("fontname"),
00086                                      const_cast<char*>("filename"),
00087                                      const_cast<char*>("sample"),
00088                                      const_cast<char*>("size"),
00089                                      const_cast<char*>("format"),
00090                                      NULL};
00091        if (!PyArg_ParseTupleAndKeywords(args, kw, "esesesi|es", kwargs,
00092                             "utf-8", &Name, "utf-8", &FileName, "utf-8", &Sample, &Size, "ascii", &format))
00093               return NULL;
00094        if (!PrefsManager::instance()->appPrefs.AvailFonts.contains(QString::fromUtf8(Name)))
00095        {
00096               PyErr_SetString(NotFoundError, QObject::tr("Font not found.","python error"));
00097               return NULL;
00098        }
00099        QString ts = QString::fromUtf8(Sample);
00100        if (ts.isEmpty())
00101        {
00102               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot render an empty sample.","python error"));
00103               return NULL;
00104        }
00105        if (!format)
00106               // User specified no format, so use the historical default of PPM format.
00107               format = "PPM";
00108        QPixmap pm = FontSample(PrefsManager::instance()->appPrefs.AvailFonts[QString::fromUtf8(Name)], Size, ts, Qt::white);
00109        // If the user specified an empty filename, return the image data as
00110        // a string. Otherwise, save it to disk.
00111        if (QString::fromUtf8(FileName).isEmpty())
00112        {
00113               QCString buffer_string = "";
00114               QBuffer buffer(buffer_string);
00115               buffer.open(IO_WriteOnly);
00116               bool ret = pm.save(&buffer, format);
00117               if (!ret)
00118               {
00119                      PyErr_SetString(ScribusException, QObject::tr("Unable to save pixmap","scripter error"));
00120                      return NULL;
00121               }
00122               int bufferSize = buffer.size();
00123               buffer.close();
00124               // Now make a Python string from the data we generated
00125               PyObject* stringPython = PyString_FromStringAndSize(buffer_string,bufferSize);
00126               // Return even if the result is NULL (error) since an exception will have been
00127               // set in that case.
00128               return stringPython;
00129        }
00130        else
00131        // Save the pixmap to a file, since the filename is non-empty
00132        {
00133               ret = pm.save(QString::fromUtf8(FileName), format);
00134               if (!ret)
00135               {
00136                      PyErr_SetString(PyExc_Exception, QObject::tr("Unable to save pixmap","scripter error"));
00137                      return NULL;
00138               }
00139               // For historical reasons, we need to return true on success.
00140 //            Py_INCREF(Py_True);
00141 //            return Py_True;
00142               Py_RETURN_TRUE;
00143        }
00144 }
00145 
00146 PyObject *scribus_getlayers(PyObject* /* self */)
00147 {
00148        if(!checkHaveDocument())
00149               return NULL;
00150        PyObject *l;
00151        l = PyList_New(ScCore->primaryMainWindow()->doc->Layers.count());
00152        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++)
00153               PyList_SetItem(l, lam, PyString_FromString(ScCore->primaryMainWindow()->doc->Layers[lam].Name.utf8()));
00154        return l;
00155 }
00156 
00157 PyObject *scribus_setactlayer(PyObject* /* self */, PyObject* args)
00158 {
00159        char *Name = const_cast<char*>("");
00160        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00161               return NULL;
00162        if(!checkHaveDocument())
00163               return NULL;
00164        if (Name == 0)
00165        {
00166               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00167               return NULL;
00168        }
00169        bool found = ScCore->primaryMainWindow()->doc->setActiveLayer(QString::fromUtf8(Name));
00170        if (found)
00171               ScCore->primaryMainWindow()->changeLayer(ScCore->primaryMainWindow()->doc->activeLayer());
00172        else
00173        {
00174               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00175               return NULL;
00176        }
00177 //     Py_INCREF(Py_None);
00178 //     return Py_None;
00179        Py_RETURN_NONE;
00180 }
00181 
00182 PyObject *scribus_getactlayer(PyObject* /* self */)
00183 {
00184        if(!checkHaveDocument())
00185               return NULL;
00186        return PyString_FromString(ScCore->primaryMainWindow()->doc->activeLayerName().utf8());
00187 }
00188 
00189 PyObject *scribus_senttolayer(PyObject* /* self */, PyObject* args)
00190 {
00191        char *Name = const_cast<char*>("");
00192        char *Layer = const_cast<char*>("");
00193        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Layer, "utf-8", &Name))
00194               return NULL;
00195        if(!checkHaveDocument())
00196               return NULL;
00197        if (Layer == "")
00198        {
00199               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00200               return NULL;
00201        }
00202        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00203        if (i == NULL)
00204               return NULL;
00205        ScCore->primaryMainWindow()->view->SelectItemNr(i->ItemNr);
00206        bool found = false;
00207        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00208        {
00209               ScCore->primaryMainWindow()->view->SelectItemNr(i->ItemNr);
00210               for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00211                      if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Layer))
00212                      {
00213                             i->LayerNr = static_cast<int>(lam);
00214                             found = true;
00215                             break;
00216                      }
00217        }
00218        if (!found)
00219        {
00220               PyErr_SetString(ScribusException, QString("Layer not found"));
00221               return NULL;
00222        }
00223 
00224 //     Py_INCREF(Py_None);
00225 //     return Py_None;
00226        Py_RETURN_NONE;
00227 }
00228 
00229 PyObject *scribus_layervisible(PyObject* /* self */, PyObject* args)
00230 {
00231        char *Name = const_cast<char*>("");
00232        int vis = 1;
00233        if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis))
00234               return NULL;
00235        if(!checkHaveDocument())
00236               return NULL;
00237        if (Name == "")
00238        {
00239               PyErr_SetString(PyExc_ValueError, QString("Cannot have an empty layer name"));
00240               return NULL;
00241        }
00242        bool found = false;
00243        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00244        {
00245               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00246               {
00247                      ScCore->primaryMainWindow()->doc->Layers[lam].isViewable = vis;
00248                      found = true;
00249                      break;
00250               }
00251        }
00252        if (!found)
00253        {
00254               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00255               return NULL;
00256        }
00257 //     Py_INCREF(Py_None);
00258 //     return Py_None;
00259        Py_RETURN_NONE;
00260 }
00261 
00262 PyObject *scribus_layerprint(PyObject* /* self */, PyObject* args)
00263 {
00264        char *Name = const_cast<char*>("");
00265        int vis = 1;
00266        if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis))
00267               return NULL;
00268        if(!checkHaveDocument())
00269               return NULL;
00270        if (Name == "")
00271        {
00272               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00273               return NULL;
00274        }
00275        bool found = false;
00276        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00277        {
00278               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00279               {
00280                      ScCore->primaryMainWindow()->doc->Layers[lam].isPrintable = vis;
00281                      found = true;
00282                      break;
00283               }
00284        }
00285        if (!found)
00286        {
00287               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00288               return NULL;
00289        }
00290 //     Py_INCREF(Py_None);
00291 //     return Py_None;
00292        Py_RETURN_NONE;
00293 }
00294 
00295 PyObject *scribus_layerlock(PyObject* /* self */, PyObject* args)
00296 {
00297        char *Name = const_cast<char*>("");
00298        int vis = 1;
00299        if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis))
00300               return NULL;
00301        if(!checkHaveDocument())
00302               return NULL;
00303        if (Name == "")
00304        {
00305               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00306               return NULL;
00307        }
00308        bool found = false;
00309        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00310        {
00311               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00312               {
00313                      ScCore->primaryMainWindow()->doc->Layers[lam].isEditable = vis;
00314                      found = true;
00315                      break;
00316               }
00317        }
00318        if (!found)
00319        {
00320               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00321               return NULL;
00322        }
00323 //     Py_INCREF(Py_None);
00324 //     return Py_None;
00325        Py_RETURN_NONE;
00326 }
00327 
00328 PyObject *scribus_layeroutline(PyObject* /* self */, PyObject* args)
00329 {
00330        char *Name = const_cast<char*>("");
00331        int vis = 1;
00332        if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis))
00333               return NULL;
00334        if(!checkHaveDocument())
00335               return NULL;
00336        if (Name == "")
00337        {
00338               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00339               return NULL;
00340        }
00341        bool found = false;
00342        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00343        {
00344               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00345               {
00346                      ScCore->primaryMainWindow()->doc->Layers[lam].outlineMode = vis;
00347                      found = true;
00348                      break;
00349               }
00350        }
00351        if (!found)
00352        {
00353               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00354               return NULL;
00355        }
00356 //     Py_INCREF(Py_None);
00357 //     return Py_None;
00358        Py_RETURN_NONE;
00359 }
00360 
00361 PyObject *scribus_layerflow(PyObject* /* self */, PyObject* args)
00362 {
00363        char *Name = const_cast<char*>("");
00364        int vis = 1;
00365        if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis))
00366               return NULL;
00367        if(!checkHaveDocument())
00368               return NULL;
00369        if (Name == "")
00370        {
00371               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00372               return NULL;
00373        }
00374        bool found = false;
00375        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00376        {
00377               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00378               {
00379                      ScCore->primaryMainWindow()->doc->Layers[lam].flowControl = vis;
00380                      found = true;
00381                      break;
00382               }
00383        }
00384        if (!found)
00385        {
00386               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00387               return NULL;
00388        }
00389 //     Py_INCREF(Py_None);
00390 //     return Py_None;
00391        Py_RETURN_NONE;
00392 }
00393 
00394 PyObject *scribus_layerblend(PyObject* /* self */, PyObject* args)
00395 {
00396        char *Name = const_cast<char*>("");
00397        int vis = 0;
00398        if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis))
00399               return NULL;
00400        if(!checkHaveDocument())
00401               return NULL;
00402        if (Name == "")
00403        {
00404               PyErr_SetString(PyExc_ValueError, QString("Cannot have an empty layer name"));
00405               return NULL;
00406        }
00407        bool found = false;
00408        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00409        {
00410               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00411               {
00412                      ScCore->primaryMainWindow()->doc->Layers[lam].blendMode = vis;
00413                      found = true;
00414                      break;
00415               }
00416        }
00417        if (!found)
00418        {
00419               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00420               return NULL;
00421        }
00422 //     Py_INCREF(Py_None);
00423 //     return Py_None;
00424        Py_RETURN_NONE;
00425 }
00426 
00427 PyObject *scribus_layertrans(PyObject* /* self */, PyObject* args)
00428 {
00429        char *Name = const_cast<char*>("");
00430        double vis = 1.0;
00431        if (!PyArg_ParseTuple(args, "esd", "utf-8", &Name, &vis))
00432               return NULL;
00433        if(!checkHaveDocument())
00434               return NULL;
00435        if (Name == "")
00436        {
00437               PyErr_SetString(PyExc_ValueError, QString("Cannot have an empty layer name"));
00438               return NULL;
00439        }
00440        bool found = false;
00441        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00442        {
00443               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00444               {
00445                      ScCore->primaryMainWindow()->doc->Layers[lam].transparency = vis;
00446                      found = true;
00447                      break;
00448               }
00449        }
00450        if (!found)
00451        {
00452               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00453               return NULL;
00454        }
00455 //     Py_INCREF(Py_None);
00456 //     return Py_None;
00457        Py_RETURN_NONE;
00458 }
00459 
00460 PyObject *scribus_glayervisib(PyObject* /* self */, PyObject* args)
00461 {
00462        char *Name = const_cast<char*>("");
00463        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00464               return NULL;
00465        if(!checkHaveDocument())
00466               return NULL;
00467        if (Name == "")
00468        {
00469               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00470               return NULL;
00471        }
00472        int i = 0;
00473        bool found = false;
00474        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++)
00475        {
00476               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00477               {
00478                      i = static_cast<int>(ScCore->primaryMainWindow()->doc->Layers[lam].isViewable);
00479                      found = true;
00480                      break;
00481               }
00482        }
00483        if (!found)
00484        {
00485               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00486               return NULL;
00487        }
00488        return PyInt_FromLong(static_cast<long>(i));
00489 }
00490 
00491 PyObject *scribus_glayerprint(PyObject* /* self */, PyObject* args)
00492 {
00493        char *Name = const_cast<char*>("");
00494        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00495               return NULL;
00496        if(!checkHaveDocument())
00497               return NULL;
00498        if (Name == "")
00499        {
00500               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00501               return NULL;
00502        }
00503        int i = 0;
00504        bool found = false;
00505        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00506        {
00507               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00508               {
00509                      i = static_cast<int>(ScCore->primaryMainWindow()->doc->Layers[lam].isPrintable);
00510                      found = true;
00511                      break;
00512               }
00513        }
00514        if (!found)
00515        {
00516               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00517               return NULL;
00518        }
00519        return PyInt_FromLong(static_cast<long>(i));
00520 }
00521 
00522 PyObject *scribus_glayerlock(PyObject* /* self */, PyObject* args)
00523 {
00524        char *Name = const_cast<char*>("");
00525        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00526               return NULL;
00527        if(!checkHaveDocument())
00528               return NULL;
00529        if (Name == "")
00530        {
00531               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00532               return NULL;
00533        }
00534        int i = 0;
00535        bool found = false;
00536        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++)
00537        {
00538               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00539               {
00540                      i = static_cast<int>(ScCore->primaryMainWindow()->doc->Layers[lam].isEditable);
00541                      found = true;
00542                      break;
00543               }
00544        }
00545        if (!found)
00546        {
00547               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00548               return NULL;
00549        }
00550        return PyInt_FromLong(static_cast<long>(i));
00551 }
00552 
00553 PyObject *scribus_glayeroutline(PyObject* /* self */, PyObject* args)
00554 {
00555        char *Name = const_cast<char*>("");
00556        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00557               return NULL;
00558        if(!checkHaveDocument())
00559               return NULL;
00560        if (Name == "")
00561        {
00562               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00563               return NULL;
00564        }
00565        int i = 0;
00566        bool found = false;
00567        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++)
00568        {
00569               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00570               {
00571                      i = static_cast<int>(ScCore->primaryMainWindow()->doc->Layers[lam].outlineMode);
00572                      found = true;
00573                      break;
00574               }
00575        }
00576        if (!found)
00577        {
00578               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00579               return NULL;
00580        }
00581        return PyInt_FromLong(static_cast<long>(i));
00582 }
00583 
00584 PyObject *scribus_glayerflow(PyObject* /* self */, PyObject* args)
00585 {
00586        char *Name = const_cast<char*>("");
00587        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00588               return NULL;
00589        if(!checkHaveDocument())
00590               return NULL;
00591        if (Name == "")
00592        {
00593               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00594               return NULL;
00595        }
00596        int i = 0;
00597        bool found = false;
00598        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++)
00599        {
00600               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00601               {
00602                      i = static_cast<int>(ScCore->primaryMainWindow()->doc->Layers[lam].flowControl);
00603                      found = true;
00604                      break;
00605               }
00606        }
00607        if (!found)
00608        {
00609               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00610               return NULL;
00611        }
00612        return PyInt_FromLong(static_cast<long>(i));
00613 }
00614 
00615 PyObject *scribus_glayerblend(PyObject* /* self */, PyObject* args)
00616 {
00617        char *Name = const_cast<char*>("");
00618        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00619               return NULL;
00620        if(!checkHaveDocument())
00621               return NULL;
00622        if (Name == "")
00623        {
00624               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00625               return NULL;
00626        }
00627        int i = 0;
00628        bool found = false;
00629        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++)
00630        {
00631               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00632               {
00633                      i = ScCore->primaryMainWindow()->doc->Layers[lam].blendMode;
00634                      found = true;
00635                      break;
00636               }
00637        }
00638        if (!found)
00639        {
00640               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00641               return NULL;
00642        }
00643        return PyInt_FromLong(static_cast<long>(i));
00644 }
00645 
00646 PyObject *scribus_glayertrans(PyObject* /* self */, PyObject* args)
00647 {
00648        char *Name = const_cast<char*>("");
00649        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00650               return NULL;
00651        if(!checkHaveDocument())
00652               return NULL;
00653        if (Name == "")
00654        {
00655               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00656               return NULL;
00657        }
00658        double i = 1.0;
00659        bool found = false;
00660        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++)
00661        {
00662               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00663               {
00664                      i = ScCore->primaryMainWindow()->doc->Layers[lam].transparency;
00665                      found = true;
00666                      break;
00667               }
00668        }
00669        if (!found)
00670        {
00671               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00672               return NULL;
00673        }
00674        return PyFloat_FromDouble(i);
00675 }
00676 
00677 PyObject *scribus_removelayer(PyObject* /* self */, PyObject* args)
00678 {
00679 //FIXME: Use the docs remove layer code
00680        char *Name = const_cast<char*>("");
00681        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00682               return NULL;
00683        if(!checkHaveDocument())
00684               return NULL;
00685        if (Name == "")
00686        {
00687               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error"));
00688               return NULL;
00689        }
00690        if (ScCore->primaryMainWindow()->doc->Layers.count() == 1)
00691        {
00692               PyErr_SetString(ScribusException, QObject::tr("Cannot remove the last layer.","python error"));
00693               return NULL;
00694        }
00695        bool found = false;
00696        for (uint lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam)
00697        {
00698               if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name))
00699               {
00700                      QValueList<Layer>::iterator it2 = ScCore->primaryMainWindow()->doc->Layers.at(lam);
00701                      int num2 = (*it2).LNr;
00702                      if (!num2)
00703                      {
00704                             // FIXME: WTF DOES THIS DO?
00705                             Py_INCREF(Py_None);
00706                             return Py_None;
00707                      }
00708                      int num = (*it2).Level;
00709                      ScCore->primaryMainWindow()->doc->Layers.remove(it2);
00710                      QValueList<Layer>::iterator it;
00711                      for (uint l = 0; l < ScCore->primaryMainWindow()->doc->Layers.count(); l++)
00712                      {
00713                             it = ScCore->primaryMainWindow()->doc->Layers.at(l);
00714                             if ((*it).Level > num)
00715                                    (*it).Level -= 1;
00716                      }
00717                      ScCore->primaryMainWindow()->doc->removeLayer(num2);
00718                      ScCore->primaryMainWindow()->doc->setActiveLayer(0);
00719                      ScCore->primaryMainWindow()->changeLayer(0);
00720                      found = true;
00721                      break;
00722               }
00723        }
00724        if (!found)
00725        {
00726               PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error"));
00727               return NULL;
00728        }
00729 //     Py_INCREF(Py_None);
00730 //     return Py_None;
00731        Py_RETURN_NONE;
00732 }
00733 
00734 PyObject *scribus_createlayer(PyObject* /* self */, PyObject* args)
00735 {
00736        char *Name = const_cast<char*>("");
00737        if (!PyArg_ParseTuple(args, "es", "utf-8", &Name))
00738               return NULL;
00739        if(!checkHaveDocument())
00740               return NULL;
00741        if (Name == "")
00742        {
00743               PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot create layer without a name.","python error"));
00744               return NULL;
00745        }
00746        ScCore->primaryMainWindow()->doc->addLayer(QString::fromUtf8(Name), true);
00747        ScCore->primaryMainWindow()->changeLayer(ScCore->primaryMainWindow()->doc->activeLayer());
00748 //     Py_INCREF(Py_None);
00749 //     return Py_None;
00750        Py_RETURN_NONE;
00751 }
00752 
00753 PyObject *scribus_getlanguage(PyObject* /* self */)
00754 {
00755        return PyString_FromString(ScCore->getGuiLanguage().utf8());
00756 }
00757 
00761 void cmdmiscdocwarnings()
00762 {
00763     QStringList s;
00764     s << scribus_setredraw__doc__ <<scribus_fontnames__doc__ << scribus_xfontnames__doc__ <<scribus_renderfont__doc__ << scribus_getlayers__doc__ << scribus_setactlayer__doc__ << scribus_getactlayer__doc__ << scribus_senttolayer__doc__ <<scribus_layervisible__doc__ <<scribus_layerprint__doc__ <<scribus_layerlock__doc__ <<scribus_layeroutline__doc__ <<scribus_layerflow__doc__ <<scribus_layerblend__doc__ <<scribus_layertrans__doc__ <<scribus_glayervisib__doc__ <<scribus_glayerprint__doc__ <<scribus_glayerlock__doc__ <<scribus_glayeroutline__doc__ <<scribus_glayerflow__doc__ <<scribus_glayerblend__doc__ <<scribus_glayertrans__doc__ <<scribus_removelayer__doc__ <<scribus_createlayer__doc__ <<scribus_getlanguage__doc__;
00765 }