ການຊ່ວຍເຫຼືອ LibreOffice 26.2
ການຄິດໄລ່ເສັ້ນທາງໂປຣໄຟລ໌ຜູ້ໃຊ້ ແລະ ໂມດູນທີ່ໃຊ້ຮ່ວມກັນຂອງ LibreOffice ສາມາດເຮັດໄດ້ດ້ວຍພາສາ Python ຫຼື Basic.
ດ້ວຍ Python shell.
>>> from <the_module> import Session
>>> print(Session.SharedPythonScripts()) # ເມັດທອດຄົງທີ່
>>> print(Session().UserName) # ຄຸນສົມບັດອອບເຈັກ
>>> input(Session().UserProfile) # ຄຸນສົມບັດອອບເຈັກ
from <the_module> import Session
def demo_session():
import screen_io as ui
ui.MsgBox(Session.Share(),title='ບ່ອນຕິດຕັ້ງທີ່ໃຊ້ຮ່ວມກັນ') # ເມັດທອດຄົງທີ່
ui.Print(Session.SharedPythonScripts()) # ເມັດທອດຄົງທີ່
s = Session() # ສ້າງອິນສະແຕນຊ໌
ui.MsgBox(s.UserName,title='ສະບາຍດີ') # ຄຸນສົມບັດອອບເຈັກ
ui.Print(s.UserPythonScripts) # ຄຸນສົມບັດອອບເຈັກ
g_exportedScripts = (demo_session,) # ແມັກໂຄຣສາທາລະນະ
Sub Session_example()
Dim s As New Session ' instance of Session class
Print "ຕຳແໜ່ງສະຄຣິບທີ່ໃຊ້ຮ່ວມກັນ:", s.SharedScripts
MsgBox s.UserName,,"ສະບາຍດີ"
Print s.UserScripts, Chr(13), s.UserPythonScripts
End Sub ' Session_example
' ຕົວຈັດການບໍລິການແມ່ນຈຸດເລີ່ມຕົ້ນສະເໝີ
' ຖ້າຍັງບໍ່ມີໂປຣແກຣມອັອບຟິດຣັນຢູ່ ມັນຈະເລີ່ມຕົ້ນໃຫ້
Set sm = WScript.CreateObject("com.sun.star.ServiceManager")
' ບໍລິການ PathSubstitution ສະແດງຂໍ້ມູນເພື່ອອ້າງອີງ
' ຕຳແໜ່ງ <UserProfile|Share>/Scripts/python ຈາກ
Set obj = sm.createInstance("com.sun.star.util.PathSubstitution")
MsgBox CreateObject("WScript.Network").UserName,, "Hello"
user = obj.getSubstituteVariableValue("$(user)")
MsgBox user & "/Scripts",, "User scripts location"
libO = Replace(obj.getSubstituteVariableValue("$(inst)"), "program/..", "Share")
MsgBox libO & "/Scripts",, "Shared scripts location"
import getpass, os, os.path, uno
class Session():
@staticmethod
def substitute(var_name):
ctx = uno.getComponentContext()
ps = ctx.getServiceManager().createInstanceWithContext(
'com.sun.star.util.PathSubstitution', ctx)
return ps.getSubstituteVariableValue(var_name)
@staticmethod
def Share():
inst = uno.fileUrlToSystemPath(Session.substitute("$(prog)"))
return os.path.normpath(inst.replace('program', "Share"))
@staticmethod
def SharedScripts():
return ''.join([Session.Share(), os.sep, "Scripts"])
@staticmethod
def SharedPythonScripts():
return ''.join([Session.SharedScripts(), os.sep, 'python'])
@property # ທາງເລືອກແທນຕົວປ່ຽນ '$(username)'
def UserName(self): return getpass.getuser()
@property
def UserProfile(self):
return uno.fileUrlToSystemPath(Session.substitute("$(user)"))
@property
def UserScripts(self):
return ''.join([self.UserProfile, os.sep, 'Scripts'])
@property
def UserPythonScripts(self):
return ''.join([self.UserScripts, os.sep, "python"])
ບໍ່ຄືກັບ Basic, ການປັບເສັ້ນທາງໃຫ້ເປັນມາດຕະຖານຈະຖືກເຮັດດ້ວຍ Python ພາຍໃນຄລາສ Session.
Option Explicit
Option Compatible
Option ClassModule
Private _ps As Object ' ສະມາຊິກສ່ວນຕົວ
Private Sub Class_Initialize()
GlobalScope.BasicLibraries.LoadLibrary("Tools")
Set _ps = CreateUnoService("com.sun.star.util.PathSubstitution")
End Sub ' ຄອນສະຕຣັກເຕີ
Private Sub Class_Terminate()
_ps = Nothing
End Sub ' ດີສະຕຣັກເຕີ
Public Property Get SharedScripts() As String
Dim inst As String, shr As String
inst = ConvertFromURL(_ps.getSubstituteVariableValue("$(prog)"))
shr = Tools.Strings.ReplaceString(inst,"Share","program")
SharedScripts = shr & GetPathSeparator() &"Scripts"
End Property ' Session.sharedScripts
Public Property Get SharedPythonScripts() As String
sharedPythonScripts = sharedScripts() & GetPathSeparator() &"python"
End Property ' Session.sharedPythonScripts
Public Property Get UserName() As String ' ຊື່ບັນຊີຜູ້ໃຊ້
userName = _ps.getSubstituteVariableValue("$(username)")
End Property ' Session.userName
Public Property Get UserProfile() As String ' ເສັ້ນທາງລະບົບໂປຣໄຟລ໌ຜູ້ໃຊ້
userProfile = ConvertFromURL(_ps.getSubstituteVariableValue("$(user)"))
End Property ' Session.userProfile
Public Property Get UserScripts() As String ' ເສັ້ນທາງລະບົບສະຄຣິບຜູ້ໃຊ້
userScripts = userProfile() & GetPathSeparator() &"Scripts"
End Property ' Session.userScripts
Public Property Get UserPythonScripts() As String ' ເສັ້ນທາງລະບົບສະຄຣິບ Python ຜູ້ໃຊ້
userPythonScripts = userScripts() & GetPathSeparator() &"python"
End Property ' Session.userPythonScripts