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


Python TmpFile.readlines方法代码示例

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


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

示例1: CustomToolDict

# 需要导入模块: from zim.fs import TmpFile [as 别名]
# 或者: from zim.fs.TmpFile import readlines [as 别名]

#.........这里部分代码省略.........

    def get_pixbuf(self, size):
        pixbuf = DesktopEntryDict.get_pixbuf(self, size)
        if pixbuf is None:
            pixbuf = gtk.Label().render_icon(gtk.STOCK_EXECUTE, size)
            # FIXME hack to use arbitrary widget to render icon
        return pixbuf

    @property
    def icon(self):
        return self['Desktop Entry'].get('Icon') or gtk.STOCK_EXECUTE
            # get('Icon', gtk.STOCK_EXECUTE) still returns empty string if key exists but no value

    @property
    def execcmd(self):
        return self['Desktop Entry']['X-Zim-ExecTool']

    @property
    def isreadonly(self):
        return self['Desktop Entry']['X-Zim-ReadOnly']

    @property
    def showintoolbar(self):
        return self['Desktop Entry']['X-Zim-ShowInToolBar']

    @property
    def showincontextmenu(self):
        return self['Desktop Entry']['X-Zim-ShowInContextMenu']

    def parse_exec(self, args=None):
        if not (isinstance(args, tuple) and len(args) == 3):
            raise AssertionError, 'Custom commands needs 3 arguments'
            # assert statement could be optimized away
        notebook, page, pageview = args

        cmd = split_quoted_strings(self['Desktop Entry']['X-Zim-ExecTool'])
        if '%f' in cmd:
            self._tmpfile = TmpFile('tmp-page-source.txt')
            self._tmpfile.writelines(page.dump('wiki'))
            cmd[cmd.index('%f')] = self._tmpfile.path

        if '%d' in cmd:
            dir = notebook.get_attachments_dir(page)
            if dir:
                cmd[cmd.index('%d')] = dir.path
            else:
                cmd[cmd.index('%d')] = ''

        if '%s' in cmd:
            if hasattr(page, 'source') and isinstance(page.source, File):
                cmd[cmd.index('%s')] = page.source.path
            else:
                cmd[cmd.index('%s')] = ''

        if '%n' in cmd:
            cmd[cmd.index('%n')] = File(notebook.uri).path

        if '%D' in cmd:
            dir = notebook.document_root
            if dir:
                cmd[cmd.index('%D')] = dir.path
            else:
                cmd[cmd.index('%D')] = ''

        if '%t' in cmd:
            text = pageview.get_selection() or pageview.get_word()
            cmd[cmd.index('%t')] = text or ''
            # FIXME - need to substitute this in arguments + url encoding

        if '%T' in cmd:
            text = pageview.get_selection(format='wiki') or pageview.get_word(format='wiki')
            cmd[cmd.index('%T')] = text or ''
            # FIXME - need to substitute this in arguments + url encoding

        return tuple(cmd)

    _cmd = parse_exec # To hook into Application.spawn and Application.run

    def run(self, args):
        self._tmpfile = None
        Application.run(self, args)
        if self._tmpfile:
            notebook, page, pageview = args
            page.parse('wiki', self._tmpfile.readlines())
            self._tmpfile = None

    def update(self, E=None, **F):
        self['Desktop Entry'].update(E, **F)

        # Set sane default for X-Zim-ShowInContextMenus
        if not (E and 'X-Zim-ShowInContextMenu' in E) \
        and not 'X-Zim-ShowInContextMenu' in F:
            cmd = split_quoted_strings(self['Desktop Entry']['X-Zim-ExecTool'])
            if any(c in cmd for c in ['%f', '%d', '%s']):
                context = 'Page'
            elif '%t' in cmd:
                context = 'Text'
            else:
                context = None
            self['Desktop Entry']['X-Zim-ShowInContextMenu'] = context
开发者ID:DarioGT,项目名称:Zim-QDA,代码行数:104,代码来源:applications.py


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