Page 1 of 1

[Solved] Call macro Basic when executing a Python macro

PostPosted: Sun Apr 21, 2019 5:17 pm
by Math
hello friends ,

I'm running the following Python macro in LibreOffice Calc , which is working correctly:
Code: Select all   Expand viewCollapse view
import urllib.request
from html.parser import HTMLParser
class MyParser(HTMLParser):
    def __init__(self,target_tag):
        HTMLParser.__init__(self)
        self.targetTag=target_tag
        self.targetFound=False
        self.dataArray=[]
    def handle_starttag(self,tag,attrs):
        self.targetFound=False
        if (tag==self.targetTag):
            self.targetFound=True
    def handle_endtag(self,tag):
        if tag==self.targetTag:
            self.targetFound=False
    def handle_data(self, data):
        if (self.targetFound):
            self.dataArray.append(data)
#######   target URL   #######################
MyUrl='https://coinmarketcap.com/#currencies_wrapper'
OpenUrl=urllib.request.urlopen(MyUrl)
#######  get the html code   ################
responseHTML=OpenUrl.read().decode('utf-8')
parser=MyParser("a")
parser.feed(responseHTML)
# LibreOffice code #
activeSheet=XSCRIPTCONTEXT.getDocument().getCurrentController().getActiveSheet()
def LastMessage(*args):
    activeSheet.getCellRangeByName("A1").setString(parser.dataArray[45])
    activeSheet.getCellRangeByName("B1").setString(parser.dataArray[46])
    activeSheet.getCellRangeByName("A2").setString(parser.dataArray[47])
    activeSheet.getCellRangeByName("B2").setString(parser.dataArray[48])

at the end of this Python macro I want to call a Basic macro that is in the same file .

here is the Basic macro information I want to run at the end of the above python macro:
filename: connexion
library: Standard
module: Module1
macro: ajustar_colunas

I did search in the forum and found a python code, I also found another python code , but neither code is working for me .

I'm grateful now for all the Help .

Re: Call macro Basic when executing a Python macro

PostPosted: Mon Apr 22, 2019 5:38 pm
by hubert lambert
Hi,

A quick example.
The basic macro:
Code: Select all   Expand viewCollapse view
Sub Main(msg)
    msgbox(msg)
End Sub

The calling python code:
Code: Select all   Expand viewCollapse view
def call_embedded_basic_macro(event=None):
    doc = XSCRIPTCONTEXT.getDocument()
    scriptprovider = doc.ScriptProvider
    basic_macro_uri 
= "vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document"
    basic_macro = scriptprovider.getScript(basic_macro_uri)
    basic_macro.invoke(("Well done!",),(),()) 

Regards.

[Solved] Call macro Basic when executing a Python macro

PostPosted: Mon Apr 22, 2019 8:28 pm
by Math
greetings hubert lambert ,

Thank you very much for your help . :super:

the python macro worked perfectly . :bravo:

Friend hug .