Feeds:
Posts
Comments

Archive for the ‘Linux’ Category

Fixing Matlab errors in Ubuntu 12.10

I recently installed Ubuntu 12.10 in my system and found that the upgrade a lot of my system. A reasonable number of fixes were simple but some of them were very annoying. In this post I just wanted to discuss two specific errors I faced and how to fix them.

I use the student version of Matlab (32 bit) on a 64 bit machine. As part of upgrade to Ubuntu 12.10 , the installer removed multiple 32 bit files which caused the issue. When I tried to run Matlab , I got the following errors :

~/matlab/bin/matlab: 1: ~/matlab/bin/util/oscheck.sh: /lib/libc.so.6: not found

~/matlab/bin/glnx86/MATLAB: error while loading shared libraries: libXpm.so.4: cannot open shared object file: No such file or directory

The first error is mostly harmless – I will describe how to fix it later in the blog post. Fixing the first error needed to install 386 (32bit) version of few packages. Of course, fixing one exposed the next error and so on. In the interest of time, I will put all the packages in the single command.

sudo apt-get install libxpm4:i386 libxmu6:i386 libxp6:i386

Running the above command worked and allowed Matlab to run. However, I then faced another issue – when I tried to save a plot, it was failing again with the following error : (fixing first caused the second)

MATLAB:dispatcher:loadLibrary Can’t load ‘~/matlab/bin/glnx86/libmwdastudio.so’: libXfixes.so.3: cannot open shared object file: No such file or directory.
??? Error while evaluating uipushtool ClickedCallback

MATLAB:dispatcher:loadLibrary Can’t load ‘~/matlab/bin/glnx86/libmwdastudio.so’: libGLU.so.1: cannot open shared object file: No such file or directory.
??? Error while evaluating uipushtool ClickedCallback

 

To fix this, run the following command :

sudo apt-get install libxfixes3:i386 libglu1-mesa:i386

Finally, to fix the innocuous error :

~matlab/bin/matlab: 1: /home/neo/gLingua/matlab/bin/util/oscheck.sh: /lib/libc.so.6: not found

do the following :

sudo ln -s /lib/x86_64-linux-gnu/libc-2.15.so /lib/libc.so.6

Of course, make sure the libc-2.xx.so version is the correct one before running this command.

 

Hope this post helped !

Read Full Post »

Ubuntu Unity is a really cool and innovative approach for Ubuntu UI. There are many people who love it and many who hate it. I fall somewhere in the middle. I am really fascinated by the possibilities that Unity offers and hope that it becomes better as it matures. Lenses are one of the coolest pieces in Unity and unfortunately not much tutorial is written. So this is my stab to fill that void. I have tried to organize as many material as possible. Your comments on improving the article is always welcome !

In my tutorial on Unity , I mentioned that if no one else writes a Lens tutorial, I will write one and here it is 🙂 Lenses in Ubuntu are a really neat idea – One simplistic way is to view them as specialized search tools. You open the appropriate lens, type something and you get a list of results. But this explanation does not really do justice to the incredible amount of flexibility that they give. Lenses can group their results, have Unity render the results in different styles, have multiple sections that influence they way search is done and so on. Unity also provides a very powerful API that allows you to write literally anything that you can think of. This post will discuss the architecture, components and their potential capabilities in detail.

Ubuntu Lens Terminology

If you are using Unity, then you must be familiar with two default lens that come with it : Application lens and Files & Folders lens. Let me use that to explain the various parts of a Lens.

Places/Lenses : Both these words represent the same idea. Places is a terminology that was primarily used when Unity was introduced. Its usage is now slowly deprecated and the word Lenses is preferred. In the rest of this blog post, I will refer it as Lenses for uniformity. Let us take a look at the various parts of lens by taking the application lens as an example.

If you click on the Application lens, you can see that it is split into two important pieces. At the top, is a search textbox like entity that allows you to enter the query. At the bottom is the results pane that shows results of your query. At the left end of the search textbox is a search result indicator. When the search is still going on, the indicator will show a spinning circle. Once the search is done, it reverts to its default icon of a cross.

Sections : The simplest way to describe sections is that they behave like categories that are non overlapping. So if a given search query might result in different results when searched under different categories, each of the qualify as a section.

Consider a simple example – You are writing a lens for StackOverflow. You may want to search questions, tags, users and so on. The results of search query q as a question is not the same as when searching q as a tag. Hence questions, tags, users become sections. Unity allows you to easily have different sections and switch between them.

Sections are the entries in the dropdown list  at the right end of the search textbox. They are optional and many places need not have it. You can see all sections of a lens by clicking on the dropdown. Taking the example of Application lens, some of the sections are “All Applications”, “Accessories”, “Games”, “Graphics” etc.

Groups : Groups is a mechanism by which you can club certain search results under a meaningful entity. Each search result, might have one or more groups that allow you to organize the results. For eg, when you search in Application lens, the groups are “Most frequently used”, “Installed”, “Available for download” etc. Groups need not be non overlapping like sections. Given a search query, same result can occur in different groups. In addition, Unity allows you to have different icons for different groups. Also, each group can be rendered in a different style. I will discuss further details later in the blog post.

Difference between Sections and Groups : There are lot of differences between groups and sections. Sections are mostly non overlapping set of entries. Each section provides a different perspective of the same search query. In contrast, groups allow you to classify the search results from a query (and a section). Groups can be considered as a way to organize the results rather than influencing how the results are obtained (which the sections do).

Results : These are the output of a search query in a lens. Given a query and a section, you get a list of entries for results. Each of them can optionally be assigned to a group. Each result entry can display information about themselves in a concise way. In addition, Unity allows them to have any URI and a mime type. So the results of one lens might be files clicking which executes them. Or it can be results from web and clicking on them opens the link in a browser and so on. Unity also allows them to have custom icons.

Unity Lens – Technical Terminology

In the following section, we will discuss some terms used in Lens development.

DBUS : DBUS is one of the most important component in the development of lens. One way to view a lens is as a daemon that accepts a search query from Unity, does some processing and returns a result along with information on how to display them. DBUS is the conduit through which the entire communication between the daemon and Unity happens. For the purpose of the lens, you need to own a bus which will be used by Unity for communication.

Lens/Place Daemon : Lens/Place daemon is a program that exposes lens functionality. A single daemon can expose multiple lens functionalities. Each lens is identified by an entry. It accepts search string from Unity and sends out search results that annotated with group and other additional information.

Place File : A place file is how you inform Unity about the various lenses that your daemon is going to expose. It is a text file that ends with .place extension and usually placed in /usr/share/unity/places . It contains different groups of entries that describe the different lenses that are exposed.

Lens Entry : A lens or an entry in the place file is distinct entity that can accept a search query and provide appropriate results. Every place file contains atleast one lens entry. Every entry has a distinct location for itself in the Unity places bar (the vertical strip) on the left. The lens entry has 3 broad components : A model each for sections, groups and results. Results contain information about the groups they fall in and how to display themselves.

