]> code.delx.au - bg-scripts/blobdiff - kde_randombg.py
Removed the bin/ and lib/ directories... Now everything is in a single directory
[bg-scripts] / kde_randombg.py
diff --git a/kde_randombg.py b/kde_randombg.py
new file mode 100755 (executable)
index 0000000..15de2c8
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# coding:utf-8
+# This is an example of a DCOP enabled application written in Python, using
+# PyKDE and the dcopexport module. Taken from server.py example in kde-bindings
+# which was written by Torben Weis and Julian Rockey
+
+import sys
+import randombg2
+from kdecore import KApplication, KCmdLineArgs, KAboutData
+from dcopexport import DCOPExObj
+from qt import QString, QStringList
+
+# the class which will expose methods to DCOP - the methods do NOT
+# need to be a member of this class.
+class RandomBGIface (DCOPExObj):
+       def __init__ (self, id = 'RandomBGIface'):
+               DCOPExObj.__init__ (self, id)
+
+               # the methods available from this app via DCOP
+               #         addMethod (<signature>, <Python method>)
+               self.addMethod('QString getCurrentWallpaper()', self.getCurrent)
+               self.addMethod('void setCurrentWallpaper(QString)', self.changeTo)
+               self.addMethod('void cycleNextWallpaper()', self.cycleNext)
+               self.addMethod('void cyclePrevWallpaper()', self.cyclePrev)
+               self.addMethod('bool writeCache()', self.writeCache)
+               
+               self.filelist = randombg2.AllRandomFileList()
+               self.filelist.doAddPaths([
+                               # Add paths here
+                       ])
+               if not  self.filelist.attemptCacheLoad(randombg2.CACHE_LOCATION):
+                       self.filelist.doScanPaths()
+               self.randombg = randombg2.RandomBG(self.filelist)
+
+       def getCurrent(self):
+               return self.filelist.getLastImage()
+
+       def changeTo(self, wallpaper):
+               self.randombg._randombg(wallpaper)
+
+       def cycleNext(self):
+               self.randombg.cycleNext()
+
+       def cyclePrev(self):
+               self.randombg.cyclePrev()
+       
+       def writeCache(self):
+               if self.filelist.doStoreCache(randombg2.CACHE_LOCATION):
+                       return True
+               else:
+                       return False
+
+description = "A basic application template"
+version                = "1.0"
+aboutData      = KAboutData ("testdcopexport", "randombg",\
+       version, description, KAboutData.License_GPL,\
+       "(C) 2006 Greg Darke")
+
+aboutData.addAuthor ("James Bunton", "Origional Version", "jbun5313@usyd.edu.au")
+aboutData.addAuthor ("Greg Darke", "Coded the WMaker/KDE backends, the persistent random lists, and general bug fixes", "gdar9540@usyd.edu.au")
+
+KCmdLineArgs.init (sys.argv, aboutData)
+
+KCmdLineArgs.addCmdLineOptions ([("+paths", "Paths to scan for images")])
+
+MYAPPID = 'randombg'
+app   = KApplication()
+dcop  = app.dcopClient()
+appid = str(dcop.registerAs(MYAPPID, False))
+if appid != MYAPPID:
+       print >>sys.stderr, 'Failed to get the applicationid of "%s", this means this program is already running' % MYAPPID
+       print 'Got "%s"' % appid
+       sys.exit(1)
+
+print "DCOP Application: %s starting" % appid
+
+randombgIface = RandomBGIface()
+
+app.exec_loop()
+
+randombgIface.filelist.doStoreCache(randombg2.CACHE_LOCATION)