예제 #1
0
파일: commandline.py 프로젝트: karlch/vimiv
    def run_path(self, path):
        """Run a path command, namely populate files or focus directory.

        Args:
            path: The path to run on.
        """
        # Expand home and use absolute path
        path = os.path.abspath(os.path.expanduser(path))
        if os.path.exists(path):
            if os.path.isdir(path):
                # Focus directory in the library
                self.app["library"].move_up(path)
                self.app["window"].last_focused = "lib"
            else:
                # If it is an image open it
                self.app.paths = []
                self.app.paths, self.app.index = populate([path])
                self.app["image"].load_image()
                #  Reload library in lib mode, do not open it in image mode
                pathdir = os.path.dirname(path)
                if self.app["window"].last_focused == "lib":
                    self.app["library"].move_up(pathdir)
                    # Focus it in the treeview so it can be accessed via "l"
                    for i, fil in enumerate(self.app["library"].files):
                        if fil in path:
                            self.app["library"].treeview.set_cursor(Gtk.TreePath(i), None, False)
                            break
                    # Show the image
                    self.app["library"].scrollable_treeview.set_hexpand(False)
                    self.app["image"].scrolled_win.show()
                else:
                    self.app["library"].move_up(pathdir, True)
        else:
            self.app["statusbar"].err_message("Warning: Not a valid path")
예제 #2
0
파일: tags.py 프로젝트: karlch/vimiv
    def load(self, tagname):
        """Load all images in a tag as current filelist.

        Args:
            tagname: Name of tag to operate on.
        """
        os.chdir(self.directory)
        # Read file and get all tagged images as list
        tagged_images = self.read(tagname)
        # Populate filelist
        self.app.paths = []
        self.app.paths = populate(tagged_images)[0]
        if self.app.paths:
            self.app["image"].scrolled_win.show()
            self.app["library"].scrollable_treeview.set_hexpand(False)
            self.app["image"].load_image()
            # Focus in library if it is open
            if self.app["library"].grid.is_visible():
                self.app["library"].reload(self.directory)
                tag_pos = self.app["library"].files.index(tagname)
                self.app["library"].treeview.set_cursor(Gtk.TreePath(tag_pos),
                                                        None, False)
            # Remember last tag selected
            self.last = tagname
        else:
            message = "Tagfile '%s' has no valid images" % (tagname)
            self.app["statusbar"].err_message(message)
            self.last = ""
예제 #3
0
파일: mark_test.py 프로젝트: aszlig/vimiv
 def setUpClass(cls):
     cls.working_directory = os.getcwd()
     os.chdir("vimiv")
     cls.settings = parse_config()
     paths, index = populate(["testimages"], False, False)
     cls.vimiv = v_main.Vimiv(cls.settings, paths, index)
     cls.vimiv.main()
     # Move away from directory
     cls.vimiv.library.scroll("j")
예제 #4
0
파일: commandline.py 프로젝트: karlch/vimiv
    def pipe(self, pipe_input):
        """Run output of external command in a pipe.

        This checks for directories, files and vimiv commands.

        Args:
            pipe_input: Command that comes from pipe.
        """
        # Leave if no pipe_input came
        if not pipe_input:
            self.app["statusbar"].err_message("No input from pipe")
            return
        # Make the pipe_input a file
        pipe_input = pipe_input.decode("utf-8")
        # List of commands without empty line
        pipe_input = pipe_input.split("\n")[:-1]
        startout = pipe_input[0]
        # Do different stuff depending on the first line of pipe_input
        if os.path.isdir(startout):
            self.app["library"].move_up(startout)
        elif os.path.isfile(startout):
            # Remember old file if no image was in filelist
            if self.app.paths:
                old_pos = [self.app.paths[self.app.index]]
                self.app.paths = []
            else:
                old_pos = []
            # Populate filelist
            self.app.paths, self.app.index = populate(pipe_input)
            if self.app.paths:  # Images were found
                self.app["image"].scrolled_win.show()
                self.app["image"].load_image()
                # Close library if necessary
                if self.app["library"].grid.is_visible():
                    self.app["library"].toggle()
            elif old_pos:  # Nothing found, go back
                self.app.paths, self.app.index = populate(old_pos)
                self.app["statusbar"].err_message("No image found")
        else:  # Run every line as an internal command
            for cmd in pipe_input:
                self.run_command(cmd)
