#!/usr/bin/env python3
########################################################################
# c2007-2022 by Paul Sherman <psherman2001@gmail.com> 
# last modified Thursday, 01/27/2022
#
# 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		
# 										
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.   
########################################################################
##  importing with system requirement checks ###########################

import sys, os, time, subprocess, string, shutil, re, fileinput, gi, cairo
gi.require_version('Gtk', '3.0')
gi.require_version('PangoCairo', '1.0')
gi.require_version("Gdk", "3.0")
from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, Pango, PangoCairo

# get path to restart app after changing font
appPath = os.path.realpath(sys.argv[0])
_args = [appPath]

gtkfile = os.path.join(os.path.expanduser("~/"), ".gtkrc.mine")
gtk3file = os.path.join(os.path.expanduser("~/"), ".config/gtk-3.0/settings.ini")
default_font = "unknown"
sList =  ["8", "9", "10", "11", "12", "14",  "16", "24", "32", "36", "40", "48", "64"]
cur = 10

# path for the icewm preferences file - should always exist on Absolute, give user hell if not :)
prefpath = os.path.expanduser("~") + "/.icewm/prefoverride"
display_text = "abcdefghijklm\nABCDEFGHIJKLM\n1234567890"

cur_font="DejaVu Sans"
cur_size = "10"
############### now for our icons and font_description  ########################			xap/absFileFinder-20220127-noarch-1AL.txz
	
font_desc = Pango.FontDescription()

close_xpm = [
"32 32 32 1",
" 	c None",
".	c #D5A7A5",
"+	c #DFBBBB",
"@	c #F0D0CF",
"#	c #FAD9D8",
"$	c #F7E3E3",
"%	c #CA8C8C",
"&	c #DD9E9E",
"*	c #C77878",
"=	c #EDB8B8",
"-	c #CD6F6E",
";	c #FDFFFC",
">	c #E08E8E",
",	c #BA5151",
"'	c #E88786",
")	c #D76868",
"!	c #B43E3A",
"~	c #E15B5A",
"{	c #D13334",
"]	c #A11B1C",
"^	c #EB7A79",
"/	c #D00000",
"(	c #E91C14",
"_	c #EC2F23",
":	c #E60000",
"<	c #C33F3F",
"[	c #ED4E4B",
"}	c #BC3532",
"|	c #B1090B",
"1	c #CF1E1F",
"2	c #ED3931",
"3	c #BA0001",
"                                ",
"    .+@@@@@@@@@###$$$$$$$$$+    ",
"   .+..............++++++++@#   ",
"  ..%%%%%%%%%&&%%&&&&&&.....@+  ",
" +*%%%%%%%%%%%%+.%&&&&&&&&&&&=+ ",
" +-%%****%%%%%@;;+>>>>>&&&&&&>+ ",
" +,***********$;;@'>>>>>>>>>&)+ ",
" +!*******--*-$;;@--*'>>>>>>>~+ ",
" +!*-*----%%--$;;=-.@.-'''''>{+ ",
" +]-----,+;;.)#;;=>;;;+-^^''~/+ ",
" +],,,,,+;;;#~#;;=';;;;+)^^^(/+ ",
" +],,,,%;;;$'~#;;=~>$;;;&~^_:/+ ",
" +],,!,$;;$)<~@;;=~~^$;;$~_:(/+ ",
" +]!!<%;;;'<~<#;;=[~[';;;^:((/+ ",
" +]!<}+;;#<<<<&;;'[[[[#;;&:((/+ ",
" +|}}}#;;&{<<{{^~[[[[[>;;#(((_+ ",
" +|}}}$;;>1{{{{{{{[[2(^;;$_(__+ ",
" +|}]}$;;>1{{{{{{{2(::^;;#_(_2+ ",
" +|]||=;;=1111112(::::=;;=(__2+ ",
" +|||3';;;<111///::::{;;;'(__2+ ",
" +|||3{;;;@3////::::(@;;;2__22+ ",
" +3|333';;;=1///:::1=;;;'(_222+ ",
" +3|3333=;;;$>{1_{'$;;;=(__222+ ",
" +3333333=;;;;;;;;;;;;=_(__222+ ",
" +3333333/^$;;;;;;;;$^((___222+ ",
" +3333333///~&#$$#=~_:((__2222+ ",
" +1|33333//////((:::((((___22[+ ",
"  !{|3333//////:::::(((((__2[!  ",
"   ![{{{{{2222222222222[[[[[!   ",
"    !!!!!!!!!!!!<<}}}}}}}}}!    ",
"                                ",
"                                "]

