[Scribus] [SCRIBUS] [ANN] MY FIRST PLUGIN: SCRIPTERNG

Henning Schröder post
Tue Nov 13 14:51:05 CET 2007


2007/11/13, Petr Vanek <petr at scribus.info>:
> Is it writtent to work with 135svn or anything else?
I developed the plugin on svn trunk. But any version using Qt4
should work.


> Anyway it looks a bit cryptic for me. Can you provide more docs in the code,
> please?
Here some explanations for the files:
 * cmake/modules/*
   - Some extra macros from PyKDE to find SIP and PyQt.
   - They are used in scribuspyqt/. There seems to exist
     some conflicts with other existing macros.
   - So I had to compile scribuspyqt alone
   - I am not sure if they work well on Windows.
 * pythonize.{cpp,h}
   - This is a nice small interface to use Python in C++
 * scripterng.{cpp,h}
   - hooks into Extras menu
   - low level plugin stuff (like in myplugin)
 * scripterngimpl.{cpp,h}
   - parent is QApplication::instance()
   - sets objectName to ScripterNG (only named objects are exposed)
   - loads Python and runs scripterng.py on startup
   - implements example function: aboutScripterNG()
   - object is magically available as Application.ScripterNG
 * scribuspyqt/scribuspyqt.{cpp,h}
   - compiles to libscribuspyqt.so
   - provides additional code to wrap without sip
   - invokeMethod using variants (to call unwrapped objects)
 * scribuspyqt/scribuspyqt.sip
   - sip interface to make invokeMethod available to Python
   - creates python module _scribuspyqt.sip
   - links against libscribuspyqt.so
 * scribuspyqt/scribuspyqt.py
   - import this module instead of _scribuspyqt directly
   - PyQtObject can be used to wrap any QObject
     - slots can be called like method
     - full property support
 * scribuspyqt/scripterng.py
   - called at startup from plugin
   - looks for application instance and make it available
   - will be used to hook into Scribus with PyQt, to provide menus to
     load scripts etc
 * scribuspyqt/pyqtscript.py
   - prove of concept: activates QtScript from Python
   - no speed loss
   - mix Python and QtScript
 * scribuspyqt/compat.py
   - start of a compatibility layer
   - provides same api as the "old" scripter


> I had a little talk with one guy from Kross team. He said they will have
> pure Qt (no kde deps) Kross ready in 2 months propably. What are
> dis/advantages of your solution comparing to Kross?
Kross is great but as you said it currently still depends on kdelibs.
ScripterNG is available now. Of course it isn't that mature but it
depends on mature technologies (PyQt, sip, pythonize). One main
difference is that I try to do most stuff in Python. So I can be more
flexible and development should be faster. I don't expect any sensible
speed loss by this approach.
Additionally if we start writing the C++ api now, we could switch later
to Kross and could still use this api.


> Do you have some ideas of "scripterng object model"? I mean what do you want
> to export from Scribus to python?
Here is an example.

  class CoreModule;

  CoreModule::CoreModule() : QObject(
            QApplication::instance()->findChild("ScripterNG")) {
    setObjectName("Core");
  }

  void CoreModule::quit(bool ask_save) {
    if (ask_save() && confirm() .. ) {
       qDebug("Bye");
       QApplication::instance()->quit();
    }
  }

  int CoreModule::answer() {
    return 42;
  }

  CoreModule *m_core = new CoreModule();


Now you can do
 >> print Application.Core.answer()
 42
 >> Application.Core.quit()
 Bye



> > PS: There still seems to be a problem in loading the module. Call
> > scribus from INSTALLPREFIX/lib/scribus/plugins/scripterng
> [..]
> ImportError: No module named _scribuspyqt
> Loading failed
_scribusqt.so could be put into /usr/Lib/python2.5/site-packages
libscribusqt.so could be put into INSTALLPREFIX/lib/scribus or
something like that
Or you set LD_LIBRARY_PATH ;)




Henning



More information about the scribus mailing list