Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/rpms/sugar-toolkit/0029-Clipboard-menu-off-screen-2201.patch
blob: 6a565401fd7b96bf10bb9ff6fad23043e676e07e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From 763478cfe719a6fc4ae9be0b8a58b8cf9ed02a47 Mon Sep 17 00:00:00 2001
From: Aleksey Lim <alsroot@member.fsf.org>
Date: Sat, 18 Dec 2010 10:25:44 +0000
Subject: [PATCH 29/33] Clipboard menu off screen #2201
Organization: Sugar Labs Foundation

New font.char_width property to return approximate char width. Set Palette's
text_maxlen to a half of the screen by defualt.
---
 src/sugar/graphics/palette.py |   21 +++++++++++++++++----
 src/sugar/graphics/style.py   |   40 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/src/sugar/graphics/palette.py b/src/sugar/graphics/palette.py
index 8a2098e..ef59163 100644
--- a/src/sugar/graphics/palette.py
+++ b/src/sugar/graphics/palette.py
@@ -45,10 +45,23 @@ class Palette(PaletteWindow):
     __gtype_name__ = 'SugarPalette'
 
     def __init__(self, label=None, accel_path=None, menu_after_content=False,
-                 text_maxlen=60, **kwargs):
-        # DEPRECATED: label is passed with the primary-text property,
-        # accel_path is set via the invoker property, and menu_after_content
-        # is not used
+                 text_maxlen=None, **kwargs):
+        """Constructor.
+
+        Keyword arguments:
+        label -- DEPRECATED, is passed with the primary-text property
+        accel_path -- DEPRECATED, is set via the invoker property
+        menu_after_content -- DEPRECATED, is not used
+        text_maxlen -- max length of palette titles after that it becomes
+                       ellipsized, possible values:
+                       None -- autodetect most appropriate value, by default
+                       <= 0 -- do not ellipsize titles
+                       > 0 -- valid width value
+
+        """
+        if text_maxlen is None:
+            text_maxlen = (gtk.gdk.screen_width() / 2) / \
+                    style.FONT_DEFAULT.char_width
 
         self._primary_text = None
         self._secondary_text = None
diff --git a/src/sugar/graphics/style.py b/src/sugar/graphics/style.py
index f081bb7..4d34a74 100644
--- a/src/sugar/graphics/style.py
+++ b/src/sugar/graphics/style.py
@@ -46,15 +46,46 @@ def _compute_zoom_factor():
 
 
 class Font(object):
+    """High level font information."""
 
-    def __init__(self, desc):
-        self._desc = desc
+    def __init__(self, desc=None):
+        """Constructor.
+
+        Keyword arguments:
+        desc -- string with font description
+
+        """
+        default_context = gtk.Label().get_pango_context()
+
+        if desc is None:
+            self._desc = default_context.get_font_description()
+        else:
+            self._desc = pango.FontDescription(desc)
+
+        metrics = default_context.get_metrics(self._desc)
+        self._char_width = max(metrics.get_approximate_char_width(),
+                metrics.get_approximate_digit_width()) / pango.SCALE
 
     def __str__(self):
-        return self._desc
+        return self._desc.to_string()
 
     def get_pango_desc(self):
-        return pango.FontDescription(self._desc)
+        """Returns pango font description object."""
+        return self._desc
+
+    pango_desc = property(get_pango_desc)
+
+    def get_char_width(self):
+        """Approximate char width.
+
+        This is merely a representative value that is useful, for example, for
+        determining the initial size for a window. Actual characters in text
+        will be wider and narrower than this.
+
+        """
+        return self._char_width
+
+    char_width = property(get_char_width)
 
 
 class Color(object):
@@ -121,6 +152,7 @@ THEME = client.get_string('/desktop/sugar/interface/gtk_theme')
 FONT_SIZE = client.get_float('/desktop/sugar/font/default_size')
 FONT_FACE = client.get_string('/desktop/sugar/font/default_face')
 
+FONT_DEFAULT = Font()
 FONT_NORMAL = Font('%s %f' % (FONT_FACE, FONT_SIZE))
 FONT_BOLD = Font('%s bold %f' % (FONT_FACE, FONT_SIZE))
 FONT_NORMAL_H = zoom(24)
-- 
1.7.4.4