~sir-rainbow/+junk/scribes-on-win

« back to all changes in this revision

Viewing changes to plugins/Selection/paragraph.py

  • Committer: goldenmyst
  • Date: 2007-09-25 17:15:52 UTC
  • Revision ID: goldenmyst@goldenmyst-desktop-20070925171552-mvrhxdd39iibs0sr
New branch. New Trigger Management System. New Trigger API. New Plugin Management System. Fix for bug triggered by PyGTK+ version 2.11 or better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Copyright © 2005 Lateef Alabi-Oki
 
3
#
 
4
# This file is part of Scribes.
 
5
#
 
6
# Scribes is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# Scribes is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with Scribes; if not, write to the Free Software
 
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 
19
# USA
 
20
 
 
21
"""
 
22
This module documents functions that perform paragraph operations.
 
23
 
 
24
@author: Lateef Alabi-Oki
 
25
@organization: The Scribes Project
 
26
@copyright: Copyright © 2005 Lateef Alabi-Oki
 
27
@license: GNU GPLv2 or Later
 
28
@contact: mystilleef@gmail.com
 
29
"""
 
30
 
 
31
def select_paragraph(textbuffer):
 
32
        """
 
33
        Select a paragraph, if any, on the current line.
 
34
 
 
35
        @param textbuffer: The text buffer in which to select a paragraph.
 
36
        @type textbuffer: A gtk.TextBuffer object.
 
37
 
 
38
        @return: Return True if a paragraph was selected.
 
39
        @rtype: A Boolean object.
 
40
        """
 
41
        from SCRIBES.cursor import get_cursor_iterator
 
42
        cursor_position = get_cursor_iterator(textbuffer)
 
43
        if cursor_position.starts_sentence() or cursor_position.ends_sentence() or cursor_position.inside_sentence():
 
44
                end_position = cursor_position.copy()
 
45
                if cursor_position.backward_line():
 
46
                        while not cursor_position.get_char() in ["\n", "\x00"]:
 
47
                                result = cursor_position.backward_line()
 
48
                                if not result:
 
49
                                        break
 
50
                        if cursor_position.get_char() in ["\n", "\x00"]:
 
51
                                cursor_position.forward_line()
 
52
                else:
 
53
                        cursor_position.backward_sentence_start()
 
54
                if end_position.forward_line():
 
55
                        while not end_position.get_char() in ["\n", "\x00"]:
 
56
                                result = end_position.forward_line()
 
57
                                if not result:
 
58
                                        break
 
59
                        if end_position.get_char() in ["\n", "\x00"]:
 
60
                                end_position.backward_line()
 
61
                        end_position.forward_sentence_end()
 
62
                else:
 
63
                        end_position.forward_sentence_end()
 
64
                textbuffer.select_range(cursor_position, end_position)
 
65
        else:
 
66
                return False
 
67
        return True