def getLocalWallpaper(): "Returns local wallpaper using dcop" # Create a dcop object: client = DCOPClient() if not client.attach(): return None # Get Wallpaper: background = DCOPObj("kdesktop", client, "KBackgroundIface") ok, wallpaper = background.currentWallpaper(0) if ok: return wallpaper else: return None
def ConnectKMail(): # Run KMail: if not os.system("kmail") == 0: raise Exception, "KMail cannot be started" # Create a dcop object: client = DCOPClient() if not client.attach(): raise Exception, "Cannot connected to KMail" # Keep this window on top: kmail = DCOPObj("kmail", client, "kmail-mainwindow#1") kmail.lower() # Return KMailIface kmail = DCOPObj("kmail", client, "KMailIface") return kmail
def setWallpaper(path): "Changes current wallpaper with the new one" # Copy file to wallpapers dir: wallpapersdir = os.path.expanduser("~/.kde/share/wallpapers") if not (os.path.isdir(wallpapersdir)): os.makedirs(wallpapersdir) newpath = os.path.join(wallpapersdir, os.path.basename(path)) shutil.copyfile(path, newpath) # Create a dcop object: client = DCOPClient() if not client.attach(): raise WallpaperError, "Wallpaper cannot be changed" # Set Wallpaper: background = DCOPObj("kdesktop", client, "KBackgroundIface") ok, wallpaper = background.setWallpaper(QString(unicode(newpath)), 6) # 6: Scaled if not ok: raise WallpaperError, "Wallpaper cannot be changed"
def openComposer(to='', cc='', bcc='', subject='', message=''): interfaces = [('kmail', 'default'), ('kontact', 'KMailIface')] client = DCOPClient() client.attach() done = False for app, part in interfaces: obj = DCOPObj(app, client, part) try: obj.openComposer(to, cc, bcc, qstr(subject), qstr(message), False, KURL()) done = True break except TypeError: pass return done
def addMessage(folder, message, kmail=None): "Adds a message to kmail with dcop interface" if not kmail: # Create a dcop object: client = DCOPClient() if not client.attach(): raise Exception, "Message cannot be added" kmail = DCOPObj("kmail", client, "KMailIface") # Add Message: ok, status = kmail.dcopAddMessage(QString(folder), message, "") if not ok: raise DCOPError, "Can not connect to kmail with DCOP" elif status == -4: raise DuplicateMessage, "Message in %s cannot be added: duplicate message" % folder elif status == -2: raise MailError, "Message in %s cannot be added: cannot add message to folder" % folder elif status == -1: raise MailError, "Message in %s cannot be added: cannot make folder" % folder elif status == 0: raise MailError, "Message in %s cannot be added: error while adding message" % folder elif status != 1: raise MailError, "Message in %s cannot be added, status: %d" % (folder, status) else: return True