r21141 by jghali -

scribus-commit scribus-commit at lists.scribus.net
Wed Mar 30 19:19:06 UTC 2016


Author: jghali
Date: Wed Mar 30 19:19:06 2016
New Revision: 21141

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21141
Log:
#13877: Replace repetitive error setting with function call

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp

Modified: trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21141&path=/trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp	Wed Mar 30 19:19:06 2016
@@ -141,8 +141,7 @@
 static PyObject * PDFfile_new(PyTypeObject *type, PyObject * /*args*/, PyObject * /*kwds*/)
 {
 // do not create new object if there is no opened document
-	if (!ScCore->primaryMainWindow()->HaveDoc) {
-		PyErr_SetString(PyExc_SystemError, "Need to open document first");
+	if (!checkHaveDocument()) {
 		return NULL;
 	}
 
@@ -326,8 +325,7 @@
 static int PDFfile_init(PDFfile *self, PyObject * /*args*/, PyObject * /*kwds*/)
 {
 	int i;
-	if (!ScCore->primaryMainWindow()->HaveDoc) {
-		PyErr_SetString(PyExc_SystemError, "Must open doc first");
+	if (!checkHaveDocument()) {
 		return -1;
 	}
 
@@ -1256,10 +1254,9 @@
 
 static PyObject *PDFfile_save(PDFfile *self)
 {
-	if (!ScCore->primaryMainWindow()->HaveDoc) {
-		PyErr_SetString(PyExc_SystemError, "Need to open document first");
+	if (!checkHaveDocument()) {
 		return NULL;
-	};
+	}
 
 	ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
 	PDFOptions& pdfOptions = currentDoc->pdfOptions();

Modified: trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21141&path=/trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/objprinter.cpp	Wed Mar 30 19:19:06 2016
@@ -68,8 +68,7 @@
 static PyObject * Printer_new(PyTypeObject *type, PyObject * /*args*/, PyObject * /*kwds*/)
 {
 // do not create new object if there is no opened document
-	if (!ScCore->primaryMainWindow()->HaveDoc) {
-		PyErr_SetString(PyExc_SystemError, "Need to open document first");
+	if (!checkHaveDocument()) {
 		return NULL;
 	}
 
@@ -132,6 +131,9 @@
 
 static int Printer_init(Printer *self, PyObject * /*args*/, PyObject * /*kwds*/)
 {
+	if (!checkHaveDocument()) {
+		return -1;
+	}
 // pool system for installed printers
 // most code is stolen and little adopted from druck.cpp
 	PyObject *allPrinters = PyList_New(0);
@@ -186,11 +188,7 @@
 // if document exist when created Printer instance
 // set to print all pages
 	PyObject *pages = NULL;
-	int num = 0;
-	if (ScCore->primaryMainWindow()->HaveDoc)
-		// which one should I use ???
-		// new = ScCore->primaryMainWindow()->view->Pages.count()
-		num = ScCore->primaryMainWindow()->doc->Pages->count();
+	int num = ScCore->primaryMainWindow()->doc->Pages->count();
 	pages = PyList_New(num);
 	if (pages){
 		Py_DECREF(self->pages);
@@ -396,8 +394,7 @@
 // Here we actually print
 static PyObject *Printer_print(Printer *self)
 {
-	if (!ScCore->primaryMainWindow()->HaveDoc) {
-		PyErr_SetString(PyExc_SystemError, "Need to open documetnt first");
+	if (!checkHaveDocument()) {
 		return NULL;
 	}
 // copied from void ScribusMainWindow::slotFilePrint() in file scribus.cpp




More information about the scribus-commit mailing list