예제 #5
0
파일: thumbnail.py 프로젝트: karlch/vimiv
    def toggle(self, select_image=False):
        """Toggle thumbnail mode.

        Args:
            select_image: If True an image was selected. Never focus the library
                then.
        """
        # Close
        if self.toggled:
            self.app["image"].scrolled_win.remove(self.iconview)
            self.app["image"].scrolled_win.add(self.app["image"].viewport)
            if self.app["window"].last_focused == "im" or select_image:
                self.app["image"].scrolled_win.grab_focus()
            elif self.app["window"].last_focused == "lib":
                self.app["library"].focus()
                # Re-expand the library if there is no image and the setting
                # applies
                if self.app["library"].expand:
                    try:
                        self.app["image"].pixbuf_original.get_height()
                    except:
                        self.app["image"].scrolled_win.hide()
                        self.app["library"].scrollable_treeview.set_hexpand(
                            True)
            self.toggled = False
        # Open thumbnail mode differently depending on where we come from
        elif self.app.paths and self.app["image"].scrolled_win.is_focus():
            self.app["window"].last_focused = "im"
            self.show()
        elif self.app["library"].files \
                and self.app["library"].treeview.is_focus():
            self.app["window"].last_focused = "lib"
            self.app.paths, self.app.index = \
                populate(self.app["library"].files)
            self.app["library"].scrollable_treeview.set_hexpand(False)
            if self.app.paths:
                self.app["image"].scrolled_win.show()
            self.show()
        else:
            self.app["statusbar"].err_message("No open image")
            return
        # Manipulate bar is useless in thumbnail mode
        if self.app["manipulate"].scrolled_win.is_visible():
            self.app["manipulate"].toggle()
        # Update info for the current mode
        self.app["statusbar"].update_info()
예제 #6
0
파일: library.py 프로젝트: karlch/vimiv
    def file_select(self, treeview, path, column, close):
        """Show image or open directory for activated file in library.

        Args:
            treeview: The Gtk.TreeView which emitted the signal.
            path: Gtk.TreePath that was activated.
            column: Column that was activated.
            close: If True close the library when finished.
        """
        count = path.get_indices()[0]
        fil = self.files[count]
        self.remember_pos(os.getcwd(), count)
        # Tags
        if os.getcwd() == self.app["tags"].directory:
            # Close if selected twice
            if fil == self.app["tags"].last:
                self.toggle()
            self.app["tags"].load(fil)
            return
        # Rest
        if os.path.isdir(fil):  # Open the directory
            self.move_up(fil)
        else:  # Focus the image and populate a new list from the dir
            # If thumbnail toggled, go out
            if self.app["thumbnail"].toggled:
                self.app["thumbnail"].toggle()
                self.treeview.grab_focus()
            if self.app.paths and fil in self.app.paths[self.app.index]:
                close = True  # Close if file selected twice
            index = 0  # Catch directories to focus correctly
            for f in self.files:
                if f == fil:
                    break
                elif os.path.isfile(f):
                    index += 1
            self.app.paths, self.app.index = populate(self.files)
            if self.app.paths:
                self.scrollable_treeview.set_hexpand(False)
                self.app["image"].scrolled_win.show()
                # Close the library depending on key and repeat
                if close:
                    # We do not need to update the image as it is done later
                    # anyway
                    self.toggle(update_image=False)
                self.app["image"].move_index(delta=index)
