#!/usr/bin/env python # A script to store and restore the positions of objects and applets in the GNOME panel # Usage: panel-tool [store|restore] # # Copyright (C) 2009 Ben Thorp # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # or download from http://www.gnu.org/licenses/gpl.txt import gconf, sys, os if (len(sys.argv) != 2): print "Error: Incorrect number of parameters" print "Usage: panel-tool.py [store|restore]" sys.exit(2) if (sys.argv[1] not in ['store','restore']): print "Error: "+sys.argv[1]+" is not a valid parameter" print "Usage: panel-tool.py [store|restore]" sys.exit(2) config_file = "panel_tool_config.txt" # All the applets and objects will be identified by this toplevel_id panel_name = "top_panel_screen0" gconf_config = gconf.client_get_default() # Get all the applets applets = gconf_config.all_dirs('/apps/panel/applets') # Get all the objects objects = gconf_config.all_dirs('/apps/panel/objects') if (sys.argv[1] == "store"): print "Storing data" # Store output_data = "" for applet in applets: if (gconf_config.get_string(applet+'/toplevel_id') == panel_name): pos = gconf_config.get_int(applet+'/position') output_data += applet+","+str(pos)+"\n" for object in objects: if (gconf_config.get_string(object+'/toplevel_id') == panel_name): pos = gconf_config.get_int(object+'/position') output_data += object+","+str(pos)+"\n" store = open(config_file, 'w') store.write(output_data) store.close() else: print "Restoring from file" # Restore store = open(config_file, 'r').readlines() for line in store: data = line.split(',') current_value = gconf_config.get_int(data[0]+'/position') store_value = int(data[1][:-1]) if (current_value != store_value): print "Changing "+data[0]+" from "+str(current_value)+" to "+str(store_value) gconf_config.set_int(data[0]+'/position', int(data[1])) else: print "Ignoring "+data[0]+" - value "+str(current_value)+" = "+str(store_value) os.system("gnome-panel --replace &")