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


Python rifle.Rifle类代码示例

本文整理汇总了Python中ranger.ext.rifle.Rifle的典型用法代码示例。如果您正苦于以下问题:Python Rifle类的具体用法?Python Rifle怎么用?Python Rifle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: initialize

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n + 1, Tab(path)) for n, path in enumerate(self.start_paths))
        tab_list = self._get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab(".")

        if not ranger.arg.clean and os.path.isfile(self.confpath("rifle.conf")):
            rifleconf = self.confpath("rifle.conf")
        else:
            rifleconf = self.relpath("config/rifle.conf")
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath("bookmarks")
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile, bookmarktype=Directory, autosave=self.settings.autosave_bookmarks
            )
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath("tagged"))

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: self.ui.suspend() if "f" not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: self.ui.initialize() if "f" not in flags else None
        self.rifle.hook_logger = self.notify

        def mylogfunc(text):
            self.notify(text, bad=True)

        self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)
开发者ID:radhermit,项目名称:ranger,代码行数:43,代码来源:fm.py

示例2: initialize

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        if not ranger.arg.clean and os.path.isfile(self.confpath("rifle.conf")):
            rifleconf = self.confpath("rifle.conf")
        else:
            rifleconf = self.relpath("defaults/rifle.conf")
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath("bookmarks")
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile, bookmarktype=Directory, autosave=self.settings.autosave_bookmarks
            )
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath("tagged"))

        if self.ui is None:
            self.ui = UI()
            self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: self.ui.suspend() if "f" not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: self.ui.initialize() if "f" not in flags else None
        self.rifle.hook_logger = self.notify

        def mylogfunc(text):
            self.notify(text, bad=True)

        self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)

        self.env.signal_bind("cd", self._update_current_tab)

        if self.settings.init_function:
            self.settings.init_function(self)
开发者ID:aspidites,项目名称:ranger,代码行数:40,代码来源:fm.py

示例3: initialize

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n + 1, Tab(path)) for n, path in enumerate(self.start_paths))
        tab_list = self.get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab('.')

        if not ranger.args.clean and os.path.isfile(self.confpath('rifle.conf')):
            rifleconf = self.confpath('rifle.conf')
        else:
            rifleconf = self.relpath('config/rifle.conf')
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        def set_image_displayer():
            self.image_displayer = self._get_image_displayer()
        set_image_displayer()
        self.settings.signal_bind('setopt.preview_images_method', set_image_displayer,
                                  priority=settings.SIGNAL_PRIORITY_AFTER_SYNC)

        self.settings.signal_bind(
            'setopt.preview_images',
            lambda signal: signal.fm.previews.clear(),
        )

        if ranger.args.clean:
            self.tags = TagsDummy("")
        elif self.tags is None:
            self.tags = Tags(self.datapath('tagged'))

        if self.bookmarks is None:
            if ranger.args.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.datapath('bookmarks')
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile,
                bookmarktype=Directory,
                autosave=self.settings.autosave_bookmarks)
            self.bookmarks.load()

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: \
            self.ui.suspend() if 'f' not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: \
            self.ui.initialize() if 'f' not in flags else None
        self.rifle.hook_logger = self.notify
        old_preprocessing_hook = self.rifle.hook_command_preprocessing

        # This hook allows image viewers to open all images in the current
        # directory, keeping the order of files the same as in ranger.
        # The requirements to use it are:
        # 1. set open_all_images to true
        # 2. ensure no files are marked
        # 3. call rifle with a command that starts with "sxiv " or "feh "
        def sxiv_workaround_hook(command):
            import re
            from ranger.ext.shell_escape import shell_quote

            if self.settings.open_all_images and \
                    not self.thisdir.marked_items and \
                    re.match(r'^(feh|sxiv|imv|pqiv) ', command):

                images = [f.relative_path for f in self.thisdir.files if f.image]
                escaped_filenames = " ".join(shell_quote(f) for f in images if "\x00" not in f)

                if images and self.thisfile.relative_path in images and \
                        "[email protected]" in command:
                    new_command = None

                    if command[0:5] == 'sxiv ':
                        number = images.index(self.thisfile.relative_path) + 1
                        new_command = command.replace("sxiv ", "sxiv -n %d " % number, 1)

                    if command[0:4] == 'feh ':
                        new_command = command.replace(
                            "feh ",
                            "feh --start-at %s " % shell_quote(self.thisfile.relative_path),
                            1,
                        )

                    if command[0:4] == 'imv ':
                        number = images.index(self.thisfile.relative_path) + 1
                        new_command = command.replace("imv ", "imv -n %d " % number, 1)

                    if command[0:5] == 'pqiv ':
                        number = images.index(self.thisfile.relative_path)
                        new_command = command.replace(
                            "pqiv ", "pqiv --action \"goto_file_byindex(%d)\" " % number, 1)

                    if new_command:
                        command = "set -- %s; %s" % (escaped_filenames, new_command)
            return old_preprocessing_hook(command)
