diff options
author | Jorge Saldivar <jsaldivar@paraguayeduca.org> | 2011-02-22 14:11:07 (GMT) |
---|---|---|
committer | Jorge Saldivar <jsaldivar@paraguayeduca.org> | 2011-02-22 14:11:07 (GMT) |
commit | 81b877fff8b567f18eef67afcc84413b1087031f (patch) | |
tree | 57a508c981f0ab2cfe2d3a4affaebc0881f99e10 | |
parent | dddfc74e629020dbf0d9504b9b8f23bde9259c09 (diff) |
Add text attributes features (bold, italic, color, underline, differents fonts name and sizes)
-rw-r--r-- | icons/bold-text.svg | 72 | ||||
-rw-r--r-- | icons/italics-text.svg | 72 | ||||
-rw-r--r-- | icons/toolbar-text.svg | 8 | ||||
-rw-r--r-- | icons/underline-text.svg | 78 | ||||
-rw-r--r-- | labyrinthactivity.py | 204 | ||||
-rw-r--r-- | src/MMapArea.py | 27 | ||||
-rw-r--r-- | src/TextThought.py | 87 | ||||
-rw-r--r-- | src/utils.py | 2 |
8 files changed, 523 insertions, 27 deletions
diff --git a/icons/bold-text.svg b/icons/bold-text.svg new file mode 100644 index 0000000..7b6b672 --- /dev/null +++ b/icons/bold-text.svg @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + enable-background="new 0 0 55 54.696" + height="54.696px" + version="1.1" + viewBox="0 0 55 54.696" + width="55px" + x="0px" + xml:space="preserve" + y="0px" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.47 r22583" + sodipodi:docname="bold-text.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"><metadata + id="metadata22"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs + id="defs20"><inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 27.348 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="55 : 27.348 : 1" + inkscape:persp3d-origin="27.5 : 18.232 : 1" + id="perspective24" /> + + + + + + + + + </defs><sodipodi:namedview + inkscape:window-height="749" + inkscape:window-width="1280" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + showgrid="false" + inkscape:zoom="8.4466873" + inkscape:cx="25.428182" + inkscape:cy="28.061519" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:current-layer="svg2" + inkscape:window-maximized="1" /><text + xml:space="preserve" + style="font-size:49.5765152px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana" + x="11.231925" + y="43.461388" + id="text3591" + transform="scale(0.90891499,1.1002129)"><tspan + sodipodi:role="line" + id="tspan3593" + x="11.231925" + y="43.461388" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:Arial Black;-inkscape-font-specification:'Arial Black, Bold'">B</tspan></text> +</svg>
\ No newline at end of file diff --git a/icons/italics-text.svg b/icons/italics-text.svg new file mode 100644 index 0000000..57a0075 --- /dev/null +++ b/icons/italics-text.svg @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + enable-background="new 0 0 55 54.696" + height="54.696px" + version="1.1" + viewBox="0 0 55 54.696" + width="55px" + x="0px" + xml:space="preserve" + y="0px" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.47 r22583" + sodipodi:docname="italics-text.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"><metadata + id="metadata22"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs + id="defs20"><inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 27.348 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="55 : 27.348 : 1" + inkscape:persp3d-origin="27.5 : 18.232 : 1" + id="perspective24" /> + + + + + + + + + </defs><sodipodi:namedview + inkscape:window-height="749" + inkscape:window-width="1280" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + showgrid="false" + inkscape:zoom="8.4466873" + inkscape:cx="25.428182" + inkscape:cy="26.560732" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:current-layer="svg2" + inkscape:window-maximized="1" /><text + xml:space="preserve" + style="font-size:49.5765152px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana" + x="20.033628" + y="43.461388" + id="text3591" + transform="scale(0.90891499,1.1002129)"><tspan + sodipodi:role="line" + id="tspan3593" + x="20.033628" + y="43.461388" + style="font-style:italic;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Verdana;-inkscape-font-specification:Verdana Italic">I</tspan></text> +</svg>
\ No newline at end of file diff --git a/icons/toolbar-text.svg b/icons/toolbar-text.svg new file mode 100644 index 0000000..075465b --- /dev/null +++ b/icons/toolbar-text.svg @@ -0,0 +1,8 @@ +<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'> +<svg enable-background="new 0 0 55 54.696" height="54.696px" version="1.1" viewBox="0 0 55 54.696" width="55px" x="0px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" y="0px"> +<g display="block" id="format-text-size"> + <g display="inline"> + <path d="M22.263,12.435 h24.656 v3.562 H36.575 V41.59 h-3.969 V15.996 H22.263 V12.435z" fill="#FFFFFF"/> + <path d="M8.953,22.435 h16.656 v3.562 h-6.344 V41.59 h-3.969 V25.997 h-6.344 V24.435z" fill="#FFFFFF"/> + </g> +</g></svg> diff --git a/icons/underline-text.svg b/icons/underline-text.svg new file mode 100644 index 0000000..66bef13 --- /dev/null +++ b/icons/underline-text.svg @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + enable-background="new 0 0 55 54.696" + height="54.696px" + version="1.1" + viewBox="0 0 55 54.696" + width="55px" + x="0px" + xml:space="preserve" + y="0px" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.47 r22583" + sodipodi:docname="underline-text.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"><metadata + id="metadata22"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs + id="defs20"><inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 27.348 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="55 : 27.348 : 1" + inkscape:persp3d-origin="27.5 : 18.232 : 1" + id="perspective24" /> + + + + + + + + + </defs><sodipodi:namedview + inkscape:window-height="749" + inkscape:window-width="1280" + inkscape:pageshadow="2" + inkscape:pageopacity="0.0" + guidetolerance="10.0" + gridtolerance="10.0" + objecttolerance="10.0" + borderopacity="1.0" + bordercolor="#666666" + pagecolor="#ffffff" + id="base" + showgrid="false" + inkscape:zoom="8.4466873" + inkscape:cx="25.428182" + inkscape:cy="26.564152" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:current-layer="svg2" + inkscape:window-maximized="1" /><text + xml:space="preserve" + style="font-size:48.60628891px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana" + x="13.169476" + y="41.071922" + id="text3591" + transform="scale(0.92705777,1.0786814)"><tspan + sodipodi:role="line" + id="tspan3593" + x="13.169476" + y="41.071922" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:Arial;-inkscape-font-specification:Arial">U</tspan></text> +<rect + style="fill:#ffffff;fill-opacity:1;stroke:none" + id="rect3671" + width="30.307743" + height="2.1310129" + x="13.141248" + y="47.548626" /></svg>
\ No newline at end of file diff --git a/labyrinthactivity.py b/labyrinthactivity.py index 954fbb4..5ac07d0 100644 --- a/labyrinthactivity.py +++ b/labyrinthactivity.py @@ -31,7 +31,10 @@ import cairo from sugar.activity import activity from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.toolcombobox import ToolComboBox +from sugar.graphics.toggletoolbutton import ToggleToolButton from sugar.graphics.radiotoolbutton import RadioToolButton +from sugar.graphics.colorbutton import ColorToolButton from sugar.graphics.menuitem import MenuItem from sugar.datastore import datastore from port.tarball import Tarball @@ -54,6 +57,8 @@ import MMapArea import ImageThought import utils +EMPTY = -800 + class EditToolbar(activity.EditToolbar): def __init__(self, _parent): activity.EditToolbar.__init__(self) @@ -170,6 +175,173 @@ class ViewToolbar(gtk.Toolbar): 'y':(geom[3] / 2.0) - (height / 2.0 + upper), 'scale':min(width_scale, height_scale)} +class TextAttributesToolbar(gtk.Toolbar): + def __init__(self, main_area): + gtk.Toolbar.__init__(self) + + self._main_area = main_area + + self.fonts_combo_box = ToolComboBox(self.__get_fonts_combo_box()) + self.fonts_combo_box.combo.connect('changed', self.__fonts_cb) + self.insert(self.fonts_combo_box, -1) + + self.font_sizes_combo_box = ToolComboBox(self.__get_font_sizes_combo_box()) + self.font_sizes_combo_box.combo.connect('changed', self.__font_sizes_cb) + self.insert(self.font_sizes_combo_box, -1) + + self.bold = ToolButton('bold-text') + self.bold.set_tooltip(_('Bold')) + self.bold.connect('clicked', self.__bold_cb) + self.insert(self.bold, -1) + + self.italics = ToolButton('italics-text') + self.italics.set_tooltip(_('Italics')) + self.italics.connect('clicked', self.__italics_cb) + self.insert(self.italics, -1) + + self.underline = ToolButton('underline-text') + self.underline.set_tooltip(_('Underline')) + self.underline.connect('clicked', self.__underline_cb) + self.insert(self.underline, -1) + + self.foreground_color = ColorToolButton() + self.foreground_color.connect('color-set', self.__foreground_color_cb) + self.insert(self.foreground_color, -1) + + self.show_all() + + def __get_fonts_combo_box(self): + context = self._main_area.pango_context + fonts_combo_box = gtk.combo_box_new_text() + fonts = context.list_families() + index_tnr = -1 + for index, font in enumerate(fonts): + pango_font = pango.FontDescription(font.get_name()) + font_name = pango_font.to_string() + fonts_combo_box.append_text(font_name) + if font_name == 'Times New' or font_name == 'Times New Roman': + index_tnr = index + if index_tnr == -1: + fonts_combo_box.set_active(0) + else: + fonts_combo_box.set_active(index_tnr) + + return fonts_combo_box + + def __get_font_sizes_combo_box(self): + font_sizes_combo_box = gtk.combo_box_new_text() + self.__font_sizes = ['8', '9', '10', '11', '12', '14', '16', '20', \ + '22', '24', '26', '28', '36', '48', '72'] + for index, size in enumerate(self.__font_sizes): + font_sizes_combo_box.append_text(size) + if size == '11': + font_sizes_combo_box.set_active(index) + return font_sizes_combo_box + + def __attribute_values(self): + attributes = {"bold":True,"italics":True,"underline":True,"font":""} + it = self._main_area.selected[0].attributes.get_iterator() + start_index = self._main_area.selected[0].index + end_index = self._main_area.selected[0].end_index + while(1): + found = False + r = it.range() + if start_index == end_index: + if r[0] <= start_index and r[1] > start_index: + found = True + elif start_index < end_index: + if r[0] > end_index: + break + if start_index == end_index and \ + r[0] < start_index and \ + r[1] > start_index: + found = True + elif start_index != end_index and r[0] <= start_index and \ + r[1] >= end_index: + found = True + else: + if r[0] > start_index: + break + if start_index == end_index and \ + r[0] < start_index and \ + r[1] > start_index: + found = True + elif start_index != end_index and r[0] <= end_index and \ + r[1] >= start_index: + found = True + + if found: + attr = it.get_attrs() + for x in attr: + if x.type == pango.ATTR_WEIGHT and \ + x.value == pango.WEIGHT_BOLD: + attributes["bold"] = False + elif x.type == pango.ATTR_STYLE and \ + x.value == pango.STYLE_ITALIC: + attributes["italics"] = False + elif x.type == pango.ATTR_UNDERLINE and \ + x.value == pango.UNDERLINE_SINGLE: + attributes["underline"] = False + elif x.type == pango.ATTR_FONT_DESC: + logging.debug("La fuente es: %s", x.desc) + attributes["font"] = x.desc + if it.next() == False: + break + + return attributes + + def __fonts_cb(self, combo_box): + font_name = combo_box.get_active_text() + font_size = self.font_sizes_combo_box.combo.get_active_text() + start_index = self._main_area.selected[0].index + end_index = self._main_area.selected[0].end_index + #if start_index != end_index: + self._main_area.set_font(font_name,font_size) + self._main_area.font_name = font_name + + def __font_sizes_cb(self, combo_box): + font_size = combo_box.get_active_text() + font_name = self.fonts_combo_box.combo.get_active_text() + start_index = self._main_area.selected[0].index + end_index = self._main_area.selected[0].end_index + #if start_index != end_index: + self._main_area.set_font(font_name,font_size) + self._main_area.font_name = font_size + + def __bold_cb(self, button): + value = self.__attribute_values()["bold"] + self._main_area.set_bold(value) + + def __italics_cb(self, button): + value = self.__attribute_values()["italics"] + self._main_area.set_italics(value) + + def __underline_cb(self, button): + value = self.__attribute_values()["underline"] + self._main_area.set_underline(value) + + def __foreground_color_cb(self, button): + color = button.get_color() + self._main_area.set_foreground_color(color) + + def change_active_font(self): + current_font = str(self.__attribute_values()["font"]) + for index, size in enumerate(self.__font_sizes): + index_size = current_font.find(size) + if index_size != -1: + current_font_name = current_font[:int(index_size)].rstrip() + current_font_size = current_font[int(index_size):] + index_cfs = index + fonts = self._main_area.pango_context.list_families() + for index, font in enumerate(fonts): + pango_font = pango.FontDescription(font.get_name()) + font_name = pango_font.to_string() + if font_name == current_font_name: + index_cf = index + break + self.fonts_combo_box.combo.set_active(index_cf) + self.font_sizes_combo_box.combo.set_active(index_cfs) + class LabyrinthActivity(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle) @@ -216,6 +388,13 @@ class LabyrinthActivity(activity.Activity): tool.props.label = _('View'), toolbar_box.toolbar.insert(tool, -1) + self.text_format_toolbar = ToolbarButton() + self.text_format_toolbar.props.page = TextAttributesToolbar(self._main_area) + self.text_format_toolbar.props.icon_name = 'toolbar-text' + self.text_format_toolbar.props.label = _('Text'), + toolbar_box.toolbar.insert(self.text_format_toolbar, -1) + self._main_area.set_text_attributes(self.text_format_toolbar) + separator = gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) @@ -226,7 +405,7 @@ class LabyrinthActivity(activity.Activity): toolbar_box.toolbar.insert(separator, -1) target_toolbar = toolbar_box.toolbar - tool_offset = 4 + tool_offset = 5 tool = StopButton(self) toolbar_box.toolbar.insert(tool, -1) @@ -274,7 +453,7 @@ class LabyrinthActivity(activity.Activity): activity_toolbar.share.props.visible = False toolbox.set_current_toolbar(1) - self.mods = [None] * 6 + self.mods = [None] * 5 self.mods[0] = RadioToolButton(named_icon='select-mode') self.mods[0].set_tooltip(_('Edit mode')) @@ -304,26 +483,26 @@ class LabyrinthActivity(activity.Activity): self.mods[3].connect('clicked', self.__mode_cb, MMapArea.MODE_IMAGE) target_toolbar.insert(self.mods[3], tool_offset + 3) - self.mods[5] = RadioToolButton(named_icon='label-mode') - self.mods[5].set_tooltip(_('Label mode')) - self.mods[5].set_accelerator(_('<ctrl>a')) - self.mods[5].set_group(self.mods[0]) - self.mods[5].connect('clicked', self.__mode_cb, MMapArea.MODE_LABEL) - target_toolbar.insert(self.mods[5], tool_offset + 4) + self.mods[4] = RadioToolButton(named_icon='label-mode') + self.mods[4].set_tooltip(_('Label mode')) + self.mods[4].set_accelerator(_('<ctrl>a')) + self.mods[4].set_group(self.mods[0]) + self.mods[4].connect('clicked', self.__mode_cb, MMapArea.MODE_LABEL) + target_toolbar.insert(self.mods[4], tool_offset + 4) - separator = gtk.SeparatorToolItem() - target_toolbar.insert(separator, tool_offset + 5) + #separator = gtk.SeparatorToolItem() + #target_toolbar.insert(separator, tool_offset + 5) tool = ToolButton('link') tool.set_tooltip(_('Link/unlink two selected thoughts')) tool.set_accelerator(_('<ctrl>l')) tool.connect('clicked', self.__link_cb) - target_toolbar.insert(tool, tool_offset + 6) + target_toolbar.insert(tool, tool_offset + 5) tool = ToolButton('edit-delete') tool.set_tooltip(_('Erase selected thought(s)')) tool.connect('clicked', self.__delete_cb) - target_toolbar.insert(tool, tool_offset + 7) + target_toolbar.insert(tool, tool_offset + 6) self.show_all() self._mode = MMapArea.MODE_TEXT @@ -347,6 +526,7 @@ class LabyrinthActivity(activity.Activity): """ if start != end: self.__change_copy_state(True) + self.text_format_toolbar.props.page.change_active_font() else: self.__change_copy_state(False) diff --git a/src/MMapArea.py b/src/MMapArea.py index ceff91b..a56525d 100644 --- a/src/MMapArea.py +++ b/src/MMapArea.py @@ -28,6 +28,7 @@ import gobject import gettext import copy import cairo +import logging _ = gettext.gettext import xml.dom.minidom as dom @@ -152,6 +153,7 @@ class MMapArea (gtk.DrawingArea): self.move_action = None self.current_root = [] self.rotation = 0 + self.text_attributes = {} self.set_events (gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK | @@ -171,6 +173,8 @@ class MMapArea (gtk.DrawingArea): self.font_name = style.font_desc.to_string() utils.default_font = self.font_name + self.font_size = utils.default_font + utils.default_colors["text"] = utils.gtk_to_cairo_color(style.text[gtk.STATE_NORMAL]) utils.default_colors["base"] = utils.gtk_to_cairo_color(style.base[gtk.STATE_NORMAL]) # Match the fixed white canvas colour (makes thought focus visible) @@ -184,6 +188,10 @@ class MMapArea (gtk.DrawingArea): utils.selected_colors["fg"] = utils.gtk_to_cairo_color(style.fg[gtk.STATE_SELECTED]) utils.selected_colors["fill"] = utils.gtk_to_cairo_color(style.base[gtk.STATE_SELECTED]) + def set_text_attributes(self, text_attributes): + self.font_combo_box = text_attributes.props.page.fonts_combo_box.combo + self.font_sizes_combo_box = text_attributes.props.page.font_sizes_combo_box.combo + def transform_coords(self, loc_x, loc_y): if hasattr(self, "transform"): return self.transform.transform_point(loc_x, loc_y) @@ -325,17 +333,27 @@ class MMapArea (gtk.DrawingArea): self.invalidate () def key_press (self, widget, event): + logging.debug("Se presiono una tecla") # Support for canvas panning keys ('hand' on XO, 'cmd' on Macs) if event.hardware_keycode == 133 or event.hardware_keycode == 134: self.translate = True + logging.debug("Evento: %s", str(event)) + logging.debug("do_filter %s", str(self.do_filter)) + #valor_retorno = self.im_context.filter_keypress (event) + #logging.debug("filter_keypress me retorna %s", str(valor_retorno)) if not self.do_filter or not self.im_context.filter_keypress (event): + logging.debug("Antes de preguntar si tengo focus") if self.focus: if self.focus.creating or \ not self.focus.process_key_press (event, self.mode): + logging.debug("Me voy a global_key_handler, dento de self.focus") return self.global_key_handler (event) + logging.debug("Retorno True dentro de self.focus") return True if len(self.selected) != 1 or not self.selected[0].process_key_press (event, self.mode): + logging.debug("Me voy a global_key_handler") return self.global_key_handler (event) + logging.debug("Termine la funcion y me voy") return True def key_release (self, widget, event): @@ -474,7 +492,8 @@ class MMapArea (gtk.DrawingArea): self.commit_handler = None if thought: try: - self.commit_handler = self.im_context.connect ("commit", thought.commit_text, self.mode, self.font_name) + logging.debug("Conectando con commit_text") + self.commit_handler = self.im_context.connect ("commit", thought.commit_text, self.mode, self.font_combo_box, self.font_sizes_combo_box) self.delete_handler = self.im_context.connect ("delete-surrounding", thought.delete_surroundings, self.mode) self.preedit_changed_handler = self.im_context.connect ("preedit-changed", thought.preedit_changed, self.mode) self.preedit_end_handler = self.im_context.connect ("preedit-end", thought.preedit_end, self.mode) @@ -486,6 +505,7 @@ class MMapArea (gtk.DrawingArea): self.do_filter = False else: self.do_filter = False + logging.debug("Estoy saliendo de hookup_im_context con do_filter=%s", str(self.do_filter)) def unselect_all (self): self.hookup_im_context () @@ -1221,10 +1241,11 @@ class MMapArea (gtk.DrawingArea): if len(self.selected) > 1: self.invalidate() - def set_font(self, font_name): + def set_font(self, font_name, font_size): if len (self.selected) == 1 and hasattr(self.selected[0], "set_font"): - self.selected[0].set_font(font_name) + self.selected[0].set_font(font_name, font_size) self.font_name = font_name + self.font_size = font_size self.invalidate() def embody_thought(self, event): diff --git a/src/TextThought.py b/src/TextThought.py index d5d5c1f..30bf007 100644 --- a/src/TextThought.py +++ b/src/TextThought.py @@ -25,6 +25,7 @@ import pango import utils import os import xml.dom +import logging from BaseThought import * import UndoManager @@ -71,6 +72,7 @@ class TextThought (ResizableThought): self.all_okay = True def index_from_bindex (self, bindex): + logging.debug("Metodo: index_from_bindex") if bindex == 0: return 0 index = 0 @@ -79,6 +81,7 @@ class TextThought (ResizableThought): return index def bindex_from_index (self, index): + logging.debug("Metodo: bindex_from_index") if index == 0: return 0 bind = 0 @@ -93,6 +96,7 @@ class TextThought (ResizableThought): return bind def attrs_changed (self): + logging.debug("Metodo: attrs_changed") bold = False italics = False underline = False @@ -105,7 +109,7 @@ class TextThought (ResizableThought): while 1: at = it.get_attrs() for x in at: - self.attrlist.insert(x) + self.attrlist.change(x) if it.next() == False: break if self.preedit: @@ -199,9 +203,11 @@ class TextThought (ResizableThought): return show_text def recalc_text_edges (self): + logging.debug("Metodo: recalc_text_edges") if (not hasattr(self, "layout")): return del self.layout + show_text = self.attrs_changed () r,g,b = utils.selected_colors["fill"] @@ -245,18 +251,25 @@ class TextThought (ResizableThought): """ def recalc_edges (self): + logging.debug("Metodo: recalc_edges") self.lr = (self.ul[0]+self.width, self.ul[1]+self.height) if not self.creating: self.recalc_text_edges() - def commit_text (self, context, string, mode, font_name): - self.set_font(font_name) + def commit_text (self, context, string, mode, font_combo_box, font_sizes_combo_box): + logging.debug("Metodo: commit_text") + font_name = font_combo_box.get_active_text() + font_size = font_sizes_combo_box.get_active_text() + self.set_font(font_name, font_size) self.add_text (string) self.recalc_edges () self.emit ("title_changed", self.text) self.emit ("update_view") def add_text (self, string): + logging.debug("Metodo: add_text") + logging.debug("Index s: %s, e: %s", str(self.index), str(self.end_index)) + logging.debug("Texto: %s", str(self.text)) if self.index > self.end_index: left = self.text[:self.end_index] right = self.text[self.index:] @@ -273,11 +286,13 @@ class TextThought (ResizableThought): bright = self.bytes[self.b_f_i (self.end_index):] change = self.index - self.end_index + len(string) else: + logging.debug("Son iguales") left = self.text[:self.index] right = self.text[self.index:] bleft = self.bytes[:self.b_f_i(self.index)] bright = self.bytes[self.b_f_i(self.index):] change = len(string) + logging.debug("L: %s, R: %s, BL: %s, BR: %s", str(left), str(right), str(bleft), str(bright)) it = self.attributes.get_iterator() changes= [] @@ -326,13 +341,16 @@ class TextThought (ResizableThought): self.bytes = bleft + str(len(string)) + bright self.bindex = self.b_f_i (self.index) self.end_index = self.index + logging.debug("String : %s", str(string)) + logging.debug("Index Again s: %s, e: %s, bi:%s", str(self.index), str(self.end_index), str(self.bindex)) def draw (self, context): + logging.debug("Metodo: draw") self.recalc_edges () ResizableThought.draw(self, context) if self.creating: return - + (textx, texty) = (self.min_x, self.min_y) if self.am_primary: r, g, b = utils.primary_colors["text"] @@ -361,6 +379,7 @@ class TextThought (ResizableThought): context.stroke () def process_key_press (self, event, mode): + logging.debug("Metodo: process_key_press") modifiers = gtk.accelerator_get_default_mod_mask () shift = event.state & modifiers == gtk.gdk.SHIFT_MASK handled = True @@ -407,6 +426,7 @@ class TextThought (ResizableThought): handled = False if clear_attrs: + logging.debug("ACABO DE BORRAR LA LISTA DE ATRIBUTOS Y REMPLACE POR UNA LISTA VACIA") del self.current_attrs self.current_attrs = [] @@ -419,6 +439,7 @@ class TextThought (ResizableThought): return handled def undo_text_action (self, action, mode): + logging.debug("Metodo: undo_text_action") self.undo.block () if action.undo_type == UndoManager.DELETE_LETTER or action.undo_type == UndoManager.DELETE_WORD: real_mode = not mode @@ -449,6 +470,7 @@ class TextThought (ResizableThought): self.undo.unblock () def delete_char (self): + logging.debug("Metodo: delete_char") if self.index == self.end_index == len (self.text): return if self.index > self.end_index: @@ -525,6 +547,7 @@ class TextThought (ResizableThought): self.end_index = self.index def backspace_char (self): + logging.debug("Metodo: backspace_char") if self.index == self.end_index == 0: return if self.index > self.end_index: @@ -606,6 +629,7 @@ class TextThought (ResizableThought): self.index = 0 def move_index_back (self, mod): + logging.debug("Metodo: move_index_back") if self.index <= 0: self.index = 0 return @@ -614,6 +638,7 @@ class TextThought (ResizableThought): self.end_index = self.index def move_index_forward (self, mod): + logging.debug("Metodo: move_index_forward") if self.index >= len(self.text): self.index = len(self.text) return @@ -622,6 +647,7 @@ class TextThought (ResizableThought): self.end_index = self.index def move_index_up (self, mod): + logging.debug("Metodo: move_index_up") tmp = self.text.decode () lines = tmp.splitlines () if len (lines) == 1: @@ -656,6 +682,7 @@ class TextThought (ResizableThought): self.end_index = self.index def move_index_down (self, mod): + logging.debug("Metodo: move_index_down") tmp = self.text.decode () lines = tmp.splitlines () if len (lines) == 1: @@ -680,6 +707,7 @@ class TextThought (ResizableThought): self.end_index = self.index def move_index_horizontal(self, mod, home=False): + logging.debug("Metodo: move_index_horizontal") lines = self.text.splitlines () loc = 0 line = 0 @@ -695,6 +723,7 @@ class TextThought (ResizableThought): line += 1 def process_button_down (self, event, coords): + logging.debug("Metodo: process_button_down") if ResizableThought.process_button_down(self, event, coords): return True @@ -733,12 +762,15 @@ class TextThought (ResizableThought): del self.current_attrs self.current_attrs = [] + logging.debug("ACABO DE BORRAR LA LISTA DE ARGUMENTOS Y REMPLACE POR UNA LISTA VACIA") + logging.debug("Index %s, End Index %s", str(self.index), str(self.end_index)) self.recalc_edges() self.emit ("update_view") self.selection_changed() def process_button_release (self, event, transformed): + logging.debug("Metodo: process_button_release") if self.orig_size: if self.creating: orig_size = self.width >= MIN_SIZE or self.height >= MIN_SIZE @@ -754,10 +786,12 @@ class TextThought (ResizableThought): return ResizableThought.process_button_release(self, event, transformed) def selection_changed (self): + logging.debug("Metodo: selection_changed") (start, end) = (min(self.index, self.end_index), max(self.index, self.end_index)) self.emit ("text_selection_changed", start, end, self.text[start:end]) def handle_motion (self, event, transformed): + logging.debug("Metodo: handle_motion") if ResizableThought.handle_motion(self, event, transformed): self.recalc_edges() return True @@ -781,6 +815,7 @@ class TextThought (ResizableThought): return False def export (self, context, move_x, move_y): + logging.debug("Metodo: export") utils.export_thought_outline (context, self.ul, self.lr, self.background_color, self.am_selected, self.am_primary, utils.STYLE_NORMAL, (move_x, move_y)) @@ -864,6 +899,7 @@ class TextThought (ResizableThought): break def rebuild_byte_table (self): + logging.debug("Metodo: rebuild_byte_table") # Build the Byte table del self.bytes self.bytes = '' @@ -965,6 +1001,7 @@ class TextThought (ResizableThought): self.emit ("update_view") def delete_surroundings(self, imcontext, offset, n_chars, mode): + logging.debug("Metodo: delete_surroundings") # TODO: Add in Attr stuff orig = len(self.text) left = self.text[:offset] @@ -1034,6 +1071,7 @@ class TextThought (ResizableThought): self.emit ("update_view") def preedit_changed (self, imcontext, mode): + logging.debug("Metodo: preedit_changed") self.preedit = imcontext.get_preedit_string () if self.preedit[0] == '': self.preedit = None @@ -1041,6 +1079,7 @@ class TextThought (ResizableThought): self.emit ("update_view") def retrieve_surroundings (self, imcontext, mode): + logging.debug("Metodo: retrieve_surroundings") imcontext.set_surrounding (self.text, -1, self.bindex) return True @@ -1069,6 +1108,7 @@ class TextThought (ResizableThought): self.undo.unblock() def create_attribute(self, attribute, start, end): + logging.debug("Metodo: create_attribute, atributo %s para lo indice: %s,%s", str(attribute), str(start), str(end)) if attribute == 'bold': return pango.AttrWeight(pango.WEIGHT_BOLD, start, end) elif attribute == 'italic': @@ -1077,6 +1117,7 @@ class TextThought (ResizableThought): return pango.AttrUnderline(pango.UNDERLINE_SINGLE, start, end) def set_attribute(self, active, attribute): + logging.debug("Metodo: set_attribute") if not self.editing: return @@ -1093,10 +1134,10 @@ class TextThought (ResizableThought): if not active: attr = pango.AttrStyle(pstyle, init, end) - if index == end_index: - self.current_attrs.change(attr) - else: - self.attributes.change(attr) + #if index == end_index: + # self.current_attrs.change(attr) + #else: + self.attributes.change(attr) tmp = [] attr = None @@ -1146,13 +1187,17 @@ class TextThought (ResizableThought): self.attributes.copy())) else: if index == end_index: + logging.debug("Los indices son iguales") attr = self.create_attribute(attribute, index, end_index) self.undo.add_undo(UndoManager.UndoAction(self, UNDO_ADD_ATTR, self.undo_attr_cb, attr)) - self.current_attrs.change(attr) + self.current_attrs.append(attr) + #self.attributes.insert(attr) else: + logging.debug("Los indices no son iguales") attr = self.create_attribute(attribute, init, end) + logging.debug("Cree el atributo: %s para los indices (%s,%s)", str(attribute), str(init), str(end)) old_attrs = self.attributes.copy() self.attributes.change(attr) self.undo.add_undo(UndoManager.UndoAction(self, UNDO_ADD_ATTR_SELECTION, @@ -1162,30 +1207,45 @@ class TextThought (ResizableThought): self.recalc_edges() def set_bold (self, active): + logging.debug("Metodo: set_bold") self.set_attribute(active, 'bold') def set_italics (self, active): + logging.debug("Metodo: set_italics") self.set_attribute(active, 'italic') def set_underline (self, active): + logging.debug("Metodo: set_underline") self.set_attribute(active, 'underline') - def set_font (self, font_name): + def set_font (self, font_name, font_size): + logging.debug("Metodo: set_font") + if not self.editing: return start = min(self.index, self.end_index) end = max(self.index, self.end_index) - - pango_font = pango.FontDescription (font_name) + + #logging.debug("Index s: %s, e: %s", str(self.index), str(self.end_index)) + logging.debug("Fuente %s", str(font_name)) + + pango_font = pango.FontDescription(font_name+" "+font_size) + + logging.debug("Fuente dp del FontDescription: %s", pango_font.to_string()) + attr = pango.AttrFontDesc (pango_font, start, end) + + logging.debug("Info Fuente desc: %s, si: %s, ei: %s", str(attr.desc), str(attr.start_index), str(attr.end_index)) if start == end: self.undo.add_undo(UndoManager.UndoAction(self, UNDO_ADD_ATTR, self.undo_attr_cb, attr)) try: + logging.debug("Voy a usar un metodo que no existe para este tipo de objeto, veremos que sale!") self.current_attrs.change(attr) except AttributeError: + logging.debug("Como evidentemente el metodo no existia, voy a usar append") self.current_attrs.append(attr) else: old_attrs = self.attributes.copy() @@ -1197,18 +1257,21 @@ class TextThought (ResizableThought): self.recalc_edges() def inside(self, inside): + logging.debug("Metodo: inside") if self.editing: self.emit ("change_mouse_cursor", gtk.gdk.XTERM) else: ResizableThought.inside(self, inside) def enter(self): + logging.debug("Metodo: enter") if self.editing: return self.orig_text = self.text self.editing = True def leave(self): + logging.debug("Metodo: leave") if not self.editing: return ResizableThought.leave(self) diff --git a/src/utils.py b/src/utils.py index 36cd159..4f19d92 100644 --- a/src/utils.py +++ b/src/utils.py @@ -72,6 +72,8 @@ selected_colors = { default_font = None +default_font_size = 10 + try: # Sugar specific tweak xo_col = get_color() |