當前位置: 首頁>>代碼示例>>Python>>正文


Python KeyBuffer.clear方法代碼示例

本文整理匯總了Python中ranger.ext.keybinding_parser.KeyBuffer.clear方法的典型用法代碼示例。如果您正苦於以下問題:Python KeyBuffer.clear方法的具體用法?Python KeyBuffer.clear怎麽用?Python KeyBuffer.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ranger.ext.keybinding_parser.KeyBuffer的用法示例。


在下文中一共展示了KeyBuffer.clear方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Environment

# 需要導入模塊: from ranger.ext.keybinding_parser import KeyBuffer [as 別名]
# 或者: from ranger.ext.keybinding_parser.KeyBuffer import clear [as 別名]
class Environment(SettingsAware, SignalDispatcher):
	"""
	A collection of data which is relevant for more than one class.
	"""

	cwd = None  # current directory
	copy = None
	cmd = None
	cut = None
	termsize = None
	history = None
	directories = None
	last_search = None
	pathway = None
	path = None

	def __init__(self, path):
		SignalDispatcher.__init__(self)
		self.path = abspath(expanduser(path))
		self._cf = None
		self.pathway = ()
		self.directories = {}
		self.keybuffer = KeyBuffer()
		self.keymaps = KeyMaps(self.keybuffer)
		self.copy = set()
		self.history = History(self.settings.max_history_size, unique=False)

		try:
			self.username = pwd.getpwuid(os.geteuid()).pw_name
		except:
			self.username = 'uid:' + str(os.geteuid())
		self.hostname = socket.gethostname()
		self.home_path = os.path.expanduser('~')

		self.signal_bind('move', self._set_cf_from_signal, priority=0.1,
				weak=True)

	def _set_cf_from_signal(self, signal):
		self._cf = signal.new

	def _set_cf(self, value):
		if value is not self._cf:
			previous = self._cf
			self.signal_emit('move', previous=previous, new=value)

	def _get_cf(self):
		return self._cf

	cf = property(_get_cf, _set_cf)

	def key_append(self, key):
		"""Append a key to the keybuffer"""

		# special keys:
		if key == curses.KEY_RESIZE:
			self.keybuffer.clear()

		self.keybuffer.add(key)

	def key_clear(self):
		"""Clear the keybuffer"""
		self.keybuffer.clear()

	def at_level(self, level):
		"""
		Returns the FileSystemObject at the given level.
		level >0 => previews
		level 0 => current file/directory
		level <0 => parent directories
		"""
		if level <= 0:
			try:
				return self.pathway[level - 1]
			except IndexError:
				return None
		else:
			directory = self.cf
			for i in range(level - 1):
				if directory is None:
					return None
				if directory.is_directory:
					directory = directory.pointed_obj
				else:
					return None
			try:
				return self.directories[directory.path]
			except AttributeError:
				return None
			except KeyError:
				return directory

	def garbage_collect(self, age, tabs):
		"""Delete unused directory objects"""
		for key in tuple(self.directories):
			value = self.directories[key]
			if age != -1:
				if not value.is_older_than(age) or value in self.pathway:
					continue
				if value in tabs.values():
					continue
#.........這裏部分代碼省略.........
開發者ID:benemal,項目名稱:ranger,代碼行數:103,代碼來源:environment.py

示例2: UI

# 需要導入模塊: from ranger.ext.keybinding_parser import KeyBuffer [as 別名]
# 或者: from ranger.ext.keybinding_parser.KeyBuffer import clear [as 別名]

#.........這裏部分代碼省略.........
        boolean = bool(boolean)
        if boolean != self.load_mode:
            self.load_mode = boolean

            if boolean:
                # don't wait for key presses in the load mode
                curses.cbreak()
                self.win.nodelay(1)
            else:
                self.win.nodelay(0)
                curses.halfdelay(20)

    def destroy(self):
        """Destroy all widgets and turn off curses"""
        DisplayableContainer.destroy(self)
        self.suspend()

    def handle_mouse(self):
        """Handles mouse input"""
        try:
            event = MouseEvent(curses.getmouse())
        except _curses.error:
            return
        if not self.console.visible:
            DisplayableContainer.click(self, event)

    def handle_key(self, key):
        """Handles key input"""

        if hasattr(self, 'hint'):
            self.hint()

        if key < 0:
            self.keybuffer.clear()

        elif not DisplayableContainer.press(self, key):
            self.keymaps.use_keymap('browser')
            self.press(key)

    def press(self, key):
        keybuffer = self.keybuffer
        self.status.clear_message()

        keybuffer.add(key)
        self.fm.hide_bookmarks()
        self.browser.draw_hints = not keybuffer.finished_parsing \
                and keybuffer.finished_parsing_quantifier

        if keybuffer.result is not None:
            try:
                self.fm.execute_console(keybuffer.result,
                        wildcards=keybuffer.wildcards,
                        quantifier=keybuffer.quantifier)
            finally:
                if keybuffer.finished_parsing:
                    keybuffer.clear()
        elif keybuffer.finished_parsing:
            keybuffer.clear()
            return False
        return True

    def handle_keys(self, *keys):
        for key in keys:
            self.handle_key(key)

    def handle_input(self):
開發者ID:niksfirefly,項目名稱:ranger,代碼行數:70,代碼來源:ui.py

示例3: UI

# 需要導入模塊: from ranger.ext.keybinding_parser import KeyBuffer [as 別名]
# 或者: from ranger.ext.keybinding_parser.KeyBuffer import clear [as 別名]

#.........這裏部分代碼省略.........
            del self.__dict__['vcsthread']
        DisplayableContainer.destroy(self)

        # Restore tmux setting `automatic-rename`
        if self.settings.update_tmux_title and 'TMUX' in os.environ:
            if self._tmux_automatic_rename:
                try:
                    check_output(['tmux', 'set-window-option',
                                  'automatic-rename', self._tmux_automatic_rename])
                except CalledProcessError:
                    pass
            else:
                try:
                    check_output(['tmux', 'set-window-option', '-u', 'automatic-rename'])
                except CalledProcessError:
                    pass

        self.suspend()

    def handle_mouse(self):
        """Handles mouse input"""
        try:
            event = MouseEvent(curses.getmouse())
        except curses.error:
            return
        if not self.console.visible:
            DisplayableContainer.click(self, event)

    def handle_key(self, key):
        """Handles key input"""
        self.hint()

        if key < 0:
            self.keybuffer.clear()

        elif not DisplayableContainer.press(self, key):
            self.keymaps.use_keymap('browser')
            self.press(key)

    def press(self, key):
        keybuffer = self.keybuffer
        self.status.clear_message()

        keybuffer.add(key)
        self.fm.hide_bookmarks()
        self.browser.draw_hints = not keybuffer.finished_parsing \
            and keybuffer.finished_parsing_quantifier

        if keybuffer.result is not None:
            try:
                self.fm.execute_console(
                    keybuffer.result,
                    wildcards=keybuffer.wildcards,
                    quantifier=keybuffer.quantifier,
                )
            finally:
                if keybuffer.finished_parsing:
                    keybuffer.clear()
        elif keybuffer.finished_parsing:
            keybuffer.clear()
            return False
        return True

    def handle_keys(self, *keys):
        for key in keys:
            self.handle_key(key)
開發者ID:sergeyguzhev,項目名稱:ranger,代碼行數:70,代碼來源:ui.py


注:本文中的ranger.ext.keybinding_parser.KeyBuffer.clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。