A full-featured desktop on a single CD that can still work on older equiptment.







 

Set System Font

Derived from FontPage (a utility I wrote to install/view fonts on Absolute), setSysFont alows you to pick the font and size you would like displayed by GTK, ICEWM in the menus, titlebars and taskbar, as well as all the menus and dialogs in Firefox.

Changes are made on a PER USER basis. All affected systems are updated without restarting X-windows.





Source Code is below the menu:

(embedded images were removed for the sake of size and readability)

It also uses a small script called "startROX", used by other stuff, which simply restarts ROX, but does some checking if hald is running and start ROX differently, depending. It simplified the script and made things a bit more modular to have it separated.




#!/usr/bin/env python
#################################################################################
# c2007 by Paul Sherman  http://www.pcbypaul.com     #
#									        #
# 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 2		#
# 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.   #
#################################################################################
##  importing with system requirement checks ####################################

import sys, os, time, commands, string, shutil, re, fileinput
import pygtk
import gobject
if gobject.pygtk_version < (2,5,9):
    print >>sys.stderr, "pyGTK version 2.6 or greater is required for this application"
    raise SystemExit
import gtk
try:
	import pango
except:
	print >> sys.stderr, "Cannot load Pango"
	raise SystemExit

f = commands.getoutput('type -path fc-list')
if not f:
	print >> sys.stderr, "You need FontConfig to run FONTpage"
	raise SystemExit

appPath = os.path.realpath(sys.argv[0])
cfile = os.path.join(os.path.expanduser("~/"), ".gtkrc-2.0")
default_font = "unknown"
fsize = 10

# path for the icewm preferences file - should always exist on Absolute, give user hell if not :)
prefpath = os.path.expanduser("~") + "/.icewm/preferences"
if not os.path.exists(prefpath):
	print "you seem to have removed your icewm preferences file."
	print "it should be located at: " 
	print prefpath
	raise SystemExit
	
# for firefox we make sure a userChrome file exists, creating one if it does not
# some folks tend to play with this, so we make sure they did not delete it post-frustration :)
mozstr = """@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* set default namespace to XUL */
"""
mozpath = commands.getoutput('ls $HOME/.mozilla/firefox/*/chrome/userChrome.css')
if re.search("ls:", mozpath):
	mozpathfolder = commands.getoutput('ls -d $HOME/.mozilla/firefox/*/chrome')
	if re.search("ls:", mozpathfolder):
		mozpath = ""
	else:
		mozpath = mozpathfolder + "/userChrome.css"
		f = open(mozpath,'w')
		f.write(mozstr)
		f.close()
		

display_text = "abcdefghijklm\nABCDEFGHIJKLM\n1234567890"

############### now for our icons and font_description  ########################		
font_desc = pango.FontDescription()

bar_xpm = [
# bar image was here
]

