473,394 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Fontproblems with PyGUI and gtk 2.4.10

Hi!

After some installation problems related to PyGUI (well, indirectly -- I
had to install new versions of: freetype, fontconfig, xft2 (from
fcpackage.2_1.tar.gz, because the latest xft2 won't compile with X4.2.0)
(which needed a patch to Xft.h because apparently the #include-style of
freetype did change), GLib, Pango, ATK, GTK+ and pygtk) I ran the
scripts from Tests and there were problems that text was cut off or
textfields were not tall enough (e.g. 09-textfield.py). I did some
digging and found the cause. The problem is in the line

gdk_font = gdk.font_from_description(self._pango_description)

in Fonts.Font._get_gdk_font(). In gtk 2.4.10 gdk_font_from_description
calls gdk_font_from_description_for_display in gdkfont-x11.c, which
contains the line

return gdk_font_load_for_display (display, "fixed");

So regardless what font is wanted, the fixed font gets loaded. The big
problem here is that some widgets use a different font but use
Font.width(), get_height() etc. for layout. Of course this give wrong
values (e.g. get_height() always returns 13, width(s) always 6*len(s)).

It looks as if Fonts.py has to be ported to fully use pango. For
get_ascent, get_descent (btw. the gdk_font based version returns ascent)
and get_height there is code which seems to work, it is just commented
and some small changes must made. But rewriting width() and x_to_pos() to
use pango seems to be not easy. At least I see no obvious way to do it.
But this change really should be made because all the GdkFont functions
are declared obsolete in the gtk+ documentation.

I've attached a patch for two small typos in Fonts.py

--- Fonts.py.orig Tue Sep 21 23:08:28 2004
+++ Fonts.py Tue Sep 21 23:12:43 2004
@@ -45,7 +45,7 @@
return self._pango_description.get_family()

def get_size(self):
- return self.self._pango_description.get_size()
+ return self._pango_description.get_size()

def get_style(self):
style = []
@@ -60,7 +60,7 @@
return self._get_gdk_font().ascent

def get_descent(self):
- return self._get_gdk_font().ascent
+ return self._get_gdk_font().descent

def get_height(self):
gdk_font = self._get_gdk_font()

and here one to change get_ascent, get_descent and get_height to pango

--- Fonts.py.orig Tue Sep 21 23:18:54 2004
+++ Fonts.py Tue Sep 21 23:15:09 2004
@@ -10,6 +10,7 @@
class Font(GFont):

_gdk_font = None
+ _pango_metrics = None

# def _from_gdk_font(cls, gdk_font):
# font = cls.__new__(cls)
@@ -56,15 +57,15 @@
style.append('italic')
return style

- def get_ascent(self):
- return self._get_gdk_font().ascent
-
- def get_descent(self):
- return self._get_gdk_font().descent
-
- def get_height(self):
- gdk_font = self._get_gdk_font()
- return gdk_font.ascent + gdk_font.descent
+# def get_ascent(self):
+# return self._get_gdk_font().ascent
+#
+# def get_descent(self):
+# return self._get_gdk_font().descent
+#
+# def get_height(self):
+# gdk_font = self._get_gdk_font()
+# return gdk_font.ascent + gdk_font.descent

def _get_gdk_font(self):
gdk_font = self._gdk_font
@@ -73,26 +74,26 @@
self._gdk_font = gdk_font
return gdk_font

-# def get_ascent(self):
-# pfm = self._get_pango_metrics()
-# return pfm.ascent
-#
-# def get_descent(self):
-# self._get_pango_metrics()
-# return self._descent
-#
-# def get_height(self):
-# self._get_pango_metrics()
-# return self._ascent + self._descent
-#
-# def _get_pango_metrics(self):
-# pfm = self._pango_metrics
-# if not pfm:
-# pfm = _pango_context.get_metrics(self._pango_description )
-# self._pango_metrics = pfm
-# self._ascent = pfm.ascent / pango.SCALE
-# self._descent = pfm.descent / pango.SCALE
-# return pfm
+ def get_ascent(self):
+ self._get_pango_metrics()
+ return self._ascent
+
+ def get_descent(self):
+ self._get_pango_metrics()
+ return self._descent
+
+ def get_height(self):
+ self._get_pango_metrics()
+ return self._ascent + self._descent
+
+ def _get_pango_metrics(self):
+ pfm = self._pango_metrics
+ if not pfm:
+ pfm = _pango_context.get_metrics(self._pango_description )
+ self._pango_metrics = pfm
+ self._ascent = pfm.get_ascent() / pango.SCALE
+ self._descent = pfm.get_descent() / pango.SCALE
+ return pfm

def width(self, s, start = 0, end = sys.maxint):
gdk_width = self._get_gdk_font().width
Jul 18 '05 #1
0 1086

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

108
by: Zooko O'Whielacronx | last post by:
I'm a fan of Greg Ewing's PyGUI . I used it to code a simple game for my son , and enjoyed it. Programming with wxPython feels like programming with a C++ tool that has been wrapped in Python....
8
by: Ron Stephens | last post by:
Can anyone give me a brief comparison of the purposes of these two projects (AnyGUI and pyGUI)? In other words, how are the motivations and goals for each project different? Ron Stephens
3
by: greg | last post by:
A small problem has come to light with PyGUI 1.6 on MacOSX systems. If you get the following exception: File "GUI/Generic/BaseAlertFunctions.py", line 5, in ? ImportError: No module named...
1
by: Arnd | last post by:
Heya, any PyGUI users out there? I needed some finer text-positioning on a canvas (ie wanted to center a string wrt a point, something show_text() doesn't provide) So I looked into the...
37
by: Michael Palmer | last post by:
As anyone knows, the state of Python GUI programming is a little fractured at this time, with many toolkits, wrappers and meta-wrappers dead and alive, with or without documentation. I've come...
2
by: Hugh | last post by:
The PyGUI website specified this place as the place for general discussion about it, so here goes.... First off - thanks for something that is so straightforward to get running on OSX... I've...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.