icon_xpm = [
"32 32 8 1",
" 	c None",
".	c #FFFFFF",
"+	c #B6DBFF",
"@	c #6DB6DB",
"#	c #2492DB",
"$	c #B6B6B6",
"%	c #494949",
"&	c #000000",
"................................",
"...................+@+..........",
"...............+#+.+##+.........",
"...............+##.+##..@@......",
"...........$$$..##.##@.+##@.....",
"..........%&&&..@#.##++###......",
"..........&&&&$.+########.......",
".........$&&&&%..@######.+@#@...",
".........%&&&&&$.+###########...",
".........&&&&&&%....+#######@...",
"........$&&&&&&&.....@####+.....",
"........%&$&&&&&$....+###@......",
"........&%.%&&&&%....+####@##@..",
".......$&$.$&&&&&....@#######@..",
".......%&...&&&&&$..@#####++@+..",
".......&%...%&&&&%..#####+......",
"......$&$...$&&&&&..+####+++....",
"......%&.....&&&&&$..#######....",
"......&%.....%&&&&%..@#+.+#@....",
".....$&%$$$$$%&&&&&..+#@..+.....",
".....%&&&&&&&&&&&&&$..##+.......",
".....&&%%%%%%%&&&&&%..@#+.......",
"....$&$.......$&&&&&............",
"....&&.........&&&&&$...........",
"...$&%.........%&&&&%...........",
"...%&$.........$&&&&&...........",
".$$&&$$.......$$&&&&&%$.........",
".%&&&&&$......&&&&&&&&&$........",
".$$$$$$.......$$$$$$$$$$........",
"................................",
"................................",
"................................"]