Results : As discussed above, a result is an entry that is the response to a query. A result can be assigned to one or more groups. In the most general sense, a result consists of 5 subparts :
(a) URI : This is a resource identifier to uniquely denote the location of search result. It can be a local item (file://) , web item (http://) and so on.
(b) Display Name : This is a name for the result that the user will see in the results pane.
(c) Comment : This is additional information about the result entry.
(d) MimeType : Since the URI can point to anything, it is important to inform Unity what action to perform when the user clicks on the result. The mimetype allows Unity to invoke the appropriate launcher.
(e) Icon : Each result can have its own icon to represent it visually. It can be an icon file or the generic name of the icon (eg video).

Renderer : Unity provides some flexibility in how the results are displayed. Each result falls into some group. We can request Unity to display each group in a specific way. This is accomplished by the use of renderers. When you setup the model for groups for the lens, we also specify how each group will be rendered. Some common renderers are :

(a) UnityDefaultRenderer : This is the default way to display the results. In this renderer, each result shows the icon and the display name beneath it.

Ubuntu Unity Lens results under UnityDefaultRenderer
(b) UnityHorizontalTileRenderer : In this renderer, the icon and display name for each result is shown. In addition, it also displays the comment associated with the result.

Ubuntu Unity Lens results under UnityHorizontalTileRenderer
(c) UnityEmptySearchRenderer : This renderer is used when the current search query returned no results. The result item construction is very similar to the results above. But the display name is displayed across the results pane.

Ubuntu Unity Lens results under UnityEmptySearchRenderer
(d) UnityShowcaseRenderer : I tried using it and the result was not much different from UnityDefaultRenderer. But according to the documentation, it should have a bigger icon.

Ubuntu Unity Lens results under UnityShowcaseRenderer
(e) UnityEmptySectionRenderer : I did not try this as it not make sense in the application I developed. Supposedly, it is used to imply that the current section is empty. If my interpretation is correct, then this is used when the current section returned no results for query but a different section might produce results. UnityEmptySearchRenderer on the other hand is used to imply that the current search query itself (regardless of the section) provides zero results.
(f) UnityFileInfoRenderer : Copying from the reference, this renderer is used in files place to show search results. Expects a valid URI, and will show extra information such as the parent folder and whatever data is in the comment column of the results.

Steps to write a Lens :

There are three major steps in writing a Lens.
(1) Writing a .place file
(2) Writing a Lens daemon
(3) If you want to distribute , Writing a service file

As an example, let us develop a Lens that does the following :
(1) It has two sections – In “Movie Names” section, only the names of the movie are shown. In “Genre” section, all movies are clubbed according to their genre which act as a groups. So if movie X is in genres Y and Z, X will be displayed in both groups Y and Z.
(2) Clicking on the result will open a browser and redirect to the IMDB page for the movie.
(3) The lens accepts queries from two places – When entered directly in the IMDB Lens and also from the dash. When searched from Dash , it will display movie names as a separate group.

At the initial state, the lens will look like this :

Ubuntu Unity Lens Initial state

For the sake of completeness, here is now it looks when you just search for Movie Names. Ubuntu Unity Lens Search for Movie Names

For the sake of completeness, here is now it looks when you just search for Genres. Basically, the results are grouped using the Genre. If a movie falls under multiple genres, it also falls into different groups. Ubuntu Unity Lens Search for Movie Genre

Let us take a look at how to write the IMDB lens as per the major steps above.

Writing a Place File :

As discussed above a place file contains the information that allows Unity to display the entries in the places bar. Information like which bus to use for communication, what shortcut to use etc are also involved. For the purpose of this tutorial, I will put up the place file I used for the IMDB lens. I will then explain the significance of each line. The file is named as imdbSearch.place and is placed in /usr/share/unity/places/ .

[Place]
DBusName=net.launchpad.IMDBSearchLens
DBusObjectPath=/net/launchpad/imdbsearchlens

[Entry:IMDBSearch]
DBusObjectPath=/net/launchpad/imdbsearchlens/mainentry
Icon=/usr/share/app-install/icons/totem.png
Name=IMDB Search
Description=Search Movies using IMDB
SearchHint=Seach Movies using IMDB
Shortcut=i
ShowGlobal=true
ShowEntry=true

[Desktop Entry]
X-Ubuntu-Gettext-Domain=imdbSearch-place

As you can see, the file has three sections. Each section contains a set of key-value pairs.

Place Section :
This is the simplest section and contains two key values – DBusName and DBusObjectPath. DBusName gives the name of the bus under which this entry can be found while DBusObjectPath provides the actual dbus object path. The names can be any valid DBus names.

Entry Section :
A place file can contain one or more entries. Each entry must contain a section that corresponds to it. Each entry will occupy a distinct location in the places bar. If there are multiple entries, each of them must have a unique name and object path. In the daemon code, all those entries must be added individually.

The various keys are :
DBusObjectPath : This is the DBus path used to communicate with this specific entry. Note that this path must be a child of mail DBusObjectPath. In our case, there is only one entry and hence we put it under the path “mainentry” of the original path.
Icon : Link to the icon file
Name : Name of the entry. When you hover over the entry in the places bar, this will be displayed.
Description : A long description of the lens. I am not sure where this is used.
SearchHint : This is the text that is displayed by default in the lens when the user selects it. In the image above, the search hint “Search Movies using IMDB”is displayed when the user selects the IMDB lens.
Shortcut : This gives the key which is used to trigger the lens. Of course, you can always use the mouse to select it. If this key is specified,then pressing Super+shortcut operns the lens. For the IMDB lens, pressing Super+i opens it.
ShowGlobal : This is an optional key and defaults to true. If it is set to false, then searches from the main dash are not sent to the lens. This seems to override the specification inside the lens daemon. ie If the place file specifies ShowGlobal as false and the daemon adds a listener to the event where user enters a query in the main dash, it is not invoked. Most of the time, I think it makes more sense for the lens to set this as false. For eg, it certainly does not make sense for IMDB lens to offer its service in the dash. Most of the time, when the user is searching in the dash, he is looking for some file or application. Polluting those results with IMDB results may not be wise. This is even more true if your lens takes a while to provide all the results.
ShowEntry : This is an optional key and defaults to true. If it is set to false, then the entry will not be displayed in the places bar. If this is set to false, then the Shortcut key becomes useless as well. Pressing the shortcut key does not invoke the lens. But if the ShowGlobal is set to true, then the lens will still be searchable via the dash. For eg, if for some reason, I decide that IMDB lens must only provide results to queries from dash I will set ShowGlobal to true and ShowEntry to false.

Desktop Entry Section :

This section is mostly optional. The most used key is that X-Ubuntu-Gettext-Domain. This key is used for internationalization purposes. If you want the lens should support internationalization, provide the appropriate entry name. If you are not familiar with internationalization in Ubuntu, there are two broad ways of achieving it : Either put all the translations statically in the file. Or put it in the appropriate .mo file which will then be put in some language-pack file. I included this line because Unity whines as “** Message: PlaceEntry Entry:IMDBSearch does not contain a translation gettext name: Key file does not have group ‘Desktop Entry'”.

Writing a Lens Daemon

The next step is to write a daemon that communicates with Unity over dbus path, does the search and returns annotated search results so that Unity can render them meaningfully. The daemon can be written in any language that support GObject introspection. Most common languages include C, Vala and Python. Vey informally, GOject is a mechanism by which bindings for other languages can be done relatively easily. The actual process needs multiple components. Based on the reference [2], this means that you must verify if the following packages are installed in the system – gir1.2-unity-3.0 , gir1.2-dee-0.5 and gir1.2-dbusmenu-glib-0.4 . Of course, the actual version numbers may change in the future. If installing does not make it work, look at the reference for additional instructions [2].

I will use the IMDB Search lens as an example to explain writing a lens daemon in Python. The full source code is in [1]. I will use snippets of the code to make the appropriate points. The first step is of course importing the appropriate libraries. If you see other Python lens file, they used to have a hack that probes Dee before importing Unity. In my tests I found it unnecessary. If you get some error in importing Unity, then take a look at other sample files [3] and do accordingly.

from gi.repository import GLib, GObject, Gio, Dee, Unity

The next step is to define the name of the bus that we will use to communicate with Unity. Note that this must exactly match the “DBusName” key in the place file.

BUS_NAME = "net.launchpad.IMDBSearchLens"

The next step is to define some constants for the sections in your lens. If your lens contain only one section, feel free to ignore the initial lines. Else define section constants appropriately. The only place where you will use these constants is to figure out which section the lens currently is in. The section ids are integers and are ordered from 0. Note that the order given here is the *exact* order in which the sections must be added to our lens in Unity.

Similarly, we can have constants for groups. Instead of creating lot of constants, I created the group ids dynamically. First, I create a list of all IMDB genres and use a hash to map the name to an integer (group id). Also note that I also have constants for groups – GROUP_EMPTY, GROUP_MOVIE_NAMES_ONLY and GROUP_OTHER.

One thing to notice is that if different sections have non overlapping groups, all of them must be defined here. Then based on current section, use the appropriate group. As an example, GROUP_MOVIE_NAMES_ONLY is used only with SECTION_NAME_ONLY. But we define it alongside other groups. Also note the group for empty, GROUP_EMPTY. This will be used if the search query returns no results.  As with sections, the order of groups defined here must exactly match the order in which they are added to group model. If you have reasonably small number of sections and groups, you can avoid the elaborate setup of writing constants.

SECTION_NAME_ONLY = 0
SECTION_GENRE_INFO = 1

allGenreGroupNames = [ "Action", "Adventure", "Animation", "Biography", "Comedy", "Crime", "Documentary", "Drama", "Family",    "Fantasy", "Film-Noir", "Game-Show", "History", "Horror", "Music",  "Musical", "Mystery", "News", "Reality-TV", "Romance", "Sci-Fi", "Sport", "Talk-Show", "Thriller", "War", "Western"]

numGenreGroups = len(allGenreGroupNames)
GROUP_EMPTY = numGenreGroups
GROUP_MOVIE_NAMES_ONLY = numGenreGroups + 1
GROUP_OTHER = numGenreGroups + 2

groupNameTogroupId = {}
#We create a hash which allows to find the group name from genre.
for i in range(len(allGenreGroupNames)):
        groupName = allGenreGroupNames[i]
        groupID = i
        groupNameTogroupId[groupName] = groupID

The next step is to define the skeleton of the lens daemon. It is a simple Python class. In the constructor, you define the entire model corresponding to each entry in the Lens. If you place file contains n entries, you will be defining n different PlaceEntryInfo. In our case we have only one. Hence we create a variable that points to the corresponding DBusObjectPath. It is impertative that the path exactly match DBusObjectPath of the entry.

Each PlaceEntryInfo consists of different models : sections_model, groups_model and results_model.  If you want the lens to respond to searches in dash, you will also need to setup global_groups_model and global_results_model . The code below contains information about the schema of the different models. You can consider them as more or less a code that can be blindly copied. If you want additional information about things that you can tweak in PlaceEntryInfo, take a look this url .

Note on Property based access :
One important thing to notice is that all the access is done using properties. There are two methods to do that :
(1) x.props.y
(2) x.get_property(“y”)

Choosing one of them is mostly based on your coding style. Choose one use it consistently.

class Daemon:
        def __init__ (self):
                self._entry = Unity.PlaceEntryInfo.new ("/net/launchpad/imdbsearchlens/mainentry")

                #set_schema("s","s") corresponds to display name for section , the icon used to display
                sections_model = Dee.SharedModel.new (BUS_NAME + ".SectionsModel");
                sections_model.set_schema ("s", "s");
                self._entry.props.sections_model = sections_model

                #set_schema("s","s") corresponds to renderer used to display group, display name for group , the icon used to display
                groups_model = Dee.SharedModel.new (BUS_NAME + ".GroupsModel");
                groups_model.set_schema ("s", "s", "s");
                self._entry.props.entry_renderer_info.props.groups_model = groups_model

                #Same as above
                global_groups_model = Dee.SharedModel.new (BUS_NAME + ".GlobalGroupsModel");
                global_groups_model.set_schema ("s", "s", "s");
                self._entry.props.global_renderer_info.props.groups_model = global_groups_model

                #set_schema(s,s,u,s,s,s) corresponds to URI, Icon name, Group id, MIME type, display name for entry, comment
                results_model = Dee.SharedModel.new (BUS_NAME + ".ResultsModel");
                results_model.set_schema ("s", "s", "u", "s", "s", "s");
                self._entry.props.entry_renderer_info.props.results_model = results_model

                #Same as above
                global_results_model = Dee.SharedModel.new (BUS_NAME + ".GlobalResultsModel");
                global_results_model.set_schema ("s", "s", "u", "s", "s", "s");
                self._entry.props.global_renderer_info.props.results_model = global_results_model

Once you have setup the models, you need to add listeners to events that you want to catch. The most important one is “notify::synchronized”. This called when Unity sets up your lens and wants to know the various groups and sections in your entry. In the code below, we add three different functions to that event. One gives the sections in the lens, other gives the groups and last gives the groups in dash.

Next we catch two events that are core to Lens – notify::active-search and notify::active-global-search . The first is triggered when the user searches something in the search textbox of the place while the second is triggered when user searches something in the dash. It is important to notice that the same search can trigger the events multiple times. By default, Unity does a decent job of batching calls providing search strings, but it is an important thing to consider if your lens does expensive operations. Take a look at the section of caching for additional details.

The event notify::active-section is triggered when the user changes the section of the lens by using the dropdown. You can then use your section constants to decide which section is currently selected.

notify::active is triggered when the user selects and leaves your place. Hence its an indirect way for your daemon to know if the lens is being visible to the user.

                # Populate the sections and groups once we are in sync with Unity
                sections_model.connect ("notify::synchronized", self._on_sections_synchronized)
                groups_model.connect ("notify::synchronized", self._on_groups_synchronized)

                #Comment the next line if you do not want your lens to be searched in dash
                global_groups_model.connect ("notify::synchronized", self._on_global_groups_synchronized)

                # Set up the signals we'll receive when Unity starts to talk to us

                # The 'active-search' property is changed when the users searches within this particular place
                self._entry.connect ("notify::active-search", self._on_search_changed)

                # The 'active-global-search' property is changed when the users searches from the Dash aka Home Screen
                #       Every place can provide results for the search query.

                #Comment the next line if you do not want your lens to be searched in dash
                self._entry.connect ("notify::active-global-search", self._on_global_search_changed)

                # Listen for changes to the section.
                self._entry.connect("notify::active-section", self._on_section_change)

                # Listen for changes to the status - Is our place active or hidden?
                self._entry.connect("notify::active", self._on_active_change)

Once you have set up the different models and functions to populate them, you need to add the entry to a PlaceController. If your lens has multiple entries, repeat the above process for each entry and once constructed call the add_entry of PlaceController to set them up. Note that the argument to PlaceController’s constructor is same as the DBusObjectPath for the Place section in your .place file.

                self._ctrl = Unity.PlaceController.new ("/net/launchpad/imdbsearchlens")
                self._ctrl.add_entry (self._entry)
                self._ctrl.export ()

Once we have setup all the models, the next step is to define the functions that are used.The first is to define the function that populates the entry’s section model. Note that we call append on the sections_model with two parameters : the name of the genre and an icon for it. You can also observe that when defined the “schema” of the sections_model, it accepted two strings. One other thing to note is the lack of use of any section constants – You must be careful to define the sections in the exact same order as the constants. In our case, it means that SECTION_NAME_ONLY followed by SECTION_GENRE_INFO.

        def _on_sections_synchronized (self, sections_model, *args):
                # Column0: display name
                # Column1: GIcon in string format. Or you can pass entire path (or use GIcon).
                sections_model.clear ()
                sections_model.append ("Movie Names", Gio.ThemedIcon.new ("video").to_string())
                sections_model.append ("Movie Genre", Gio.ThemedIcon.new ("video").to_string())

The next step is to define a set of groups. Due to the nature of this lens, we reuse the list to form it. Notice the use of UnityEmptySearchRenderer for the GROUP_EMPTY. For this example, I have used UnityHorizontalTileRenderer. Your lens might need some other renderer – Take a look at the renderer section above for a discussion of the different renderers.

                # Column0: group renderer, # Column1: display name, # Column2: GIcon in string format Or you can pass entire path (or use GIcon).
                groups_model.clear ()

                #Remember to add groups in the order you defined above (ie when defining constants)
                for groupName in allGenreGroupNames:
                        groups_model.append ("UnityHorizontalTileRenderer", groupName, Gio.ThemedIcon.new ("sound").to_string())
                #GROUP_EMPTY
                groups_model.append ("UnityEmptySearchRenderer", "No results found from IMDB", Gio.ThemedIcon.new ("sound").to_string())
                #GROUP_MOVIE_NAMES_ONLY
                groups_model.append ("UnityHorizontalTileRenderer", "Movie Names", Gio.ThemedIcon.new ("sound").to_string())
                #GROUP_OTHER
                groups_model.append ("UnityHorizontalTileRenderer", "Other", Gio.ThemedIcon.new ("sound").to_string())

The next step is to define the function that is called when the search changes in the place search box. Notice how we use the entry object to get the current section, the current results, current search query and so on. Finally, we invoke search_finished function which calls search.finished() which signals to Unity that we are done processing the query.

        def _on_search_changed (self, *args):
                entry = self._entry
                self.active_section = entry.get_property("active-section")
                search = self.get_search_string()
                results = self._entry.props.entry_renderer_info.props.results_model
                print "Search changed to: '%s'" % search
                self._update_results_model (search, results)
                #Signal completion of search
                self.search_finished()

There are other functions which we can detail. But mostly, they are very similar to code shown here. You can take a look at the python file linked below [1] for full glory.

So far all we have done is using some boilerplate code. From now on though, the code starts to differ based on the application. So I have not included the code that actually produces the results here. Take a look at the python file for details.

Testing Instructions

Once you have written the python file , you want to test your baby. Here are the steps :

(1) Include the following code in your daemon. This code was literaly copied from Unity Sample Place [3] code.

if __name__ == "__main__":
        session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
        session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None, 'org.freedesktop.DBus', '/org/freedesktop/DBus', 'org.freedesktop.DBus', None)
        result = session_bus.call_sync('RequestName', GLib.Variant ("(su)", (BUS_NAME, 0x4)), 0, -1, None)

        # Unpack variant response with signature "(u)". 1 means we got it.
        result = result.unpack()[0]

        if result != 1 :
                print >> sys.stderr, "Failed to own name %s. Bailing out." % BUS_NAME
                raise SystemExit (1)

        daemon = Daemon()
        GObject.MainLoop().run()

(2) Copy your place file to /usr/share/unity/places/ . If you have any custom icons, copy them to the location specified in your .place file.
(3) Open up a new terminal and invoke your daemon file. Also remember to set the executable bit on.
(4) Open up another terminal and type “setsid unity”. Using setsid is a very neat trick I learnt from the sample place file. Basically, it starts Unity in a new session. This forces it to read all the place files again. Also if you make any change to the daemon code, you can kill it and restart it. Unity will start communicating with your new daemon. Additionally, setsid will also ensure that Unity does not have controlling terminal but will still dump all debug information in the terminal it was opened.
(5) Open the lens and type your query and watch the results appear !

Debugging Checklist

If your lens is not working as expected, here are somethings to verify :

(1) Make sure that your place file is copied to /usr/share/unity/places .
(2) Make sure that busname and object path match exactly in your place file and your daemon file.
(3) Make sure that Python file has its executable bit on. This is important if you want to run it a service/daemon that runs automatically. More on that below.
(4) If you are simply testing it, then is your Daemon file running ? If you are running it as a service, is your service file contain information that match your place and daemon file ?
(5) Did you restart Unity  – preferably as “setsid unity”
(6) Did you make any recent changes to place file ? If so make sure it is copied and restart Unity.
(7) Check for any exception information in the terminal that you started your daemon. If its a service, enable logging and examing the log files.
(8) Check if your lens is actually started. If you used “setsid unity” in a terminal, it would be logging the various steps it does. One sample invocation showing successful starting of lenses is this :

    ** (<unknown>:6114): DEBUG: PlaceEntry: Applications
