]> code.delx.au - bg-scripts/blob - kde_randombg.py
wallchanger: Fixed multiple monitors on OSX again.
[bg-scripts] / kde_randombg.py
1 #!/usr/bin/env python
2 # coding:utf-8
3 # This is an example of a DCOP enabled application written in Python, using
4 # PyKDE and the dcopexport module. Taken from server.py example in kde-bindings
5 # which was written by Torben Weis and Julian Rockey
6
7 import sys
8 import randombg2
9 from kdecore import KApplication, KCmdLineArgs, KAboutData
10 from dcopexport import DCOPExObj
11 from qt import QString, QStringList
12
13 # the class which will expose methods to DCOP - the methods do NOT
14 # need to be a member of this class.
15 class RandomBGIface (DCOPExObj):
16 def __init__ (self, id = 'RandomBGIface'):
17 DCOPExObj.__init__ (self, id)
18
19 # the methods available from this app via DCOP
20 # addMethod (<signature>, <Python method>)
21 self.addMethod('QString getCurrentWallpaper()', self.getCurrent)
22 self.addMethod('void setCurrentWallpaper(QString)', self.changeTo)
23 self.addMethod('void cycleNextWallpaper()', self.cycleNext)
24 self.addMethod('void cyclePrevWallpaper()', self.cyclePrev)
25 self.addMethod('bool writeCache()', self.writeCache)
26
27 self.filelist = randombg2.AllRandomFileList()
28 self.filelist.doAddPaths([
29 # Add paths here
30 ])
31 if not self.filelist.attemptCacheLoad(randombg2.CACHE_LOCATION):
32 self.filelist.doScanPaths()
33 self.randombg = randombg2.RandomBG(self.filelist)
34
35 def getCurrent(self):
36 return self.filelist.getLastImage()
37
38 def changeTo(self, wallpaper):
39 self.randombg._randombg(wallpaper)
40
41 def cycleNext(self):
42 self.randombg.cycleNext()
43
44 def cyclePrev(self):
45 self.randombg.cyclePrev()
46
47 def writeCache(self):
48 if self.filelist.doStoreCache(randombg2.CACHE_LOCATION):
49 return True
50 else:
51 return False
52
53 description = "A basic application template"
54 version = "1.0"
55 aboutData = KAboutData ("testdcopexport", "randombg",\
56 version, description, KAboutData.License_GPL,\
57 "(C) 2006 Greg Darke")
58
59 aboutData.addAuthor ("James Bunton", "Origional Version", "jbun5313@usyd.edu.au")
60 aboutData.addAuthor ("Greg Darke", "Coded the WMaker/KDE backends, the persistent random lists, and general bug fixes", "gdar9540@usyd.edu.au")
61
62 KCmdLineArgs.init (sys.argv, aboutData)
63
64 KCmdLineArgs.addCmdLineOptions ([("+paths", "Paths to scan for images")])
65
66 MYAPPID = 'randombg'
67 app = KApplication()
68 dcop = app.dcopClient()
69 appid = str(dcop.registerAs(MYAPPID, False))
70 if appid != MYAPPID:
71 print >>sys.stderr, 'Failed to get the applicationid of "%s", this means this program is already running' % MYAPPID
72 print 'Got "%s"' % appid
73 sys.exit(1)
74
75 print "DCOP Application: %s starting" % appid
76
77 randombgIface = RandomBGIface()
78
79 app.exec_loop()
80
81 randombgIface.filelist.doStoreCache(randombg2.CACHE_LOCATION)