summaryrefslogtreecommitdiffstats
path: root/dcoppython/test
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /dcoppython/test
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'dcoppython/test')
-rw-r--r--dcoppython/test/Makefile.am3
-rw-r--r--dcoppython/test/README-server19
-rwxr-xr-xdcoppython/test/automate_presentation.py30
-rw-r--r--dcoppython/test/dcopserver/Makefile.am36
-rw-r--r--dcoppython/test/dcopserver/README8
-rw-r--r--dcoppython/test/dcopserver/gen.py46
-rw-r--r--dcoppython/test/dcopserver/hi16-app-kdedcoptest.pngbin0 -> 1033 bytes
-rw-r--r--dcoppython/test/dcopserver/hi32-app-kdedcoptest.pngbin0 -> 2749 bytes
-rw-r--r--dcoppython/test/dcopserver/kdedcoptest.cpp27
-rw-r--r--dcoppython/test/dcopserver/kdedcoptest.desktop6
-rw-r--r--dcoppython/test/dcopserver/kdedcoptest.h38
-rw-r--r--dcoppython/test/dcopserver/kdedcoptestui.rc8
-rw-r--r--dcoppython/test/dcopserver/main.cpp54
-rw-r--r--dcoppython/test/dcopserver/mainclass.cpp20
-rw-r--r--dcoppython/test/dcopserver/mainclass.h23
-rw-r--r--dcoppython/test/server.py48
-rw-r--r--dcoppython/test/signal.py41
-rw-r--r--dcoppython/test/test.py15
-rw-r--r--dcoppython/test/test2.py28
-rw-r--r--dcoppython/test/test3.py14
-rw-r--r--dcoppython/test/test4.py24
21 files changed, 488 insertions, 0 deletions
diff --git a/dcoppython/test/Makefile.am b/dcoppython/test/Makefile.am
new file mode 100644
index 00000000..35deee5d
--- /dev/null
+++ b/dcoppython/test/Makefile.am
@@ -0,0 +1,3 @@
+
+subdirs = dcopserver
+
diff --git a/dcoppython/test/README-server b/dcoppython/test/README-server
new file mode 100644
index 00000000..3d2528b8
--- /dev/null
+++ b/dcoppython/test/README-server
@@ -0,0 +1,19 @@
+The file server.py contains an example of using the DCOP bindings to run a DCOP server in Python.
+
+Run python server.py, then in another console:
+
+[julian] julian$ dcop `dcop | grep petshop`
+qt
+parrot
+[julian] julian$ dcop `dcop | grep petshop` parrot
+QCStringList interfaces()
+QCStringList functions()
+QString squawk(QString)
+void setAge(int)
+int age()
+[julian] julian$ dcop `dcop | grep petshop` parrot setAge 5
+[julian] julian$ dcop petshop-29530 parrot squawk 'How many volts for a vrooom?'
+This parrot, 5 months old, squawks: How many volts for a vrooom?
+[julian] julian$
+
+
diff --git a/dcoppython/test/automate_presentation.py b/dcoppython/test/automate_presentation.py
new file mode 100755
index 00000000..0c75e108
--- /dev/null
+++ b/dcoppython/test/automate_presentation.py
@@ -0,0 +1,30 @@
+# Python version of David Faure's <faure@kde.org> dcop presentation automation script for kpresenter
+#
+# Simon Hausmann <hausmann@kde.org>
+from time import sleep
+import pcop
+import pydcop
+
+app = pydcop.anyAppCalled( "kpresenter" )
+
+if not app: raise RuntimeError, "Couldn't find a running KPresenter"
+
+doc = app.KoApplicationIface.getDocuments()[0]
+view = doc.view(0)
+
+startAction = view.action( "screen_start" )
+
+print "Starting Presentation %s" % doc.url()
+
+startAction.activate()
+
+sleep( 5 )
+
+act = view.action( "screen_next" )
+while startAction.enabled() == 0:
+ sleep( 10 )
+ if startAction.enabled() == 0:
+ act.activate()
+
+view.screenStop()
+print "Presentation finished."
diff --git a/dcoppython/test/dcopserver/Makefile.am b/dcoppython/test/dcopserver/Makefile.am
new file mode 100644
index 00000000..61610ae5
--- /dev/null
+++ b/dcoppython/test/dcopserver/Makefile.am
@@ -0,0 +1,36 @@
+# set the include path for X, qt and KDE
+INCLUDES = $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = kdedcoptest.h
+
+# let automoc handle all of the meta source files (moc)
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kdedcoptest.pot
+
+KDE_ICON = kdedcoptest
+
+#########################################################################
+# APPLICATION SECTION
+#########################################################################
+# this is the program that gets installed. it's name is used for all
+# of the other Makefile.am variables
+bin_PROGRAMS = kdedcoptest
+
+# the application source, library search path, and link libraries
+kdedcoptest_SOURCES = main.cpp kdedcoptest.cpp kdedcoptest_iface.skel mainclass.cpp
+kdedcoptest_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+kdedcoptest_LDADD = $(LIB_KDEUI)
+
+# this is where the desktop file will go
+shelldesktopdir = $(kde_appsdir)/Utilities
+shelldesktop_DATA = kdedcoptest.desktop
+
+# this is where the shell's XML-GUI resource file goes
+shellrcdir = $(kde_datadir)/kdedcoptest
+shellrc_DATA = kdedcoptestui.rc
+
+h_inc.h: gen.py
+ python gen.py
diff --git a/dcoppython/test/dcopserver/README b/dcoppython/test/dcopserver/README
new file mode 100644
index 00000000..47e69273
--- /dev/null
+++ b/dcoppython/test/dcopserver/README
@@ -0,0 +1,8 @@
+What's this doing here? It's here to help if you're developing the Python DCOP bindings themselves. You don't need it if you just want to _use_ the bindings.
+
+It's a simple DCOP server in C++, that can be used to conveniently test the Python DCOP interface (or any other DCOP binding, for that matter). The script gen.py generates simple get/set DCOP methods for a variety of types.
+
+Note that gen.py is _not_ automatically invoked from the Makefile, so you should run it yourself before doing make.
+
+Julian Rockey
+kde@jrockey.com
diff --git a/dcoppython/test/dcopserver/gen.py b/dcoppython/test/dcopserver/gen.py
new file mode 100644
index 00000000..ae2947af
--- /dev/null
+++ b/dcoppython/test/dcopserver/gen.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+type_list = ['KURL', 'QDate', 'QTime', 'QDateTime', 'QRect', 'QString', 'int', 'QFont', 'QSize', 'QPoint', 'QPointArray' ]
+
+inc_exceptions = {'QDate': None, 'QTime': None, 'KURL' : 'kurl'}
+
+iface_inc_list = ['dcopobject']
+
+iface_inc_list += [ t.lower() for t in type_list if t[0]=='Q' and t not in inc_exceptions ]
+iface_inc_list += inc_exceptions.values()
+
+iface_inc_1 = ['class DCOPDemoIface : virtual public DCOPObject {',
+ ' K_DCOP',
+ ' k_dcop:']
+h_inc = []
+cpp_inc = []
+
+for t in type_list:
+ iface_inc_1.append("virtual void set%sVal(const %s &val) = 0; " % (t,t) )
+ iface_inc_1.append("virtual %s %sVal() const = 0;" % (t,t) )
+
+ h_inc.append("virtual void set%sVal(const %s &val); " % (t,t) )
+ h_inc.append("virtual %s %sVal() const;" % (t,t) )
+ h_inc.append("%s m_%sValue;" % (t,t) )
+
+ cpp_inc.append("void MainClass::set%sVal(const %s & val) {" % (t,t) )
+ cpp_inc.append(" m_%sValue = val; }" % t)
+ cpp_inc.append("%s MainClass::%sVal() const {" % (t,t) )
+ cpp_inc.append(" return m_%sValue; }" % t)
+
+iface_inc = []
+for inc in iface_inc_list:
+ if inc: iface_inc.append("#include <%s.h>" % inc)
+iface_inc += iface_inc_1
+iface_inc.append("};")
+
+files = {'kdedcoptest_iface.h': iface_inc,
+ 'h_inc.h': h_inc,
+ 'cpp_inc.h': cpp_inc
+ }
+
+for (fname,data) in files.items():
+ outf = file(fname,'w')
+ for d in data:
+ outf.write(d+'\n')
+ outf.close()
diff --git a/dcoppython/test/dcopserver/hi16-app-kdedcoptest.png b/dcoppython/test/dcopserver/hi16-app-kdedcoptest.png
new file mode 100644
index 00000000..4ed606c1
--- /dev/null
+++ b/dcoppython/test/dcopserver/hi16-app-kdedcoptest.png
Binary files differ
diff --git a/dcoppython/test/dcopserver/hi32-app-kdedcoptest.png b/dcoppython/test/dcopserver/hi32-app-kdedcoptest.png
new file mode 100644
index 00000000..45ae1a11
--- /dev/null
+++ b/dcoppython/test/dcopserver/hi32-app-kdedcoptest.png
Binary files differ
diff --git a/dcoppython/test/dcopserver/kdedcoptest.cpp b/dcoppython/test/dcopserver/kdedcoptest.cpp
new file mode 100644
index 00000000..3046eaac
--- /dev/null
+++ b/dcoppython/test/dcopserver/kdedcoptest.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2003 Julian Rockey <kde@jrockey.com>
+ */
+
+#include "kdedcoptest.h"
+
+#include <qlabel.h>
+
+#include <kmainwindow.h>
+#include <klocale.h>
+
+KDEDcopTest::KDEDcopTest()
+ : KMainWindow( 0, "KDEDcopTest" )
+{
+ // set the shell's ui resource file
+ //setXMLFile("kdedcoptestui.rc");
+
+ //new QLabel( "Hello World", this, "hello label" );
+ m_mainClass = new MainClass();
+}
+
+KDEDcopTest::~KDEDcopTest()
+{
+ if (m_mainClass) delete m_mainClass;
+}
+
+#include "kdedcoptest.moc"
diff --git a/dcoppython/test/dcopserver/kdedcoptest.desktop b/dcoppython/test/dcopserver/kdedcoptest.desktop
new file mode 100644
index 00000000..beee065d
--- /dev/null
+++ b/dcoppython/test/dcopserver/kdedcoptest.desktop
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Name=KDEDcopTest
+Exec=kdedcoptest
+Icon=kdedcoptest
+Type=Application
+Comment=A simple KDE Application
diff --git a/dcoppython/test/dcopserver/kdedcoptest.h b/dcoppython/test/dcopserver/kdedcoptest.h
new file mode 100644
index 00000000..42a54da6
--- /dev/null
+++ b/dcoppython/test/dcopserver/kdedcoptest.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2003 Julian Rockey <kde@jrockey.com>
+ */
+
+#ifndef _KDEDCOPTEST_H_
+#define _KDEDCOPTEST_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <kmainwindow.h>
+
+#include "mainclass.h"
+
+/**
+ * @short Application Main Window
+ * @author Julian Rockey <kde@jrockey.com>
+ * @version 0.1
+ */
+class KDEDcopTest : public KMainWindow
+{
+ Q_OBJECT
+public:
+ /**
+ * Default Constructor
+ */
+ KDEDcopTest();
+
+ /**
+ * Default Destructor
+ */
+ virtual ~KDEDcopTest();
+private:
+ MainClass *m_mainClass;
+};
+
+#endif // _KDEDCOPTEST_H_
diff --git a/dcoppython/test/dcopserver/kdedcoptestui.rc b/dcoppython/test/dcopserver/kdedcoptestui.rc
new file mode 100644
index 00000000..7f6ee828
--- /dev/null
+++ b/dcoppython/test/dcopserver/kdedcoptestui.rc
@@ -0,0 +1,8 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui name="kdedcoptest" version="1">
+<MenuBar>
+ <Menu name="custom"><text>C&amp;ustom</text>
+ <Action name="custom_action" />
+ </Menu>
+</MenuBar>
+</kpartgui>
diff --git a/dcoppython/test/dcopserver/main.cpp b/dcoppython/test/dcopserver/main.cpp
new file mode 100644
index 00000000..5335ffe9
--- /dev/null
+++ b/dcoppython/test/dcopserver/main.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2003 Julian Rockey <kde@jrockey.com>
+ */
+
+#include "kdedcoptest.h"
+#include <kapplication.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
+
+static const char *description =
+ I18N_NOOP("A KDE KPart Application");
+
+static const char *version = "0.1";
+
+static KCmdLineOptions options[] =
+{
+// { "+[URL]", I18N_NOOP( "Document to open" ), 0 },
+ { 0, 0, 0 }
+};
+
+int main(int argc, char **argv)
+{
+ KAboutData about("kdedcoptest", I18N_NOOP("KDEDcopTest"), version, description,
+ KAboutData::License_GPL, "(C) 2003 Julian Rockey", 0, 0, "kde@jrockey.com");
+ about.addAuthor( "Julian Rockey", 0, "kde@jrockey.com" );
+ KCmdLineArgs::init(argc, argv, &about);
+ KCmdLineArgs::addCmdLineOptions( options );
+ KApplication app;
+ KDEDcopTest *mainWin = 0;
+
+ if (app.isRestored())
+ {
+ RESTORE(KDEDcopTest);
+ }
+ else
+ {
+ // no session.. just start up normally
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ // TODO: do something with the command line args here
+
+ mainWin = new KDEDcopTest();
+ app.setMainWidget( mainWin );
+ mainWin->show();
+
+ args->clear();
+ }
+
+ int ret = app.exec();
+
+ delete mainWin;
+ return ret;
+}
diff --git a/dcoppython/test/dcopserver/mainclass.cpp b/dcoppython/test/dcopserver/mainclass.cpp
new file mode 100644
index 00000000..d74b7f10
--- /dev/null
+++ b/dcoppython/test/dcopserver/mainclass.cpp
@@ -0,0 +1,20 @@
+/***************************************************************************
+ * Copyright (C) 2003 by Julian Rockey *
+ * kde@jrockey.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "mainclass.h"
+
+
+MainClass::MainClass()
+ : DCOPDemoIface(), DCOPObject("test")
+{}
+
+MainClass::~MainClass()
+{}
+
+#include "cpp_inc.h"
diff --git a/dcoppython/test/dcopserver/mainclass.h b/dcoppython/test/dcopserver/mainclass.h
new file mode 100644
index 00000000..7d4f7f4e
--- /dev/null
+++ b/dcoppython/test/dcopserver/mainclass.h
@@ -0,0 +1,23 @@
+
+#ifndef MAINCLASS_H
+#define MAINCLASS_H
+
+
+#include "kdedcoptest_iface.h"
+
+/**
+ *
+ * Julian Rockey
+ **/
+class MainClass : virtual public DCOPDemoIface
+{
+public:
+ MainClass();
+
+ ~MainClass();
+
+#include "h_inc.h"
+
+};
+
+#endif
diff --git a/dcoppython/test/server.py b/dcoppython/test/server.py
new file mode 100644
index 00000000..479b0236
--- /dev/null
+++ b/dcoppython/test/server.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+# This is an example of a DCOP serving application written in Python, using
+# the dcoppython KDE bindings.
+
+# something goes wrong if you don't import pcop first.
+# Have to do this till I find out why...
+import pcop
+import pydcop
+
+class ParrotObject(pydcop.DCOPServerObject):
+ """DCOP server object"""
+
+ def __init__(self, id='parrot'):
+ pydcop.DCOPServerObject.__init__(self, id)
+
+ # DCOP needs types, so we need to initialise the object with the methods that
+ # it's going to provide.
+ self.setMethods( [
+ ('int age()', self.get_age),
+ ('void setAge(int)', self.set_age),
+ ('QString squawk(QString)', self.squawk),
+ ])
+
+ # set up object variables
+ self.parrot_age = 7
+
+ def get_age(self):
+ return self.parrot_age
+
+ def set_age(self,age):
+ self.parrot_age = age
+
+ def squawk(self, what_to_squawk):
+ return "This parrot, %i months old, squawks: %s" % (self.parrot_age, what_to_squawk)
+
+
+appid = pydcop.registerAs('petshop')
+print "Server: %s starting" % appid
+
+parrot = ParrotObject()
+another_parrot = ParrotObject('polly')
+
+# Enter event loop
+while 1:
+ pydcop.processEvents()
+
+
diff --git a/dcoppython/test/signal.py b/dcoppython/test/signal.py
new file mode 100644
index 00000000..f9d087c6
--- /dev/null
+++ b/dcoppython/test/signal.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+# This is an example of how to use DCOP Signals with
+# the dcoppython KDE bindings.
+
+# something goes wrong if you don't import pcop first.
+# Have to do this till I find out why...
+import pcop
+import pydcop
+
+class MyObject(pydcop.DCOPServerObject):
+ """DCOP server object"""
+
+ def __init__(self, id='pythontest'):
+ pydcop.DCOPServerObject.__init__(self, id)
+
+ # DCOP needs types, so we need to initialise the object with the methods that
+ # it's going to provide.
+ self.setMethods( [('void test(QString)', self.test)])
+
+ def test(self, data):
+ print "New Weather for " + data
+
+appid = pydcop.registerAs('dcopSignalTest')
+print "Server: %s starting" % appid
+
+pytest = MyObject()
+
+sender = "KWeatherService"
+senderObj = "WeatherService"
+signal = "fileUpdate(QString)"
+receiverObj = "pythontest"
+slot = "test(QString)"
+volatile = 1
+
+pydcop.connectDCOPSignal(sender,senderObj,signal,receiverObj,slot,volatile)
+# Enter event loop
+while 1:
+ pydcop.processEvents()
+
+
diff --git a/dcoppython/test/test.py b/dcoppython/test/test.py
new file mode 100644
index 00000000..5ead172a
--- /dev/null
+++ b/dcoppython/test/test.py
@@ -0,0 +1,15 @@
+import pcop
+import pydcop
+
+#res = pcop.dcop_call( "kspread", "default", "getDocuments", () )
+
+res = pydcop.anyAppCalled("kspread").default.getDocuments()
+print res
+print res[0].appname
+print res[0].name
+
+m = res[0].map()
+
+print m.tableNames()
+
+print "done"
diff --git a/dcoppython/test/test2.py b/dcoppython/test/test2.py
new file mode 100644
index 00000000..1a56f917
--- /dev/null
+++ b/dcoppython/test/test2.py
@@ -0,0 +1,28 @@
+
+import pcop
+import pydcop
+
+app = pydcop.anyAppCalled( "kspread" );
+
+res = app.default.getDocuments()
+
+print res
+print res[0].appname
+print res[0].name
+
+m = res[0].map()
+
+print m.tableNames()
+
+x = m.table('Sheet2')
+
+if x:
+ print x
+ print "===================="
+ print x._name
+ print "===================="
+ print x._name()
+ print "===================="
+else: print "Could not find sheet called Sheet2"
+
+print "done"
diff --git a/dcoppython/test/test3.py b/dcoppython/test/test3.py
new file mode 100644
index 00000000..aa13ed8b
--- /dev/null
+++ b/dcoppython/test/test3.py
@@ -0,0 +1,14 @@
+
+import pcop
+import pydcop
+
+app = pydcop.anyAppCalled("kspread")
+
+table = app.default.getViews()[0]
+
+table.setSelection( ( 2, 2, 4, 6 ) )
+
+table.setSelectionBgColor( (100, 100, 240) )
+print rect
+
+print "done"
diff --git a/dcoppython/test/test4.py b/dcoppython/test/test4.py
new file mode 100644
index 00000000..b87a071f
--- /dev/null
+++ b/dcoppython/test/test4.py
@@ -0,0 +1,24 @@
+
+import pcop
+import pydcop
+
+app = pydcop.anyAppCalled("kspread")
+
+doc = app.default.getDocuments()[0]
+
+table = doc.map().tables()[0]
+
+table.cell( 1, 1 ).setValue( 1 )
+
+x = 2
+
+while x < 5:
+ y = 2
+ while y < 5:
+ previousCell = table.cell( x - 1, y - 1 )
+ cell = table.cell( x, y )
+ cell.setValue( previousCell.value() + 1.0 )
+ y = y + 1
+ x = x + 1
+
+