1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #include "guiapp.h"
8 #include "cmdutil.h"
9 #include "scribuscore.h"
10 #include "scribusview.h"
11
12 #include <QApplication>
13 #include <QCursor>
14 #include <QProgressBar>
15 #include <QString>
16
scribus_statusmessage(PyObject *,PyObject * args)17 PyObject *scribus_statusmessage(PyObject* /* self */, PyObject* args)
18 {
19 char *aText;
20 if (!PyArg_ParseTuple(args, "es", "utf-8", &aText))
21 return nullptr;
22 ScCore->primaryMainWindow()->setStatusBarInfoText(QString::fromUtf8(aText));
23 Py_RETURN_NONE;
24 }
25
scribus_progressreset(PyObject *)26 PyObject *scribus_progressreset(PyObject* /* self */)
27 {
28 ScCore->primaryMainWindow()->mainWindowProgressBar->reset();
29 qApp->processEvents();
30 Py_RETURN_NONE;
31 }
32
scribus_progresssettotalsteps(PyObject *,PyObject * args)33 PyObject *scribus_progresssettotalsteps(PyObject* /* self */, PyObject* args)
34 {
35 int steps;
36 if (!PyArg_ParseTuple(args, "i", &steps))
37 return nullptr;
38 ScCore->primaryMainWindow()->mainWindowProgressBar->setMaximum(steps);
39 ScCore->primaryMainWindow()->mainWindowProgressBar->setValue(0);
40 qApp->processEvents();
41 Py_RETURN_NONE;
42 }
43
scribus_progresssetprogress(PyObject *,PyObject * args)44 PyObject *scribus_progresssetprogress(PyObject* /* self */, PyObject* args)
45 {
46 int position;
47 if (!PyArg_ParseTuple(args, "i", &position))
48 return nullptr;
49 if (position > ScCore->primaryMainWindow()->mainWindowProgressBar->maximum())
50 {
51 PyErr_SetString(PyExc_ValueError, QString("Tried to set progress > maximum progress").toLocal8Bit().constData());
52 return nullptr;
53 }
54 ScCore->primaryMainWindow()->mainWindowProgressBar->setValue(position);
55 qApp->processEvents();
56 Py_RETURN_NONE;
57 }
58
59
scribus_setcursor(PyObject *,PyObject * args)60 PyObject *scribus_setcursor(PyObject* /* self */, PyObject* args)
61 {
62 char *aCursor;
63 qDebug("WARNING! SetCursor() is not stable!");
64 if (!PyArg_ParseTuple(args, "es", "ascii", &aCursor))
65 return nullptr;
66 if (strcmp(aCursor, "wait") == 0)
67 qApp->changeOverrideCursor(Qt::WaitCursor);
68 // else
69 // qApp->restoreOverrideCursor();
70 Py_RETURN_NONE;
71 }
72
scribus_docchanged(PyObject *,PyObject * args)73 PyObject *scribus_docchanged(PyObject* /* self */, PyObject* args)
74 {
75 int aValue;
76 if (!PyArg_ParseTuple(args, "i", &aValue))
77 return nullptr;
78 if (!checkHaveDocument())
79 return nullptr;
80 ScCore->primaryMainWindow()->slotDocCh(static_cast<bool>(aValue));
81 /*
82 if (aValue>0)
83 ScCore->primaryMainWindow()->slotDocCh(true);
84 else
85 ScCore->primaryMainWindow()->slotDocCh(false);*/
86 Py_RETURN_NONE;
87 }
88
scribus_zoomdocument(PyObject *,PyObject * args)89 PyObject *scribus_zoomdocument(PyObject* /* self */, PyObject* args)
90 {
91 double zoomFactor;
92 if (!PyArg_ParseTuple(args, "d", &zoomFactor))
93 return nullptr;
94 if (!checkHaveDocument())
95 return nullptr;
96 if (zoomFactor > 0.0 || zoomFactor == -100.0)
97 ScCore->primaryMainWindow()->slotZoom(zoomFactor);
98 else
99 {
100 PyErr_SetString(PyExc_ValueError, QString("The zoom factor should be greater than 0.0 or equal to -100.0. See help(zoomFactor).").toLocal8Bit().constData());
101 return nullptr;
102 }
103 Py_RETURN_NONE;
104 }
105
106 /*
107 * Gives the possibility to scroll the document.
108 * 13.12.2007: Joachim Neu
109 */
scribus_scrolldocument(PyObject *,PyObject * args)110 PyObject *scribus_scrolldocument(PyObject*,PyObject* args)
111 {
112 int moveX = 0, moveY = 0;
113 if (!PyArg_ParseTuple(args, "ii", &moveX, &moveY))
114 return nullptr;
115 if (!checkHaveDocument())
116 return nullptr;
117 ScCore->primaryMainWindow()->view->scrollBy(moveX,moveY);
118 Py_RETURN_NONE;
119 }
120
121 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
122 with header files structure untouched (docstrings are kept near declarations)
123 PV */
guiappdocwarnings()124 void guiappdocwarnings()
125 {
126 QStringList s;
127 s << scribus_docchanged__doc__
128 << scribus_progressreset__doc__
129 << scribus_progresssetprogress__doc__
130 << scribus_progresssettotalsteps__doc__
131 << scribus_scrolldocument__doc__
132 << scribus_setcursor__doc__
133 << scribus_statusmessage__doc__
134 << scribus_zoomdocument__doc__;
135 }
136