예제 #7
0
파일: app.py 프로젝트: karlch/vimiv
    def activate_vimiv(self, app):
        """Starting point for the vimiv application.

        Args:
            app: The application itself.
        """
        parse_dirs(self.directory)
        self.init_widgets()
        self.create_window_structure()
        app.add_window(self["window"])
        # Show everything and then hide whatever needs to be hidden
        self["window"].show_all()
        self["manipulate"].scrolled_win.hide()
        self["commandline"].entry.hide()
        self["completions"].hide()
        # Statusbar depending on setting
        if self["statusbar"].hidden:
            self["statusbar"].bar.hide()
        self["statusbar"].set_separator_height()
        # Try to generate imagelist recursively from the current directory if
        # recursive is given and not paths exist
        if self.settings["GENERAL"]["recursive"] and not self.paths:
            shuffle = self.settings["GENERAL"]["shuffle"]
            self.paths, self.index = populate([os.getcwd()], True, shuffle)
        # Show the image if an imagelist exists
        if self.paths:
            self["image"].load_image()
            # Show library at the beginning?
            if not self["library"].show_at_start:
                self["library"].grid.hide()
            self["image"].scrolled_win.grab_focus()
            # Start in slideshow mode?
            if self["slideshow"].at_start:
                self["slideshow"].toggle()
        else:
            # Slideshow without paths makes no sense
            self["slideshow"].running = False
            self["library"].reload(os.getcwd())
            if self["library"].expand:
                self["image"].scrolled_win.hide()
            self["statusbar"].err_message("No valid paths, opening library viewer")
예제 #8
0
파일: app.py 프로젝트: karlch/vimiv
    def do_open(self, files, n_files, hint):
        """Open files by populating self.paths and self.index.

        Args:
            files: List of Gio.Files.
            n_files: Number of files.
            hint: Special string for user, always empty in vimiv.
        """
        filenames = [fil.get_path() for fil in files]
        # Move to the directory of the first argument
        if os.path.isdir(filenames[0]):
            working_directory = filenames[0]
        else:
            working_directory = os.path.dirname(filenames[0])
        if os.path.exists(working_directory):
            os.chdir(working_directory)
        # Populate list of images
        recursive = self.settings["GENERAL"]["recursive"]
        shuffle = self.settings["GENERAL"]["shuffle"]
        self.paths, self.index = populate(filenames, recursive, shuffle)

        # Activate vimiv after opening files
        self.activate_vimiv(self)
예제 #9
0
파일: app.py 프로젝트: karlch/vimiv
    def do_handle_local_options(self, options):
        """Handle commandline arguments.

        Args:
            options: The dictionary containing all options given to the
                commandline.
        Return:
            Exitcode or -1 to continue
        """

        def set_option(name, section, setting, value=0):
            """Set a setting in self.settings according to commandline option.

            Args:
                name: Name of the commandline option
                section: Name of section in self.settings to modify.
                setting: Name of setting in self.settings to modify.
                value: One of 0, 1 or 2.
                    0: Set setting to False.
                    1: Set setting to True.
                    2: Set setting to value given in the commandline.
            """
            if options.contains(name):
                valuedict = {0: False, 1: True}
                if value == 2:
                    valuedict[2] = options.lookup_value(name).unpack()
                self.settings[section][setting] = valuedict[value]

        # If the version option is given, print version and exit 0
        if options.contains("version"):
            information = Information()
            print(information.get_version())
            return 0
        # Temp basedir removes all current settings and sets them to default
        if options.contains("temp-basedir"):
            self.settings = set_defaults()
            self.directory = mkdtemp()

        # If we start from desktop, move to the wanted directory
        # Else if the input does not come from a tty, e.g. find "" | vimiv, set
        # paths and index according to the input from the pipe
        if options.contains("start-from-desktop"):
            os.chdir(self.settings["LIBRARY"]["desktop_start_dir"])
        elif not sys.stdin.isatty():
            tty_paths = []
            for line in sys.stdin:
                tty_paths.append(line.rstrip("\n"))
            self.paths, self.index = populate(tty_paths)

        set_option("bar", "GENERAL", "display_bar", 1)
        set_option("no-bar", "GENERAL", "display_bar", 0)
        set_option("library", "LIBRARY", "show_library", 1)
        set_option("no-library", "LIBRARY", "show_library", 0)
        set_option("fullscreen", "GENERAL", "start_fullscreen", 1)
        set_option("no-fullscreen", "GENERAL", "start_fullscreen", 0)
        set_option("shuffle", "GENERAL", "shuffle", 1)
        set_option("no-shuffle", "GENERAL", "shuffle", 0)
        set_option("recursive", "GENERAL", "recursive", 1)
        set_option("no-recursive", "GENERAL", "recursive", 0)
        set_option("slideshow", "GENERAL", "start_slideshow", 1)
        set_option("slideshow-delay", "GENERAL", "slideshow_delay", 2)
        set_option("geometry", "GENERAL", "geometry", 2)
        return -1  # To continue