** (<unknown>:6114): DEBUG: PlaceEntry: Commands
** (<unknown>:6114): DEBUG: PlaceEntry: Files & Folders
** (<unknown>:6114): DEBUG: PlaceEntry: IMDB Search
** (<unknown>:6114): DEBUG: /com/canonical/unity/ applicationsplace
** (<unknown>:6114): DEBUG: /com/canonical/unity/filesplace
** (<unknown>:6114): DEBUG: /net/launchpad/imdbsearchlens

(9) If your lens works but puts results in strange groups, make sure that order of groups in synchronize and the constants are same.
(10) Common errors and fixes :


** Message: PlaceEntry Entry:IMDBSearch does not contain a translation gettext name: Key file does not have group ‘Desktop Entry’ :

This is not an error. If this annoys you add a [Desktop Entry] section. See above for details.

** (<unknown>:6114): WARNING **: Unable to connect to PlaceEntryRemote net.launchpad.IMDBSearchLens: No name owner

This is again not an error but indicates that either your daemon program is not running or is not able to own the bus specified in the .place file.

Installation Instructions

Since I primarily wrote the IMDB lens for learning Unity, I do not know much about the actual installation process. Here are some generic tips :

(1) If you want a simple method of installation, use distutils. It accepts a list of files and the location where they must be copied. This is the cleanest way.
(2) If you are going to install it and expect the lens to start automatically, then you should write a .service file that knows which bus start and which file to invoke to make that happen. The service file is usually put in “/usr/share/dbus-1/services/” . In this case, also make sure that the daemon file is actually executable !

[D-BUS Service]
Name=net.launchpad.IMDBSearchLens
Exec=/path/to/daemom/file

Various Tips On Writing Lenses

(1) Most of the simple daemons use constants for sections and groups. If you want them to setup them up dynamically, take a look how it is done in the IMDB lens.
(2) Avoiding repeated searches :
When the user enters a query in the lens, it is not necessary that the search function will be called only once. Remember that there is no concept of return key to indicate that query is complete. In fact, if the user presses the return key, it selects (and opens) the first result. The way Unity handles this scenario is by batching the calls. Lets say the user wants to search “blah blah2”. If the user continuously types the query with minimal interruption of the keyword, then the entire query will be sent to lens in one shot. On the other hand, if the user is a slow typer and enters “blah b” before waiting for a second or so, Unity will call the search function with partial query. When the user completes the query , the lens will be called with the entire query.

This behavior complicates your lens behavior, especially if the processing is time consuming. There are different techniques to avoid running calculations repeatedly (IMDB lens uses the first two techniques):
(a) Have a cutoff : Your code might decide not to search if the length of string is less that say 4 characters.
(b) Have a cache with timeout : You can use a local cache that stores your previous results . When you get a new query, check your cache first and return the results from it. For added benefit, have a cache timeout that removes elements that were added long time ago.
(c) Memoize using functools : A very cool technique that is used in other lenses is to memoize the function call. This technique works if the function is reasonably simple – the key is the function argument and the value is the return value of the function. One simple example is shown below. In the example, we defined a decorator called memoize_infinitely and apply it to function foo. Foo accepts an input and returns an output. This decorator, automagically creates a cache for each function. When the function is called with some argument, it is first checked in the cache. If it is found, then it is returned without invoking the function. Else the function is called and the result is stored in the cache. This technique is widely used. For a specific example,take a look at the AskUbuntu lens [3] .

import functools
def memoize_infinitely(function):
    cache = {}
    @functools.wraps(function)
    def wrapped(*args):
        if not args in cache:
            cache[args] = function(*args)
        return cache[args]
    return wrapped

@memoize_infinitely
def foo(input):
	return input + 1

(3) Handling long computations :
If your lens returns lot of results or the processing for each result entry takes a lot of time, then its a good idea to display the information as it arrives. The results model has a function called flush_revision_queue which periodically sends the data so far to Unity. For eg, in the case of IMDB lens , fetching the genre information is expensive. So, the code flushes the results every time five movies were processed. This allows the user to see some results without waiting for eternity to get complete results.

