Wednesday, April 20, 2011

Disper indicator for switching Nvidia display modes on Ubuntu 11.04 Natty

This is a small Pyhton script which displays an indicator for Disper in Ubuntu 11.04 Natty (Unity desktop).

Disper can be found at http://launchpad.net/disper.

As far as I know this is the only command line utility which can handle the TwinView settings for Nvidia cards.


import gobject
import gtk
import appindicator
import commands

def single(w):
    commands.getstatusoutput('disper -s')

def extend(w):
    commands.getstatusoutput('disper -e')

def clone(w):
    commands.getstatusoutput('disper -c')

def add_menu_item(name, action):
  menu_item = gtk.MenuItem(name)
  menu.append(menu_item)
  menu_item.connect("activate", action)
  menu_item.show()
    
if __name__ == "__main__":
  ind = appindicator.Indicator ("disper-indicator",
                              "gsd-xrandr",
                              appindicator.CATEGORY_HARDWARE)
  ind.set_status (appindicator.STATUS_ACTIVE)

  menu = gtk.Menu()
 
  add_menu_item('Single', single)
  add_menu_item('Extend', extend)
  add_menu_item('Clone', clone)

  ind.set_menu(menu)

  gtk.main()
Post a Comment