close_xpm = [
# close image was here]

icon_xpm = [
# icon image was here
]

bar_thin_xpm = [
# thin bar image was here
]

			
class ShowFonts:
		
	def get_font_list(self=None, e=None):
		raw_list = commands.getoutput('fc-list')
		line_list = string.split(raw_list, "\n")
		
		fl = []
		for i in range(len(line_list)):
			ftemp = string.split(line_list[i], ':')
			fl.append(ftemp[0])

		fl.sort()
		last = fl[-1]
		for i in range(len(fl)-2, -1, -1):
			if last==fl[i]: del fl[i]
			else: last=fl[i]
		return fl
		
		
	def info(self, message):
		box = gtk.MessageDialog(None, 0, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, message)
		box.set_position(gtk.WIN_POS_CENTER)
		box.set_title('Information')
		box.run()
		box.destroy()	
		
		
	def alert(self, message):
		box = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message)
		box.set_position(gtk.WIN_POS_CENTER)
		box.set_title('Error')
		box.run()
		box.destroy()		
		
		
	def changed_font(self, evt=None, data=None):
		font_name = self.combo.get_active_text()
		font_desc.set_family(font_name)
		self.f_display.set_text(display_text)
		self.f_display.modify_font(font_desc)
	
			
	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)

	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.STATE_NORMAL, None)
		self.f_display.modify_fg(gtk.STATE_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 display_font(self, btn):
		fn = self.combo.get_active_text()
		fs = int(self.combo_size.get_active_text())
		self.font_display_window(btn, fn, fs)
			
				

	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 makeChange(self, w=None):	
		font_name = self.combo.get_active_text()
		font_size = self.combo_size.get_active_text()
		# first, change the gtk setting
		try:
			file = open( cfile, 'w' )
			file.write( 'gtk-font-name="' + font_name + ' ' + font_size + '"' )
			file.close()
		except:
			print >> sys.stderr, "Cannot write configuration file to your home directory."
			raise SystemExit
			
		# make adjustments to the icewm preferences for menu and taskbar
		# any theme font settings will prevent this :(
		fset = font_name + ':size=' + font_size
		f1=commands.getoutput('grep MenuFontNameXft %s' % prefpath)
		f2=commands.getoutput('grep NormalTaskBarFontNameXft %s' % prefpath)
		f3=commands.getoutput('grep ActiveTaskBarFontNameXft %s' % prefpath)
		f4=commands.getoutput('grep TitleFontNameXft %s' % prefpath)
		
		t1 = 'MenuFontNameXft="' + fset + '"'
		t2 = 'NormalTaskBarFontNameXft="' + fset + '"'
		t3 = 'ActiveTaskBarFontNameXft="' + fset + ':bold"'
		t4 = 'TitleFontNameXft="' + fset + '"'

		for line in fileinput.input(prefpath, inplace=1):
			if f1 in line:
        			print line.replace(f1, t1),
			elif f2 in line:
				print line.replace(f2, t2),
			elif f3 in line:
				print line.replace(f3, t3),
			elif f4 in line:
				print line.replace(f4, t4),
			else:
				print line,
		try:
			cmd = 'killall -HUP icewm 2&>/dev/null'
			os.system(cmd)
		except:
			pass
		#################################################################	
		# Now the ROX_Filer
		try:
			os.system('killall -9 ROX-Filer')
		except:
			pass
		try:
			os.system('startROX')
		except:
			pass
		###################################################################
		# and finally kick these settings into firefox check if font family 
		# and size lines are there change if they are, append if not
		if not mozpath == "":
			# adjust size as Firefox display runs a quite large on the fonts
			msize = font_size
			sTmp = int(font_size)
			if sTmp == 18:
				msize = str(14)
			elif sTmp == 16:
				msize = str(12)
			elif sTmp == 14:
				msize = str(11)
			elif sTmp == 12:
				msize = str(10)
			elif sTmp == 10:
				msize = str(9)
			elif sTmp == 9:
				msize = str(8)
			else:
				pass
			# now put these funky settings into the firefox userChrome.css
			mozstr = 'menubar, menubutton, menulist, menu, menuitem, textbox, toolbar, tab, tree, tooltip{ font-family: ' + font_name + ' !important; font-size: ' + msize + ' !important; }'
			fmoz = commands.getoutput('grep font-family %s 2>/dev/null' % mozpath)
			try:
				if not fmoz:
					f = open(mozpath,"a")
					f.write(mozstr)
					f.close()
				else:
					for line in fileinput.input(mozpath, inplace=1):
    						print line.replace(fmoz, mozstr),
			except:
				pass


#########################################################################################################
#########################################################################################################
	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(cfile):
			try:
				file = open( cfile, 'w' )
				file.write( "gtk-font-name=\"Aerial 10\"" )
				file.close()
			except:
				print >> sys.stderr, "Cannot write configuration file to your home directory."
				raise SystemExit
		
		###########  close button, bar anf logo  ################
		bar = gtk.gdk.pixbuf_new_from_xpm_data(bar_xpm)
		thin_bar = gtk.gdk.pixbuf_new_from_xpm_data(bar_thin_xpm)
		closer = gtk.gdk.pixbuf_new_from_xpm_data(close_xpm)
		icon = gtk.gdk.pixbuf_new_from_xpm_data(icon_xpm)

		bar_img = gtk.Image()
		sm_bar = gtk.Image()
		close_img = gtk.Image()
		self.txt_pix = gtk.Image()

		bar_img.set_from_pixbuf(bar)
		close_img.set_from_pixbuf(closer)
		sm_bar.set_from_pixbuf(thin_bar)


		###########  window setup  ################
		
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.set_title("Absolute System Font Setting")
		self.window.set_border_width(5)
		self.window.set_default_size(500, 280)
		self.window.set_position(gtk.WIN_POS_CENTER)
		self.window.set_geometry_hints(self.window, 500, 280, 600, 380)
		self.window.connect("delete_event", self.delete_event)
		self.tooltips = gtk.Tooltips()
		self.window.set_icon(icon)

		###########  layout  ################
		vbox = gtk.VBox(False, 16)
		self.window.add(vbox)

		###########  close and bar and logo ################
		top_box = gtk.HBox(False, 0)
		vbox.pack_start(top_box, False, True, 0)

		btn_close = gtk.Button()
		btn_close.add(close_img)
		btn_close.set_relief(gtk.RELIEF_NONE)
		
		btn_close.connect("clicked", self.doClose)
		self.tooltips.set_tip(btn_close, "CLOSE")

		top_box.pack_end(btn_close, False, False, 0)
		top_box.pack_start(bar_img, False, False, 0)


		###########  Lower boxes layout ########

		bot_box = gtk.HBox(True,0)
		vbox.pack_start(bot_box, False, False, 0)
		self.bot_L_box = gtk.VBox(False,8)
		self.bot_C_box = gtk.VBox(False,8)
		self.bot_R_box = gtk.VBox(False,8)
		
		bot_box.pack_start(self.bot_L_box, True, True, 20)
		bot_box.pack_start(self.bot_C_box, False, False, 0)
		bot_box.pack_start(self.bot_R_box, False, False, 0)

		self.new_box = gtk.HBox(True, 0)
		vbox.pack_start(self.new_box, False, False, 0)	
			
		vbox.pack_start(sm_bar, False, False, 0)
		
		last_box = gtk.VBox(False,10)
		vbox.pack_start(last_box, False, False, 0)

		##########  left box setup  ###############

		### static text label ###
		lbl_font_face = gtk.Label("Font Face Name")
		self.bot_L_box.pack_start(lbl_font_face, False, False, 0)
		lbl_font_face.set_markup('Font Name')


		#### Font Name combo box  ###
		self.combo = gtk.combo_box_new_text()
		flist = self.get_font_list()
		
		# gets the PATH of the font
		x = 0
		cur = 0
		default_font = lbl_font_face.get_pango_context().get_font_description().get_family()
		default_size = str(lbl_font_face.get_pango_context().get_font_description().get_size() / 1024)
		
		for l in flist:
			self.combo.append_text(l)
			if default_font == l:
				cur = x
			x += 1
                self.combo.set_active(cur)	
		self.bot_L_box.pack_start(self.combo, False, False, 0)


		### static text label ###
		lbl_font_size = gtk.Label("Font Size:")
		self.bot_C_box.pack_start(lbl_font_size, False, False, 0)
		lbl_font_size.set_markup('Font Size')

		#### Font Name combo box  ###
		self.combo_size = gtk.combo_box_new_text()
		f_size = ["8", "9", "10", "11", "12", "14",  "16", "18"]
		# set font size - iterates through possible values of f_size for a match
		y = 0
		scur = 0
		for l in f_size:
			self.combo_size.append_text(l)
			if default_size == l:
				scur = y
			y += 1
                self.combo_size.set_active(scur)		
		self.bot_C_box.pack_start(self.combo_size, False, False, 0)		

		lbl_make_change = gtk.Label("Commit")
		self.bot_R_box.pack_start(lbl_make_change, False, False, 0)
		lbl_make_change.set_markup('Commit')
		self.set_font = gtk.Button("Commit Changes")
		self.bot_R_box.pack_start(self.set_font, False, False, 0)
		self.set_font.connect("clicked", self.makeChange)	
		set_txt_lbl = self.set_font.get_children()[0]
		set_txt_lbl.set_markup('Change Font')
		self.tooltips.set_tip(self.set_font, "This will make the font change and\nrestart icewm and ROX to display the new settings.\nAny open ROX-Filer windows will be closed.")
		
		####################################################################################	
		###  font display  ###
		
		self.control_box = gtk.HBox(True, 0)
		last_box.pack_start(self.control_box, True, True, 0)
		
		self.event_box = gtk.EventBox()
		self.control_box.pack_start(self.event_box, False, False, 0)
		

		self.f_display = gtk.Label(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(fsize) * 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()

	class font_display_window(gtk.Window):

		def delete_event(self, e=None):
			self.destroy()

		def __init__(self, e=None, fn=None, fs=None):
			gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)

			if fs==None: fs=10
			if fn==None: fn="Aerial"
			self.connect("destroy", self.delete_event)
			f_desc = pango.FontDescription()
			f_desc.set_family(fn)
			f_desc.set_size(fs * 1024)
        		self.set_title(fn)
			self.set_border_width(0)
			self.set_position(gtk.WIN_POS_CENTER)
			lbl = gtk.Label("")
			lbl.set_padding(2, 2)
			lbl.set_text(display_text)
			lbl.modify_font(f_desc)
			lbl.show()
			box1 = gtk.VBox()
			box1.pack_start(lbl)
			self.add(box1)
			box1.show()
			self.show()
			
			
def main(argv):	
	ShowFonts(argv)
	gtk.main()
	
if __name__ == "__main__":
	main(sys.argv)			





Tux Pages created on Absolute OS Graphics made/edited by the Gimp   Created with the Gimp byPaul