Links

    [1] The code for IMDB lens which I have tried to comment as much as possible is my github page. For convenience, I have also given the individual files : Readme, imdb-search.py, imdbSearch.place .

    [2] Unity Places – now with 100% More Python : This blog post contains a brief discussion on developing Unity lenses in Python. It has some info on installation and links to a sample lens in Python. I would advise you to start with the sample lens code given in this blog post before making drastic changes. This way you can make sure that the initial lens setup is fine and the issue is really in your code 🙂
[3] Link to some Good Unity Python Lens codes : As of now there are few other good Unity lenses written in Python. Here are some of  my favorites – AskUbuntu lens, Launchpad lens, Evernote lens, Book-Search lens, Music search lens , Spotify lens . I have tried to incorporate all cool features in IMDB Search lens , so that it will become a one stop place for most important Lens features 🙂

    [4] Ubuntu Unity Architecture : This contains some language independent discussion of Unity architecture and additional information of the data structure it uses.
[4] IMDbPy : The IMDB search lens was developed using the excellent IMDbPy library. It has very convenient API that allows development of IMDB based applications a snap.

  [5] Ubuntu Unity Lens Python API Links : Here are some links for documentation that I found  – Dee API, Unity API . The document for Unity also encompasses the documentation for Places.

Read Full Post »

In this post , I assume that you use Ubuntu (with English) and want to use it to read or write Tamil stuff. Hence , I discuss steps to view Tamil web pages and also edit files in Tamil. This post will not tell you how to get a localized Tamil version of Ubuntu.

Reading Web Pages in Tamil

This is the most common requirement. You have Ubuntu and you want to visit and read , say, Tamil newspapers or blog posts. To do that install the following packages :

sudo apt-get install language-support-fonts-ta ttf-tamil-fonts ttf-indic-fonts-core

These three packages should solve the problem of Tamil fonts from multiple websites. ttf-indic-fonts-core  adds some popular Tamil fonts (in addition to other fonts for Indian languages) and ttf-tamil-fonts adds some more additional Tamil fonts.

Writing in Tamil

Writing in Tamil is done by adding Tamil keyboard layout to Ubuntu. If you are in a version before Natty (11.04), then use “System -> Preferences –> Keyboard” . If you are using Natty, then click on the power icon on the right hand top of the screen and select “System Settings”. In the settings dialog, choose Hardware tab and then select Keyboard. This will open up keyboard preferences menu.

Select the “Layouts” tab and click on Add . In the “Choose a Layout” dialog, go to the Language tab and select Tamil as the language. Choose your preferred variant . I have chosen “India Tamil Unicode”.  Click “Add” to add the language.

If you notice, the top panel will automatically get the keyboard layout indicator which highlights the currently selected language. This selection is application specific . For eg, if you selected Tamil when typing in gedit and then went to say LibreOffice, you will be typing in your default language in LibreOffice. Initially this behavior is a bit confusing, but usually makes lot of sense in practice.

In the Layouts tab, click on Options and set an appropriate key combination in the entry “Key(s) to change layout”.  I use “Shift+Caps Lock”. This is useful as otherwise , you need to key toggling in the keyboard indicator. If you are keyboard person, this is the best way to switch over all the languages in your layout. If there are multiple, then pressing “Shift+Caps Lock” cycles through your choices. The keyboard applet/indicator will change appropriately.

Unfortunately, most Tamil keyboard layouts are not mnemonic based and it takes quite a while to get used to. But once it starts working, it’s a great liberating feeling to type in another languages.

Using Tamil

Since Linux has a great internationalization support, you can use Tamil for other purposes also. For eg, I use Tamil to name folders ! Or sometimes even write some personal stuff 🙂 . Most applications including Nautilus has multilingual support and things should seamlessly !

Read Full Post »

R is one of the coolest language designed and I am having lot of fun using it. It has become my preferred language of programming next only to Python. If you are also using Ubuntu, the rate of update of R in Ubuntu’s official repositories is slightly slow. If you want to get the latest packages as soon as possible, then the best option is to add some CRAN mirror to your Ubuntu repository. This by itself is straightforward. I decided to write this post on how to solve the GPG error if you get it.

Steps

(1) Decide on which CRAN repository you want to use. Finding the nearest one usually gives the best speed. Lets say it is http://cran.cnr.berkeley.edu/ . Append "bin/linux/ubuntu". Typically this works. You can confirm this by going to this url in the browser too.
(2) Add this to your Ubuntu repository. There are multiple ways. In the steps, below, replace http://cran.cnr.berkeley.edu/bin/linux/ubuntu with your mirror

(a) Synaptic -> Settings -> Repositories -> Other Software -> Add . In the apt line enter "deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu natty/".
(b) sudo vim /etc/apt/sources.list and add "deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu natty/" at the end. If you are not comfortable with vim, use gedit but instead of sudo , used gksudo.
(c)sudo add-apt-repository deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu natty/

 

(3) Refresh the source repository by using refresh in Synaptic or using  "sudo apt-get update "
(4) Install R or any other package you want. If you are installing R , I suggest you install r-base-dev instead of r-base. If you are installing some R package , check if it exists with the name r-cran-* . Else, install it using install.packages command inside R.
(5) Enjoy 🙂

Fixing GPG Errors

When I did these steps, I got an error like the following (This occurred when I updated last month, this might be fixed now !):

GPG error: http://cran.cnr.berkeley.edu natty/ Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 51716619E084DAB9

If you get the error, enter the following commands in the terminal.

     gpg –keyserver keyserver.ubuntu.com –recv-key E084DAB9
     gpg -a –export E084DAB9 | sudo apt-key add –

Repeat the steps above and this should fix the key error.

Read Full Post »

Hamster is one of my favorite apps in Linux. I use it so much that I had previously written a post on it at Time Tracking in Linux using Hamster. One of the problems, I faced when I installed Natty was that it does away with the notification area (or systray). This means that the hamster applet will not be loaded in the panel automatically.

In the Launchpad, there exists a bug that discusses ways to add indicator support to Hamster. The author of Hamster has indicated that ,for now, he is not going to write a version for GNOME 3.0 (using GNOME Shell). I took a look at the code and it seems interesting – although I am not fully familiar with hamster graphics methods. If Unity support is not built into hamster in the near future, I will take a stab at it. In this article, I discuss some workarounds to still use Hamster in Ubuntu Unity or GNOME Shell  . They range from the easiest to hardest.

Method 1

If you are using Ubuntu Unity, the best alternative is to use the hamster version developed by Alberto Milone. The description of his work is this page – Appindicator for Hamster . Basically, he created a child class of HamsterApplet which has appindicator support. Pretty neat ! I browsed through the code and it seems straightforward. Hopefully, it will go into the upstream.

The instructions to use it are given in the linked page. Basically, you download the python code from hamster-appindicator’s github page. If you do not know how to use git , then just download the raw Python file . Put it in some folder and invoke it as "python hamster-indicator.py &". You can also add it to your Ubuntu startup applications !

Method 2

Since hamster applet is nothing but a Python app, you can technically invoke it as a standalone application instead of an applet. Most of the time, the utility must be in your path. You can invoke it as "hamster-time-tracker &" (or "python /usr/bin/hamster-time-tracker &") and by default, it will open a new stand alone window for the tracker. One thing to notice is that, this view does not have the "Add earlier activity" button. So this is only useful , if you want to add tasks starting now. Or you can muck around with Hamster’s use of negative time (-x a@b,c means I have been doing activity a of category b with description c for the last x minutes).

