本文整理汇总了Python中ranger.ext.keybinding_parser.KeyBuffer类的典型用法代码示例。如果您正苦于以下问题:Python KeyBuffer类的具体用法?Python KeyBuffer怎么用?Python KeyBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KeyBuffer类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, env=None, fm=None):
self.keybuffer = KeyBuffer()
self.keymaps = KeyMaps(self.keybuffer)
self.redrawlock = threading.Event()
self.redrawlock.set()
if fm is not None:
self.fm = fm
示例2: __init__
def __init__(self, env=None, fm=None): # pylint: disable=super-init-not-called
self.keybuffer = KeyBuffer()
self.keymaps = KeyMaps(self.keybuffer)
self.redrawlock = threading.Event()
self.redrawlock.set()
self.titlebar = None
self._viewmode = None
self.taskview = None
self.status = None
self.console = None
self.pager = None
self._draw_title = None
self._tmux_automatic_rename = None
self.browser = None
if fm is not None:
self.fm = fm
示例3: __init__
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)
示例4: __init__
def __init__(self, env=None, fm=None):
self.keybuffer = KeyBuffer()
self.keymaps = KeyMaps(self.keybuffer)
if fm is not None:
self.fm = fm
示例5: UI
class UI(DisplayableContainer):
is_set_up = False
load_mode = False
is_on = False
termsize = None
def __init__(self, env=None, fm=None):
self.keybuffer = KeyBuffer()
self.keymaps = KeyMaps(self.keybuffer)
if fm is not None:
self.fm = fm
def setup_curses(self):
os.environ['ESCDELAY'] = '25' # don't know a cleaner way
try:
self.win = curses.initscr()
except _curses.error as e:
if e.args[0] == "setupterm: could not find terminal":
os.environ['TERM'] = 'linux'
self.win = curses.initscr()
self.keymaps.use_keymap('browser')
DisplayableContainer.__init__(self, None)
def initialize(self):
"""initialize curses, then call setup (at the first time) and resize."""
self.win.leaveok(0)
self.win.keypad(1)
self.load_mode = False
curses.cbreak()
curses.noecho()
curses.halfdelay(20)
try:
curses.curs_set(int(bool(self.settings.show_cursor)))
except:
pass
curses.start_color()
curses.use_default_colors()
self.settings.signal_bind('setopt.mouse_enabled', _setup_mouse)
_setup_mouse(dict(value=self.settings.mouse_enabled))
if not self.is_set_up:
self.is_set_up = True
self.setup()
self.win.addstr("loading...")
self.win.refresh()
self._draw_title = curses.tigetflag('hs') # has_status_line
self.update_size()
self.is_on = True
if self.settings.update_tmux_title:
sys.stdout.write("\033kranger\033\\")
sys.stdout.flush()
def suspend(self):
"""Turn off curses"""
self.win.keypad(0)
curses.nocbreak()
curses.echo()
try:
curses.curs_set(1)
except:
pass
if self.settings.mouse_enabled:
_setup_mouse(dict(value=False))
curses.endwin()
self.is_on = False
def set_load_mode(self, boolean):
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"""
#.........这里部分代码省略.........
示例6: Environment
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
#.........这里部分代码省略.........
示例7: UI
class UI( # pylint: disable=too-many-instance-attributes,too-many-public-methods
DisplayableContainer):
ALLOWED_VIEWMODES = 'miller', 'multipane'
is_set_up = False
load_mode = False
is_on = False
termsize = None
def __init__(self, env=None, fm=None): # pylint: disable=super-init-not-called
self.keybuffer = KeyBuffer()
self.keymaps = KeyMaps(self.keybuffer)
self.redrawlock = threading.Event()
self.redrawlock.set()
self.titlebar = None
self._viewmode = None
self.taskview = None
self.status = None
self.console = None
self.pager = None
self._draw_title = None
self._tmux_automatic_rename = None
self.browser = None
if fm is not None:
self.fm = fm
def setup_curses(self):
os.environ['ESCDELAY'] = '25' # don't know a cleaner way
try:
self.win = curses.initscr()
except curses.error as ex:
if ex.args[0] == "setupterm: could not find terminal":
os.environ['TERM'] = 'linux'
self.win = curses.initscr()
self.keymaps.use_keymap('browser')
DisplayableContainer.__init__(self, None)
def initialize(self):
"""initialize curses, then call setup (at the first time) and resize."""
self.win.leaveok(0)
self.win.keypad(1)
self.load_mode = False
curses.cbreak()
curses.noecho()
curses.halfdelay(20)
try:
curses.curs_set(int(bool(self.settings.show_cursor)))
except curses.error:
pass
curses.start_color()
try:
curses.use_default_colors()
except curses.error:
pass
self.settings.signal_bind('setopt.mouse_enabled', _setup_mouse)
self.settings.signal_bind('setopt.freeze_files', self.redraw_statusbar)
_setup_mouse(dict(value=self.settings.mouse_enabled))
if not self.is_set_up:
self.is_set_up = True
self.setup()
self.win.addstr("loading...")
self.win.refresh()
self._draw_title = curses.tigetflag('hs') # has_status_line
# Save tmux setting `automatic-rename`
if self.settings.update_tmux_title and 'TMUX' in os.environ:
try:
self._tmux_automatic_rename = check_output(
['tmux', 'show-window-options', '-v', 'automatic-rename']).strip()
except CalledProcessError:
self._tmux_automatic_rename = None
self.update_size()
self.is_on = True
if self.settings.update_tmux_title and 'TMUX' in os.environ:
sys.stdout.write("\033kranger\033\\")
sys.stdout.flush()
if 'vcsthread' in self.__dict__:
self.vcsthread.unpause()
def suspend(self):
"""Turn off curses"""
if 'vcsthread' in self.__dict__:
self.vcsthread.pause()
self.vcsthread.paused.wait()
self.win.keypad(0)
curses.nocbreak()
curses.echo()
try:
curses.curs_set(1)
except curses.error:
pass
#.........这里部分代码省略.........