Input/Output sa Screen

Ang Python standard output file ay hindi available kapag nagpapatakbo ng Python macros mula sa Mga Tool – Macros - Patakbuhin ang Macro ... menu. Ang pagtatanghal ng output ng isang module ay nangangailangan ng Python interactive console. Mga tampok tulad ng input() , print() , repr() at str() ay makukuha mula sa shell ng Python.

tip

LibreOffice msgbox Ang module ng Python ay nagmumungkahi ng isang msgbox() pamamaraan na inilalarawan sa Paglikha ng Mga Tagapakinig ng Kaganapan at Paggawa ng dialog handler mga halimbawang pahina.


Nagmumungkahi ang LibreOffice Basic InputBox() , Msgbox() at Print() mga function ng screen I/O. Umiiral ang mga alternatibong Python na umaasa sa alinman sa LibreOffice API Abstract Windowing Toolkit, alinman sa Python hanggang sa Basic na mga function na tawag. Ang huli ay nagmumungkahi ng isang syntax na sadyang malapit sa Basic, at gumagamit ng Python module sa tabi ng Basic na module. Ang API Scripting Framework ay ginagamit para magsagawa ng Basic, BeanShell, JavaScript at Python inter-languages function calls.

Syntax ng Python:

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

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

Print(txt)

Mga halimbawa:

>>> 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)

Pag-install:

screen_io Module ng Python


        # -*- coding: utf-8 -*-
        from __future__ import unicode_literals
        
        def MsgBox(prompt: str, buttons=0, title='LibreOffice') -> int:
            """ Nagpapakita ng dialog box na naglalaman ng mensahe at nagbabalik ng value."""
            xScript = _getScript("_MsgBox")
            res = xScript.invoke((prompt,buttons,title), (), ())
            return res[0]
        
        def InputBox(prompt: str, title='LibreOffice', defaultValue='') -> str:
            """ Nagpapakita ng prompt sa isang dialog box kung saan maaaring maglagay ng text ang user."""
            xScript = _getScript("_InputBox")
            res = xScript.invoke((prompt,title,defaultValue), (), ())
            return res[0]
        
        def Print(message: str):
            """Ina-output ang mga tinukoy na string o numeric na expression sa isang dialog box."""
            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

MsgBox at InputBox pamamaraan mula sa Pangunahing serbisyo kasama sa ang mga aklatan ng ScriptForge direktang tumawag sa kanilang mga katutubong Basic counterparts.


uiScripts Pangunahing modyul


        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

Ang Alternatibong Python Script Organizer (APSO) extension ay nag-aalok ng isang msgbox() function sa labas nito apso_utils modyul.


Mangyaring suportahan kami!