当前位置: 首页>>代码示例>>Python>>正文


Python Dispatch._FlagAsMethod方法代码示例

本文整理汇总了Python中win32com.client.Dispatch._FlagAsMethod方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatch._FlagAsMethod方法的具体用法?Python Dispatch._FlagAsMethod怎么用?Python Dispatch._FlagAsMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32com.client.Dispatch的用法示例。


在下文中一共展示了Dispatch._FlagAsMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OpenOfficeImport

# 需要导入模块: from win32com.client import Dispatch [as 别名]
# 或者: from win32com.client.Dispatch import _FlagAsMethod [as 别名]
class OpenOfficeImport(SongImport):
    """
    Import songs from Impress/Powerpoint docs using Impress
    """
    def __init__(self, manager, **kwargs):
        """
        Initialise the class. Requires a songmanager class which is passed to SongImport for writing song to disk
        """
        super(OpenOfficeImport, self).__init__(manager, **kwargs)
        self.document = None
        self.process_started = False

    def do_import(self):
        if not isinstance(self.import_source, list):
            return
        try:
            self.start_ooo()
        except NoConnectException as exc:
            self.log_error(
                self.import_source[0],
                translate('SongsPlugin.SongImport', 'Cannot access OpenOffice or LibreOffice'))
            log.error(exc)
            return
        self.import_wizard.progress_bar.setMaximum(len(self.import_source))
        for filename in self.import_source:
            if self.stop_import_flag:
                break
            filename = str(filename)
            if os.path.isfile(filename):
                self.open_ooo_file(filename)
                if self.document:
                    self.process_ooo_document()
                    self.close_ooo_file()
                else:
                    self.log_error(self.file_path, translate('SongsPlugin.SongImport', 'Unable to open file'))
            else:
                self.log_error(self.file_path, translate('SongsPlugin.SongImport', 'File not found'))
        self.close_ooo()

    def process_ooo_document(self):
        """
        Handle the import process for OpenOffice files. This method facilitates
        allowing subclasses to handle specific types of OpenOffice files.
        """
        if self.document.supportsService("com.sun.star.presentation.PresentationDocument"):
            self.process_presentation()
        if self.document.supportsService("com.sun.star.text.TextDocument"):
            self.process_doc()

    def start_ooo(self):
        """
        Start OpenOffice.org process
        TODO: The presentation/Impress plugin may already have it running
        """
        if is_win():
            self.start_ooo_process()
            self.desktop = self.ooo_manager.createInstance('com.sun.star.frame.Desktop')
        else:
            context = uno.getComponentContext()
            resolver = context.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver', context)
            uno_instance = None
            loop = 0
            while uno_instance is None and loop < 5:
                try:
                    uno_instance = get_uno_instance(resolver)
                except NoConnectException:
                    time.sleep(0.1)
                    log.exception("Failed to resolve uno connection")
                    self.start_ooo_process()
                    loop += 1
                else:
                    manager = uno_instance.ServiceManager
                    self.desktop = manager.createInstanceWithContext("com.sun.star.frame.Desktop", uno_instance)
                    return
            raise Exception('Unable to start LibreOffice')

    def start_ooo_process(self):
        """
        Start the OO Process
        """
        try:
            if is_win():
                self.ooo_manager = Dispatch('com.sun.star.ServiceManager')
                self.ooo_manager._FlagAsMethod('Bridge_GetStruct')
                self.ooo_manager._FlagAsMethod('Bridge_GetValueObject')
            else:
                cmd = get_uno_command()
                process = QtCore.QProcess()
                process.startDetached(cmd)
            self.process_started = True
        except:
            log.exception("start_ooo_process failed")

    def open_ooo_file(self, file_path):
        """
        Open the passed file in OpenOffice.org Impress
        """
        self.file_path = file_path
        if is_win():
            url = file_path.replace('\\', '/')
#.........这里部分代码省略.........
开发者ID:crossroadchurch,项目名称:paul,代码行数:103,代码来源:openoffice.py

示例2: OooImport

# 需要导入模块: from win32com.client import Dispatch [as 别名]
# 或者: from win32com.client.Dispatch import _FlagAsMethod [as 别名]
class OooImport(SongImport):
    """
    Import songs from Impress/Powerpoint docs using Impress
    """
    def __init__(self, manager, **kwargs):
        """
        Initialise the class. Requires a songmanager class which is passed
        to SongImport for writing song to disk
        """
        SongImport.__init__(self, manager, **kwargs)
        self.document = None
        self.processStarted = False

    def doImport(self):
        if not isinstance(self.importSource, list):
            return
        try:
            self.startOoo()
        except NoConnectException as exc:
            self.logError(
                self.importSource[0],
                translate('SongsPlugin.SongImport', 'Cannot access OpenOffice or LibreOffice'))
            log.error(exc)
            return
        self.importWizard.progressBar.setMaximum(len(self.importSource))
        for filename in self.importSource:
            if self.stopImportFlag:
                break
            filename = unicode(filename)
            if os.path.isfile(filename):
                self.openOooFile(filename)
                if self.document:
                    self.processOooDocument()
                    self.closeOooFile()
                else:
                    self.logError(self.filepath, translate('SongsPlugin.SongImport', 'Unable to open file'))
            else:
                self.logError(self.filepath, translate('SongsPlugin.SongImport', 'File not found'))
        self.closeOoo()

    def processOooDocument(self):
        """
        Handle the import process for OpenOffice files. This method facilitates
        allowing subclasses to handle specific types of OpenOffice files.
        """
        if self.document.supportsService("com.sun.star.presentation.PresentationDocument"):
            self.processPres()
        if self.document.supportsService("com.sun.star.text.TextDocument"):
            self.processDoc()

    def startOoo(self):
        """
        Start OpenOffice.org process
        TODO: The presentation/Impress plugin may already have it running
        """
        if os.name == u'nt':
            self.startOooProcess()
            self.desktop = self.oooManager.createInstance(u'com.sun.star.frame.Desktop')
        else:
            context = uno.getComponentContext()
            resolver = context.ServiceManager.createInstanceWithContext(u'com.sun.star.bridge.UnoUrlResolver', context)
            uno_instance = None
            loop = 0
            while uno_instance is None and loop < 5:
                try:
                    uno_instance = get_uno_instance(resolver)
                except NoConnectException:
                    time.sleep(0.1)
                    log.exception("Failed to resolve uno connection")
                    self.startOooProcess()
                    loop += 1
                else:
                    manager = uno_instance.ServiceManager
                    self.desktop = manager.createInstanceWithContext("com.sun.star.frame.Desktop", uno_instance)
                    return
            raise

    def startOooProcess(self):
        try:
            if os.name == u'nt':
                self.oooManager = Dispatch(u'com.sun.star.ServiceManager')
                self.oooManager._FlagAsMethod(u'Bridge_GetStruct')
                self.oooManager._FlagAsMethod(u'Bridge_GetValueObject')
            else:
                cmd = get_uno_command()
                process = QtCore.QProcess()
                process.startDetached(cmd)
            self.processStarted = True
        except:
            log.exception("startOooProcess failed")

    def openOooFile(self, filepath):
        """
        Open the passed file in OpenOffice.org Impress
        """
        self.filepath = filepath
        if os.name == u'nt':
            url = filepath.replace(u'\\', u'/')
            url = url.replace(u':', u'|').replace(u' ', u'%20')
            url = u'file:///' + url
#.........这里部分代码省略.........
开发者ID:marmyshev,项目名称:transitions,代码行数:103,代码来源:oooimport.py


注:本文中的win32com.client.Dispatch._FlagAsMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。