39
39
self.parser.add_option("--plugin", dest="plugin", default="shell", type="string", metavar="NAME", help=u"default:[%default] The plugin to use, the following are currently supported: deluge, email, exaile, feedparser, forecast, googlecalendar, null, pidgin, processinfo, rhythmbox, shell, tomboy, twitter")
40
40
self.parser.add_option("--css", dest="css", type="string", metavar="FILE", help=u"Override the css stylesheet file path to use for html output")
41
41
self.parser.add_option("--colour", dest="colour", type="string", default="default", metavar="NAME", help=u"default:[%default] Override the default css stylesheet colour, if css is overridden this option will not apply. Colour names supported are: default, white, black, green, blue")
42
self.parser.add_option("--noheader", dest="noheader", default=False, action="store_true", help=u"Turn off header output. This will override any header template setting to be nothing")
42
self.parser.add_option("--noheader", dest="noheader", default=False, action="store_true", help=u"Turn off header output. This will override any header template setting to be nothing")
43
43
self.parser.add_option("--headertemplate", dest="headertemplate", type="string", metavar="FILE", help=u"Override the header template for the plugin, default or config based template ignored.")
44
44
self.parser.add_option("--template", dest="template", type="string", metavar="FILE", help=u"Override the template for the plugin, default or config based template ignored.")
45
45
self.parser.add_option("--config", dest="config", type="string", metavar="FILE", help=u"Override the config for the plugin.")
50
50
self.parser.add_option("--y", dest="y", type="int", default=0, metavar="NUMBER", help=u"default:[%default] The required vertical placement from the top")
51
51
self.parser.add_option("--allworkspaces", dest="allworkspaces", default=False, action="store_true", help=u"If set output will be shown on all workspaces, rather than the current one")
52
52
self.parser.add_option("--wallpaper", dest="wallpaper", type="string", metavar="FILE", help=u"Override the wallpaper filepath in case it isn't found automatically")
53
self.parser.add_option("--noresize", dest="noresize", default=False, action="store_true", help=u"Turn off resizing of the wallpaper used/found. This will override default resizing to screen res, allowing the app to have an alternative background just for itself etc")
53
self.parser.add_option("--noresize", dest="noresize", default=False, action="store_true", help=u"Turn off resizing of the wallpaper used/found. This will override default resizing to screen res, allowing the app to have an alternative background just for itself etc")
54
54
self.parser.add_option("--windowmanager", dest="windowmanager", type="string", default="gnome", metavar="NAME", help=u"default:[%default] Tell the app which windows manager is in use, options are gnome, kde3, kde4, xfce4, compiz (compiz option is not implemented yet!)")
55
self.parser.add_option("--backgroundblend", dest="backgroundblend", default="0", type="int", metavar="NUMBER", help=u"default:[%default] The optional blending ratio for the backgroundcolour which is set. The default of 0 does no blending, the maximum of 100 will blend \"out\" all the wallpaper. Use this option to give some visual separation to the output from the wallpaper.")
56
self.parser.add_option("--backgroundcolour", dest="backgroundcolour", default="0,0,0", type="string", metavar="RGBValues", help=u"default:[%default] The optional colours to use for blending into the background. They should be input in the form \"R,G,B\". Not used if --backgroundblend=0")
55
57
self.parser.add_option("--verbose", dest="verbose", default=False, action="store_true", help=u"Outputs verbose info to the terminal (and logfile if setup) for both the main app and associated plugins")
56
58
self.parser.add_option("--version", dest="version", default=False, action="store_true", help=u"Displays the version of the script.")
57
self.parser.add_option("--logfile", dest="logfile", type="string", metavar="FILE", help=u"If a filepath is set, the main app and any associated plugins log errors to the filepath. If --verbose is set, verbose info will be logged to file.")
59
self.parser.add_option("--logfile", dest="logfile", type="string", metavar="FILE", help=u"If a filepath is set, the main app and any associated plugins log errors to the filepath. If --verbose is set, verbose info will be logged to file.")
59
61
def parse_args(self):
60
62
(options, args) = self.parser.parse_args()
105
107
self.htmloverride = "<h1>Plugin %s not found</h1>"%self.options.plugin
107
109
self.htmloverride = None
109
111
# setup default css for plugin if required, applying the colour option
110
112
if self.options.css == None:
111
113
self.options.css = app_path+"/style/plugin_"+self.options.plugin+"_"+self.options.colour+".css"
113
115
self.htmloverride = None
115
117
self.updateInfo()
117
119
self.logger.info("Outputting the following HTML:\n%s"%self.html)
119
121
# setup the window and show
120
122
#infowindow = gtk.Window(gtk.WINDOW_TOPLEVEL)
121
123
self.add(self.browser)
123
125
self.set_keep_below(True)
124
126
self.set_decorated(False)
125
127
self.set_skip_pager_hint(True)
126
128
self.set_skip_taskbar_hint(True)
127
129
self.set_double_buffered(True)
129
131
self.set_default_size(self.options.width, self.options.height)
130
132
self.set_gravity(gtk.gdk.GRAVITY_NORTH_WEST)
132
134
self.move(self.options.x,self.options.y)
134
136
# check to see whether we need to make the app "stick" on all workspaces or not
135
137
if self.options.allworkspaces == True:
140
142
if self.options.interval > 0:
141
143
# time to setup a refresh of the browser
142
144
gobject.timeout_add(self.options.interval*1000, self.updateInfo)
144
146
def updateInfo(self, widget=None):
146
148
if self.options.url != None:
147
149
self.browser.open(self.options.url)
150
152
if self.htmloverride != None:
151
153
self.browser.load_string(self.htmloverride, "text/html", "iso-8859-15", "about:")
155
157
pluginhtml = self.plugin.getHTML(self.options)
157
159
if self.background != None:
158
160
self.html = u"<html>\n<head>\n<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>\n<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"file://"+self.options.css+"\"/>\n</head>\n<body background=\"file://"+self.background+"\" style=\"background-attachment:fixed;\">\n"+pluginhtml+"\n</body>\n</html>\n"
160
162
self.html = u"<html>\n<head>\n<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>\n<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"file://"+self.options.css+"\"/>\n</head>\n<body>\n"+pluginhtml+"\n</body>\n</html>\n"
162
164
self.browser.load_string(self.html, "text/html", "iso-8859-15", "about:")
166
168
def updateBackgroundAndInfo(self, widget=None):
167
169
self.generateBackground(self.options.x,self.options.y, self.options.width, self.options.height)
168
170
self.updateInfo(widget)
172
def copyContentToClipboard(self, widget=None):
173
clipboard = gtk.clipboard_get()
174
clipboard.set_text(self.html)
170
177
def displayPopup(self, view, menu):
172
179
# remove all menu items from the popup, we want our own only!
173
180
items = menu.get_children()
174
181
for item in items:
175
182
menu.remove(item)
177
184
# add menu items as required
178
185
quititem = gtk.ImageMenuItem(gtk.STOCK_QUIT)
179
186
menu.append(quititem)
180
187
quititem.connect('activate', self.destroy)
182
189
reloaditem = gtk.ImageMenuItem(gtk.STOCK_REFRESH)
183
190
menu.append(reloaditem)
184
191
reloaditem.connect('activate', self.updateBackgroundAndInfo)
193
copycontent = gtk.ImageMenuItem(gtk.STOCK_COPY)
194
menu.append(copycontent)
195
copycontent.connect('activate', self.copyContentToClipboard)
188
199
def windowConfigure(self, window, event):
190
201
if (self.options.x,self.options.y) != window.get_position():
191
202
(self.options.x,self.options.y) = window.get_position()
192
203
output = "Window moved to %s,%s"%(self.options.x,self.options.y)
194
205
self.logger.info(output)
195
206
self.updateBackgroundAndInfo()
197
208
def generateBackground(self, x, y, width, height):
201
212
wallpaper = self.getWallpaperPath()
203
214
if os.path.exists(wallpaper) == True:
204
215
img = Image.open(wallpaper)
206
217
if self.options.noresize == False:
207
218
# scale the image to the screen resolution if not the same size
208
# this will not cater for all situations, but until retrieving the
219
# this will not cater for all situations, but until retrieving the
209
220
# root pixmap via Xlib is working this is the best option
210
221
disp = display.Display()
211
222
scr = disp.screen()
212
223
screensize = (scr.width_in_pixels, scr.height_in_pixels)
213
224
if img.size != screensize:
214
225
img = img.resize(screensize, Image.BICUBIC)
216
227
# crop the screen res based image and save for use
217
228
box = (x, y, x+width, y+height)
219
230
# crop the un-resized image based on the top left corner
220
231
box = (0, 0, width, height)
235
# get blending options and blend background into wallpaper
236
# only blend if necessary
239
blend = self.options.backgroundblend / 100.0
241
self.logger.error("Failed to interpret backgroundblend option, using default of 0...")
222
newimg = img.crop(box)
247
colours = self.options.backgroundcolour.split(",")
248
colour = (int(colours[0]),int(colours[1]),int(colours[2]))
250
self.logger.error("Failed to interpret backgroundcolour option, using default of 0,0,0...")
253
mask = Image.new(img.mode, img.size, colour)
254
img = Image.blend(img, mask, blend)
256
# save the img to use
223
257
tempfile = "/tmp/"+self.options.plugin+"_"+str(uuid.uuid1())+".jpg"
224
newimg.save(tempfile)
226
260
# delete the old background image if there
227
261
if self.background != None and os.path.exists(self.background):
228
262
os.remove(self.background)
232
266
self.logger.error("Invalid wallpaper, using nothing...")
233
267
self.background = ""
235
269
except Exception, e:
236
270
self.logger.error("Failed to setup a wallpaper, using nothing..."+"\n"+traceback.format_exc())
237
271
self.background = ""
239
273
def getWallpaperPath(self):
241
275
if self.options.wallpaper != None:
242
276
# handle home directory if passed
243
277
return os.path.expanduser(self.options.wallpaper)
246
280
# may need the screen number
247
281
#disp = display.Display()
250
284
if self.options.windowmanager.lower() == "gnome":
251
285
# use the nautilus wallpaper
252
286
gconf_path_wallpaper = '/desktop/gnome/background/'
253
287
client = gconf.client_get_default()
254
288
return client.get_string(gconf_path_wallpaper + 'picture_filename' )
256
290
elif self.options.windowmanager.lower() == "kde3":
257
291
return self.getShellCommandOutput("dcop kdesktop KBackgroundIface currentWallpaper 0")
259
293
elif self.options.windowmanager.lower() == "kde4":
260
294
return self.getShellCommandOutput("grep 'wallpaper=' ~/.kde/share/config/plasma-appletsrc | tail --bytes=+11")
262
296
elif self.options.windowmanager.lower() == "xfce4":
264
298
desktopxml = minidom.parse(os.path.expanduser("~/.config/xfce4/mcs_settings/desktop.xml")).documentElement
317
351
self.logger.addHandler(ch)
319
353
if self.options.logfile != None:
321
355
#create file handler and set level to debug
322
356
fh = logging.FileHandler(self.options.logfile)
323
357
if self.options.verbose == True:
324
358
fh.setLevel(logging.DEBUG)
326
fh.setLevel(logging.ERROR)
360
fh.setLevel(logging.ERROR)
327
361
fh.setFormatter(formatter)
328
362
self.logger.addHandler(fh)
333
367
def destroy(self, widget, data=None):
336
370
logging.shutdown()
338
372
# delete the background image
339
373
if os.path.exists(self.background):
340
374
os.remove(self.background)
342
376
if __name__ == "__main__":
344
378
parser = CommandLineParser()
345
379
(options, args) = parser.parse_args()
347
381
if options.version == True:
348
print >> sys.stdout,"gnome-desktop-info v.0.19"
382
print >> sys.stdout,"gnome-desktop-info v.0.20"
350
384
if options.verbose == True:
351
385
print >> sys.stdout, "*** INITIAL OPTIONS:"
352
386
print >> sys.stdout, " url:", options.url
353
387
print >> sys.stdout, " plugin:", options.plugin
354
print >> sys.stdout, " css:", options.css
388
print >> sys.stdout, " css:", options.css
355
389
print >> sys.stdout, " interval:", options.interval
356
390
print >> sys.stdout, " width:", options.width
357
391
print >> sys.stdout, " height:", options.height