#!/usr/bin/python
"""
wmizer is a configuration tool for wmi.
Copyright (C) 2004  Wilson Oliveira

This file is part of wmizer.

wmizer 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 2 of the License, or
(at your option) any later version.

wmizer 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 wmizer; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""

import gtk
import gtk.glade 
import gtk.gdk
import gobject
import pango
import os
import sys
import re

class appgui:
	def __init__(self):
		self.xml = gtk.glade.XML("/usr/share/wmizer/wmizer.glade")
		self.xml.signal_autoconnect(self)

		widgets = ( # windows
					'main_window', 'open_file_dialog', 'save_file_dialog', 'about_dialog',
					# global
					'toolbuttonNew', 'toolbuttonOpen', 'toolbuttonRevert', 'toolbuttonSave',
					'toolbuttonSaveAs',	'toolbuttonAbout', 'toolbuttonQuit', 'comboboxMain',
					'notebookMain', 'statusbar',
					# actions
					'notebookActions', 'treeviewExtern', 'treeviewIntern', 'treeviewChain',
					'entryAlias', 'entryCommand', 'entryShortcut', 'labelAlias', 'labelCommand',
					'buttonGrab', 'buttonStop', 'buttonClear', 'buttonAdd', 'buttonRemove',
					'buttonApply',
					# common
					'checkbuttonBar', 'checkbuttonFrame', 'spinbuttonBorder',
					'spinbuttonResize',	'entryMenu', 'entrySlot', 'entryChain', 'entryTerminal',
					'radiobuttonfont1', 'radiobuttonfont2',
					# theme
					'exec_entry', 'fontbutton', 'font_entry',
					'theme_entry', 'author_entry', 'email_entry', 'area' )
		
		for widget in widgets:
			exec "self.%s = self.xml.get_widget('%s')" % (widget,widget)

		for i in range(1, 54):
			exec "self.colorbutton%s = self.xml.get_widget('colorbutton%s')" % (i,i)

		for i in range(1, 24):
			exec "self.radiobutton%s = self.xml.get_widget('radiobutton%s')" % (i, i)

		# liststore extern
		self.liststore_extern = gtk.ListStore(*[gobject.TYPE_STRING]*3)
		self.liststore_extern.set_sort_column_id(0, 0)
		self.treeviewExtern.set_model(self.liststore_extern)
		renderer=gtk.CellRendererText()
		column=gtk.TreeViewColumn('alias', renderer, text=0)
		self.treeviewExtern.append_column(column)
		column=gtk.TreeViewColumn('command', renderer, text=1)
		self.treeviewExtern.append_column(column)
		column=gtk.TreeViewColumn("shortcut", renderer, text=2)
		self.treeviewExtern.append_column(column)

		# liststore intern
		self.liststore_intern = gtk.ListStore(*[gobject.TYPE_STRING]*2)
		self.liststore_intern.set_sort_column_id(0, 0)
		self.treeviewIntern.set_model(self.liststore_intern)		
		column=gtk.TreeViewColumn('action', renderer, text=0)
		self.treeviewIntern.append_column(column)
		column=gtk.TreeViewColumn("shortcut", renderer, text=1)
		self.treeviewIntern.append_column(column)

		# liststore chain
		self.liststore_chain = gtk.ListStore(*[gobject.TYPE_STRING]*3)
		self.liststore_chain.set_sort_column_id(0, 0)
		self.treeviewChain.set_model(self.liststore_chain)
		column=gtk.TreeViewColumn('alias', renderer, text=0)
		self.treeviewChain.append_column(column)
		column=gtk.TreeViewColumn('chain', renderer, text=1)
		self.treeviewChain.append_column(column)
		column=gtk.TreeViewColumn("shortcut", renderer, text=2)
		self.treeviewChain.append_column(column)

		# paths and files
		home_dir = os.getenv('HOME')
		self.save_file_dialog.set_current_folder(home_dir + '/.wmi/')
		self.open_file_dialog.set_current_folder(home_dir + '/.wmi/')	
		self.actions_conf_file = home_dir + '/.wmi/actions.conf'
		self.actions_session_file = home_dir + '/.wmi/actions.session'
		self.common_file = home_dir + '/.wmi/common.conf'
		self.theme_file = ''
		
		# initialize "global" vars
		self.status_id = self.statusbar.get_context_id("status")
		self.pangolayout = self.area.create_pango_layout('')
		self.iter = None
		self.keys = []
		self.shortcut_grab = False
		
		# check if wmi is running
		wmi_grep = os.popen("pgrep -x wmi")
		if len(wmi_grep.read()) == 0:
			self.wmi_is_running = False
		else:
			self.wmi_is_running = True
		wmi_grep.close()
		
		# parsings
		self.parse_xmodmap()
		self.parse_actions()
		self.parse_common()

		self.clear_theme()
		self.comboboxMain.set_active(0)
		
	def on_toolbuttonNew_clicked(self, widget):
		
		self.theme_file = ''
		self.clear_theme()
		
		self.main_window.set_title("wmizer: new theme")
		self.statusbar.pop(self.status_id)
		self.statusbar.push(self.status_id, "new theme")

	def on_toolbuttonOpen_clicked(self, widget):
		self.open_file_dialog.show()
		
	def on_toolbuttonRevert_clicked(self, toolbutton):

		option = self.comboboxMain.get_active()
		
		if option == 0:
			# clear all liststores
			self.liststore_extern.clear()
			self.liststore_intern.clear()
			self.liststore_chain.clear()
			self.entryAlias.set_text("")
			self.entryCommand.set_text("")
			self.entryShortcut.set_text("")
		
			self.parse_actions()
			status_msg = "actions.conf reverted"
		elif option == 1:
			self.parse_common()
			status_msg = "common.conf reverted"
		else:
			if self.theme_file <> '':
				self.clear_theme()
				self.parse_theme()
				status_msg = "theme reverted"
			else:
				status_msg = "unsaved theme cannot be reverted"

		self.statusbar.pop(self.status_id)
		self.statusbar.push(self.status_id, status_msg)

	def on_toolbuttonSave_clicked(self, widget):

		option = self.comboboxMain.get_active()
	
		if option == 0:
			self.save_actions()
			
			self.statusbar.pop(self.status_id)
			self.statusbar.push(self.status_id, "actions.conf saved")			
		elif option == 1:
			self.save_common()
			
			self.statusbar.pop(self.status_id)
			self.statusbar.push(self.status_id, "common.conf saved")
		else:
			if self.theme_file == '':
				
				self.save_file_dialog.set_current_name("theme.conf")
				self.save_file_dialog.show()
			else:
				self.save_theme()

	def on_toolbuttonSaveAs_clicked(self, widget):
		if self.theme_file == '':
			self.save_file_dialog.set_current_name("theme.conf")
		else:
			self.save_file_dialog.set_filename(self.theme_file)
		self.save_file_dialog.show()

	def on_toolbuttonAbout_clicked(self, widget):
		self.about_dialog.show()

	def on_comboboxMain_changed(self, combobox):
		if combobox.get_active() == 0:
			self.toolbuttonNew.set_sensitive(False)
			self.toolbuttonOpen.set_sensitive(False)
			self.toolbuttonSaveAs.set_sensitive(False)
			self.notebookMain.set_current_page(0)
			
			self.main_window.set_title("wmizer: " + self.actions_conf_file)
		elif combobox.get_active() == 1:
			self.toolbuttonNew.set_sensitive(False)
			self.toolbuttonOpen.set_sensitive(False)
			self.toolbuttonSaveAs.set_sensitive(False)
			self.notebookMain.set_current_page(1)

			self.main_window.set_title("wmizer: " + self.common_file)
		else:
			self.toolbuttonNew.set_sensitive(True)
			self.toolbuttonOpen.set_sensitive(True)
			self.toolbuttonSaveAs.set_sensitive(True)
			self.notebookMain.set_current_page(2)

			if self.theme_file == '':
				self.main_window.set_title("wmizer: new theme")
			else:
				self.main_window.set_title("wmizer: " + self.theme_file)

	def on_fontbutton_clicked(self, widget):
		self.radiobuttonfont1.set_active(True)
	
	def on_font_entry_insert_text(self, widget, *args):
		self.radiobuttonfont2.set_active(True)

	def on_open_file_dialog_response(self, dialog, response, *args):
		if response == gtk.RESPONSE_OK:
			self.clear_theme()
			self.theme_file = dialog.get_filename()			
			self.parse_theme()
			self.close_dialog(dialog)

			self.main_window.set_title("wmizer: " + self.theme_file)
			self.statusbar.pop(self.status_id)
			self.statusbar.push(self.status_id, "theme loaded")
		else:
			self.close_dialog(dialog)

	def on_save_file_dialog_response(self, dialog, response, *args):
		if response == gtk.RESPONSE_OK:
			self.theme_file = dialog.get_filename()
			if self.theme_file <> '':
				self.main_window.set_title("wmizer: " + self.theme_file)
				self.save_theme()
			self.close_dialog(dialog)
		else:
			self.close_dialog(dialog)

	def close_dialog(self, dialog, event=None):
		dialog.hide()
		return gtk.TRUE

	def gtk_main_quit(self, *args):
		gtk.main_quit()

##########################
# ACTIONS.CONF FUNCTIONS #
##########################

	def parse_actions(self):

		files = []	
		# actions.conf
		try:
			f = open(self.actions_conf_file)
		except IOError:
			pass
		else:
			f_actions_conf = f.read().splitlines()
			f.close()
			files.append(f_actions_conf)

		# actions.session
		try:
			f = open(self.actions_session_file)
		except IOError:
			pass
		else:
			f_actions_session = f.read().splitlines()
			f.close()
			files.append(f_actions_session)

		extern = []
		intern = []
		chain = []		
		for actions_file in files:
			for line in actions_file:
				# find "extern.alias.cmd" line
				if re.match("extern\..+?\.cmd(\s)?=(\s)?.+", line):
					index1 = line.index('=')
					index2 = line[:index1].index(".cmd")
					alias = line[7:index2]

					# avoid duplication
					exists = False
					for i in extern:
						if alias == i[0]:
							exists = True
					if exists:
						continue

					command = line[index1+1:].strip()
					if command[0] == '"' and command [-1] == '"':
						command = command[1:-1]
				
					# find correspondent "extern.alias.keys" line
					shortcut = None
					for line2 in actions_file:
						if re.match("extern\.%s\.keys(\s)?=(\s)?.+" % (alias), line2):
							shortcut = line2[line2.index('=')+1:].strip()
							break
	
					if shortcut:
						extern.append([alias, command, shortcut])

				# find "intern.alias.keys" line
				elif re.match("intern\..+?\.keys(\s)?=(\s)?.+", line):
					index1 = line.index(".keys")
					action = line[7:index1]

					# avoid duplication
					exists = False
					for i in intern:
						if action == i[0]:
							exists = True
					if exists:
						continue

					shortcut = line[line.index("=")+1:].strip()
					intern.append([action, shortcut])

				# find "chain.alias.keys" line
				elif re.match("chain\..+?\.keys(\s)?=(\s)?.+", line):
					index1 = line.index('=')
					index2 = line[:index1].index(".keys")
					alias = line[6:index2]

					# avoid duplication
					exists = False
					for i in chain:
						if alias == i[0]:
							exists = True
					if exists:
						continue
				
					shortcut = line[index1+1:].strip()

					# find correspondent "chain.alias.seq" line
					chainseq = None
					for line2 in actions_file:
						if re.match("chain\.%s\.seq(\s)?=(\s)?.+" % (alias), line2):
							chainseq = line2[line2.index('=')+1:].strip()
							break

					if chainseq:
						chain.append([alias, chainseq, shortcut])			

		self.fill_textviews(extern, intern, chain)
		self.changed_alias = {}
		self.removed_alias = []

	def fill_textviews(self, extern, intern, chain):

		for i in extern:
			self.liststore_extern.append((i[0], i[1], i[2]))
		
		for i in intern:
			self.liststore_intern.append((i[0], i[1]))
		
		# add the remaining intern functions
		try:
			f = open("/usr/share/wmizer/intern_functions.list")
		except IOError:
			pass
		else:
			functions = f.read().splitlines()
			f.close()
			for i in functions:
				exists = False
				for j in intern:
					if i == j[0]:
						exists = True
						break
				if not exists:
					self.liststore_intern.append((i, ""))
		
		for i in chain:
			self.liststore_chain.append((i[0], i[1], i[2]))

	def save_actions(self):

		if self.wmi_is_running:
			for alias in self.removed_alias:
				os.system("wmiremote -a destroy-action+" + alias)
				
		f = open(self.actions_conf_file, 'w')
		self.liststore_extern.foreach(self.print_to_action_file, (0, f))
		self.liststore_intern.foreach(self.print_to_action_file, (1, f))
		self.liststore_chain.foreach(self.print_to_action_file, (2, f))
		f.close()

		try:
			os.remove(self.actions_session_file)
		except OSError:
			pass

		self.changed_alias = {}
		self.removed_alias = []
		
	def print_to_action_file(self, model, path, iter, user_data):
		
		option = user_data[0]
		f = user_data[1]
		
		if option == 0:
			alias = model.get_value(iter, 0)
			command = model.get_value(iter, 1)
			shortcut = model.get_value(iter, 2)
			print >> f, "extern." + alias + ".cmd=" + '"' + command + '"'
			print >> f, "extern." + alias + ".keys=" + shortcut
		elif option == 1:
			if model.get_value(iter, 1) <> '':
				action = model.get_value(iter, 0)
				shortcut = model.get_value(iter, 1)
				print >> f, "intern." + action + ".keys=" + shortcut
		else:
			alias = model.get_value(iter, 0)
			chain = model.get_value(iter, 1)
			shortcut = model.get_value(iter, 2)
			print >> f, "chain." + alias + ".keys=" + shortcut
			print >> f, "chain." + alias + ".seq=" + chain

	def on_notebookActions_switch_page(self, notebook, page, page_num):
		if page_num == 1:
			self.entryCommand.set_text("")
			self.labelCommand.set_sensitive(False)
			self.entryAlias.set_sensitive(False)
			self.entryCommand.set_sensitive(False)
			self.buttonAdd.set_sensitive(False)
			self.buttonRemove.set_sensitive(False)
			
			self.on_treeviewIntern_cursor_changed(self.treeviewIntern)
		else:
			self.labelCommand.set_sensitive(True)
			self.entryAlias.set_sensitive(True)
			self.entryCommand.set_sensitive(True)
			self.buttonAdd.set_sensitive(True)
			self.buttonRemove.set_sensitive(True)
			
			if page_num == 0:
				self.on_treeviewExtern_cursor_changed(self.treeviewExtern)
			else:
				self.on_treeviewChain_cursor_changed(self.treeviewChain)

	def on_treeviewExtern_cursor_changed(self, treeview):
		
		selection = treeview.get_selection()
		self.iter = selection.get_selected()[1]		
		
		if self.iter:
			self.entryAlias.set_text(self.liststore_extern.get_value(self.iter,0))
			self.entryCommand.set_text(self.liststore_extern.get_value(self.iter,1))
			self.entryShortcut.set_text(self.liststore_extern.get_value(self.iter,2))
		else:
			self.entryAlias.set_text("")
			self.entryCommand.set_text("")
			self.entryShortcut.set_text("")

	def on_treeviewIntern_cursor_changed(self, treeview):
		
		selection = treeview.get_selection()
		self.iter = selection.get_selected()[1]

		if self.iter:
			self.entryAlias.set_text(self.liststore_intern.get_value(self.iter,0))
			self.entryShortcut.set_text(self.liststore_intern.get_value(self.iter,1))
		else:
			self.entryAlias.set_text("")
			self.entryShortcut.set_text("")
			
	def on_treeviewChain_cursor_changed(self, treeview):
		
		selection = treeview.get_selection()
		self.iter = selection.get_selected()[1]

		if self.iter:
			self.entryAlias.set_text(self.liststore_chain.get_value(self.iter,0))
			self.entryCommand.set_text(self.liststore_chain.get_value(self.iter,1))
			self.entryShortcut.set_text(self.liststore_chain.get_value(self.iter,2))
		else:
			self.entryAlias.set_text("")
			self.entryCommand.set_text("")
			self.entryShortcut.set_text("")

	def parse_xmodmap(self):
		f = os.popen("xmodmap","r")
		f_list = f.read().splitlines()
		f.close()
		
		self.xmodmap = {}
		for line in f_list:
			line = line.split()
			if len(line) > 0 and line[0] <> 'xmodmap:':
				key = line[0]
				if key == 'control':
					key = 'ctrl'
				values = []
				for i in line[1:]:
					if i[0] <> '(':
						values.append(i)
				if len(values) > 0:
					self.xmodmap[key] = values

		self.modifiers = ('ctrl', 'shift', 'alt', 'mod1', 'mod2', 'mod3', 'mod4', 'mod5')
	
	def on_buttonGrab_clicked(self, widget):		
		self.buttonGrab.set_sensitive(False)
		self.buttonStop.set_sensitive(True)
		self.toolbuttonRevert.set_sensitive(False)
		self.toolbuttonSave.set_sensitive(False)
		self.toolbuttonAbout.set_sensitive(False)
		self.toolbuttonQuit.set_sensitive(False)
		self.buttonAdd.set_sensitive(False)
		self.buttonRemove.set_sensitive(False)
		self.buttonApply.set_sensitive(False)
		self.comboboxMain.set_sensitive(False)
		self.notebookActions.set_sensitive(False)
		self.entryAlias.set_sensitive(False)
		self.entryCommand.set_sensitive(False)
		self.labelAlias.set_sensitive(False)
		self.labelCommand.set_sensitive(False)

		self.shortcut_grab = True
		gtk.gdk.keyboard_grab(self.entryShortcut.window)
		gtk.gdk.pointer_grab(self.main_window.window,
								owner_events = True,
								confine_to=self.main_window.window,
								cursor=gtk.gdk.Cursor(gtk.gdk.MOUSE))

		self.entryShortcut.set_text("")
		
	def on_buttonStop_clicked(self, widget):						
		self.buttonGrab.set_sensitive(True)
		self.buttonStop.set_sensitive(False)
		self.toolbuttonRevert.set_sensitive(True)
		self.toolbuttonSave.set_sensitive(True)
		self.toolbuttonAbout.set_sensitive(True)
		self.toolbuttonQuit.set_sensitive(True)
		self.buttonApply.set_sensitive(True)
		self.comboboxMain.set_sensitive(True)
		self.notebookActions.set_sensitive(True)
		self.labelAlias.set_sensitive(True)
		
		page_num = self.notebookActions.get_current_page()

		if page_num <> 1:
			self.entryAlias.set_sensitive(True)
			self.entryCommand.set_sensitive(True)
			self.buttonAdd.set_sensitive(True)
			self.buttonRemove.set_sensitive(True)
			self.labelCommand.set_sensitive(True)
		
		self.shortcut_grab = False
		gtk.gdk.keyboard_ungrab()
		gtk.gdk.pointer_ungrab()

	def on_buttonClear_clicked(self, widget):
		self.entryShortcut.set_text("")

	def on_main_window_key_press_event(self, widget, event):
		
		if self.shortcut_grab:

			keyval = gtk.gdk.keyval_to_lower(event.keyval)
			key = gtk.gdk.keyval_name(keyval)

			txt = self.entryShortcut.get_text()
			if len(txt)>0 and txt[-1] <> '+':
				txt = txt + '::'		
			
			# check if key has alias in xmodmap
			for k in self.xmodmap.keys():
				if key in self.xmodmap[k]:
					if key in ('Alt_L', 'Meta_L'):
						key = 'alt'
					else:
						key = k
					break
			
			if key in self.modifiers:
				if key not in self.keys:
					self.keys.append(key)
					self.entryShortcut.set_text(txt + key + "+")
			else:
				self.entryShortcut.set_text(txt+key)
				self.keys = []	

			# avoid navigation through keyboard
			if key in ('Tab', 'ISO_Left_Tab'):
				return True

	def on_main_window_key_release_event(self, widget, event):
		txt = self.entryShortcut.get_text()
		if len(txt)>0 and txt[-1] == '+':
			if '::' not in txt:
				self.entryShortcut.set_text("")
			else:
				index = txt.rfind('::')
				self.entryShortcut.set_text(txt[:index])
			self.keys = []

	def on_main_window_button_press_event(self, widget, event):
		if self.shortcut_grab:
			txt = self.entryShortcut.get_text()
			if len(txt)>0 and txt[-1] == '+':
				self.entryShortcut.set_text(txt+"Button%s" % (event.button))
				self.keys = []

	def on_buttonAdd_clicked(self, widget):
		alias = self.entryAlias.get_text()
		alias = alias.replace(' ','')
		command = self.entryCommand.get_text()

		# prevents empty alias and commands
		if alias == '' or command == '':
			return

		shortcut = self.entryShortcut.get_text()

		# self.alias_count validation avoids duplicated aliases
		self.alias_count = 0
		if self.notebookActions.get_current_page() == 0:
			self.liststore_extern.foreach(self.check_alias, alias)
			if self.alias_count == 0:
				self.liststore_extern.append((alias, command, shortcut))
		else:
			self.liststore_chain.foreach(self.check_alias, alias)
			if self.alias_count == 0:
				self.liststore_chain.append((alias, command, shortcut))

	def on_buttonRemove_clicked(self, widget):
		if self.notebookActions.get_current_page() == 0:
			selection = self.treeviewExtern.get_selection()
			if selection.get_selected()[1]:
				alias = self.liststore_extern.get_value(self.iter, 0)
				self.iter = self.liststore_extern.remove(self.iter)
		else:
			selection = self.treeviewChain.get_selection()
			if selection.get_selected()[1]:
				alias = self.liststore_chain.get_value(self.iter, 0)
				self.iter = self.liststore_chain.remove(self.iter)

		try:
			alias
		except NameError:
			return
		else:
			# gets original alias name (if modified)
			for key in self.changed_alias.keys():
				if self.changed_alias[key] == alias:
					alias = key
					break
			
			self.removed_alias.append(alias)
			
			self.entryAlias.set_text("")
			self.entryCommand.set_text("")
			self.entryShortcut.set_text("")

	def on_buttonApply_clicked(self, widget):
		alias = self.entryAlias.get_text()
		alias = alias.replace(' ','')
		command = self.entryCommand.get_text()

		page_num = self.notebookActions.get_current_page()

		# prevents empty alias and commands(except if we are in the intern section)
		if alias == '' or (command == '' and page_num <> 1):
			return
		
		shortcut = self.entryShortcut.get_text()

		# self.alias_count validation avoids duplicated aliases
		self.alias_count = 0
		if self.iter:
			if page_num == 0:
				self.liststore_extern.foreach(self.check_alias, alias)
				if self.alias_count == 0 or (self.alias_count == 1 and \
					alias == self.liststore_extern.get_value(self.iter, 0)):
				
					# tracks original alias names (for possible later removal)
					old_alias = self.liststore_extern.get_value(self.iter, 0)
					if alias <> old_alias:

						for key in self.changed_alias.keys():
							if self.changed_alias[key] == old_alias:
								self.changed_alias[key] = alias	
								break
						else:
							self.changed_alias[old_alias] = alias
					
					self.liststore_extern.set_value(self.iter, 0, alias)
					self.liststore_extern.set_value(self.iter, 1, command)
					self.liststore_extern.set_value(self.iter, 2, shortcut)
			elif page_num == 1:
				self.liststore_intern.set_value(self.iter, 0, alias)
				self.liststore_intern.set_value(self.iter, 1, shortcut)
			else:
				self.liststore_chain.foreach(self.check_alias, alias)
				if self.alias_count == 0 or (self.alias_count == 1 and \
					alias == self.liststore_chain.get_value(self.iter, 0)):

					# tracks original alias names (for possible later removal)
					old_alias = self.liststore_chain.get_value(self.iter, 0)
					if alias <> old_alias:

						for key in self.changed_alias.keys():
							if self.changed_alias[key] == old_alias:
								self.changed_alias[key] = alias	
								break
						else:
							self.changed_alias[old_alias] = alias

					self.liststore_chain.set_value(self.iter, 0, alias)
					self.liststore_chain.set_value(self.iter, 1, command)
					self.liststore_chain.set_value(self.iter, 2, shortcut)

	# avoids duplicated aliases
	def check_alias(self, model, path, iter, alias):
		if alias == model.get_value(iter, 0):
			self.alias_count += 1

#########################
# COMMON.CONF FUNCTIONS #
#########################

	def parse_common(self):
#(5-6)
		# load default options (common.conf might not exist)

		active_radiobuttons = (1, 3, 5, 8, 11, 13, 14, 17, 19, 20, 22)
							
		for i in active_radiobuttons:
			exec "self.radiobutton%d.set_active(True)" % (i)
		
		self.checkbuttonBar.set_active(True)
		self.checkbuttonFrame.set_active(True)
		self.spinbuttonBorder.set_value(3)
		self.spinbuttonResize.set_value(10)
		self.entryMenu.set_text("xterm,restart,quit")
		self.entrySlot.set_text("default")
		self.entryChain.set_text("")
		self.entryTerminal.set_text("xterm -e")

		# parse common.conf
		try:
			f = open(self.common_file)
		except IOError:
			return		
		f_common = f.read().splitlines()
		f.close()
		
		for line in f_common:
			if len(line) > 0 and line[0] <> '#':
				if re.match("autocompletion\.mode(\s)?=(\s)?(default|regex)", line):
					if line[line.index('=')+1:].strip() == 'default':
						self.radiobutton1.set_active(True)
					else:
						self.radiobutton2.set_active(True)
				elif re.match("bar\.buttons(\s)?=(\s)?(yes|no)", line):
					if line[line.index('=')+1:].strip() == 'yes':
						self.checkbuttonBar.set_active(True)
					else:
						self.checkbuttonBar.set_active(False)
				elif re.match("border\.width(\s)?=(\s)?\d+", line):
					border_width = int(line[line.index('=')+1:].strip())
					self.spinbuttonBorder.set_value(border_width)
				elif re.match("cycle\.mode(\s)?=(\s)?(default|stacked\-tabbing)", line):
					if line[line.index('=')+1:].strip() == 'default':
						self.radiobutton5.set_active(True)
					else:
						self.radiobutton6.set_active(True)
				elif re.match("default\.bar\-mode(\s)?=(\s)?(hide|show)", line):
					if line[line.index('=')+1:].strip() == 'hide':
						self.radiobutton16.set_active(True)
					else:
						self.radiobutton17.set_active(True)
				elif re.match("default\.border\-mode(\s)?=(\s)?(hide|show)", line):
					if line[line.index('=')+1:].strip() == 'hide':
						self.radiobutton18.set_active(True)
					else:
						self.radiobutton19.set_active(True)
				elif re.match("default\.client\-mode(\s)?=(\s)?(float|max)", line):
					if line[line.index('=')+1:].strip() == 'float':
						self.radiobutton3.set_active(True)
					else:
						self.radiobutton4.set_active(True)
				elif re.match("default\.transient\-mode(\s)?=(\s)?(float|max)", line):
					if line[line.index('=')+1:].strip() == 'float':
						self.radiobutton20.set_active(True)
					else:
						self.radiobutton21.set_active(True)
				elif re.match("frame\.buttons(\s)?=(\s)?(yes|no)", line):
					if line[line.index('=')+1:].strip() == 'yes':
						self.checkbuttonFrame.set_active(True)
					else:
						self.checkbuttonFrame.set_active(False)
				elif re.match("menu\.actions(\s)?=", line):
					text = line[line.index('=')+1:].strip()
					self.entryMenu.set_text(text)
				elif re.match("resize\-move\.factor(\s)?=(\s)?\d+", line):
					resize_factor = int(line[line.index('=')+1:].strip())
					self.spinbuttonResize.set_value(resize_factor)
				elif re.match("slot\.adjustment(\s)?=(\s)?(bottom|center|top)", line):
					option = line[line.index('=')+1:].strip()
					if option == 'bottom':
						self.radiobutton7.set_active(True)
					elif option == 'center':
						self.radiobutton8.set_active(True)
					else:
						self.radiobutton9.set_active(True)
				elif re.match("slot\.alignment(\s)?=(\s)?(left|right)", line):
					if line[line.index('=')+1:].strip() == 'left':
						self.radiobutton10.set_active(True)
					else:
						self.radiobutton11.set_active(True)
				elif re.match("slot\.mode(\s)?=(\s)?(non-overlap|overlap)", line):
					if line[line.index('=')+1:].strip() == 'non-overlap':
						self.radiobutton22.set_active(True)
					else:
						self.radiobutton23.set_active(True)
				elif re.match("slot\.style(\s)?=(\s)?(solid|transparent)", line):
					if line[line.index('=')+1:].strip() == 'solid':
						self.radiobutton12.set_active(True)
					else:
						self.radiobutton13.set_active(True)
				elif re.match("slot\.tabs(\s)?=", line):
					text = line[line.index('=')+1:].strip()
					self.entrySlot.set_text(text)
				elif re.match("startup\.chain(\s)?=", line):
					text = line[line.index('=')+1:].strip()
					self.entryChain.set_text(text)
				elif re.match("statusbar\.alignment(\s)?=(\s)?(bottom|top)", line):
					if line[line.index('=')+1:].strip() == 'bottom':
						self.radiobutton14.set_active(True)
					else:
						self.radiobutton15.set_active(True)
				elif re.match("terminal(\s)?=", line):
					text = line[line.index('=')+1:].strip()
					text = text.replace('"','')
					self.entryTerminal.set_text(text)

	def save_common(self):
		f = open(self.common_file, 'w')

		if self.radiobutton1.get_active():
			print >> f, "autocompletion.mode=default"
		else:
			print >> f, "autocompletion.mode=regex"			

		if self.checkbuttonBar.get_active():
			print >> f, "bar.buttons=yes"
		else:
			print >> f, "bar.buttons=no"

		print >> f, "border.width=%s" % (self.spinbuttonBorder.get_value_as_int())

		if self.radiobutton5.get_active():
			print >> f, "cycle.mode=default"
		else:
			print >> f, "cycle.mode=stacked-tabbing"

		if self.radiobutton16.get_active():
			print >> f, "default.bar-mode=hide"
		else:
			print >> f, "default.bar-mode=show"

		if self.radiobutton18.get_active():
			print >> f, "default.border-mode=hide"
		else:
			print >> f, "default.border-mode=show"

		if self.radiobutton3.get_active():
			print >> f, "default.client-mode=float"
		else:
			print >> f, "default.client-mode=max"

		if self.radiobutton20.get_active():
			print >> f, "default.transient-mode=float"
		else:
			print >> f, "default.transient-mode=max"

		if self.checkbuttonFrame.get_active():
			print >> f, "frame.buttons=yes"
		else:
			print >> f, "frame.buttons=no"

		text = self.entryMenu.get_text().strip()
		if text == '':
			print >> f, 'menu.actions='
		else:
			print >> f, 'menu.actions=%s' % (text)

		print >> f, "resize-move.factor=%s" % (self.spinbuttonResize.get_value_as_int())

		if self.radiobutton7.get_active():
			print >> f, "slot.adjustment=bottom"
		elif self.radiobutton8.get_active():
			print >> f, "slot.adjustment=center"
		else:
			print >> f, "slot.adjustment=top"

		if self.radiobutton10.get_active():
			print >> f, "slot.alignment=left"
		else:
			print >> f, "slot.alignment=right"

		if self.radiobutton22.get_active():
			print >> f, "slot.mode=non-overlap"
		else:
			print >> f, "slot.mode=overlap"

		if self.radiobutton12.get_active():
			print >> f, "slot.style=solid"
		else:
			print >> f, "slot.style=transparent"

		text = self.entrySlot.get_text().strip()
		if text == '':
			print >> f, 'slot.tabs='
		else:
			print >> f, 'slot.tabs=%s' % (text)

		text = self.entryChain.get_text().strip()
		if text == '':
			print >> f, 'startup.chain='
		else:
			print >> f, 'startup.chain=%s' % (text)

		if self.radiobutton14.get_active():
			print >> f, "statusbar.alignment=bottom"
		else:
			print >> f, "statusbar.alignment=top"
		
		text = self.entryTerminal.get_text().strip()
		if text == '':
			print >> f, 'terminal="xterm -e"'
		else:
			print >> f, 'terminal="%s"' % (text)

		f.close()

########################
# THEME.CONF FUNCTIONS #
########################

# BUG: fonts are not being updated on first preview

	def clear_theme(self):
		for i in range(1, 54):
			exec 'self.colorbutton%s.set_color(gtk.gdk.color_parse("#ffffff"))' % i
		for entry in ('exec_entry','font_entry','theme_entry','author_entry', 'email_entry'):
			exec "self.%s.set_text('')" % entry
		self.radiobuttonfont1.set_active(True)

		self.area.queue_draw()

	def parse_theme(self):
		f = open(self.theme_file)
		f_list = f.read().splitlines()
		f.close()

		for line in f_list:
			if len(line) > 0 and line[0] <> '#':
				# parse color elements
				if line[:6] == 'color.':
					index = line.index('=')
					key = line[:index].rstrip()
					color = line[index+1:].strip()
					color = color.replace('\\','')

					try:						
						exec 'self.%s.set_color(gtk.gdk.color_parse("%s"))' % (theme_conf[key],color)
					except TypeError:
						pass
				# parse exec
				elif line[:5] == 'exec=':
					cmd = line[5:].strip()
					cmd = cmd.replace('"','')
					self.exec_entry.set_text(cmd)
				# parse font
				elif line[:5] == 'font=':
					font = line[5:].strip()
					font = font.replace('"','')
					self.font_entry.set_text(font)
					self.radiobuttonfont2.set_active(True)
			# parse theme name, author and email
			elif re.match("# wmizer:[\w ]+by[\w ]+\([\w@.]*\)", line):
				line = line[10:].lstrip()
				index = line.index(' by ')
				self.theme_entry.set_text(line[:index])

				line = line[index+4:]
				index = line.index('(')
				self.author_entry.set_text(line[:index].rstrip())
				
				self.email_entry.set_text(line[index+1:line.index(')')].strip())

	def save_theme(self):
		f = open(self.theme_file, 'w')

		theme = self.theme_entry.get_text()
		author = self.author_entry.get_text()
		email = self.email_entry.get_text()

		if theme == '':
			theme = 'Untitled'
		if author == '':
			author = 'Unknown'

		print >> f, "# wmizer: %s by %s (%s)" % (theme,author,email)

		keys = theme_conf.keys()
		keys.sort()
		for key in keys:
			exec "color = self.%s.get_color()" % theme_conf[key]

			# convert colors from 0-65535 range to 0-255 and then to hex
			red = color.red * 255 / 65535
			if red < 16:
				red = "0" + str(hex(red))[-1]
			else:
				red = str(hex(red))[-2:]
		
			green = color.green * 255 / 65535
			if green < 16:
				green = "0" + str(hex(green))[-1]
			else:
				green = str(hex(green))[-2:]

			blue = color.blue * 255 / 65535
			if blue < 16:
				blue = "0" + str(hex(blue))[-1]
			else:
				blue = str(hex(blue))[-2:]

			color = "#" + red + green + blue

			print >> f, "%s=\\%s" % (key,color.upper())
		
		print >> f, 'exec="%s"' % self.exec_entry.get_text()

		if self.radiobuttonfont1.get_active():
			font = self.fontbutton.get_font_name().split(' ')[:-1]
			font = ' '.join(font)
		else:
			font = self.font_entry.get_text()
		print >> f, 'font="%s"' % font

		f.close()

		self.statusbar.pop(self.status_id)
		self.statusbar.push(self.status_id, "theme saved")

#####################
# DRAWING FUNCTIONS #
#####################

	def on_area_expose_event(self, area, event):
		self.gc = area.window.new_gc()

		self.draw_bars(area)
		self.draw_labels(area)
		self.draw_frames(area)
		self.draw_tabs(area)
		self.draw_buttons(area)
		self.draw_meter(area)

		self.gc.set_rgb_fg_color(gtk.gdk.color_parse("black"))
		area.window.draw_rectangle(self.gc, True, 3, 36, 570, 190)
		area.window.draw_rectangle(self.gc, True, 3, 248, 570, 190)

		font_desc = pango.FontDescription('fixed 16')
		self.pangolayout.set_font_description(font_desc)		
		self.gc.set_rgb_fg_color(gtk.gdk.color_parse("white"))
		self.pangolayout.set_text("ACTIVE")
		area.window.draw_layout(self.gc, 258, 121, self.pangolayout)
		self.pangolayout.set_text("INACTIVE")
		area.window.draw_layout(self.gc, 248, 333, self.pangolayout)
		
		font_desc = pango.FontDescription('fixed 9')
		self.pangolayout.set_font_description(font_desc)
		self.draw_menu(area)

	def draw_menu(self, area):
	
		# normal
		bg = self.colorbutton23.get_color()
		shadow = self.colorbutton2.get_color()
		shine = self.colorbutton3.get_color()
		self.draw_rectangle(area, 0, 17, 194, 106, bg, shadow, shine)
		
		self.gc.set_rgb_fg_color(self.colorbutton29.get_color())
		self.pangolayout.set_text("xterm")
		area.window.draw_layout(self.gc, 25, 19, self.pangolayout)
		self.pangolayout.set_text("restart")
		area.window.draw_layout(self.gc, 25, 34, self.pangolayout)
		self.pangolayout.set_text("------------------------")
		area.window.draw_layout(self.gc, 25, 64, self.pangolayout)
		self.pangolayout.set_text("workspace 1  >>")
		area.window.draw_layout(self.gc, 25, 79, self.pangolayout)
		self.pangolayout.set_text("workspace 2  >>")
		area.window.draw_layout(self.gc, 25, 94, self.pangolayout)
		self.pangolayout.set_text("workspace 3  >>")
		area.window.draw_layout(self.gc, 25, 109, self.pangolayout)
		
		# focussed
		bg = self.colorbutton22.get_color()
		shadow = self.colorbutton24.get_color()
		shine = self.colorbutton26.get_color()
		self.draw_rectangle(area, 1, 48, 192, 14, bg, shadow, shine)

		self.gc.set_rgb_fg_color(self.colorbutton28.get_color())
		self.pangolayout.set_text("quit")
		area.window.draw_layout(self.gc, 25, 49, self.pangolayout)

	def draw_bars(self, area):
		bg = self.colorbutton1.get_color()
		shadow = self.colorbutton2.get_color()
		shine = self.colorbutton3.get_color()
		self.draw_rectangle(area, 0, 0, 575, 16, bg, shadow, shine)
		self.draw_rectangle(area, 0, 441, 575, 16, bg, shadow, shine)
		#self.draw_rectangle(area, 238, 442, 337, 14, bg, shadow, shine)

		self.gc.set_rgb_fg_color(self.colorbutton4.get_color())
		self.pangolayout.set_text("wmizer")
		area.window.draw_layout(self.gc, 475, 443, self.pangolayout)
		self.pangolayout.set_text("cpu")
		area.window.draw_layout(self.gc, 540, 443, self.pangolayout)
		
	def draw_meter(self, area):
		
		x = 520
		y = 442
		width = 7
		height = 14
		bg = self.colorbutton50.get_color()	
		shadow = self.colorbutton51.get_color()		
		shine = self.colorbutton52.get_color()
		figure = self.colorbutton53.get_color()

		self.draw_rectangle(area, x, y, width, height, bg, shadow, shine)

		self.gc.set_rgb_fg_color(figure)
		area.window.draw_rectangle(self.gc, True, x+1, y+height/2, width-1, height/2)

	def draw_labels(self, area):
		
		# focussed
		bg = self.colorbutton22.get_color()
		shadow = self.colorbutton24.get_color()
		shine = self.colorbutton26.get_color()
		self.draw_rectangle(area, 20, 442, 107, 14, bg, shadow, shine)

		self.gc.set_rgb_fg_color(self.colorbutton28.get_color())
		self.pangolayout.set_text("workspace 1")
		area.window.draw_layout(self.gc, 42, 443, self.pangolayout)
		
		# normal
		bg = self.colorbutton23.get_color()
		shadow = self.colorbutton25.get_color()
		shine = self.colorbutton27.get_color()
		self.draw_rectangle(area, 128, 442, 107, 14, bg, shadow, shine)
		
		self.gc.set_rgb_fg_color(self.colorbutton29.get_color())
		self.pangolayout.set_text("workspace 2")
		area.window.draw_layout(self.gc, 150, 443, self.pangolayout)

		# focusreq
		bg = self.colorbutton46.get_color()
		shadow = self.colorbutton47.get_color()
		shine = self.colorbutton48.get_color()
		self.draw_rectangle(area, 236, 442, 107, 14, bg, shadow, shine)
		
		self.gc.set_rgb_fg_color(self.colorbutton49.get_color())
		self.pangolayout.set_text("workspace 3")
		area.window.draw_layout(self.gc, 258, 443, self.pangolayout)		

	def draw_frames(self, area):
		
		# focussed
		bg = self.colorbutton16.get_color()
		shadow = self.colorbutton18.get_color()
		shine = self.colorbutton20.get_color()
		self.draw_rectangle(area, 0, 17, 575, 211, bg, shadow, shine)
		
		# normal
		bg = self.colorbutton17.get_color()
		shadow = self.colorbutton19.get_color()
		shine = self.colorbutton21.get_color()
		self.draw_rectangle(area, 0, 229, 575, 211, bg, shadow, shine)

	def draw_tabs(self, area):
		
		# active focussed
		bg = self.colorbutton30.get_color()
		shadow = self.colorbutton34.get_color()
		shine = self.colorbutton38.get_color()
		self.draw_rectangle(area, 373, 20, 149, 14, bg, shadow, shine)

		self.gc.set_rgb_fg_color(self.colorbutton42.get_color())
		self.pangolayout.set_text("focussed")
		area.window.draw_layout(self.gc, 424, 21, self.pangolayout)

		# active normal
		bg = self.colorbutton31.get_color()
		shadow = self.colorbutton35.get_color()
		shine = self.colorbutton39.get_color()
		self.draw_rectangle(area, 223, 20, 149, 14, bg, shadow, shine)
		self.draw_rectangle(area, 3, 20, 219, 14, bg, shadow, shine)

		self.gc.set_rgb_fg_color(self.colorbutton43.get_color())
		self.pangolayout.set_text("normal")
		area.window.draw_layout(self.gc, 281, 21, self.pangolayout)
		
		# inactive focussed
		bg = self.colorbutton32.get_color()
		shadow = self.colorbutton36.get_color()
		shine = self.colorbutton40.get_color()
		self.draw_rectangle(area, 3, 232, 284, 14, bg, shadow, shine)

		self.gc.set_rgb_fg_color(self.colorbutton44.get_color())
		self.pangolayout.set_text("focussed")
		area.window.draw_layout(self.gc, 122, 233, self.pangolayout)

		# inactive normal
		bg = self.colorbutton33.get_color()
		shadow = self.colorbutton37.get_color()
		shine = self.colorbutton41.get_color()
		self.draw_rectangle(area, 288, 232, 284, 14, bg, shadow, shine)

		self.gc.set_rgb_fg_color(self.colorbutton45.get_color())
		self.pangolayout.set_text("normal")
		area.window.draw_layout(self.gc, 413, 233, self.pangolayout)

	def draw_buttons(self, area):
		
		# normal
		bg = self.colorbutton5.get_color()
		shadow = self.colorbutton7.get_color()
		shine = self.colorbutton9.get_color()
		fig_shadow = self.colorbutton11.get_color()
		fig_shine = self.colorbutton13.get_color()
		self.draw_button_float(area, bg, shadow, shine, fig_shadow, fig_shine)
		self.draw_button_input(area, bg, shadow, shine, fig_shadow, fig_shine)
		self.draw_button_lower(area, bg, shadow, shine, fig_shadow, fig_shine)
		self.draw_button_close(area, bg, shadow, shine, fig_shadow, fig_shine)
		
		# pressed
		bg = self.colorbutton6.get_color()
		shadow = self.colorbutton8.get_color()
		shine = self.colorbutton10.get_color()
		fig_shadow = self.colorbutton12.get_color()
		fig_shine = self.colorbutton14.get_color()
		self.draw_button_menu(area, bg, shadow, shine, fig_shadow, fig_shine)		

	def draw_button_menu(self, area, bg, shadow, shine, fig_shadow, fig_shine):
		
		x = 1
		y = 1
		self.draw_rectangle(area, x, y, 16, 14, bg, shadow, shine)

		self.gc.set_rgb_fg_color(fig_shine)
		area.window.draw_line(self.gc, x+3, y+3, x+13, y+3)
		area.window.draw_line(self.gc, x+3, y+7, x+13, y+7)
		area.window.draw_line(self.gc, x+3, y+11, x+13, y+11)
		self.gc.set_rgb_fg_color(fig_shadow)
		area.window.draw_line(self.gc, x+3, y+4, x+13, y+4)
		area.window.draw_line(self.gc, x+3, y+8, x+13, y+8)
		area.window.draw_line(self.gc, x+3, y+12, x+13, y+12)
		
	def draw_button_float(self, area, bg, shadow, shine, fig_shadow, fig_shine):	

		xy = ((559,1),(541,20))
		
		for i in xy:
			x = i[0]
			y = i[1]
			self.draw_rectangle(area, x, y, 15, 14, bg, shadow, shine)
			self.draw_rectangle(area, x+6, y+6, 6, 5, bg, fig_shadow, fig_shine)
			self.draw_rectangle(area, x+3, y+3, 6, 5, bg, fig_shadow, fig_shine)
			area.window.draw_line(self.gc, x+6, y+6, x+9, y+6)
			area.window.draw_line(self.gc, x+6, y+7, x+6, y+8)

	def draw_button_input(self, area, bg, shadow, shine, fig_shadow, fig_shine):
		
		x = 1
		y = 442
		self.draw_rectangle(area, x, y, 16, 14, bg, shadow, shine)
		self.draw_rectangle(area, x+3, y+3, 3, 8, bg, fig_shadow, fig_shine)
		self.draw_rectangle(area, x+10, y+3, 3, 8, bg, fig_shadow, fig_shine)
		
	def draw_button_lower(self, area, bg, shadow, shine, fig_shadow, fig_shine):
		
		x = 525
		y = 20
		self.draw_rectangle(area, x, y, 15, 14, bg, shadow, shine)
		self.draw_rectangle(area, x+3, y+8, 9, 3, bg, fig_shadow, fig_shine)

	def draw_button_close(self, area, bg, shadow, shine, fig_shadow, fig_shine):
		
		x = 557
		y = 20
		self.draw_rectangle(area, x, y, 15, 14, bg, shadow, shine)
		self.draw_rectangle(area, x+6, y+5, 4, 4, bg, fig_shadow, fig_shine)
	
	def draw_rectangle(self, area, x, y, width, height, bg, shadow, shine):

		# background
		self.gc.set_rgb_fg_color(bg)
		area.window.draw_rectangle(self.gc, True, x+1, y+1, width-1, height-1)
		
		# shadow
		self.gc.set_rgb_fg_color(shadow)
		area.window.draw_rectangle(self.gc, False, x, y, width, height)
		
		# shine
		self.gc.set_rgb_fg_color(shine)
		area.window.draw_line(self.gc, x, y, x+width-1, y)
		area.window.draw_line(self.gc, x, y+1, x, y+height-1)

theme_conf={'color.bar.background' : 'colorbutton1',
			'color.bar.shadow' : 'colorbutton2',
			'color.bar.shine' : 'colorbutton3',
			'color.bar.text' : 'colorbutton4',
			'color.button.background.normal' : 'colorbutton5',
			'color.button.background.pressed' : 'colorbutton6',
			'color.button.border.shadow.normal' : 'colorbutton7',
			'color.button.border.shadow.pressed' : 'colorbutton8',
			'color.button.border.shine.normal' : 'colorbutton9',
			'color.button.border.shine.pressed' : 'colorbutton10',
			'color.button.figure.shadow.normal' : 'colorbutton11',
			'color.button.figure.shadow.pressed' : 'colorbutton12',
			'color.button.figure.shine.normal' : 'colorbutton13',
			'color.button.figure.shine.pressed' : 'colorbutton14',
			'color.focusreq.background' : 'colorbutton46',
			'color.focusreq.shine' : 'colorbutton47',
			'color.focusreq.shadow' : 'colorbutton48',
			'color.focusreq.text' : 'colorbutton49',
			'color.frame.pseudo' : 'colorbutton15',
			'color.frame.background.focussed' : 'colorbutton16',
			'color.frame.background.normal' : 'colorbutton17',
			'color.frame.shadow.focussed' : 'colorbutton18',
			'color.frame.shadow.normal' : 'colorbutton19',
			'color.frame.shine.focussed' : 'colorbutton20',
			'color.frame.shine.normal' : 'colorbutton21',
			'color.label.background.focussed' : 'colorbutton22',
			'color.label.background.normal' : 'colorbutton23',
			'color.label.shadow.focussed' : 'colorbutton24',
			'color.label.shadow.normal' : 'colorbutton25',
			'color.label.shine.focussed' : 'colorbutton26',
			'color.label.shine.normal' : 'colorbutton27',
			'color.label.text.focussed' : 'colorbutton28',
			'color.label.text.normal' : 'colorbutton29',
			'color.meter.background' : 'colorbutton50',
			'color.meter.border.shadow' : 'colorbutton51',
			'color.meter.border.shine' : 'colorbutton52',
			'color.meter.figure' : 'colorbutton53',
			'color.tab.background.active.focussed' : 'colorbutton30',
			'color.tab.background.active.normal' : 'colorbutton31',
			'color.tab.background.inactive.focussed' : 'colorbutton32',
			'color.tab.background.inactive.normal' : 'colorbutton33',
			'color.tab.shadow.active.focussed' : 'colorbutton34',
			'color.tab.shadow.active.normal' : 'colorbutton35',
			'color.tab.shadow.inactive.focussed' : 'colorbutton36',
			'color.tab.shadow.inactive.normal' : 'colorbutton37',
			'color.tab.shine.active.focussed' : 'colorbutton38',
			'color.tab.shine.active.normal' : 'colorbutton39',
			'color.tab.shine.inactive.focussed' : 'colorbutton40',
			'color.tab.shine.inactive.normal' : 'colorbutton41',
			'color.tab.text.active.focussed' : 'colorbutton42',
			'color.tab.text.active.normal' : 'colorbutton43',
			'color.tab.text.inactive.focussed' : 'colorbutton44',
			'color.tab.text.inactive.normal' : 'colorbutton45'}

app=appgui()
gtk.main()
