2

I am trying to create a unity lens, how to execute a command when we select an entry from unity-lens in the following code results.append(url, icon, category, mime-type, text, comment, drag and drop url) i tried to set file://, but it opens the file with text editor (if it is not readable with text editor it do nothing) Please help

Thank you Vishnu V

0

1 Answer 1

1

You can connect to the activate-uri signal to perform actions on a result displayed in a lens.

Using Python

First, you need to connect the activate-uri signal in the Daemon's init function (where you connect the search-changed and filters-changed)

self.scope.connect ("activate-uri", self.activate_uri)

Then, create a activate_uri function in the Daemon.

def activate_uri(self, scope, uri):
  #Do stuff with uri here
  return Unity.ActivationResponse (handled = Unity.HandledType.HIDE_DASH, goto_uri = '')

This function takes the scope object and the url parameter from the result. url does not necessarily need to be a uri, but must be text. You can do whatever you want with the text in the function. At the end of the function, you need to return the Unity.ActivationResponse as detailed above in order to close the dash.

Have a look at http://bazaar.launchpad.net/~markjtully/+junk/calendar-lens/view/30/calendar-lens-daemon.py line 101 & 274-296 for an example of this in action.

Using Quickly or unity-singlet

With quickly, it is even easier: Add a function

def handle_uri(self, scope, uri): 
  # Do stuff with the uri here

to your lens class (in __init__.py). It will be automatically connected to the signal, you do not have to take care of this. Don't forget to add from gi.repository import Unity to your import statements.

2
  • Thank you for the reply, but i created lens using quickly edit ( source: developer.ubuntu.com/2012/04/…). But there is no Daemon class or init function. please help
    – Vishnu V
    Jun 19, 2012 at 14:40
  • @VishnuV: With quickly, it is even easier: Add a function def handle_uri(self, scope, uri): to your lens class (in __init__.py) with the content described by Teester for the activate_uri function. Tt will be automatically connected to the signal, you do not have to take care of this. Don't forget to add from gi.repository import Unity to your import statements. Jun 23, 2012 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .