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


Python View.search_query方法代码示例

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


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

示例1: Kunai

# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import search_query [as 别名]
class Kunai(object):

    RE_DESPICTION_DELAY = 0.05

    def __init__(self, function_name, request, kwargs, descriptors=None):
        self.global_lock = threading.Lock()
        self.render_name = function_name
        self.request = request
        self.action_name = kwargs.get('action')
        self.args_for_action = None
        self.parser = ExecFileParser()
        self.keyhandler = KeyHandler()
        self.conf = Config()

        if descriptors is None:
            self.stdin = sys.stdin
            self.stdout = sys.stdout
            self.stderr = sys.stderr
        else:
            self.stdin = descriptors['stdin']
            self.stdout = descriptors['stdout']
            self.stderr = descriptors['stderr']

    def __enter__(self):
        self.stdscr = curses.initscr()
        curses.curs_set(0)

        display = Display()
        screen = Screen(self.stdscr, self.request)
        self.view = View(display, screen)

        # Invalidation Ctrl + z
        signal.signal(signal.SIGINT, lambda signum, frame: None)
        self.stdscr.keypad(True)

        curses.raw()
        curses.noecho()
        curses.cbreak()
        curses.nonl()

        return self

    def __exit__(self, exc_type, exc_value, traceback):
        """Exit and action or call next kunai action
        """
        curses.nl()
        curses.endwin()
        if self.action_name:
            # next action
            self.parser.pick_command(self.action_name)
            for const in self.parser.code_obj.co_consts:
                # XXX get only action method code object
                if isinstance(const, types.CodeType):
                    self.parser.set_importmodule_code(const)
                    exec(self.parser.code_obj, {
                        # set globals
                        self.render_name: self.args_for_action,
                    })
        else:
            # finish
            self.execute_command()

    def loop(self):
        # initialize
        self.view.refresh_display()
        self.updating_timer = None

        def despiction():
            self.view.search_query(self.keyhandler.current_key)

        while True:
            self.view.refresh_display()
            try:
                key = self.stdscr.getch()
                self.keyhandler.handle_key(key)
                if self.keyhandler.has_query:
                    with self.global_lock:

                        if self.updating_timer is not None:
                            # clear timer
                            self.updating_timer.cancel()
                            self.updating_timer = None
                        timer = threading.Timer(self.RE_DESPICTION_DELAY,
                                                despiction)
                        self.updating_timer = timer
                        timer.start()

                Command(self)
            except TerminateLoop as e:
                return e.value

    def finish(self, value=0):
        raise TerminateLoop(self.finish_with_exit_code(value))

    def cancel(self):
        raise TerminateLoop(self.cancel_with_exit_code())

    def finish_with_exit_code(self, value):
        if isinstance(self.request, dict):
            self.args_for_action = self.request[self.view.select_line.strip().decode('utf-8')]
#.........这里部分代码省略.........
开发者ID:wanshot,项目名称:templa,代码行数:103,代码来源:cli.py


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