Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-12-18 10:25:44 (GMT)
committer Anish Mangal <anish@activitycentral.com>2012-04-27 10:04:45 (GMT)
commit90b538a07b7813f8278e61883dae96cb3e12ae2f (patch)
treee41a7affae2550148513e1b961de344f03a7e230
parent3af98641a4471468caa61705f0fba1205247ec29 (diff)
Clipboard menu off screen #2201
New font.char_width property to return approximate char width. Set Palette's text_maxlen to a half of the screen by defualt.
-rw-r--r--src/sugar/graphics/palette.py21
-rw-r--r--src/sugar/graphics/style.py40
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)