Add '_' prefix for private method names.

svn: r10453
This commit is contained in:
Zsolt Foldvari 2008-04-02 20:34:29 +00:00
parent 39ea377b81
commit c773f9dd67

View File

@ -31,7 +31,7 @@ from gettext import gettext as _
import re import re
import logging import logging
_LOG = logging.getLogger(".StyledTextBuffer") _LOG = logging.getLogger(".Editors.StyledTextBuffer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -186,15 +186,16 @@ class StyledTextBuffer(gtk.TextBuffer):
"""An extended TextBuffer for handling StyledText strings. """An extended TextBuffer for handling StyledText strings.
StyledTextBuffer is an interface between GRAMPS' L{StyledText} format StyledTextBuffer is an interface between GRAMPS' L{StyledText} format
and gtk.TextBuffer. To get/set the text use the L{get_text} and and gtk.TextBuffer. To set and get the text use the L{set_text} and
L{set_text} methods. L{get_text} methods.
It provides an action group (L{format_action_group}) for GUIs. StyledTextBuffer provides an action group (L{format_action_group})
for GUIs.
StyledTextBuffer has a regexp pattern matching mechanism too. To add a StyledTextBuffer has a regexp pattern matching mechanism too. To add a
regexp pattern to match in the text use the L{match_add} method. To check regexp pattern to match in the text use the L{match_add} method. To check
if there's a match at a certain position in the text use the L{match_check} if there's a match at a certain position in the text use the L{match_check}
method. method. For an example how to use the matching see L{EditNote}.
""" """
__gtype_name__ = 'StyledTextBuffer' __gtype_name__ = 'StyledTextBuffer'
@ -214,22 +215,22 @@ class StyledTextBuffer(gtk.TextBuffer):
# Setup action group used from user interface # Setup action group used from user interface
format_toggle_actions = [ format_toggle_actions = [
('italic', gtk.STOCK_ITALIC, None, None, ('italic', gtk.STOCK_ITALIC, None, None,
_('Italic'), self.on_toggle_action_activate), _('Italic'), self._on_toggle_action_activate),
('bold', gtk.STOCK_BOLD, None, None, ('bold', gtk.STOCK_BOLD, None, None,
_('Bold'), self.on_toggle_action_activate), _('Bold'), self._on_toggle_action_activate),
('underline', gtk.STOCK_UNDERLINE, None, None, ('underline', gtk.STOCK_UNDERLINE, None, None,
_('Underline'), self.on_toggle_action_activate), _('Underline'), self._on_toggle_action_activate),
] ]
self.toggle_actions = [action[0] for action in format_toggle_actions] self.toggle_actions = [action[0] for action in format_toggle_actions]
format_actions = [ format_actions = [
('font', 'gramps-font', None, None, ('font', 'gramps-font', None, None,
_('Font'), self.on_action_activate), _('Font'), self._on_action_activate),
('foreground', 'gramps-font-color', None, None, ('foreground', 'gramps-font-color', None, None,
_('Font Color'), self.on_action_activate), _('Font Color'), self._on_action_activate),
('background', 'gramps-font-bgcolor', None, None, ('background', 'gramps-font-bgcolor', None, None,
_('Background Color'), self.on_action_activate), _('Background Color'), self._on_action_activate),
('clear', gtk.STOCK_CLEAR, None, None, ('clear', gtk.STOCK_CLEAR, None, None,
_('Clear'), self._format_clear_cb), _('Clear'), self._format_clear_cb),
] ]
@ -418,7 +419,7 @@ class StyledTextBuffer(gtk.TextBuffer):
color = gtk.gdk.color_parse(hex) color = gtk.gdk.color_parse(hex)
return color return color
def get_selection(self): def _get_selection(self):
bounds = self.get_selection_bounds() bounds = self.get_selection_bounds()
if not bounds: if not bounds:
iter = self.get_iter_at_mark(self._insert) iter = self.get_iter_at_mark(self._insert)
@ -435,19 +436,19 @@ class StyledTextBuffer(gtk.TextBuffer):
bounds = (iter, self.get_iter_at_offset(iter.get_offset() + 1)) bounds = (iter, self.get_iter_at_offset(iter.get_offset() + 1))
return bounds return bounds
def apply_tag_to_selection(self, tag): def _apply_tag_to_selection(self, tag):
selection = self.get_selection() selection = self._get_selection()
if selection: if selection:
self.apply_tag(tag, *selection) self.apply_tag(tag, *selection)
def remove_tag_from_selection(self, tag): def _remove_tag_from_selection(self, tag):
selection = self.get_selection() selection = self._get_selection()
if selection: if selection:
self.remove_tag(tag, *selection) self.remove_tag(tag, *selection)
def remove_format_from_selection(self, format): def _remove_format_from_selection(self, format):
start, end = self.get_selection() start, end = self._get_selection()
tags = self.get_tag_from_range(start.get_offset(), end.get_offset()) tags = self._get_tag_from_range(start.get_offset(), end.get_offset())
for tag_name in tags.keys(): for tag_name in tags.keys():
if tag_name.startswith(format): if tag_name.startswith(format):
for start, end in tags[tag_name]: for start, end in tags[tag_name]:
@ -455,7 +456,7 @@ class StyledTextBuffer(gtk.TextBuffer):
self.get_iter_at_offset(start), self.get_iter_at_offset(start),
self.get_iter_at_offset(end+1)) self.get_iter_at_offset(end+1))
def get_tag_from_range(self, start=None, end=None): def _get_tag_from_range(self, start=None, end=None):
"""Extract gtk.TextTags from buffer. """Extract gtk.TextTags from buffer.
Return only the name of the TextTag from the specified range. Return only the name of the TextTag from the specified range.
@ -509,7 +510,7 @@ class StyledTextBuffer(gtk.TextBuffer):
# Callbacks # Callbacks
def on_toggle_action_activate(self, action): def _on_toggle_action_activate(self, action):
"""Toggle a format. """Toggle a format.
Toggle formats are e.g. 'bold', 'italic', 'underline'. Toggle formats are e.g. 'bold', 'italic', 'underline'.
@ -518,7 +519,7 @@ class StyledTextBuffer(gtk.TextBuffer):
if self._internal_toggle: if self._internal_toggle:
return return
start, end = self.get_selection() start, end = self._get_selection()
if action.get_active(): if action.get_active():
self.apply_tag_by_name(action.get_name(), start, end) self.apply_tag_by_name(action.get_name(), start, end)
@ -527,7 +528,7 @@ class StyledTextBuffer(gtk.TextBuffer):
setattr(self, action.get_name(), action.get_active()) setattr(self, action.get_name(), action.get_active())
def on_action_activate(self, action): def _on_action_activate(self, action):
"""Apply a format.""" """Apply a format."""
format = action.get_name() format = action.get_name()
@ -565,8 +566,8 @@ class StyledTextBuffer(gtk.TextBuffer):
_LOG.debug("applying format '%s' with value '%s'" % (format, value)) _LOG.debug("applying format '%s' with value '%s'" % (format, value))
tag = self._find_tag_by_name(format, value) tag = self._find_tag_by_name(format, value)
self.remove_format_from_selection(format) self._remove_format_from_selection(format)
self.apply_tag_to_selection(tag) self._apply_tag_to_selection(tag)
setattr(self, format, value) setattr(self, format, value)
@ -578,7 +579,7 @@ class StyledTextBuffer(gtk.TextBuffer):
""" """
for format in self.formats: for format in self.formats:
self.remove_format_from_selection(format) self._remove_format_from_selection(format)
def on_key_press_event(self, widget, event): def on_key_press_event(self, widget, event):
"""Handle formatting shortcuts.""" """Handle formatting shortcuts."""
@ -618,7 +619,7 @@ class StyledTextBuffer(gtk.TextBuffer):
txt = unicode(txt) txt = unicode(txt)
# extract tags out of the buffer # extract tags out of the buffer
g_tags = self.get_tag_from_range() g_tags = self._get_tag_from_range()
r_tags = [] r_tags = []
for g_tagname, g_ranges in g_tags.items(): for g_tagname, g_ranges in g_tags.items():