123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- def getNewString(theString):
- """helper function
- """
- if (not theString):
- return ""
-
- if len(theString) >= 2 and theString[:2].isupper():
-
- newString = theString[0].upper() + theString[1:].lower()
- elif theString[0].isupper():
-
- newString = theString.lower()
- else:
-
- newString = theString.upper()
- return newString
- def capitalisePython():
- """Change the case of the selected or current word(s).
- If at least the first two characters are "UPpercase, then it is changed
- to first char "Uppercase".
- If the first character is "Uppercase", then it is changed to
- all "lowercase".
- Otherwise, all are changed to "UPPERCASE".
- """
-
-
- xModel = XSCRIPTCONTEXT.getDocument()
-
-
- xSelectionSupplier = xModel.getCurrentController()
-
- xIndexAccess = xSelectionSupplier.getSelection()
- count = xIndexAccess.getCount()
- if(count >= 1):
- i = 0
- while i < count:
- xTextRange = xIndexAccess.getByIndex(i)
- theString = xTextRange.getString()
-
- if len(theString) == 0:
-
-
- xText = xTextRange.getText()
- xWordCursor = xText.createTextCursorByRange(xTextRange)
- if not xWordCursor.isStartOfWord():
- xWordCursor.gotoStartOfWord(False)
- xWordCursor.gotoNextWord(True)
- theString = xWordCursor.getString()
- newString = getNewString(theString)
- if newString:
- xWordCursor.setString(newString)
- xSelectionSupplier.select(xWordCursor)
- else:
- newString = getNewString(theString)
- if newString:
- xTextRange.setString(newString)
- xSelectionSupplier.select(xTextRange)
- i += 1
- g_exportedScripts = capitalisePython,
|