2 LeenO menu and basic function dispatcher
10 from os
import listdir
11 from os.path
import isfile, join
14 from com.sun.star.task
import XJobExecutor
19 from com.sun.star.awt
import MessageBoxButtons
as MSG_BUTTONS
20 def msgbox(*, Title='Errore interno', Message=''):
21 """ Create message box
22 type_msg: infobox, warningbox, errorbox, querybox, messbox
23 http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1awt_1_1XMessageBoxFactory.html
25 ctx = uno.getComponentContext()
26 sm = ctx.getServiceManager()
27 toolkit = sm.createInstance(
'com.sun.star.awt.Toolkit')
28 parent = toolkit.getDesktopWindow()
29 buttons=MSG_BUTTONS.BUTTONS_OK
31 mb = toolkit.createMessageBox(parent, type_msg, buttons, Title, str(Message))
49 Legge il numero di versione di LibreOffice.
51 aConfigProvider = uno.getComponentContext().ServiceManager.createInstance(
"com.sun.star.configuration.ConfigurationProvider")
52 arg = uno.createUnoStruct(
'com.sun.star.beans.PropertyValue')
54 arg.Value =
'/org.openoffice.Setup/Product'
55 return aConfigProvider.createInstanceWithArguments(
56 "com.sun.star.configuration.ConfigurationAccess",
57 (arg, )).ooSetupVersionAboutBox
61 This function should fix python path adding it to current sys path
63 Useless here, just kept for reference
66 myPath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
67 myPath = os.path.join(myPath,
"pythonpath")
68 if myPath
not in sys.path:
69 sys.path.append(myPath)
74 This function reload all Leeno modules found in pythonpath
77 myPath = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
78 myPath = os.path.join(myPath,
"pythonpath")
81 pythonFiles = [f[: -3]
for f
in listdir(myPath)
if isfile(join(myPath, f))
and f.endswith(
".py")]
84 module = importlib.import_module(f)
87 importlib.reload(module)
92 LeenO menu and basic function dispatcher
108 This function gets called when a menu item is selected
109 or when a basic function calls PyScript()
113 if DISABLE_CACHE != 0:
118 ModFunc = arg.split(
'.')
121 module = importlib.import_module(ModFunc[0])
123 print(
"Module '", ModFunc[0],
"' not found")
131 func = getattr(module, ModFunc[1])
133 print(
"Function '", ModFunc[1],
"' not found in Module '", ModFunc[0],
"'")
135 Title=
"Errore interno",
136 Text=f
"Funzione '{ModFunc[1]}' non trovata nel modulo '{ModFunc[0]}'")
140 if len(self.
args) == 0:
145 except Exception
as e:
149 pir = uno.getComponentContext().getValueByName(
150 '/singletons/com.sun.star.deployment.PackageInformationProvider')
151 expath = pir.getPackageLocation(
'org.giuseppe-vizziello.leeno')
153 code_file = uno.fileUrlToSystemPath(expath + os.altsep +
154 'leeno_version_code')
156 code_file = uno.fileUrlToSystemPath(expath + os.sep +
157 'leeno_version_code')
158 f = open(code_file,
'r')
159 msg =
"OS: " + sys.platform +
' / LibreOffice-' +
loVersion() +
' / '+ f.readline() +
"\n\n"
162 print(
"sys.exc_info:", sys.exc_info())
163 sysinfo = sys.exc_info()
164 exceptionClass = sysinfo[0].__name__
165 msg += str(sysinfo[1])
166 if msg ==
'-1' or msg ==
'':
167 msg += str(sysinfo[0])
171 tbInfo = traceback.extract_tb(tb)[-1]
172 function = tbInfo.name
174 file = os.path.split(tbInfo.filename)[1]
177 "File: '" + file +
"'\n" +
178 "Line: '" + str(line) +
"'\n" +
179 "Function: '" + function +
"'\n")
180 msg +=
"-" * 30 +
"\n"
181 msg +=
"BACKTRACE:\n"
182 for bkInfo
in traceback.extract_tb(tb):
183 function = bkInfo.name
184 line = str(bkInfo.lineno)
185 file = os.path.split(bkInfo.filename)[1]
186 msg += f
"File:{file}, Line:{line}, Function:{function}\n"
192 g_ImplementationHelper = unohelper.ImplementationHelper()
193 g_ImplementationHelper.addImplementation(
195 "org.giuseppe-vizziello.leeno.dispatcher",
196 (
"com.sun.star.task.Job",),)