<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>handyfloss &#187; glade</title>
	<atom:link href="http://handyfloss.net/tag/glade/feed/" rel="self" type="application/rss+xml" />
	<link>http://handyfloss.net</link>
	<description>Because FLOSS is handy, isn&#039;t it?</description>
	<lastBuildDate>Mon, 30 Aug 2010 10:37:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Changing font style in PyGTK ComboBox</title>
		<link>http://handyfloss.net/2009.06/changing-font-style-in-pygtk-combobox/</link>
		<comments>http://handyfloss.net/2009.06/changing-font-style-in-pygtk-combobox/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 10:34:16 +0000</pubDate>
		<dc:creator>isilanes</dc:creator>
				<category><![CDATA[Free software and related beasts]]></category>
		<category><![CDATA[about me]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[FLOSS]]></category>
		<category><![CDATA[glade]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://handyfloss.net/?p=762</guid>
		<description><![CDATA[I am using the Glade Interface Designer to produce (very) small (and simple) graphical apps for my Neo FreeRunner. I produce the graphical layout in the form of an XML file (using Glade), then load this XML from a PyGTK program. The thing is some defaults are not really usable for a device such as [...]]]></description>
			<content:encoded><![CDATA[<p>I am using the <a href="http://en.wikipedia.org/wiki/Glade Interface Designer">Glade Interface Designer</a> to produce (very) small (and simple) graphical apps for my <a href="http://en.wikipedia.org/wiki/Neo FreeRunner">Neo FreeRunner</a>. I produce the graphical layout in the form of an <a href="http://en.wikipedia.org/wiki/XML">XML</a> file (using Glade), then load this XML from a <a href="http://en.wikipedia.org/wiki/PyGTK">PyGTK</a> program.</p>
<p>The thing is some defaults are not really usable for a device such as the NFR. For example, default fonts are in general too small for the tiny screen of the Neo, which favors apps with only a few, big and shinny buttons. In the case of Label widgets, you can use <a href="http://library.gnome.org/devel/pango/unstable/PangoMarkupFormat.html">Pango markup format</a> with the <tt>set_markup</tt> method, as follows:</p>
<div class="codeblock">
<pre>
mylabel  = self.glade.get_widget('label1')
txt  = '&lt;span font_size="80000" color="red"&gt;%s&lt;/span&gt;' % (text_string)
mylabel.set_markup(txt)
</pre>
</div>
<p>However, for other widgets it is not so evident. For example, in ComboBoxes (buttons with a drop-down list), you can&#8217;t put in the item list anything other than strings, which are displayed literally (markup is not interpreted). Moreover, CBs do not have a &#8220;<tt>set_font_style</tt>&#8221; method, or anything similar.</p>
<p>Searching the web did not provide immediate results, but I managed to find <a href="http://eccentric.cx/misc/pygtk/pygtkfaq.html#4.1">this FAQ item</a> at eccentric.cx. I quote:</p>
<blockquote><p>
<b>4.1.581 How do I change font properties on gtk.Labels and other widgets?</b><br />
Easy:</p>
<pre>
 label = gtk.Label("MyLabel")
 label.modify_font(pango.FontDescription("sans 48"))
</pre>
<p>This method applies to all widgets that use text, so you can change the text of gtk.Entry and other widgets in the same manner.</p>
<p>Note that, some widgets are only containers for others, like gtk.Button. For those you&#8217;d have to get the child widget. For a gtk.Button do this:</p>
<pre>
  if button.get_use_stock():
     label = button.child.get_children()[1]
  elif isinstance(button.child, gtk.Label):
     label = button.child
  else:
     raise ValueError("button does not have a label")
</pre>
<p>Last changed on Thu Sep 1 14:46:30 2005 by Johan Dahlin (johan-at-gnome-org)
</p></blockquote>
<p>In the case of a CB, we have to pick its child (which is the list itself), and modify it thusly:</p>
<div class="codeblock">
<pre>
cbox = self.glade.get_widget("CBlist")
cblist  = cbox.child
cblist.modify_font(pango.FontDescription("sans 32"))
</pre>
</div>
<p>In my examples above, a class has been created in the script beforehand, and it binds to the Glade XML:</p>
<div class="codeblock">
<pre>
class whatever:

  def __init__(self):

    #Set the Glade file
    self.glade    = gtk.glade.XML(<i>gladefile</i>)
    self.glade.signal_autoconnect(self)
</pre>
</div>
<p>Of course, the <tt>CBlist</tt> and <tt>MyLabel</tt> mentioned in my code are the appropriate widget names defined in that XML.</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://handyfloss.net/2010.03/speed-up-pygtk-and-cairo-by-reusing-images/" title="Speed up PyGTK and Cairo by reusing images (March 18, 2010)">Speed up PyGTK and Cairo by reusing images</a> (0)</li>
	<li><a href="http://handyfloss.net/2009.07/plzma-py-a-wrapper-for-parallel-implementation-of-lzma-compression/" title="plzma.py: a wrapper for parallel implementation of LZMA compression (July 23, 2009)">plzma.py: a wrapper for parallel implementation of LZMA compression</a> (3)</li>
	<li><a href="http://handyfloss.net/2009.12/chopzip-a-parallel-implementation-of-arbitrary-compression-algorithms/" title="ChopZip: a parallel implementation of arbitrary compression algorithms (December 20, 2009)">ChopZip: a parallel implementation of arbitrary compression algorithms</a> (2)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://handyfloss.net/2009.06/changing-font-style-in-pygtk-combobox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
