| View previous topic :: View next topic |
| Author |
Message |
srikb47 General User

Joined: 28 Feb 2010 Posts: 27 Location: Chennai
|
Posted: Sun Apr 04, 2010 8:56 pm Post subject: help needed formatng string using python macros |
|
|
| hi guys i need to know how can i under line a particular string using python macro pl can some one help me out |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Tue Apr 06, 2010 6:27 am Post subject: |
|
|
| Code: | from com.sun.star.awt.FontUnderline import SINGLE
def set_underline():
doc = XSCRIPTCONTEXT.getDocument()
text = doc.getText()
text.setString('Moge')
cursor = text.createTextCursor()
cursor.goRight(4, True)
cursor.CharUnderline = SINGLE |
|
|
| Back to top |
|
 |
srikb47 General User

Joined: 28 Feb 2010 Posts: 27 Location: Chennai
|
Posted: Tue Apr 06, 2010 10:00 am Post subject: help needed formatng string using python macros |
|
|
hi hanya i've modified the code that u have sent me a little to search the entire document and underlie the particular occurrence of that string but all i am getting is the words in the entire document gets underlined can u tell me where i;ve gone wrong
| Code: |
import string
import uno
from com.sun.star.awt.FontUnderline import SINGLE
def set_underline():
ctx = uno.getComponentContext()
smgr = ctx.getServiceManager()
resolver = smgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", ctx)
#Load services
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
#Load current Document
document = desktop.getCurrentComponent()
#set cursor
cursor = document.Text.createTextCursor()
#Create Search Descriptor
search = document.createSearchDescriptor()
a="hi"
cursor.goRight(8, True)
search = document.createSearchDescriptor()
search.SearchAll=True
if a:
a=cursor.CharUnderline = SINGLE
|
|
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Wed Apr 07, 2010 1:18 am Post subject: |
|
|
Try with findAll method.
| Code: | from com.sun.star.awt.FontUnderline import SINGLE
def set_underline():
doc = XSCRIPTCONTEXT.getDocument()
search = doc.createSearchDescriptor()
search.SearchString = "hi"
search.SearchAll = True
founds = doc.findAll(search)
if founds:
for i in range(founds.getCount()):
founds.getByIndex(i).CharUnderline = SINGLE |
|
|
| Back to top |
|
 |
srikb47 General User

Joined: 28 Feb 2010 Posts: 27 Location: Chennai
|
Posted: Wed Apr 07, 2010 8:10 am Post subject: help needed formatng string using python macros |
|
|
Thanks a lot hanya it works i have an small doubt in
| Code: |
search.SearchAll=TRUE
|
method dose it search word by word if it dose dose how can i store it in some variable cos i've created a dictionary and need to verify the word in the doc to the word in the dic and if the word in the doc is wrong i need to underline it that's the main reason i asked for string underlining in OOo help me out here or is there any other way to search the doc word by word. |
|
| Back to top |
|
 |
srikb47 General User

Joined: 28 Feb 2010 Posts: 27 Location: Chennai
|
Posted: Fri Apr 09, 2010 7:17 am Post subject: help needed formatng string using python macros |
|
|
hey hanya i found how to search through the doc word by word
| Code: |
import string
import uno
from com.sun.star.awt.FontUnderline import SINGLE
def set_underline():
ctx = uno.getComponentContext()
smgr = ctx.getServiceManager()
resolver = smgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", ctx)
#Load services
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
#Load current Document
document = desktop.getCurrentComponent()
#set cursor
cursor = document.Text.createTextCursor()
#Create Search Descriptor
search = document.createSearchDescriptor()
if not cursor.isStartOfWord():
cursor.gotoStartOfWord(False)
cursor.gotoEndOfWord(True)
#cursor.goRight(100, True)
aa=cursor.getString()
print aa
cursor.gotoNextWord(True)
|
the code works fine untill here but if i add an while statement to print the next word it is not worng can u tell me wat wrong i have done here. Here is my while statement
| Code: |
bb=cursor.gotoNextWord(True)
while bb
cursor.gotoEndOfWord(False)
a=cursor.getString()
print a
|
|
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Fri Apr 09, 2010 8:24 am Post subject: |
|
|
Hmm, like the following?
| Code: | aa=cursor.getString()
print aa
cursor.gotoNextWord(False)
bb=cursor.gotoEndOfWord(True)
while bb:
cursor.gotoEndOfWord(True)
a=cursor.getString()
print a
bb=cursor.gotoNextWord(False) |
|
|
| Back to top |
|
 |
srikb47 General User

Joined: 28 Feb 2010 Posts: 27 Location: Chennai
|
Posted: Fri Apr 09, 2010 8:50 am Post subject: help needed formatng string using python macros |
|
|
| yes hanya i needed the same thing but the first word of the doc is stored in "aa" and rest in "a" wat should i do to store all the words in an single variable how must i change the while statement can u tell me |
|
| Back to top |
|
 |
srikb47 General User

Joined: 28 Feb 2010 Posts: 27 Location: Chennai
|
Posted: Fri Apr 09, 2010 9:05 am Post subject: help needed formatng string using python macros |
|
|
| No need haya i got the answer my self u were a lot of help to me in creating the gui and here now thanks a lot i learned a lot for ur guidelines thanks a lot for the help that u have given me |
|
| Back to top |
|
 |
|