OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

help needed formatng string using python macros

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
srikb47
General User
General User


Joined: 28 Feb 2010
Posts: 27
Location: Chennai

PostPosted: Sun Apr 04, 2010 8:56 pm    Post subject: help needed formatng string using python macros Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Tue Apr 06, 2010 6:27 am    Post subject: Reply with quote

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
View user's profile Send private message
srikb47
General User
General User


Joined: 28 Feb 2010
Posts: 27
Location: Chennai

PostPosted: Tue Apr 06, 2010 10:00 am    Post subject: help needed formatng string using python macros Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Wed Apr 07, 2010 1:18 am    Post subject: Reply with quote

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
View user's profile Send private message
srikb47
General User
General User


Joined: 28 Feb 2010
Posts: 27
Location: Chennai

PostPosted: Wed Apr 07, 2010 8:10 am    Post subject: help needed formatng string using python macros Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
srikb47
General User
General User


Joined: 28 Feb 2010
Posts: 27
Location: Chennai

PostPosted: Fri Apr 09, 2010 7:17 am    Post subject: help needed formatng string using python macros Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Fri Apr 09, 2010 8:24 am    Post subject: Reply with quote

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
View user's profile Send private message
srikb47
General User
General User


Joined: 28 Feb 2010
Posts: 27
Location: Chennai

PostPosted: Fri Apr 09, 2010 8:50 am    Post subject: help needed formatng string using python macros Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
srikb47
General User
General User


Joined: 28 Feb 2010
Posts: 27
Location: Chennai

PostPosted: Fri Apr 09, 2010 9:05 am    Post subject: help needed formatng string using python macros Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group