Zapodaće/Wudaće na wobrazowce

Standardna wudaćowa dataja Python k dispoziciji njeje, hdyž so makra Python z Nastroje – Makra – Makro wuwjesć… wuwjedu. Předstajenje wudaća modula sej interaktiwnu konsolu Python wužaduje. Funkcije kaž input(), print(), repr() a str() su z konsole Python k dispoziciji.

tip

Modul Python LibreOffice msgbox metodu msgbox() skići, kotraž so w přikładowych stronach Podawkowe posłuchaki wutworić a Dialogowy předźěłowak wutworić zwobraznjuje.


LibreOffice Basic funkcije InputBox(), Msgbox() a Print() za zapodaće/wudaće na wobrazowce skići. Su alternatiwy Python, kotrež pak na LibreOffice API Abstract Windowing Toolkit pak na funkciske wuwołanja Python do Basic bazuja. Poslednje syntaksu skići, kotraž je z wotpohladom blisko syntaksy Basic a wužiwa modul Python nimo modula Basic. API „Scripting Framework“ so wužiwa, zo by funkciske wuwołanja mjez Basic, BeanShell, JavaScript a Python wuwjedł.

Syntaksa Python:

MsgBox(txt, buttons=0, title=None)

InputBox(txt, title=None, default=None)

Print(txt)

Přikłady:

>>> import screen_io as ui

>>> reply = ui.InputBox('Please enter a phrase', title='Dear user', defaultValue="here..")

>>> rc = ui.MsgBox(reply, title="Confirmation of phrase")

>>> age = ui.InputBox('How old are you?', title="Hi")

>>> ui.Print(age)

Instalacija:

Modul Python screen_io


        # -*- coding: utf-8 -*-
        from __future__ import unicode_literals
        
        def MsgBox(prompt: str, buttons=0, title='LibreOffice') -> int:
            """ Pokazuje dialogowe polo, kotrež powěsć wobsahuje a hódnotu wróća."""
            xScript = _getScript("_MsgBox")
            res = xScript.invoke((prompt,buttons,title), (), ())
            return res[0]
        
        def InputBox(prompt: str, title='LibreOffice', defaultValue='') -> str:
            """ Pokazuje namołwu w dialogowym polu, hdźež wužiwar móže tekst zapodać."""
            xScript = _getScript("_InputBox")
            res = xScript.invoke((prompt,title,defaultValue), (), ())
            return res[0]
        
        def Print(message: str):
            """Wudawa podate znamješkowe rjećazki abo numeriske wurazy w dialogowym polu."""
            xScript = _getScript("_Print")
            xScript.invoke((message,), (), ())
        
        import uno
        from com.sun.star.script.provider import XScript
        def _getScript(script: str, library='Standard', module='uiScripts') -> XScript:
            sm = uno.getComponentContext().ServiceManager
            mspf = sm.createInstanceWithContext("com.sun.star.script.provider.MasterScriptProviderFactory", uno.getComponentContext())
            scriptPro = mspf.createScriptProvider("")
            scriptName = "vnd.sun.star.script:"+library+"."+module+"."+script+"?language=Basic&location=application"
            xScript = scriptPro.getScript(scriptName)
            return xScript
    
note

Metodźe MsgBox a InputBox ze słužby Basic, kotraž je w bibliotekach ScriptForge wobsahowana, swoje natiwne pendanty Basic direktnje wuwołujetej.


Modul Basic uiScripts


        Option Explicit
        Private Function _MsgBox( prompt As String, Optional buttons As Integer, _
                Optional title As String ) As Integer
            _MsgBox = MsgBox( prompt, buttons, title )
        End Function
        Private Function _InputBox( prompt As String, Optional title As String, _
                Optional default As String) As String
            _InputBox = InputBox( prompt, title, default )
        End Function
        Private Sub _Print( msg As String )
            Print msg
        End Sub
    
tip

Rozšěrjenje Alternative Python Script Organizer (APSO) funkciju msgbox() zwonka swojeho modula apso_utils skići.


Prošu podpěrajće nas!