If you want to add earlier activities, invoke hamster as ,

    hamster-time-tracker toggle

  There are other options also. The entire list is overview|statistics|edit|preferences|about|toggle . The overview mode opens the "Overview" window that allows you to browse your activities for this week/month etc. The statistics mode shows a chart of your activities. The edit mode opens a new window that usually shows up when you click on "Add new activity". It allows you to enter activity,category, description, tags starting at arbitrary time.

The only catch is that it does not always visible and hence you might forget that it even exists ! If you are not as absent minded, then this is the best way to go (especially in GNOME 3.0 or GNOME Shell).

Method 3

Use this method, if none of the above works. This is only for masochistic hardcore geeks. The basic idea is to use the hamster-service that runs in the background and use the hamster’s command line utility. Just invoking the command line tool "hamster-cli" will give you a list of options. They are :

(1) list-activities : You can invoke this option to list all the activities and their respective categories. The format of output is activity@category . This is useful if you want to add a category using command line. The invocation is
    hamster-cli list-activities
(2) list-categories : This will show a list of all available categories. Usually this is superfluos as list-activities gives you the categories also.
(3) stop : This stops the task that is currently being tracked by hamster.
(4) list : This , by default(without arguments) , shows all the activities tracked for today. You can also give hh:mm-hh:mm option to display activities between specific time.

    hamster-cli list
    hamster-cli list 00:00-12:00

   
The first shows all of today’s tracked tasks while the second shows till 12 PM.

(5) start : The most important switch. This allows you to add a new activity – This can start now or at an earlier time. The format of entry is to give a activity with its category, optionally start time and description.

Currently, you cannot add new category or activity types using hamster-cli. You can only add/track a task using existing activity/category. If you want to add new activity/category use "hamster-time-tracker preferences" command to open Hamster’s preferences dialog which will allow you to do that .

    hamster-cli start "Blogging@Blogging"
    hamster-cli start "Blogging@Blogging,Hamster Post" 19:00-21:00
    hamster-cli start "Blogging@Blogging,Hamster Post" -00:40:00

The first invocation starts a new ongoing task of activity type Blogging and category type "Blogging" (after the @). The second invocation adds an earlier task of blogging between 7-9 PM. The third invocation starts a new task of blogging that started 40 minutes ago and still ongoing.

Hamster allows a more sophisticated time specification mechanism for start. I will put the details verbatim from the help of hamster-cli.

Time formats:
    * ‘YYYY-MM-DD hh:mm:ss’: Absolute time. Defaulting to 0 for the time
            values missing, and current day for date values.
            E.g. (considering 2010-03-09 16:30:20 as current date, time):
                2010-03 13:15:40 is 2010-03-09 13:15:40
                2010-03-09 13:15 is 2010-03-09 13:15:00
                2010-03-09 13    is 2010-03-09 00:13:00
                2010-02 13:15:40 is 2010-02-09 13:15:40
                13:20            is 2010-03-09 13:20:00
                20               is 2010-03-09 00:20:00
    * ‘-hh:mm:ss’: Relative time. From the current date and time. Defaulting
            to 0 for the time values missing, same as in absolute time.
           

To see other information, type "hamster-cli" without any arguments in the command line. It will show a helpful list of commands.

Method 4

One of the comments in the Launchpad asked for Hamster to behave like a docky helper. If thats your thing, follow the instructions at  this page . I have not personally tried it but hopefuly it will work.

Method 5

This is something I tried but did not work. Basically, I tried to add hamster to the whitelist of applications that are allowed to use notification area in Unity. You can find the details of how to enable any application to use systray at this askubuntu question.

I tried entering various incantations like hamster,Hamster,Time Tracker,hamster-time-tracker, hamster-tracker and so on. Somehow none of these worked. If anyone got it to work please let me know in the commands.

 

In conclusion, Hamster is one of the coolest apps in Linux and this post discusses some workaround for using it in Unity or GNOME 3.0 /GNOME Shell. Hopefully, indicator support will be built in the upstream itself soon. Have fun with Hamster !

Read Full Post »

In this post, I plan to talk about Ubuntu Unity. There has been hundreds of post on Unity . I will try to refrain from posting yet another Unity review. I assume that by choice or force, you are currently a Unity user. I plan to discuss how to make your life more productive by mastering it. So I will discuss various shortcuts, configurations and other cool stuff that I found in my 3 months(From Mar 2011) of active usage. Hence, this post will be slightly more technical. If you want an introductory post/review on Unity, check out the exceptional post by Ryan Paul here   .

Introduction

Unity has been one of the most controversial products released recently and the reaction has been surprisingly polarized. Lot of people hate it and lot of people love it. Whatever be your position, it is a good idea to learn to use the Unity paradigm because this is the direction that most of Linux community is moving. For eg, GNOME Shell, which is another popular alternative for Unity , also has similar design vision. So, it is safe to say Unity is a harbinger of a potential UI revolution in Linux. Whether this will cause more users to come to Linux is yet another matter 🙂

Terminology

Before we discuss about Unity, I think it is a good idea to give an orientation of various Unity components. This will help you when you read other posts or when you ask questions in some forums.

Unity :  Unity is nothing but a desktop “shell” to GNOME. GNOME Shell is yet another alternative. One of the key things to understand is that Unity was designed as lightweight shell as it was focused towards netbooks running Ubuntu. Understanding this will provide an appreciation of Unity’s design decisions. Since  it is targeted towards netbooks, it tries to conserve screen space as much as possible. Unity was ported to desktop in Natty. It is internally written as plugin for Compiz.

Ayatana : This is another name that you will come across. Ayatana can be considered as an umbrella project primarily focusing on UI and design stuff in Ubuntu. Some of the notable projects are Unity, Unity 2D,  MultiTouch, App indicators, Me-Menu and Notify OSD. See their launchpad page for more of the projects they run.

Unity-2D : Unity 2D can be considered as poor man’s Unity.  If your computer does not have the necessary hardware capabilities to run Unity, Unity-2D will act as the fallback. In Natty, the classic GNOME was provided as the fallback. Starting from Oneiric, Unity-2D will be the fallback. It is primarily written in QML and uses Metacity. Even Unity-2D replaces panel, launcher and other stuff.

Mutter , Clutter , Compiz and other stuff : Unity is primarily written as a plugin for Compiz window manager. The toolkit uses in Nux which is claimed to be faster than Clutter. Nux acts as an interface between Compiz and Unity. GNOME Shell uses Mutter (Metacity Clutter) as the window manager. Metacity is yet another window manager used in GNOME 2.2+ . Clutter is the toolkit. Both Nux and Clutter are opengl toolkits that provide convenient hardware based acceleration if available. This is the reason why both Unity and GNOME Shell uses a toolkit that has this support. For Unity 2D, the window manager is Metacity (even though Compiz can be used). If all of this confuses you , ignore it. Other than hard core geeks, nobody cares about these.

Wayland : This is a development that I am excited about. Wayland is primarily a display management system (also a protocol), just like X Window system. Instead of making some assumptions about Network and stuff, Wayland allows you to use native opengl to provide great graphics. The vision is quite fascinating and I hope it will turn out great.

Now that you know the overall big  picture, lets dive down to specific UI elements in Unity. The following text is based on my interpretation of Canonical’s design blog and this excellent AskUbuntu question  .

Ubuntu Button : This is the big button on the left top of the screen.

Launcher : This is the entire strip on the left that comes up when you hover over the left side of your screen. This will contain multiple types of icons. Icons that act as launcher icons for other applications, icons that show the currently running applications , lenses and workspace switcher.

Accordion : If you open lot of applications such that the launcher does not fit,  the icons are displayed in an accordion fashion – Basically, few of the icons are vertically stacked and if you hover your mouse over them it expands to show the icons that are present there.

Sigil : As said before, Launcher may contain some icons always – even if the application is not running. If the corresponding application is launched (or some other application), the icon in the launcher will contain a small white arrow called the sigil. It denotes that the application is currently running. The number of sigils denotes the number of instances of the same application.

