To comment on the following update, log in, then open the issue:
http://www.openoffice.org/issues/show_bug.cgi?id=82861
                 Issue #|82861
                 Summary|Python: Capitalize macro
               Component|Word processor
                 Version|OOo 2.3
                Platform|All
                     URL|
              OS/Version|All
                  Status|UNCONFIRMED
       Status whiteboard|
                Keywords|
              Resolution|
              Issue type|PATCH
                Priority|P3
            Subcomponent|programming
             Assigned to|mru
             Reported by|the_gray_cardinal





------- Additional comments from [EMAIL PROTECTED] Mon Oct 22 17:57:41 +0000 
2007 -------
Macro Capitalise.py is distributed with OpenOffice v2.3. But I don't like it 
much because of the following reasons: 
1. It doesn't work with the last word in a file, when there isn't any text or 
line feed after this word. 
2. If you work with a word that has caret within it (not with a selected piece 
of text), for some reason Capitalise.py selects this word after processing. 
3. If you deal with some non-adjacent selected pieces of text inside a 
document, a runtime exception occurs. 
4. If you deal with a word that contains the caret and stands at the end of a 
line, after which there is a blank line, Capitalise.py adds another blank line. 
Here is my version of the Capitalise.py, free of the above peculiarities: 
=======================================================================
# copyleft © The gray Cardinal, Russia, http://script-coding.info/ 

def CapitalizeString(theString): 
    # Capitalize function 
    if (not theString or len(theString) == 0): 
        return "" 
    if theString[0].isupper() and len(theString) >= 2 and theString[1].isupper
(): 
        newString = theString[0:1].upper() + theString[1:].lower() 
    elif theString[0].isupper(): 
        newString = theString.lower() 
    else: 
        newString = theString.upper() 
    import re 
    newString = re.sub('\n', '', newString) 
    return newString 

def Capitalize(dummy = ''): 
    ''' 
    Macro for Writer. 
    Changes the case of the selected pieces of text or the word with the caret 
within it. 
    ''' 
    xController = XSCRIPTCONTEXT.getDocument().getCurrentController() 
    # current selection 
    xIndexAccess = xController.getSelection() 
    # number of selected pieces of text 
    count = xIndexAccess.getCount() 
    if count == 1 and len(xIndexAccess.getByIndex(0).getString()) == 0: 
        # No selection. Process the word with the caret within it. 
        xTextRange = xIndexAccess.getByIndex(0) 
        xWordCursor = xTextRange.getText().createTextCursorByRange(xTextRange) 
        if not xWordCursor.isStartOfWord(): xWordCursor.gotoStartOfWord(False) 
        xWordCursor.gotoEndOfWord(True) 
        theString = xWordCursor.getString() 
        # processing of the text 
        newString = CapitalizeString(theString) 
        # replace the text by the processed text 
        xWordCursor.setString(newString) 
    else: 
        # Selection occurred. Now process all the selected pieces of text. 
        i = 0 
        while i < count: 
            # selected piece of text 
            xTextRange = xIndexAccess.getByIndex(i) 
            # text of selected piece of text 
            theString = xTextRange.getString() 
            if len(theString) > 0: 
                # process the text 
                newString = CapitalizeString(theString) 
                # replace the text by the processed text 
                xTextRange.setString(newString) 
                # selection 
                xController.select(xTextRange) 
                # If some non-adjacent pieces of text were selected (by Ctrl), 
                # only the selection of the last piece of text will be 
restored. 
                # Unfortunately, there is no way to restore selection of all 
the pieces of text. 
            i += 1 
    return None 

g_exportedScripts = Capitalize,

---------------------------------------------------------------------
Please do not reply to this automatically generated notification from
Issue Tracker. Please log onto the website and enter your comments.
http://qa.openoffice.org/issue_handling/project_issues.html#notification

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to