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.

enter image description here

I want to change GUI menu of ubuntu. That is, I want to add a icon at the menu (top of screen), after clicking that a menu will be shown and selecting particular option will run a particular command.

Can some please help me

share|improve this question
    
do you have the option to alt-right click on the bar? –  pfeiffep Apr 6 '13 at 16:23
    
I am using gnome there is no such option on bar....I have added my desktop image in question –  TLE Apr 7 '13 at 7:27
    
In gnome session fallback I have that option - sorry I can't help –  pfeiffep Apr 7 '13 at 10:39

1 Answer 1

up vote 2 down vote accepted

You can create a simple python applet. Here is a very simple applet I have which I have noted where to put your commands and names for the commands:

#!/usr/bin/env python
import sys
import gtk
import appindicator
import subprocess
import os

repo_name = "Name Of Indicator"

def sh_escape(s):
    return s.replace("\"","\\\"")

class Commands:
    def __init__(self, title="Unknown", command=""):
        self.title = title
        self.command = command

commandArr = [];
commandArr.append(Commands("Command 1 name","command one"))
commandArr.append(Commands("Command 2 name","command two"))


class RemoteApplet:
    def __init__(self):
        self.ind = appindicator.Indicator(repo_name,
                                           repo_name,
                                           appindicator.CATEGORY_APPLICATION_STATUS)
        self.ind.set_label(repo_name)
        self.ind.set_status(appindicator.STATUS_ACTIVE)
        self.ind.set_attention_icon("new-messages-red")

        self.menu_setup()
        self.ind.set_menu(self.menu)

    def menu_setup(self):
        self.menu = gtk.Menu()
        self.command_items = []
        cnt = 0
        for x in commandArr:
            self.command_items.append(gtk.MenuItem(x.title))
            self.command_items[-1].connect("activate", self.handleitem, cnt)
            self.command_items[-1].show()
            self.menu.append(self.command_items[-1])
            cnt += 1
        self.quit_item = gtk.MenuItem("Quit")
        self.quit_item.connect("activate", self.quit)
        self.quit_item.show()
        self.menu.append(self.quit_item)

    def main(self):
        self.login()
        print "Started!"
        gtk.main()

    def quit(self, widget):
        sys.exit(0)

    def login(self):
        pass

    def handleitem(self, widget, index):
        print "Running... " + commandArr[index].command
        proc = subprocess.Popen(commandArr[index].command,stdout=subprocess.PIPE, shell=True)
        (out, err) = proc.communicate()
        os.system("/usr/bin/notify-send \"" + sh_escape(repo_name + " - Output") + "\" \"" + sh_escape(out) + "\"")


if __name__ == "__main__":
    print "Starting..."
    indicator = RemoteApplet()
    indicator.main()
share|improve this answer
    
But how can I create icon and by clicking on that I can run my commands. –  TLE Apr 7 '13 at 8:30
    
I would assume you would instead or running the line self.ind.set_label(repo_name) run `self.ind.set_icon('path-to-icon.jpg')' –  Benjamin Kaiser Apr 7 '13 at 10:31
    
This code only works in unity how to make it work in gnome. –  TLE Apr 14 '13 at 19:25
    
There is a bottom bar in Gnome 3 that has your applets. The applet will be there. –  Benjamin Kaiser Apr 15 '13 at 0:01

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.