Quicklist : Quicklists are another really cool idea in Unity. Although not as polished as Windows 7, it shows lot of promise. Quicklists are the common tasks that you do in an application that is accessible to you when you right click the application’s launcher item. Quicklists can be anything – For eg quicklist for a browser might be to open a new instance, open in incognito mode, go to specific site etc.  Alternatively, if you use Banshee/Rhythmbox, you can have all the music controls (Play/Pause/Next/Previous) in the right click.

Dash : The full screen black translucent overlay that appears when you press Super. Alternatively, you can click on the Ubuntu button. It contains a search option and also broadly classifies applications like Media, Internet etc.

Lenses : Lenses are one of the coolest ideas in Unity. Even though Dash allows you to search , its use is fairly limited to items in your computer. Lenses take the idea of the dash and extend it in such a way that it can search arbitrarily anything. You can kinda consider “Files and Folders” and “Applications” on the launcher as a special kind of lenses. They are currently called Places but their usage will be deprecated. There are lot of other cool lenses – For eg, one which searches sub-reddits , one that searches contacts , Amazon , Youtube etc. The API is also pretty awesome. I was able to code a lens to show the latest tweets of a user just by typing their name within couple of hours. If no one writes, I will write Lens tutorial sometime soon !

Panel : The strip that is at the top. The panel has been thoroughly given a facelift in Unity. It now performs lot of tasks. By default, it shows the title of the current active applications. When you hover your mouse over it , it shows the menu items of the applications. On the right hand side are the app indicators.

Global Menu : Also called as Application menu. When an application is active, this part of the panel will show the window controls  (Maximize/Minimize/Close) and the window title. If you hover over the panel or press Alt key, it changes to the menu of the application.

App Indicators : These are the icons on the right side for the panel.  By default it contains Sound, Network, Mail/Chat indicator, time , Me-Menu etc. You also add other indicators if you wish. To see the potential of these indicators, check out the sound indicator. It contains all the buttons to control playing and also allows you to select other playlists.

Overlay Scrollbar : Overlay scrollbar is one of the innovations in Unity designed to save space. In a typical application that needs scrolling, the scrollbars appear taking up valuable pixels. In Unity, the scroll bar appears as a thin strip. If you move your mouse over it, the classical scrollbar appears.

Keyboard Shortcuts for Accessing Unity Items

Exhaustively discussing all the features of Unity is beyond the scope of this blog post. If you are interested, see Ryan Paul’s article linked above. I will discuss the most important stuff and will intersperse mouse and keyboard based access. If you are a keyboard junkie, all of Unity’s keyboard shortcuts are here  .

Launcher : This can be activated by hovering over the left end of the screen. Alternatively, you can class keep pressing Super key for couple of seconds to make it visible. The initial delay is to prevent accidental invocation. If you are not comfortable with the default behavior, you can change it . See the section of unity configuration below. Since Unity removed the bottom panel that used to show active windows in the current workspace,  viewing the launcher is one way to see all the open applications.

Launcher Items : Once the launcher is visible , you can click on any launcher item to launch the application (if not already running) or bring it to the foreground. If you are a keyboard person, keep pressing the Super key. The launcher will appear with a character appearing on each of the icon. Pressing the character along with Super key will launch the application. For eg, Super+a starts the application places and Super+1 launches the application corresponding to the first icon in the launcher. Pressing Shift or using middle click will start a new instance.

Operations on Launcher Items : The default set of launcher items are not ideal and you many want to do some personalization. The simplest is reordering of icons. You can do it by either clicking on an icon and moving it up. Or you can click on it, pull it to the right and then place it at the right place.

If you want to remove a launcher item,you can drag the icon to the trash. Unfortunately, the obvious action of pulling the icon out of the launcher does not seem to remove the icon. If you have used any docks like docky or AWN , this might seem unintuitive.  If you want the icon to never appear in launcher, launch the application and right click on the icon and unselect ‘Keep in launcher’ option.

If you want to add a new application,the easiest way is to launch it by other means. Once the icon shows up in the launcher, right click it and select ‘Keep In Launcher’. Putting arbitrary application is a bit tricky. See the ‘Advanced’ section for details.

Lenses : Super+A opens the application places (lens) and Super+F opens the the Files and Folders lens. Super+T opens the trash.

Dash : Pressing Super and releasing it immediately brings the dash. If you use Alt+F2, it brings out Dash version of “Run” dialog.

App Indicators : Pressing F10 highlights the first app indicator menu which you can use keyboard navigation keys to select. To move to the other indicators press left or right arrow keys. For eg, pressing F10 for me opens the network indicator. Pressing right opens the volume indicator applet and so on. Of course, pressing Esc removes the focus from indicators.

Show Desktop : Pressing Super+D minimizes all the windows and shows the desktop. Pressing it again restores the windows.

Workspaces : If you press Super+W , it will create an Expose like effect showing all non minimized windows in all workspaces. If you want only for current workspace, type Shift+Alt+Up arrow. Moving a window to another workspace is not obvious as the bottom panel is removed. There are two ways : Press Super+S and it shows all the workspaces with the current window highlighted in current workspace. You can now use mouse to move window across the workspaces. If you want to move using keyboard, press Ctrl+Alt+Shift+ Arrow keys. You can may recognize that Ctrl+Alt+Arrow is the key combination to move across workspaces. Adding a shift, moves the window to the appropriate workspace.

Configuration and Personalization

One of the nicest things about is that it is highly configurable – Especially, if you do not mind getting your hands dirty with terminal stuff. In this section, I will discuss basic configuration of Unity and how to personalize it using quicklists and additional lenses.

To do the basic configuration, you would have to install “CompizConfig Settings Manager” (ccsm) from Synaptic. Once you have installed it press “Alt+F2” and enter “about:config” to access it. If you typed “ccsm” instead, search for Unity in the search box and get the “Ubuntu Unity Plugin” dialog.

 

My favorite settings are :
(1) Hide Launcher to “Dodge Windows”
(2) In Experimental tab, set “Backlight Mode” to “Backlight Toggles” . This will help you identify active and inactive launcher icons from their backlights.
(3) Launcher Icon size to 32 pixels.

 

Custom Launchers:
You might custom applications to your launcher. There are multiple ways to do that – The easiest is the following :
(1) Right click the desktop and select “Create Launcher”
(2) Set the launcher type – typically it is Application
(3) Enter the name of the launcher. This will be the name the Launcher icon will show if you hover over it or right click it.
(4) Enter the full command line path in Command field.
(5) Optionally enter a comment. You can also edit the icon by clicking on the icon’s icon 🙂
(6) Click ok and save the item. This will be saved in your desktop.
(7) Now drag this item on to the launcher.
(8) Voila ! The item is added to the launcher !

 

Custom QuickLists :
You can also create custom quicklists. The method is not very hard but involves editing configuration files manually.  The basic idea is as following :
(1) Find a similar .desktop file from /usr/share/applications/ and copy it to ~/.local/share/applications/ with the name as per your wish. Of course, you can keep it in any folder you wish but ~/.local/share/application is customary.
(2) If your .desktop file has a line like “OnlyShowIn=GNOME;”, change it “OnlyShowIn=GNOME;Unity;”
(3) At the end of the file , add the following line “X-Ayatana-Desktop-Shortcuts=shortcut1;shortcut2” . Replace shortcutx with your name of shortcuts. Each of them , except the last, must be separated by semicolon. It is better to have each shortcut name to be a single word.
(4) For each of the shortcut, add a section like this :

[shortcut1 Shortcut Group]
Name=Blah
Exec=Command to run
TargetEnvironment=Unity

(5) Things to note above are that the name of the shortcut at the beginning and in each section must match exactly.
(6) Go to this folder using Nautilus. If you want to see hidden files, press Ctrl+H. Or type “xdg-open ~/.local/share/applications/” in the command line. Now drag and drop the file you modified into Launcher.
(7) Remember, if you delete this desktop file, the launcher icon will also go !