class ShowFonts:

	def get_font_list(self=None, e=None):
		fl = []
		font_map = PangoCairo.font_map_get_default()
		families = font_map.list_families()
		# get family names, put in a list, sort it and ship it out...
		for f in font_map.list_families():
			fl.append(f.get_name())
		fl.sort()
		return fl


	def info(self, message):
		box = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, message)
		box.set_transient_for(self.window)
		box.set_position(Gtk.WindowPosition.CENTER)
		box.set_title('Information')
		box.run()
		box.destroy()	


	def alert(self, message):
		box = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, message)
		box.set_transient_for(self.window)
		box.set_position(Gtk.WindowPosition.CENTER)
		box.set_title('Error')
		box.run()
		box.destroy()		


	def changed_font(self, evt=None, data=None):
		font_name = self.combo.get_active_text()
		
		print(font_name)
		
		font_desc.set_family(font_name)
		self.f_display.set_text(display_text)
		self.f_display.modify_font(font_desc)
		self.window.resize(800, 400)


	def change_size(self, evt=None):
		font_size = self.combo_size.get_active_text()
		font_desc.set_size(int(font_size) * 1024)
		self.f_display.modify_font(font_desc)
		self.window.resize(800, 400)

	def destroy(self, widget, data=None):
		Gtk.main_quit()


	def reset(self, e=None):
		self.combo.set_active(0)
		self.combo_size.set_active(4)
		self.event_box.modify_bg(Gtk.StateFlags.NORMAL, None)
		self.f_display.modify_fg(Gtk.StateFlags.NORMAL, None)
		self.tog_bold.set_active(False) 
		self.tog_it.set_active(False)
		self.f_display.set_text(self.combo.get_active_text())


	def f_del_event(self, e=None):
		self.win.destroy()


	def delete_event(self, widget, event, data=None):
		Gtk.main_quit()


	def doClose(self, w=None):
		Gtk.main_quit()

	def check_ice_pref(self):
		if not os.path.exists(prefpath):
			over_txt = """TitleFontNameXft="DejaVu Sans:size=11"
StatusFontNameXft="monospace:size=10:bold"
QuickSwitchFontNameXft="monospace:size=10:bold"
NormalButtonFontNameXft="DejaVu Sans:size=10"
ActiveButtonFontNameXft="DejaVu Sans:size=10:bold"
NormalTaskBarFontNameXft="DejaVu Sans:size=10"
ActiveTaskBarFontNameXft="DejaVu Sans:size=10:bold"
ToolButtonFontNameXft="DejaVu Sans:size=10"
NormalWorkspaceFontNameXft="DejaVu Sans:size=10"
ActiveWorkspaceFontNameXft="DejaVu Sans:size=10"
MinimizedWindowFontNameXft="DejaVu Sans:size=10"
ListBoxFontNameXft="DejaVu Sans:size=10"
ToolTipFontNameXft="DejaVu Sans:size=10"
ClockFontNameXft="monospace:size=10"
ApmFontNameXft="monospace:size=10"
InputFontNameXft="monospace:size=10"
LabelFontNameXft="DejaVu Sans:size=10"
MenuFontNameXft="DejaVu Sans:size=10"
"""
			try:
				file = open( prefpath, 'w' )
				file.write( over_txt )
				file.close()
			except:
				self.alert("Icewm preferences override file missing.\nIt should be located in your home directory at\n.icewm/prefoverride")
				return "pref_not_set"
		else:
			return "pref_set"


	def get_term(self):
		term_font = subprocess.getoutput('grep "xterm\*faceName" $HOME/.Xresources 2>/dev/null')
		if term_font == "":
				term_font = 10
		else:
			term_font = term_font.split("=")[-1]
			if not term_font:
					term_font = 10
		return str(term_font)

	def get_current_font(self):
		tmp_font = subprocess.getoutput('grep "TitleFontNameXft" $HOME/.icewm/prefoverride 2>/dev/null')
		if tmp_font == "":
				tmp_font = "DejaVu Sans"
		else:
			tmp_font = tmp_font.split("=")[1].replace('"', '')
			if ":" in tmp_font:
				tmp_font = tmp_font.split(":")[0]
			if not tmp_font:
					tmp_font = "DejaVu Sans"
		return str(tmp_font)
		
		
	def get_cur_size(self):
		tmp_size = subprocess.getoutput('grep "TitleFontNameXft" $HOME/.icewm/prefoverride 2>/dev/null')
		if term_font == "":
				tmp_size = "10"
		else:
			tmp_size = term_font.split("=")[-1].replace('"', '')
			if not tmp_size:
					tmp_size = "10"
		return str(tmp_size)
		
		
		
	def get_menu(self):
		menu_font = subprocess.getoutput('grep "MenuFontNameXft" $HOME/.icewm/prefoverride 2>/dev/null')
		if menu_font == "":
				menu_font = 10
		else:
			menu_font = menu_font.split("=")[-1].replace('"', '')
			if ":" in menu_font:
				menu_font = menu_font.split(":")[0]
			if not menu_font in sList:
					menu_font = 10
		return str(menu_font)

	def makeChange(self, w=None):	
		font_name = self.combo.get_active_text()
		# fix possible multi-font string (comma is a give-away...)
		try:
			font_name = string.split(font_name, ",")[1]
		except:
			pass

		font_size = self.combo_size.get_active_text()
		menu_size = self.combo_size.get_active_text()

		self.info("\nFont changes are about to be made,\nall open windows will temporarily flash \nafter configuration files are written \nand windows are re-opened.\n\n")

		# first, change the gtk settings (both gtk2 and gtk3) ############################################
		# gtk2 section
		font_string = "\"" + font_name + ' ' + font_size + "\""
		fTxt0 = "gtk-font-name="
		gtk2str = fTxt0 + font_string + "\n"

		if not os.path.exists(gtkfile):
			try:
				file = open( gtkfile, 'w' )
				file.write( gtk2str )
				file.close()
			except:
				sys.stderr.write("Cannot write gtk configuration file to your home directory.")
				raise SystemExit

		whole = ""
		file = open(gtkfile)
		while 1:
			line = file.readline()
			if not line:
				break
			if re.match('gtk-font-name', line):
				continue
			elif line == "\n":
				continue
			whole = whole + line
		whole = whole + gtk2str
		file.close()
		nfile = open(gtkfile, "w")
		nfile.write(whole)
		nfile.close()
		
		#gtk3 section ###############################################
		gtk3str = "gtk-font-name = " + font_name + " " + font_size + "\n"
		if not os.path.exists(gtk3file):
			try:
				file = open( gtk3file, 'w' )
				file.write( gtk3str )
				file.close()
			except:
				sys.stderr.write("Cannot write gtk3 configuration file to your home directory.")
				raise SystemExit
		whole = ""
		file = open(gtk3file)
		while 1:
			line = file.readline()
			if not line:
				break
			if re.match('gtk-font-name', line):
				continue
			elif line == "\n":
				continue
			whole = whole + line
		whole = whole + gtk3str
		file.close()
		
		nfile = open(gtk3file, "w")
		nfile.write(whole)
		nfile.close()

		# ###############################################################################
		# set the Xterm font size
		xPath = os.path.expanduser("~") + "/.Xresources"
		cXfont = self.combo_size2.get_active_text()
		xLine = 'xterm*faceName: Hack:style=Regular:size=' + cXfont
		######################
		# if ~/.Xresources does not exist
		if not os.path.exists(xPath):
			try:
				file = open( xPath, 'w' )
				file.write( xLine )
				file.close()
			except:
				pass
		else:
			fx=subprocess.getoutput('grep "xterm\*faceName" %s 2>/dev/null' % xPath)

			# below will append the font-setting line
			if fx == "":
				try:
					file = open( xPath, 'a' )
					file.write( xLine.rstrip('\n'),)
					file.close()
				except:
					pass
			else:
				# this is the usual situation, changing the line that sets the xterm font size...
				for line in fileinput.input(xPath, inplace=1):
					if fx in line:
						print (xLine.rstrip('\n'),)
					else:
						print (line.rstrip('\n'),)

		try:
			os.system("xrdb -merge  %s 2>/dev/null" % xPath)
		except:
			pass

		# ###############################################################			
		# make adjustments to the icewm preferences for general system and taskbar
		# any theme font settings will prevent this :(

		fset = font_name + ':size=' + font_size	
		newlines = []
		newlines += ['TitleFontNameXft="' + fset + '"']
		newlines += ['StatusFontNameXft="monospace:size=' + font_size + ':bold"']
		newlines += ['QuickSwitchFontNameXft="monospace:size=' + font_size + ':bold"']
		newlines += ['NormalButtonFontNameXft="' + fset + '"']
		newlines += ['ActiveButtonFontNameXft="' + fset + ':bold"']
		newlines += ['NormalTaskBarFontNameXft="' + fset + '"']
		newlines += ['ActiveTaskBarFontNameXft="' + fset + ':bold"']
		newlines += ['ToolButtonFontNameXft="' + fset + '"']
		newlines += ['NormalWorkspaceFontNameXft="' + fset + '"']
		newlines += ['ActiveWorkspaceFontNameXft="' + fset + '"']
		newlines += ['MinimizedWindowFontNameXft="' + fset + '"']
		newlines += ['ListBoxFontNameXft="' + fset + '"']
		newlines += ['ToolTipFontNameXft="' + fset + '"']
		newlines += ['ClockFontNameXft="monospace:size=' + font_size + '"']
		newlines += ['ApmFontNameXft="monospace:size=' + font_size + '"']
		newlines += ['InputFontNameXft="monospace:size=' + font_size + '"']
		newlines += ['LabelFontNameXft="' + fset + '"']

		# write out the icewm prefoveride file
		wr = open(prefpath, 'w')
		for aline in newlines:
			wr.write(aline + "\n")	
		wr.close()

		# add font menu size to the icewm prefoveride file
		menufontsize = self.combo_size3.get_active_text()
		if self.cb_menu.get_active() == True:
			menuline = 'MenuFontNameXft="' + font_name + ':size=' + menufontsize + ':bold"\n'
		else:
			menuline = 'MenuFontNameXft="' + font_name + ':size=' + menufontsize + '"\n'
			
		with open(prefpath, "a") as preffile:
			preffile.write(menuline)

		# add bold clock to the icewm prefoveride file
		
		i = sList.index(font_size)
		if i < 12:
			i = i + 1
		clockFontSize = (sList[i])
		if self.cb_clock.get_active() == True:
			clockline = 'ClockFontNameXft="' + font_name + ':size=' + clockFontSize + ':bold"\n'
		else:
			clockline = 'ClockFontNameXft="' + font_name + ':size=' + font_size + '"\n'
			
		with open(prefpath, "a") as preffile:
			preffile.write(clockline)
			
			
	#	Stop ROX-Filer
		try:
			os.system('killall -q -9 ROX-Filer > /dev/null 2>&1')
		except:
			pass
	#	Stop iDesk
		try:
			os.system('killall -q -9 idesk > /dev/null 2>&1')
		except:
			pass
	#	# Now qtfm
		try:
			os.system('killall -q -9 qtfm > /dev/null 2>&1')
			os.system('killall -q -9 qtfm-tray > /dev/null 2>&1')
		except:
			pass

	# Now we restart icewm without the window manager
		try:
			cmd = 'killall -HUP icewm 2&>/dev/null'
			os.system(cmd)
		except:
			pass

	# since we use idesk for desktop, restart it	
		try:
			os.system('idesk 2>/dev/null&')
		except:
			pass

	# restart qtfm tray
		try:
			os.system('qtfm-tray 2>/dev/null&')
		except:
			pass

		# restart the font selection itself...
		os.execv(appPath, ['python'] + _args)