#.........这里部分代码省略.........
开发者ID:nfnty,项目名称:ranger,代码行数:101,代码来源:fm.py

示例4: FM

class FM(Actions,  # pylint: disable=too-many-instance-attributes
         SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0
    mode = 'normal'  # either 'normal' or 'visual'.
    search_method = 'ctime'

    _previous_selection = None
    _visual_reverse = False
    _visual_pos_start = None
    _visual_move_cycles = None

    def __init__(self, ui=None, bookmarks=None, tags=None, paths=None):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        self.ui = ui if ui is not None else UI()
        self.start_paths = paths if paths is not None else ['.']
        self.directories = dict()
        self.bookmarks = bookmarks
        self.current_tab = 1
        self.tabs = {}
        self.tags = tags
        self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS)
        self.py3 = sys.version_info >= (3, )
        self.previews = {}
        self.default_linemodes = deque()
        self.loader = Loader()
        self.copy_buffer = set()
        self.do_cut = False
        self.metadata = MetadataManager()
        self.image_displayer = None
        self.run = None
        self.rifle = None
        self.thistab = None

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

        mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types'))
        mimetypes.knownfiles.append(self.relpath('data/mime.types'))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n + 1, Tab(path)) for n, path in enumerate(self.start_paths))
        tab_list = self.get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab('.')

        if not ranger.args.clean and os.path.isfile(self.confpath('rifle.conf')):
            rifleconf = self.confpath('rifle.conf')
        else:
            rifleconf = self.relpath('config/rifle.conf')
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        def set_image_displayer():
            self.image_displayer = self._get_image_displayer()
        set_image_displayer()
        self.settings.signal_bind('setopt.preview_images_method', set_image_displayer,
                                  priority=settings.SIGNAL_PRIORITY_AFTER_SYNC)

        self.settings.signal_bind(
            'setopt.preview_images',
            lambda signal: signal.fm.previews.clear(),
        )

        if ranger.args.clean:
            self.tags = TagsDummy("")
        elif self.tags is None:
            self.tags = Tags(self.datapath('tagged'))

        if self.bookmarks is None:
            if ranger.args.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.datapath('bookmarks')
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile,
                bookmarktype=Directory,
                autosave=self.settings.autosave_bookmarks)
            self.bookmarks.load()

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: \
            self.ui.suspend() if 'f' not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: \
            self.ui.initialize() if 'f' not in flags else None
#.........这里部分代码省略.........
开发者ID:nfnty,项目名称:ranger,代码行数:101,代码来源:fm.py

示例5: FM

