]> code.delx.au - bg-scripts/blob - bin/kde_randombg.py
b2fd661db5b3e73f9802bbc6a7256e38ad9be076
[bg-scripts] / bin / 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 '/home/greg/images_sfw/Futakoi',
30 '/home/greg/images_sfw/Moon Phase',
31 '/home/greg/images_sfw/Ouran High',
32 '/home/greg/images_sfw/Paniponi',
33 '/home/greg/images_sfw/Popotan',
34 '/home/greg/images_sfw/Rozen Maiden',
35 '/home/greg/images_sfw/Yotsuba',
36 '/home/greg/images_sfw/chobits',
37 '/home/greg/images_sfw/ichigo Mashimaro',
38 '/home/greg/images_sfw/カードキャプターさくら',
39 '/home/greg/images_sfw/涼宮ハルヒの憂鬱',
40 '/home/greg/images_sfw/灼眼のシャナ',
41 '/home/greg/images_sfw/舞-乙HiME',
42 '/home/greg/images_sfw/舞HiME',
43 '/home/greg/images_sfw/魔法先生ネギま',
44 '/home/greg/images_sfw/魔法少女リリカルなのは'])
45 #for path in ['/home/greg/images_sfw/Air','/home/greg/images_sfw/Azumanga Daioh','/home/greg/images_sfw/Futakoi','/home/greg/images_sfw/Karin','/home/greg/images_sfw/Love Hina','/home/greg/images_sfw/Moon Phase','/home/greg/images_sfw/Neon Genesis','/home/greg/images_sfw/Ouran High','/home/greg/images_sfw/Paniponi','/home/greg/images_sfw/Popotan','/home/greg/images_sfw/Rozen Maiden','/home/greg/images_sfw/Yotsuba','/home/greg/images_sfw/chobits','/home/greg/images_sfw/dot Hack','/home/greg/images_sfw/ichigo Mashimaro','/home/greg/images_sfw/kasimasi','/home/greg/images_sfw/カードキャププターさくら','/home/greg/images_sfw/涼宮ハルヒの憂鬱','/home/greg/images_sfw/灼眼のシャナ','/home/greg/images_sfw/舞-乙HiME','/home/greg/images_sfw/舞HiME','/home/greg/images_sfw/魔法先生ネギま','/home/greg/images_sfw/魔法少女リリカルなのは']:
46 # self.filelist.doAddPath(path)
47 if not self.filelist.attemptCacheLoad(randombg2.CACHE_LOCATION):
48 self.filelist.doScanPaths()
49 self.randombg = randombg2.RandomBG(self.filelist)
50
51 def getCurrent(self):
52 return self.filelist.getLastImage()
53
54 def changeTo(self, wallpaper):
55 self.randombg._randombg(wallpaper)
56
57 def cycleNext(self):
58 self.randombg.cycleNext()
59
60 def cyclePrev(self):
61 self.randombg.cyclePrev()
62
63 def writeCache(self):
64 if self.filelist.doStoreCache(randombg2.CACHE_LOCATION):
65 return True
66 else:
67 return False
68
69 description = "A basic application template"
70 version = "1.0"
71 aboutData = KAboutData ("testdcopexport", "randombg",\
72 version, description, KAboutData.License_GPL,\
73 "(C) 2006 Greg Darke")
74
75 aboutData.addAuthor ("James Bunton", "Origional Version", "jbun5313@usyd.edu.au")
76 aboutData.addAuthor ("Greg Darke", "Coded the WMaker/KDE backends, the persistent random lists, and general bug fixes", "gdar9540@usyd.edu.au")
77
78 KCmdLineArgs.init (sys.argv, aboutData)
79
80 KCmdLineArgs.addCmdLineOptions ([("+paths", "Paths to scan for images")])
81
82 MYAPPID = 'randombg'
83 app = KApplication()
84 dcop = app.dcopClient()
85 appid = str(dcop.registerAs(MYAPPID, False))
86 if appid != MYAPPID:
87 print >>sys.stderr, 'Failed to get the applicationid of "%s", this means this program is already running' % MYAPPID
88 print 'Got "%s"' % appid
89 sys.exit(1)
90
91 print "DCOP Application: %s starting" % appid
92
93 randombgIface = RandomBGIface()
94
95 app.exec_loop()
96
97 randombgIface.filelist.doStoreCache(randombg2.CACHE_LOCATION)