htnawsaj

FormatText.py

Aug 21st, 2013
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. ##########################################################################
  2. ##Modified the script from http://www.macdrifter.com/2012/07/pythonista-app-from-toy-to-tool.html
  3. ##Thanks to this http://www.macstories.net/stories/editorial-for-ipad-review/ for pointing it.
  4. ##########################################################################
  5.  
  6.  
  7. import sys
  8. import re
  9. import urllib
  10. import android
  11.  
  12. def titleCase(s):
  13.     newText = re.sub(r"[A-Za-z]+('[A-Za-z]+)?",lambda mo: mo.group(0)[0].upper() + mo.group(0)[1:].lower(),s)
  14.     return newText
  15.  
  16. droid = android.Android()
  17.  
  18. inputString= droid.dialogGetInput("Select Conversion:","[1] Title Case\n[2] lowercase\n[3] UPPERCASE\n[4] Capital case\n[5] Strip Leading\n[6] Strip Trailing\n[7] Strip All\n[8] URL Quote\n[x] Exit")
  19.  
  20. formatType = inputString.result
  21. if formatType == "x":
  22.     droid.dialogCreateAlert("Result","Closing as per your choice")
  23.     droid.dialogShow()
  24. else:
  25.     rawInput = droid.dialogGetInput("Input","Enter the string to convert")
  26.     userInput = rawInput.result
  27.  
  28. if formatType == "1":
  29.     outString =  titleCase(userInput)
  30. elif formatType == "2":
  31.     outString = userInput.lower()
  32. elif formatType == "3":
  33.     outString = userInput.upper()
  34. elif formatType == "4":
  35.     outString = userInput.capitalize()
  36. elif formatType == "5":
  37.     outString = userInput.lstrip()
  38. elif formatType == "7":
  39.     outString = userInput.strip()
  40. elif formatType == "8":
  41.     outString = urllib.quote(userInput)
  42.  
  43. droid.setClipboard(outString)
  44. droid.dialogCreateAlert("Result",outString + "\n This string is also copied to the clipboard")
  45. droid.dialogShow()
Advertisement
Add Comment
Please, Sign In to add comment