class FM(Actions, SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0
    mode = "normal"  # either 'normal' or 'visual'.
    search_method = "ctime"

    _previous_selection = None
    _visual_reverse = False
    _visual_start = None
    _visual_start_pos = None

    def __init__(self, ui=None, bookmarks=None, tags=None, paths=["."]):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        if ui is None:
            self.ui = UI()
        else:
            self.ui = ui
        self.start_paths = paths
        self.directories = dict()
        self.log = deque(maxlen=20)
        self.bookmarks = bookmarks
        self.current_tab = 1
        self.tabs = {}
        self.tags = tags
        self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS)
        self.py3 = sys.version_info >= (3,)
        self.previews = {}
        self.loader = Loader()
        self.copy_buffer = set()
        self.do_cut = 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.log.append("ranger {0} started! Process ID is {1}.".format(__version__, os.getpid()))
        self.log.append("Running on Python " + sys.version.replace("\n", ""))

        mimetypes.knownfiles.append(os.path.expanduser("~/.mime.types"))
        mimetypes.knownfiles.append(self.relpath("data/mime.types"))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n + 1, Tab(path)) for n, path in enumerate(self.start_paths))
        tab_list = self._get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab(".")

        if not ranger.arg.clean and os.path.isfile(self.confpath("rifle.conf")):
            rifleconf = self.confpath("rifle.conf")
        else:
            rifleconf = self.relpath("config/rifle.conf")
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath("bookmarks")
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile, bookmarktype=Directory, autosave=self.settings.autosave_bookmarks
            )
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath("tagged"))

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: self.ui.suspend() if "f" not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: self.ui.initialize() if "f" not in flags else None
        self.rifle.hook_logger = self.notify

        def mylogfunc(text):
            self.notify(text, bad=True)

        self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)

    def destroy(self):
        debug = ranger.arg.debug
        if self.ui:
            try:
                self.ui.destroy()
            except:
                if debug:
                    raise
        if self.loader:
#.........这里部分代码省略.........
开发者ID:radhermit,项目名称:ranger,代码行数:101,代码来源:fm.py

示例6: main

def main():
    """initialize objects and run the filemanager"""
    import locale
    import ranger.api
    from ranger.container.settings import Settings
    from ranger.core.shared import FileManagerAware, SettingsAware
    from ranger.core.fm import FM

    if not sys.stdin.isatty():
        sys.stderr.write("Error: Must run ranger from terminal\n")
        raise SystemExit(1)

    try:
        locale.setlocale(locale.LC_ALL, '')
    except:
        print("Warning: Unable to set locale.  Expect encoding problems.")

    # so that programs can know that ranger spawned them:
    level = 'RANGER_LEVEL'
    if level in os.environ and os.environ[level].isdigit():
        os.environ[level] = str(int(os.environ[level]) + 1)
    else:
        os.environ[level] = '1'

    if not 'SHELL' in os.environ:
        os.environ['SHELL'] = 'sh'

    ranger.arg = arg = parse_arguments()
    if arg.copy_config is not None:
        fm = FM()
        fm.copy_config_files(arg.copy_config)
        return 1 if arg.fail_unless_cd else 0 # COMPAT
    if arg.list_tagged_files:
        fm = FM()
        try:
            f = open(fm.confpath('tagged'), 'r')
        except:
            pass
        else:
            for line in f.readlines():
                if len(line) > 2 and line[1] == ':':
                    if line[0] in arg.list_tagged_files:
                        sys.stdout.write(line[2:])
                elif len(line) > 0 and '*' in arg.list_tagged_files:
                    sys.stdout.write(line)
        return 1 if arg.fail_unless_cd else 0 # COMPAT

    SettingsAware._setup(Settings())

    if arg.selectfile:
        arg.selectfile = os.path.abspath(arg.selectfile)
        arg.targets.insert(0, os.path.dirname(arg.selectfile))

    targets = arg.targets or ['.']
    target = targets[0]
    if arg.targets:  # COMPAT
        if target.startswith('file://'):
            target = target[7:]
        if not os.access(target, os.F_OK):
            print("File or directory doesn't exist: %s" % target)
            return 1
        elif os.path.isfile(target):
            sys.stderr.write("Warning: Using ranger as a file launcher is "
                   "deprecated.\nPlease use the standalone file launcher "
                   "'rifle' instead.\n")
            def print_function(string):
                print(string)
            from ranger.ext.rifle import Rifle
            fm = FM()
            if not arg.clean and os.path.isfile(fm.confpath('rifle.conf')):
                rifleconf = fm.confpath('rifle.conf')
            else:
                rifleconf = fm.relpath('config/rifle.conf')
            rifle = Rifle(rifleconf)
            rifle.reload_config()
            rifle.execute(targets, number=ranger.arg.mode, flags=ranger.arg.flags)
            return 1 if arg.fail_unless_cd else 0 # COMPAT

    crash_traceback = None
    try:
        # Initialize objects
        fm = FM(paths=targets)
        FileManagerAware._setup(fm)
        load_settings(fm, arg.clean)

        if arg.list_unused_keys:
            from ranger.ext.keybinding_parser import (special_keys,
                    reversed_special_keys)
            maps = fm.ui.keymaps['browser']
            for key in sorted(special_keys.values(), key=lambda x: str(x)):
                if key not in maps:
                    print("<%s>" % reversed_special_keys[key])
            for key in range(33, 127):
                if key not in maps:
                    print(chr(key))
            return 1 if arg.fail_unless_cd else 0 # COMPAT

        if fm.username == 'root':
            fm.settings.preview_files = False
            fm.settings.use_preview_script = False