# end of makeChange ######################

#########################################################################################################
#########################################################################################################
	def __init__(self, marg):
		self.window = None
		# make sure the ~/.gtkrc-2.0 file exists and plug in the default font value if it does 
		# not, bail if we cannot create this (because all else would be for naught.)
		if not os.path.exists(gtkfile):
			try:
				file = open( gtkfile, 'w' )
				file.write( "gtk-font-name=\"DejaVu Sans 10\"" )
				file.close()
			except:
				print >> sys.stderr, "Cannot write configuration file to your home directory."
				raise SystemExit
		if self.check_ice_pref() == "pref_not_set":
			raise SystemExit

		
		screen = Gdk.Screen.get_default()
		gtk_provider = Gtk.CssProvider()
		gtk_context = Gtk.StyleContext()
		gtk_context.add_provider_for_screen(screen, gtk_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
		
		###########  close button and logo  ################
		closer = GdkPixbuf.Pixbuf.new_from_xpm_data(close_xpm)
		icon = GdkPixbuf.Pixbuf.new_from_xpm_data(icon_xpm)
		close_img = Gtk.Image()
		self.txt_pix = Gtk.Image()
		close_img.set_from_pixbuf(closer)

		###########  window setup  ################

		self.window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
		self.window.set_title("Absolute System Font Setting - 20220127")
		self.window.set_border_width(24)

		self.window.set_position(Gtk.WindowPosition.CENTER)
		self.window.connect("delete_event", self.delete_event)
		self.window.set_icon(icon)

		grid = Gtk.Grid(column_homogeneous=True, column_spacing=22, row_spacing=4)
		self.window.add(grid)		

		btn_close = Gtk.Button()
		btn_close.add(close_img)
		btn_close.set_property("tooltip-text", "Close the Application")
		btn_close.connect("clicked", self.doClose)
		#grid.attach(bar_img, 0, 0, 2, 1)
		grid.attach(btn_close, 4, 0, 1, 1)

		lbl_blankT = Gtk.Label()
		grid.attach(lbl_blankT, 0, 0, 5, 1)
		#lbl_blankT.set_use_markup(True)
		#lbl_blankT.set_name("red_head")
		#css = '#red_head { background-color: #d60e0a; }'
		lbl_blankT.set_markup('<span size="29000" foreground="#FFFFFF" background="#d60e0a"><b><i> Set System Font                                                 </i></b></span>')

		lbl_blankT2 = Gtk.Label()
		grid.attach(lbl_blankT2, 0, 1, 5, 1)

		### static text label ###
		lbl_font_face = Gtk.Label()
		grid.attach(lbl_font_face, 0, 2, 2, 1)
		lbl_font_face.set_markup('<span size="14000" foreground="#334D63"><b>Font Name</b></span>')

		#### Font Name combo box  ###
		self.combo = Gtk.ComboBoxText()
		flist = self.get_font_list()
		x = 0
		cur = 0
		#default_font = lbl_font_face.get_pango_context().get_font_description().get_family()
		default_font = self.get_current_font()
		default_size = str(round(lbl_font_face.get_pango_context().get_font_description().get_size() / 1024))
		
		print(default_font)
		print(default_size)
		
		
		for l in flist:
			l = l.strip()
			self.combo.append_text(l)
			if default_font == l:
				cur = x
			x += 1
			self.combo.set_active(cur)	
		grid.attach(self.combo,0, 3, 2, 1)
		self.combo.set_property("tooltip-text", "Font used by GTK apps\n(including both file managers)\nAs well as the taskbar in Icewm.\n\nFont Changes displayed  in lower panel.")
		
		### Font Size label ###
		lbl_font_size = Gtk.Label()
		grid.attach(lbl_font_size, 2, 2, 1, 1)
		lbl_font_size.set_markup('<span size="14000" foreground="#222222"><b>Size</b></span>')

		#### Font Size combo box  ###
		self.combo_size = Gtk.ComboBoxText()
		f_size = sList
		y = 0
		scur = 0
		for l in f_size:
			self.combo_size.append_text(l)
			if default_size.split(".")[0] == str(l):
				scur = y
			y += 1
			self.combo_size.set_active(scur)	
		grid.attach(self.combo_size, 2, 3, 1, 1)
		self.combo_size.set_property("tooltip-text", "Font size for GTK apps\n(including both file managers)\nAs well as the taskbar in Icewm.\n\nSize Changes displayed  in lower panel.")

		###Termlabel ###
		lbl_term_size = Gtk.Label()
		grid.attach(lbl_term_size, 3, 2, 1, 1)
		lbl_term_size.set_markup('<span size="14000" foreground="#555555"><b>Xterm</b></span>')

		#### Font Size (Term) combo box  ###
		self.combo_size2 = Gtk.ComboBoxText()
		tX = self.get_term()
		y = 0
		scur = 0
		for l in sList:
			self.combo_size2.append_text(l)
			if tX == l:
				scur = y
			y += 1
			self.combo_size2.set_active(scur)		
		grid.attach(self.combo_size2, 3, 3, 1, 1)
		self.combo_size2.set_property("tooltip-text", "Set XTerm (Bash) font size")		

		###Menulabel ###
		lbl_menu_size = Gtk.Label()
		grid.attach(lbl_menu_size, 4, 2, 1, 1)
		lbl_menu_size.set_markup('<span size="14000" foreground="#334D63"><b>Menu</b></span>')

		#### Font Size (Menu) combo box  ###
		self.combo_size3 = Gtk.ComboBoxText()
		tM = self.get_menu()
		y = 0
		scur = 0
		for m in sList:
			self.combo_size3.append_text(m)
			if tM == m:
				scur = y
			y += 1
			self.combo_size3.set_active(scur)		
		grid.attach(self.combo_size3, 4, 3, 1, 1)
		self.combo_size3.set_property("tooltip-text",  "Set Menu font size")	

		lbl_blank = Gtk.Label()
		lbl_blank.set_hexpand(True)
		grid.attach(lbl_blank, 0, 4, 5, 2)

		self.cb_clock = Gtk.CheckButton(label=" Bold Clock")
		self.cb_clock.get_children()[0].set_markup('<span size="14000" foreground="#555555"><b>Bold Clock</b></span>')
		self.cb_clock.set_tooltip_text('Set this if you want the taskbar\nclock slightly larger and bold.')
		grid.attach(self.cb_clock, 0, 6, 1, 1)
		if os.path.exists(prefpath):
			if subprocess.getoutput('grep -R ClockFontNameXft "%s" | grep bold 2>/dev/null' %  prefpath):
				self.cb_clock.set_active(True)


		self.set_font = Gtk.Button.new_with_label("Change Font")
		grid.attach(self.set_font, 2, 6, 1, 1)
		self.set_font.connect("clicked", self.makeChange)	
		set_txt_lbl = self.set_font.get_children()[0]
		set_txt_lbl.set_markup('<span size="12000" foreground="#CA0603"><b>Change Font</b></span>')
		self.set_font.set_property("tooltip-text",  "Makes system font changes.\nRestarts icewm, qtfm and ROX to display the new settings.")

		self.cb_menu = Gtk.CheckButton(label=" Bold Menu")
		self.cb_menu.get_children()[0].set_markup('<span size="14000" foreground="#555555"><b>Bold Menu</b></span>')
		self.cb_menu.set_tooltip_text('Set this if you want the start\nmenu text to be bold.')
		grid.attach(self.cb_menu, 4, 6, 1, 1)
		if os.path.exists(prefpath):
			if subprocess.getoutput('grep -R MenuFontNameXft "%s" | grep bold 2>/dev/null' %  prefpath):
				self.cb_menu.set_active(True)

		lbl_blank1 = Gtk.Label()
		lbl_blank1.set_hexpand(True)
		grid.attach(lbl_blank1, 0, 7, 5, 2)

		sep = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
		# Load the CSS
		cssSEP = b"""#red_sep.red { background-image: image(red); }"""
		gtk_provider.load_from_data(cssSEP)
		sep.set_name("red_sep")
		sep_style_context = sep.get_style_context()
		sep_style_context.add_class("red")
		grid.attach(sep, 0, 9, 5, 1)

		lbl_blank2 = Gtk.Label()
		lbl_blank2.set_hexpand(True)
		grid.attach(lbl_blank2, 0, 11, 5, 2)

		self.event_box = Gtk.EventBox()
		grid.attach(self.event_box, 0, 13, 5, 1)
		self.f_display = Gtk.Label()
		self.f_display.set_markup(display_text)
		font_name = self.combo.get_active_text()
		font_desc.set_family(font_name)
		# font size for pango gets multiplied by 1024
		font_desc.set_size(int(default_size) * 1024)

		#self.f_display.modify_font(font_desc)
		self.event_box.add(self.f_display)

		###  connect the display to the combo changes  ###
		self.combo.connect('changed', self.changed_font)
		self.combo_size.connect('changed', self.change_size)

		self.window.show_all()
		self.combo.grab_focus()


def main(argv):	
	ShowFonts(argv)
	Gtk.main()

if __name__ == "__main__":
	main(sys.argv)
