All 9 entries tagged Gnome

View all 30 entries tagged Gnome on Warwick Blogs | View entries tagged Gnome at Technorati | There are no images tagged Gnome on this blog

May 15, 2015

Because 'dconf update' looks at modification time of directory not files

Are you making modifications to a dconf profile, running 'dconf update' and wondering why the settings aren't applying? I was. And this is why…


I have some dconf settings that I want to set conditionally and that's done by writing relevant value to a file like this:

#!/bin/bash

F=/etc/dconf/db/foo.d/blah

if [ "$(something)" = "yes" ];then
   V='true';
else
   V='false';
fi

cat > "${F}" << EOF
[what/ever/]
key=${V}
EOF

dconf update

/etc/dconf/db/foo.d/blah was getting updated, but the setting wasn't being applied. I noticed the binary database /etc/dconf/db/foo wasn't being updated, which was evident by the modification time stamp not changing after 'dconf update' was run.

Eventually I discovered that 'dconf update' doesn't look at the file modification times, it looks at the modification time of the directory containing the files. See https://bugzilla.gnome.org/show_bug.cgi?id=708258 Changing the contents of the file by writing to it with cat doesn't cause the modification time of the enclosing directory to change. So I needed to also change the modification time of foo.d, which can be done with touch

#!/bin/bash

F=/etc/dconf/db/foo.d/blah

[ as above cut for brevity ]

touch $(dirname ${F})
dconf update

With that additional touch command, things started to work as desired.


August 04, 2010

18 degrees celcius and rainy

Follow-up to 9 degrees celcius from Mike's blag

Looks like the new owners of Coventry Airport have found the switch that turns the weather data feed back on.

Right weather



July 29, 2010

Milking a meme – sad Keanu comes to www2

This Greasemonkey script here adds a depiction of sad Keanu to web pages hosted at www2.warwick.ac.uk (or perhaps more accurately, webpages created using Sitebuilder hosted at www2).

For example, here he is surveying http://www2.warwick.ac.uk/insite/

Sad Keanu on Intranet homepage


Special bonus script for GNOME users: Python script to display sad Keanu in GTK window

Displays a sad Keanu image in a transparent GTK window that you can position where you wish. E.g.

sad_keanu_gtk example

To move him hold down Alt and then click and drag. I was going to sit him on the bottom GNOME panel, but sadly it seems windows can't be set to be above the panel, so his legs aren't visible.


July 19, 2010

adding and removing items from gconf lists

So the other day I found myself wanting to add and remove items from a gconf key of type list. Reading and writing the whole list is easy, but I couldn't find a method for adding or removing an item from the list, nor a helpful blog or forum post describing someone else's method. So I wrote a script. It could probably be more efficient and there's at least one circumstance under which it won't work that I've already thought of and subsequently forgotten. But here it is anyway.

#!/bin/bash

# adds or removes an item from a gconf list

# N.B if you specify add, then the item will be added regardless of whether it
# is already in the list. if you only want to add the item but only if it's not
# already in the list, then call the script once with remove and then again with add

name=$(basename $0)