#.........这里部分代码省略.........
开发者ID:manolomartinez,项目名称:ranger,代码行数:101,代码来源:main.py

示例7: initialize

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n+1, Tab(path)) for n, path in
                enumerate(self.start_paths))
        tab_list = self._get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab('.')

        if not ranger.arg.clean and os.path.isfile(self.confpath('rifle.conf')):
            rifleconf = self.confpath('rifle.conf')
        else:
            rifleconf = self.relpath('config/rifle.conf')
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath('bookmarks')
            self.bookmarks = Bookmarks(
                    bookmarkfile=bookmarkfile,
                    bookmarktype=Directory,
                    autosave=self.settings.autosave_bookmarks)
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath('tagged'))

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: \
            self.ui.suspend() if 'f' not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: \
            self.ui.initialize() if 'f' not in flags else None
        self.rifle.hook_logger = self.notify

        # This hook allows image viewers to open all images in the current
        # directory, keeping the order of files the same as in ranger.
        # The requirements to use it are:
        # 1. set open_all_images to true
        # 2. ensure no files are marked
        # 3. call rifle with a command that starts with "sxiv " or "feh "
        def sxiv_workaround_hook(command):
            import re
            from ranger.ext.shell_escape import shell_quote

            if self.settings.open_all_images and \
                    len(self.thisdir.marked_items) == 0 and \
                    re.match(r'^(feh|sxiv) ', command):

                images = [f.basename for f in self.thisdir.files if f.image]
                escaped_filenames = " ".join(shell_quote(f) \
                        for f in images if "\x00" not in f)

                if images and self.thisfile.basename in images and \
                        "[email protected]" in command:
                    new_command = None

                    if command[0:5] == 'sxiv ':
                        number = images.index(self.thisfile.basename) + 1
                        new_command = command.replace("sxiv ",
                                "sxiv -n %d " % number, 1)

                    if command[0:4] == 'feh ':
                        new_command = command.replace("feh ",
                            "feh --start-at %s " % \
                            shell_quote(self.thisfile.basename), 1)

                    if new_command:
                        command = "set -- %s; %s" % (escaped_filenames,
                                new_command)
            return command

        self.rifle.hook_command_preprocessing = sxiv_workaround_hook

        def mylogfunc(text):
            self.notify(text, bad=True)
        self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)
开发者ID:trishume,项目名称:MacRanger,代码行数:85,代码来源:fm.py

示例8: FM

