Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '12 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. –  Marcel Stimberg Jun 23 '12 at 12:00
    
Thank you very much :-) Problem Solved :-) –  Vishnu V Jun 24 '12 at 13:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.