One thing to realize is that to get access to these quicklists, the launcher icon need not always be in the Launcher. For eg, I want the quicklists for Banshee but I do not want Banshee’s icon cluttering up my space. If you are like me, make the change to the desktop file and put it in ~/.local/share/applications but do not drag and drop to Launcher. When you start the application, then Unity will automatically show the quicklist options. If the application is closed, the icon also goes away !

If you are too lazy to do all these, check out this link  for lot of awesome custom launchers and quick lists.

 

GNOME Applets :
Every Gnome user will have their own share of Gnome applets. Unfortunately, Gnome applets by themselves are not possible to be used directly in Unity. This is not just a Unity . The same holds for Gnome Shell too ! In Unity, they have to be adapted to use the indicator api to showup on the panel.

Systray Access :
You may use lot of applications that lands up in Systray. In Unity, you many notices that they are not shown at all. Most of the time , it does not really matter. But if you really wish to make the application show up, you need to add the application to a whitelist. The details are given in the following link  .

Lenses :
It is not very easy to create custom lenses without knowing programming. Some of the currently popular ones are given in the link  . I really like the Gwibber based lens. I am looking for a lens that uses tracker for better file search though.

Tips

This is a random collection of tips that I found useful. Some of them are discussed elsewhere in this post too !

(1) To launch a new instance of an application, middle click the launcher icon . Pressing Shift will also start a new instance.
(2) To move an application another workspace, make sure the application has the focus. Press Super+S and move the application to appropriate workspace. Alternative press Ctrl+Alt+Shift+ Arrow key to move it.
(3) If you like global menu bar and want Chrome to have it, enter “about:flags” in Chrome. Search and enable the “Experimental GNOME menu bar support” .
(4) To access the Unity settings manager, press Alt+F2 and type “about:config”. This directly gives the dialog to change Unity’s settings. To go to Compiz settings,  use “ccsm”. 
(5) If you mess up your Unity settings, try “unity –reset” .
(6) If you want to access special quicklist for an application but do not want the application taking up valuable space in Launcher when not active, there is a way to do that. Create the desktop file and put it in ~/.local/share/applications but do not drag and drop to Launcher. When you start the application, then Unity will automatically show the quicklist options. If the application is closed, the icon also goes away !
(6) If you were a hamster time tracking applet user and lost it in Unity, there is a hack that makes it work ! Check out this link for details http://albertomilone.com/wordpress/?p=502 . This works perfectly for my use !

Resources

There are lot of excellent links that helped me compile this list.
(1)  Ryal Paul’s in depth Unity review : http://arstechnica.com/open-source/reviews/2011/05/riding-the-narwhal-ars-reviews-unity-in-ubuntu-1104.ars .
(2) Power user’s guide to Unity : http://castrojo.tumblr.com/post/4795149014/the-power-users-guide-to-unity
(3) Unity Lens Architecture document : https://wiki.ubuntu.com/Unity/Lenses
(4) Unity place sample  : https://code.launchpad.net/~unity-team/unity-place-sample/unity-place-python

Read Full Post »

    I installed Natty Narwhal when the beta1 came few days ago. I wanted to write a blog post with the instructions to upgrade to Natty but kept postponing it due to Unity issues I was facing. Now that the system is working as I prefer, I thought I will put out a brief post on upgrading with a few tid-bits on using Unity. I am collecting some useful tips on Unity for the power users and will put out a post about it sometime soon.

    There has been lot of confusion about installing Natty. Most of the initial beta1 reviews were very critical with some calling it as the worst Ubuntu beta ever. I also had a horrible experience initially. During my initial install, Ubuntu Unity failed to work and the screen will have black patches wherever my mouse points. I tried lot of different configurations like installing Nvidia drivers or using Nouveau drivers and so on and nothing worked for almost a week. I was pretty disappointed. But after a week and few updates later, Unity started working like a charm. As of now , I do not have any issues in Natty so I can confidently advise people to upgrade it from Maverick.
       

To Upgrade or not to upgrade ?

    This is probably the first question you must decide – For me the answer is simple : If you are running some production server or anything sensitive , don’t install it. Just wait for two more weeks. The final version goes out on Apr 28th.  If it is your personal laptop, you are Linux geek and wanted to earn some karma, then what are you waiting for ? Start the upgrade ! Of course, there might be minor hitches and potential instability as it is still in beta – But if my experience is any guide, it is very stable now. The things you gain by installing outweighs the minor annoyances.

Upgrading to Natty from Maverick

    The conventional method that is specified in the Ubuntu website is to type the following in the terminal (or by pressing Alt+F2 and typing it in the Run dialog)

    update-manager -d

The other equivalent command is of course :

    update-manager –devel-release

Most of the time , I assume that this should do the job. Your update manager will open up, show that Natty (11.04) is available for download. All you need to do is click on "Upgrade" , sit back and relax !

For some reason, this upgrade took a huge amount of time. I had a reasonably fast internet but still the installation took almost 2 hours. Of course, your mileage will vary. The upgrade by itself was quite straightforward and no surprises.

What if you cannot see the upgrade option to Natty

1. Go to System -> Administration -> Software sources.
2. Click on the "Updates" tab and check "Pre-released updates".
3. Click on "Close" button. This will refresh the package list and most likely will open up the package manager that will show a huge list of packages to upgrade. Hopefully, it will also show "Natty Narwhal (11.04)" upgrade option.
4. Now close the update manager and open the Software sources again (same  as step 1). Now undo what you did in Step 2 – Un check the “Pre-released updates” option.
5. Click on "Close" button and the package list will be refreshed again. Now you should see the upgrade option to Natty saying : "New distribution release ‘11.04’ is available". You can alternatively run "update-manager -d" command to get this option !

Some Random Stuff

1. In case, Unity does not work for you , you can fall back to Ubuntu Classic. In the login screen, select your username and press enter. The control will go to the password textbox. Now, at the bottom of the screen, you will see a session selector. Select "Ubuntu Classic". This will allow you to have the classic GNOME-ish desktop.

2. One of my favorite Linux utilities – hamster-applet is not working in Natty due to the whole Unity and common menu thing. I need to figure out a way to make it work. There is a launchpad bug[https://bugs.launchpad.net/ubuntu/+source/unity/+bug/686062 ] which discusses the alternatives. Subscribe if you are interested.

3. The transition to Unity was very hard for me. This is especially true because I was a keyboard heavy user with lot of custom key bindings. Suddenly, all of them were useless. Even more annoying was the fact that GNOME-Do was not getting invoked when I pressed Super+Space as Unity gobble the keystroke. Unity did have a "gnome-do’-ish dash but it was a bit awkward to me. It was quite annoying when I have to remember that I need to press Alt-F2(Super-A) for searching applications and Super-F for files and folders. GNOME-Do has a more unified interface which is also more customizable as of now.

4. The fact that Unity uses the Super (Windows) key wrecked havoc on my keyboard shortcuts. In addition to GNOME-Do, I had other shortcuts like Windows-G for gedit, Windows-C for Chrome etc. So I searched a lot to find how to change the Unity’s default activation key. Most of the results were crap. The best result is given by this gem : http://askubuntu.com/questions/29553/how-can-i-configure-unity . Basically, you need to install ‘CompizConfig Settings Manager’. Invoke it and search for Unity. Click on ‘Ubuntu Unity Plugin’ and in the behavior tab, change the setting for the entry ‘Key to show the launcher’.

5. Some excellent links that details keyboard shortcuts for Unity are : http://askubuntu.com/questions/28086/unity-keyboard-mouse-shortcuts and http://www.multimediaboom.com/ubuntu-11-04-unity-keyboard-shortcuts-key/ .

 

Hope you have fun with Natty. I will put out a post soon on customizing Unity for power users.

Read Full Post »

Older Posts »