if [ $# -lt 3 ];then
echo "Usage: ${name} gconf_key item add|remove";
echo "E.g.:"
echo "${name} /apps/cheese/selected_effects vertical-flip add";
exit 1;
fi

if [ ! "$3" = "add" -a ! "$3" = "remove" ];then
echo "${name}: third argument must be either 'add' or 'remove'.";
exit 1;
fi

key=$1

item=$2

current_value=$(gconftool-2 --get ${key});

current_value=${current_value/[/}
current_value=${current_value/]/}

if [ "$3" = "remove" ];then

new_value=$(echo $current_value | tr ',' '\n' | grep -v ^${item}$ |tr '\n' ',' | sed 's/,$//');
# note removal of trailing , if present
elif [ "$3" = "add" ];then

# only want a , in front of ${item} if there's something in the list already
if [ -n "${current_value}" ];then
new_value="${current_value},";
fi
new_value="${new_value}${item}";
fi

new_value="[${new_value}]";
#echo $new_value

gconftool-2 --set $key --type list --list-type=string "${new_value}";




March 01, 2010

Staring at the

Writing about web page http://sohowww.nascom.nasa.gov/data/realtime-images.html

SOHO image wallpaper script grabs one or all of the latest SOHO images once an hour and sets it/them as your GNOME wallpaper. I was going to make it work for Mac OS X as well but by the time I'd found out how to set the relevant properties from a script I couldn't be bothered. (Mac OS X doesn't provide a way to set the background colour or the placement  (introduced in Snow Leopard) from a script. You have to alter the plist file and then restart the Dock as described here.)

Example screenshots:

$ ./soho_image_wallpaper

SOHO image wallpaper (all)

$ ./soho_image_wallpaper blue zoom

SOHO image wallpaper (blue zoom)


December 15, 2009

9 degrees celcius

The weather indicator in the top right of my GNOME desktop has been saying 9 degrees celcius for the last few days:

Wrong Weather

Which is clearly wrong. I think I've just worked out why it's not updating. A common source of weather data is airports. GNOME gets it's weather information from airports. For Coventry it uses Coventry Airport. Coventry Airport has been closed due to financial difficulties. Various sites which would usually display information from it's weather data feed all say 'no data'. So looks like the closure of Coventry Airport extends to it's weather data feed. Later on I might look at making it use an alternate data source.


December 03, 2009

University Advent Calender as your (though maybe not your) wallpaper.

Writing about web page http://www.warwick.ac.uk/adventcalendar/

For no good reason other than because the idea got stuck in my head, a script (advent wallpaper script) which grabs an image of the University advent calender, does some stuff to it, sets it as your wallpaper and then adds a launcher to the panel that when clicked shows what's 'behind' today's door with the icon for the corresponding door as it's icon. Assuming you use GNOME for your desktop environment that is. Which statistically speaking, you probably don't.

Example screengrab (to click is to make larger):

Uni Advent Calender as wallpaper



Requires ImageMagick, gnome-web-photo, curl and Epiphany (the web browser not the holiday). Call from a cron-job or login script of something to automatically update wallpaper should you feel the desire to do so.


November 24, 2009

Fun with xkcd, bash, Imagemgick and GNOME

A script (xkcdannotated) which takes an xkcd comic then annotates it with the title and alt text like so:

xkcd.com - Silent Hammer

Invoked with no arguments uses the most recent comic, can also be told to use a specific comic or to use a random comic. Tested on Linux and Mac OS X.

A script (xkcdwallpaper)which calls xkcdannotated then sets the result as your GNOME wallpaper. Arguments as per xkcdannotated. Can also be told to overlay the comic on top of another image and set the result as the wallpaper.


November 16, 2009

Generating Freedesktop.org spec compliant thumbnails

A lot of Linux software that needs to generate thumbnails of an image uses the freedesktop.org thumbnail specification. This is good as it means if one application has already made a thumbnail of an image then another application can make use of it rather than generating it's own. I recently found myself looking for a way to generate such thumbnails.

The impetus for this was gnome-appearance-properties. This is the application which allows you to do stuff like change your wallpaper. Sadly as the number of wallpapers available increases it's usability decreases to some extent. The reason for this is that the user interface is frozen until all the wallpaper thumbnails are displayed. This in itself isn't too bad, unless you have thousands of wallpapers, but if it's combined with a lack of pre-generated thumbnails the user interface is frozen until all the thumbnails have been generated. This is annoying because if there are few hundred wallpapers available thumbnail generation can take over thirty seconds even on a decent spec machine. Thirty seconds during which the user is left looking at an unresponsive interface. There is long standing bug report regarding this, that I can't currently locate, which makes the very sensible suggestion that the thumbnails should be loaded asynchronously. Hopefully at some point someone will implement that, but in the mean time I found myself wondering whether it was possible to script the generation of thumbnails in advance.

My first thought was ImageMagick and a bash script because I'm already familiar with those. As it turns out ImageMagick comes very, very close to being able to generate such thumbnails using the -thumbnail option. I say close, because whilst it inserts both the MTime and URI information required by the freedesktop.org spec, it generates the URI incorrectly by inserting one too many slashes at the start. It creates

$ convert /usr/share/pixmaps/backgrounds/cosmos/earthrise.jpg -thumbnail 128x foo.png
$ identify -verbose foo.png | grep Thumb::URI
Thumb::URI: file:////usr/share/pixmaps/backgrounds/cosmos/earthrise.jpg

when it needs to be

 Thumb::URI: file:///usr/share/pixmaps/backgrounds/cosmos/earthrise.jpg

At time of writing this is actually fixed, but only in the svn version. If you have 6.5.7-8 or later then you should find it generates the URI properly. If you have an older version you can create the thumbnails like this:

#!/bin/bash
# makethumb - script to generate thumbnails to freedesktop.org spec
# *** Assumes GNU coreutils. ***
file=$1
saveto=~/.thumbnails/normal
tagfile=/tmp/$(basename $0)_tags
mkdir -p $saveto
thumbname=$(echo -n file://$file | md5sum| cut -d " " -f 1);
mtime=$(date +%s -r "$file")
echo "Thumb::URI={file://${file}}" >$tagfile
echo "Thumb::MTime={${mtime}}" >>$tagfile
convert -resize 128x -strip +profile "*" $file MIFF:- | cat $tagfile - | convert MIFF:- "PNG:${saveto}/${thumbname}.png"
rm -f $tagfile
$ makethumb /usr/share/pixmaps/backgrounds/cosmos/earthrise.jpg

Generating thumbnails this way is quite slow though. Using

$ find  /usr/share/pixmaps/backgrounds/ -type f -exec ~/makethumb {} \;

332 thumbnails took around 1:15 in my tests, though obviously this will vary depending on the spec of the machine. I tried using a variant of the script which generated thumbnails for all the files in a given directory, so only invoking the script once instead of multiple times. There was no significant difference in speed between the two methods though.

So I started looking for some way to use GNOME's thumbnail generation capabilities. The only example I could find of doing this used Python GTK bindings and was incomplete. I've only ever cobbled together one python script before, (that was also to use GTK bindings), but I managed to put together this

#!/usr/bin/python
# makethumb.py - script to generate thumbnails using GTK bindings

import gnome.ui
import gnomevfs
import time
import sys
import os

file=sys.argv[1]

uri=gnomevfs.get_uri_from_local_path(file)
mime=gnomevfs.get_mime_type(file)
mtime=int(time.strftime("%s",time.localtime(os.path.getmtime(file))))
thumbFactory = gnome.ui.ThumbnailFactory(gnome.ui.THUMBNAIL_SIZE_NORMAL)
if thumbFactory.can_thumbnail(uri ,mime, 0):
thumbnail=thumbFactory.generate_thumbnail(uri, mime)
if thumbnail != None:
thumbFactory.save_thumbnail(thumbnail, uri, mtime)

Using that to generate thumbnails in the same manner shown above for the bash script was about ten seconds faster. However after some experimentation I put together this (updated 15/8/11 to include suggestions from comment 2):

#!/usr/bin/python
# makethumbs.py - generates thumbnails for all files in a directory

import gnome.ui
import gnomevfs
import time
import os

dir="/usr/share/pixmaps/backgrounds/"

thumbFactory = gnome.ui.ThumbnailFactory(gnome.ui.THUMBNAIL_SIZE_NORMAL)

for subdir, dirs, files in os.walk(dir):
for file in files:
path = os.path.join(subdir, file)
uri = gnomevfs.get_uri_from_local_path(path)
mime=gnomevfs.get_mime_type(subdir+"/"+file)
mtime = int(os.path.getmtime(path))
print uri
print mtime
if thumbFactory.can_thumbnail(uri ,mime, 0):
thumbnail=thumbFactory.generate_thumbnail(uri, mime)
if thumbnail is not None:
thumbFactory.save_thumbnail(thumbnail, uri, mtime)

I found that generates 332 thumbnails in around 9 seconds. A massive difference to repeatedly invoking the makethumb.py script. I expect there are people who could provide a detailed explanation of why it's so much faster. I am not one of them.

It's also interesting to note that I've found this script generates thumbnails around three times faster than the gnome-appearance-properties creates them. Why that is I have no idea. The thumbs that result are not identical. The thumbnails generated by the Python script have the width and height of the original image embedded in them whilst the ones generated by gnome-appearance-properties do not. The ones generated by gnome-appearance-properties have a very lightly larger file size and the Channel Statistics embedded in the thumbnails are different too. However both sets of thumbnails say they were generated by GNOME::ThumbnailFactory.

Interesting as all this is, (to me anyway if it's not to you then why did you read this far?), it's all about generating thumbnails on a per-user basis. What if it was possible to have a system wide cache of per-generated thumbnails. E.g. you install a bunch of wallpapers and along with them you can install thumbnails that will be used rather than each user generating their own. The freedesktop.org thumbnail spec does cover this. So I tried creating such thumbnails. gnome-appearance-properties ignored them. When I say ignored them, I don't mean it looked at them and didn't use them, the output of strace indicates that it doesn't even look to see they exist. Which is a shame.


Search this blog

Tags

RSS2.0 Atom
Not signed in
Sign in

Powered by BlogBuilder
© MMXXIV