Re: [Deskbar] New Volume Handler



This one uses theme icons. Thanks Raphael. The code is also greatly
simplified and commented a bit now.

Cheers
Mikkel

On Fri, 2005-10-14 at 21:16 +0200, Raphael Slinckx wrote:
> On Fri, 2005-10-14 at 19:55 +0100, Joao Inacio wrote:
> > On 10/14/05, Mikkel Kamstrup Erlandsen <kamstrup daimi au dk> wrote:
> > > Oh btw. The icons i attached to the volume handler should be extracted
> > > to data/art/...
> > >
> > 
> > hmm why not use the current theme's default icons?
> 
> Yes using the gtk theme named icons is the way to go.
> I can modify it when it's in CVS, or you can look at the file handler to
> see how to retreive the icons..
> 
> Raf
> _______________________________________________
> deskbar-applet-list mailing list
> deskbar-applet-list gnome org
> http://mail.gnome.org/mailman/listinfo/deskbar-applet-list
import os, sys, cgi
import ConfigParser
from os.path import join
from gettext import gettext as _

import deskbar
from deskbar.handler import Handler
from deskbar.handler import Match

import gtk, gnome, gnomevfs


NAME = "Search for Volumes"
EXPORTED_CLASS = "VolumeHandler"
PRIORITY = 150

NETWORK_URIS = ["http", "ftp", "smb", "sftp"]
AUDIO_URIS = ["cdda"]

factory = gnome.ui.ThumbnailFactory(gnome.ui.THUMBNAIL_SIZE_NORMAL)
icon_theme = gtk.icon_theme_get_default()

class VolumeMatch (Match):
	def __init__(self, handler, drive, icon=None):
		pixbuf = icon_theme.load_icon(drive.get_icon(), deskbar.ICON_SIZE, gtk.ICON_LOOKUP_USE_BUILTIN)
		deskbar.handler.Match.__init__(self, handler, drive.get_display_name(), pixbuf)
		self.__drive = drive
	
	def action(self, text=None):
		os.spawnlp(os.P_NOWAIT, "gnome-open", "gnome-open", self.__drive.get_activation_uri())
		
	def get_verb(self):
		return _("Open " +self.get_uri_desc()+ " <b>%(name)s</b>")
		
	def get_uri_desc (self):
		uri_scheme = gnomevfs.get_uri_scheme( self.__drive.get_activation_uri() ) 
		if uri_scheme in NETWORK_URIS:
			return _("network place")
		elif uri_scheme in AUDIO_URIS:
			return _("audio disk")
		else:
			return _("location")

class VolumeHandler (Handler):
	
	def __init__(self):
		deskbar.handler.Handler.__init__(self, "gnome-dev-harddisk.png")
		self.__locations = []
		
	def get_priority(self):
		return PRIORITY
		
	def query(self, query, max=5):
		result = []
		query = query.lower()
		
		# We search both mounted_volumes() and connected_drives.
		# This way an audio cd in the cd drive will show up both
		# on "au" and "cd".
		# Drives returned by mounted_volumes() and connected_drives()
		# does not have the same display_name() strings.
		for drive in gnomevfs.VolumeMonitor().get_mounted_volumes() + gnomevfs.VolumeMonitor().get_connected_drives():
			if not drive.is_user_visible() : continue
			if not drive.is_mounted () : continue
			if not drive.get_display_name().lower().startswith(query): continue
			result.append (VolumeMatch (self, drive))
		
		return result[:max]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]