CallWizard.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # This file is part of the LibreOffice project.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #
  8. # This file incorporates work covered by the following license notice:
  9. #
  10. # Licensed to the Apache Software Foundation (ASF) under one or more
  11. # contributor license agreements. See the NOTICE file distributed
  12. # with this work for additional information regarding copyright
  13. # ownership. The ASF licenses this file to you under the Apache
  14. # License, Version 2.0 (the "License"); you may not use this file
  15. # except in compliance with the License. You may obtain a copy of
  16. # the License at http://www.apache.org/licenses/LICENSE-2.0 .
  17. #
  18. import unohelper
  19. import traceback
  20. from .LetterWizardDialogImpl import LetterWizardDialogImpl, Desktop
  21. from com.sun.star.lang import XServiceInfo
  22. from com.sun.star.task import XJobExecutor
  23. # pythonloader looks for a static g_ImplementationHelper variable
  24. g_ImplementationHelper = unohelper.ImplementationHelper()
  25. g_implName = "com.sun.star.wizards.letter.CallWizard"
  26. # implement a UNO component by deriving from the standard unohelper.Base class
  27. # and from the interface(s) you want to implement.
  28. class CallWizard(unohelper.Base, XJobExecutor, XServiceInfo):
  29. def __init__(self, ctx):
  30. # store the component context for later use
  31. self.ctx = ctx
  32. def trigger(self, args):
  33. try:
  34. lw = LetterWizardDialogImpl(self.ctx.ServiceManager)
  35. lw.startWizard(self.ctx.ServiceManager)
  36. except Exception as e:
  37. print ("Wizard failure exception " + str(type(e)) +
  38. " message " + str(e) + " args " + str(e.args) +
  39. traceback.format_exc())
  40. @classmethod
  41. def callRemote(self):
  42. #Call the wizard remotely(see README)
  43. try:
  44. ConnectStr = \
  45. "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
  46. xLocMSF = Desktop.connect(ConnectStr)
  47. lw = LetterWizardDialogImpl(xLocMSF)
  48. lw.startWizard(xLocMSF)
  49. except Exception as e:
  50. print ("Wizard failure exception " + str(type(e)) +
  51. " message " + str(e) + " args " + str(e.args) +
  52. traceback.format_exc())
  53. def getImplementationName(self):
  54. return g_implName
  55. def supportsService(self, ServiceName):
  56. return g_ImplementationHelper.supportsService(g_implName, ServiceName)
  57. def getSupportedServiceNames(self):
  58. return g_ImplementationHelper.getSupportedServiceNames(g_implName)
  59. g_ImplementationHelper.addImplementation( \
  60. CallWizard, # UNO object class
  61. g_implName, # implementation name
  62. ("com.sun.star.task.Job",),) # list of implemented services
  63. # (the only service)
  64. # vim:set shiftwidth=4 softtabstop=4 expandtab: