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


Python View.change_pointer方法代码示例

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


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

示例1: Controller

# 需要导入模块: from view import View [as 别名]
# 或者: from view.View import change_pointer [as 别名]
class Controller(object):
    """ Window/keyboard controller. """
    def __init__(self):
        self.model = Model()
        self.view = View()

        self.socket = UDSClient()
        self.socket.register(Protocol.FULL_HISTORY, self.model.history.set)
        self.socket.register(Protocol.NEW_ENTRY, self.model.history.add)

        self.commands = {"q": self._quit,
                         "j": lambda: self.view.change_pointer(1),
                         "k": lambda: self.view.change_pointer(-1),
                         "y": lambda: self._copy_pointed(None),
                         "u": lambda: self._copy_pointed("lower"),
                         "U": lambda: self._copy_pointed("upper"),
                         "v|V": self._toggle_details_view,
                         "\t": self._toggle_match_url,
                         r'\+': lambda: self.view.resize(1),
                         r'\-': lambda: self.view.resize(-1),
                         r'/(.*)[^\]]$': self._search}

        self.running = True

    def _search(self):
        "Prepare to filter items by search term."
        self.model.set_search()
        self.view.highlighted_item = 0
        self.view.pointer = 0

    def _quit(self):
        "Update state so that everyone knows the program should close."
        self.running = False

    def _clear_buffer(self, how_much=None):
        "Clear keyboard buffer."
        if how_much is None:
            how_much = len(self.model.kb_buffer)
        self.model.kb_buffer = self.model.kb_buffer[:-how_much]

    def _toggle_details_view(self):
        "Show/hide details view."
        self.view.details_window_show = not self.view.details_window_show

    def _toggle_match_url(self):
        "Toggle the match url toggle."
        self.model.match_url = not self.model.match_url
        self.view.highlighted_item = 0
        self.view.pointer = 0

    def _copy_pointed(self, mode=""):
        """Copy an item into the clipboard.
           Can copy as all upper or all lower, depending on mode chosen."""
        pointed = self.model.filtered_items[self.view.pointer].encode("utf-8")

        write_text = pointed.upper() if mode == "upper" else \
                     pointed.lower() if mode == "lower" else \
                     pointed

        ClipboardFactory.create().put_text(write_text)

    def update(self):
        "Update the visible items and draw."
        self.model.filter()
        self.view.update(self.model)

    def wait_for_key_and_process(self):
        "Wait for a key press and process it."
        self.update()

        key = self.view.get_key()
        if key in (None, Keys.LEFT, Keys.RIGHT):
            return

        if key == Keys.ENTER:
            self._clear_buffer()
        elif key == Keys.ESCAPE:
            self.model.search_text = ""
            self.model.kb_buffer = ""
        elif key == Keys.BACKSPACE:
            self._clear_buffer(1)
        elif key == Keys.UP:
            self.view.change_pointer(-1)
        elif key == Keys.DOWN:
            self.view.change_pointer(1)
        else:
            self.model.kb_buffer += key

            for key, value in self.commands.iteritems():
                regex = re.compile(r'\A' + key + r'\Z')
                match = regex.match(self.model.kb_buffer)

                if match is not None:
                    value()
                    break

            if len(self.model.kb_buffer) == 0 or self.model.kb_buffer[0] != "/":
                self._clear_buffer()

    def close(self):
#.........这里部分代码省略.........
开发者ID:jlcordeiro,项目名称:Clipp,代码行数:103,代码来源:controllers.py


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