class FM(Actions, SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0
    mode = 'normal'  # either 'normal' or 'visual'.
    search_method = 'ctime'

    _previous_selection = None
    _visual_reverse = False
    _visual_start = None
    _visual_start_pos = None

    def __init__(self, ui=None, bookmarks=None, tags=None, paths=['.']):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        if ui is None:
            self.ui = UI()
        else:
            self.ui = ui
        self.start_paths = paths
        self.directories = dict()
        self.log = deque(maxlen=20)
        self.image_displayer = ImageDisplayer(self)
        self.bookmarks = bookmarks
        self.current_tab = 1
        self.tabs = {}
        self.tags = tags
        self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS)
        self.py3 = sys.version_info >= (3, )
        self.previews = {}
        self.loader = Loader()
        self.copy_buffer = set()
        self.do_cut = False
        self.control_server = RangerControlServer(self)

        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.log.append('ranger {0} started! Process ID is {1}.' \
                .format(__version__, os.getpid()))
        self.log.append('Running on Python ' + sys.version.replace('\n',''))

        mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types'))
        mimetypes.knownfiles.append(self.relpath('data/mime.types'))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n+1, Tab(path)) for n, path in
                enumerate(self.start_paths))
        tab_list = self._get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab('.')

        if not ranger.arg.clean and os.path.isfile(self.confpath('rifle.conf')):
            rifleconf = self.confpath('rifle.conf')
        else:
            rifleconf = self.relpath('config/rifle.conf')
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath('bookmarks')
            self.bookmarks = Bookmarks(
                    bookmarkfile=bookmarkfile,
                    bookmarktype=Directory,
                    autosave=self.settings.autosave_bookmarks)
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath('tagged'))

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: \
            self.ui.suspend() if 'f' not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: \
            self.ui.initialize() if 'f' not in flags else None
        self.rifle.hook_logger = self.notify

        # This hook allows image viewers to open all images in the current
        # directory, keeping the order of files the same as in ranger.
        # The requirements to use it are:
        # 1. set open_all_images to true
        # 2. ensure no files are marked
        # 3. call rifle with a command that starts with "sxiv " or "feh "
        def sxiv_workaround_hook(command):
#.........这里部分代码省略.........
开发者ID:trishume,项目名称:MacRanger,代码行数:101,代码来源:fm.py

示例9: FM

class FM(Actions, SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0

    def __init__(self, ui=None, bookmarks=None, tags=None):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        self.ui = ui
        self.log = deque(maxlen=20)
        self.bookmarks = bookmarks
        self.tags = tags
        self.tabs = {}
        self.py3 = sys.version_info >= (3,)
        self.previews = {}
        self.current_tab = 1
        self.loader = Loader()

        self.log.append("ranger {0} started! Process ID is {1}.".format(__version__, os.getpid()))
        self.log.append("Running on Python " + sys.version.replace("\n", ""))

        mimetypes.knownfiles.append(os.path.expanduser("~/.mime.types"))
        mimetypes.knownfiles.append(self.relpath("data/mime.types"))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        if not ranger.arg.clean and os.path.isfile(self.confpath("rifle.conf")):
            rifleconf = self.confpath("rifle.conf")
        else:
            rifleconf = self.relpath("defaults/rifle.conf")
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        if self.bookmarks is None:
            if ranger.arg.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath("bookmarks")
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile, bookmarktype=Directory, autosave=self.settings.autosave_bookmarks
            )
            self.bookmarks.load()

        if not ranger.arg.clean and self.tags is None:
            self.tags = Tags(self.confpath("tagged"))

        if self.ui is None:
            self.ui = UI()
            self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: self.ui.suspend() if "f" not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: self.ui.initialize() if "f" not in flags else None
        self.rifle.hook_logger = self.notify

        def mylogfunc(text):
            self.notify(text, bad=True)

        self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)

        self.env.signal_bind("cd", self._update_current_tab)

        if self.settings.init_function:
            self.settings.init_function(self)

    def destroy(self):
        debug = ranger.arg.debug
        if self.ui:
            try:
                self.ui.destroy()
            except:
                if debug:
                    raise
        if self.loader:
            try:
                self.loader.destroy()
            except:
                if debug:
                    raise

    def block_input(self, sec=0):
        self.input_blocked = sec != 0
        self.input_blocked_until = time() + sec

    def input_is_blocked(self):
        if self.input_blocked and time() > self.input_blocked_until:
            self.input_blocked = False
        return self.input_blocked

    def copy_config_files(self, which):
        if ranger.arg.clean:
            sys.stderr.write("refusing to copy config files in clean mode\n")
            return
        import shutil

        def copy(_from, to):
            if os.path.exists(self.confpath(to)):
                sys.stderr.write("already exists: %s\n" % self.confpath(to))
            else:
#.........这里部分代码省略.........
开发者ID:aspidites,项目名称:ranger,代码行数:101,代码来源:fm.py


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