[gimp] pygimp: pyconsole: use appropriate Pango function to estimate char width
- From: Kristian Rietveld <kristian src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] pygimp: pyconsole: use appropriate Pango function to estimate char width
- Date: Fri, 29 Apr 2016 19:52:52 +0000 (UTC)
commit cd5dfb86429be05266f532ca24a4238697136347
Author: Kristian Rietveld <kris loopnest org>
Date: Fri Apr 29 08:33:21 2016 +0200
pygimp: pyconsole: use appropriate Pango function to estimate char width
plug-ins/pygimp/plug-ins/pyconsole.py | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/plug-ins/pygimp/plug-ins/pyconsole.py b/plug-ins/pygimp/plug-ins/pyconsole.py
index 2f01c4a..3b71074 100644
--- a/plug-ins/pygimp/plug-ins/pyconsole.py
+++ b/plug-ins/pygimp/plug-ins/pyconsole.py
@@ -385,13 +385,17 @@ class _ReadLine(object):
self.__delete(iter, end)
def __get_width(self):
+ '''Estimate the number of characters that will fit in the area
+ currently allocated to this widget.'''
+
if not (self.flags() & gtk.REALIZED):
return 80
- layout = pango.Layout(self.get_pango_context())
- letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- layout.set_text(letters)
- pix_width = layout.get_pixel_size()[0]
- return self.allocation.width * len(letters) / pix_width
+
+ context = self.get_pango_context()
+ metrics = context.get_metrics(context.get_font_description(),
+ context.get_language())
+ pix_width = metrics.get_approximate_char_width()
+ return self.allocation.width * pango.SCALE / pix_width
def __print_completions(self, completions):
line_start = self.__get_text(self.__get_start(), self.__get_cursor())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]