ການຊ່ວຍເຫຼືອ LibreOffice 26.2
ໄຟລ໌ຜົນອອກມາດົນຕະຖານຂອງ Python ແມ່ນບໍ່ມີໃຫ້ໃຊ້ ເມື່ອມີການເຮັດວຽກມາໂຄຣ Python ຈາກເມນູ ... ການສະແດງຜົນອອກຂອງໂມດູນຈຳເປັນຕ້ອງໃຊ້ຄອນໂຊລແບບໂຕ້ຕອບຂອງ Python. ຄຸນສົມບັດຕ່າງໆ ເຊັ່ນ input(), print(), repr() ແລະ str() ແມ່ນມີໃຫ້ໃຊ້ຈາກ Python shell.
LibreOffice ໂມດູນ Python msgbox ສະເໜີເມັດທອດ msgbox() ທີ່ສະແດງໃຫ້ເຫັນໃນໜ້າຕົວຢ່າງ ການສ້າງຕົວຮັບຟັງເຫດການ ແລະ ການສ້າງຕົວຈັດການໄດອາລັອກ.
LibreOffice Basic ມີຟັງຊັນ InputBox(), Msgbox() ແລະ Print(). ໃນ Python ກໍມີທາງເລືອກອື່ນທີ່ໃຊ້ API ຂອງ LibreOffice ຫຼື ການເອີ້ນໃຊ້ຟັງຊັນ Basic ຈາກ Python.
MsgBox(txt, buttons=0, title=None)
InputBox(txt, title=None, default=None)
Print(txt)
>>> 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)
ສຳເນົາໂມດູນ Python screen_io ໃສ່ໃນ ແມັກໂຄຣຂອງຂ້ອຍ ພາຍໃຕ້ pythonpath,
ສຳເນົາໂມດູນ Basic uiScripts ໃນຄັງໂປຣແກຣມ Basic ມາດຕະຖານ ມາກໂຄຣຂອງຂ້ອຍ,
ເລີ່ມຕົ້ນ LibreOffice ໃໝ່.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
def MsgBox(prompt: str, buttons=0, title='LibreOffice') -> int:
""" ສະແດງກ່ອງໄດອາລັອກທີ່ມີຂໍ້ຄວາມ ແລະ ສົ່ງຄືນຄ່າ."""
xScript = _getScript("_MsgBox")
res = xScript.invoke((prompt,buttons,title), (), ())
return res[0]
def InputBox(prompt: str, title='LibreOffice', defaultValue='') -> str:
""" ສະແດງກ່ອງຂໍ້ຄວາມໃຫ້ຜູ້ໃຊ້ປ້ອນຂໍ້ຄວາມ."""
xScript = _getScript("_InputBox")
res = xScript.invoke((prompt,title,defaultValue), (), ())
return res[0]
def Print(message: str):
"""ສະແດງຂໍ້ຄວາມ ຫຼື ຕົວເລກທີ່ລະບຸໃນກ່ອງໄດອາລັອກ."""
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
MsgBox ແລະ InputBox ເມັດທອດ ຈາກ ບໍລິການ Basic ທີ່ລວມຢູ່ໃນ ໄລບຣາຣີ ScriptForge ເອີ້ນໃຊ້ໂດຍກົງກັບຄູ່ຮ່ວມ Basic ດັ້ງເດີມຂອງພວກມັນ.
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
ສ່ວນເສີມ Alternative Python Script Organizer (APSO) ມີຟັງຊັນ msgbox() ໃຫ້ໃຊ້ຈາກໂມດູນ apso_utils ຂອງມັນ.