示例#1
0
 def test_read_file(self):
     """Check if a file is read correctly into a list of its lines."""
     helpers.read_file("tmp_testdir/bar")
     self.assertTrue(os.path.exists("tmp_testdir/bar"))
     with open("tmp_testdir/baz", "w") as created_file:
         created_file.write("vimiv\nis\ngreat")
     created_file_content = helpers.read_file("tmp_testdir/baz")
     self.assertEqual(created_file_content, ["vimiv", "is", "great"])
示例#2
0
 def test_read_file(self):
     """Check if a file is read correctly into a list of its lines."""
     helpers.read_file("tmp_testdir/bar")
     self.assertTrue(os.path.exists("tmp_testdir/bar"))
     with open("tmp_testdir/baz", "w") as created_file:
         created_file.write("vimiv\nis\ngreat")
     created_file_content = helpers.read_file("tmp_testdir/baz")
     self.assertEqual(created_file_content, ["vimiv", "is", "great"])
示例#3
0
    def __init__(self, app, settings):
        """Create the necessary objects and settings.

        Args:
            app: The main vimiv application to interact with.
            settings: Settings from configfiles to use.
        """
        self.app = app
        general = settings["GENERAL"]

        # Command line
        self.entry = Gtk.Entry()
        self.entry.connect("activate", self.handler)
        self.entry.connect("key_press_event", self.app["keyhandler"].run, "COMMAND")
        self.entry.connect("changed", self.check_close)
        self.entry.set_hexpand(True)

        # Cmd history from file
        self.history = read_file(os.path.join(self.app.directory, "history"))

        # Defaults
        self.pos = 0
        self.sub_history = []
        self.search_positions = []
        self.search_case = general["search_case_sensitive"]
        self.incsearch = general["incsearch"]
        if self.incsearch:
            self.entry.connect("changed", self.incremental_search)
        self.last_filename = ""
        self.running_threads = []
示例#4
0
    def __init__(self, app, settings):
        """Create the necessary objects and settings.

        Args:
            app: The main vimiv application to interact with.
            settings: Settings from configfiles to use.
        """
        self.app = app
        general = settings["GENERAL"]

        # Command line
        self.entry = Gtk.Entry()
        self.entry.connect("activate", self.handler)
        self.entry.connect("key_press_event",
                           self.app["eventhandler"].run, "COMMAND")
        self.entry.connect("changed", self.check_close)
        self.entry.set_hexpand(True)

        # Cmd history from file
        self.history = read_file(os.path.join(self.app.directory, "history"))

        # Defaults
        self.pos = 0
        self.sub_history = []
        self.search_positions = []
        self.search_case = general["search_case_sensitive"]
        self.incsearch = general["incsearch"]
        if self.incsearch:
            self.entry.connect("changed", self.incremental_search)
        self.last_index = 0
        self.running_processes = []
        self.last_focused = ""
示例#5
0
文件: tags_test.py 项目: aszlig/vimiv
 def test_tag_create_remove(self):
     """Create and remove a tag."""
     taglist = ["./testimages/arch-logo.png", "./testimages/arch_001.jpg"]
     taglist = [os.path.abspath(image) for image in taglist]
     self.vimiv.tags.write(taglist, "arch_test_tag")
     created_file = os.path.expanduser("~/.vimiv/Tags/arch_test_tag")
     file_content = read_file(created_file)
     self.assertEqual(file_content, taglist)
     self.vimiv.tags.remove("arch_test_tag")
     self.assertFalse(os.path.isfile(created_file))
示例#6
0
文件: tags_test.py 项目: karlch/vimiv
 def test_tag_create_remove(self):
     """Create and remove a tag."""
     taglist = ["vimiv/testimages/arch-logo.png", "vimiv/testimages/arch_001.jpg"]
     taglist = [os.path.abspath(image) for image in taglist]
     self.vimiv["tags"].write(taglist, "arch_test_tag")
     created_file = os.path.expanduser("~/.vimiv/Tags/arch_test_tag")
     file_content = read_file(created_file)
     self.assertEqual(file_content, taglist)
     self.vimiv["tags"].remove("arch_test_tag")
     self.assertFalse(os.path.isfile(created_file))
示例#7
0
文件: tags.py 项目: aszlig/vimiv
    def read(self, tagname):
        """Read a tag and return the images in it.

        Args:
            tagname: Name of tag to operate on.

        Return: List of images in the tag called tagname.
        """
        tagfile_name = os.path.join(self.directory, tagname)
        tagged_images = read_file(tagfile_name)
        return tagged_images
示例#8
0
文件: tags_test.py 项目: aszlig/vimiv
 def test_tag_append(self):
     """Append to a tag."""
     taglist = [os.path.abspath("./testimages/arch-logo.png")]
     self.vimiv.tags.write(taglist, "arch_test_tag")
     taglist2 = [os.path.abspath("./testimages/arch_001.jpg")]
     self.vimiv.tags.write(taglist2, "arch_test_tag")
     complete_taglist = taglist + taglist2
     created_file = os.path.expanduser("~/.vimiv/Tags/arch_test_tag")
     file_content = read_file(created_file)
     self.assertEqual(file_content, complete_taglist)
     self.vimiv.tags.remove("arch_test_tag")
示例#9
0
文件: tags_test.py 项目: sahwar/vimiv
 def test_tag_create_remove_with_whitespace(self):
     """Create and remove a tag with whitespace in the name."""
     taglist = ["vimiv/testimages/arch-logo.png",
                "vimiv/testimages/arch_001.jpg"]
     taglist = [os.path.abspath(image) for image in taglist]
     self.vimiv["tags"].write(taglist, "arch test tag")
     created_file = os.path.join(self.tagdir, "arch test tag")
     file_content = read_file(created_file)
     self.assertEqual(file_content, taglist)
     self.vimiv["tags"].remove("arch test tag")
     self.assertFalse(os.path.isfile(created_file))
示例#10
0
文件: tags_test.py 项目: karlch/vimiv
 def test_tag_append(self):
     """Append to a tag."""
     taglist = [os.path.abspath("vimiv/testimages/arch-logo.png")]
     self.vimiv["tags"].write(taglist, "arch_test_tag")
     taglist2 = [os.path.abspath("vimiv/testimages/arch_001.jpg")]
     self.vimiv["tags"].write(taglist2, "arch_test_tag")
     complete_taglist = taglist + taglist2
     created_file = os.path.expanduser("~/.vimiv/Tags/arch_test_tag")
     file_content = read_file(created_file)
     self.assertEqual(file_content, complete_taglist)
     self.vimiv["tags"].remove("arch_test_tag")
示例#11
0
文件: tags.py 项目: karlch/vimiv
    def read(self, tagname):
        """Read a tag and return the images in it.

        Args:
            tagname: Name of tag to operate on.

        Return:
            List of images in the tag called tagname.
        """
        tagfile_name = os.path.join(self.directory, tagname)
        tagged_images = read_file(tagfile_name)
        return tagged_images
示例#12
0
    def __init__(self, app, settings):
        """Create the necessary objects and settings.

        Args:
            app: The main vimiv application to interact with.
            settings: Settings from configfiles to use.
        """
        super().__init__(app)
        general = settings["GENERAL"]

        # Command line
        self.entry = Gtk.Entry()
        self.entry.connect("activate", self.handler)
        self.entry.connect("key_press_event", self.app["eventhandler"].run,
                           "COMMAND")
        self.entry.connect("changed", self.check_close)
        self.entry.set_hexpand(True)

        # Cmd history from file
        datadir = os.path.join(GLib.get_user_data_dir(), "vimiv")
        os.makedirs(datadir, exist_ok=True)
        # If there is a history file in the old location move it and inform the
        # user
        # TODO remove this in a new version, assigned for 0.10
        old_histfile = os.path.expanduser("~/.vimiv/history")
        new_histfile = os.path.join(datadir, "history")
        if os.path.isfile(old_histfile):
            if os.path.isfile(new_histfile):
                message = "There is a history file in the deprecated location" \
                    " %s and the new location %s. Using the new one. If you " \
                    "want the history from the old file you will have to " \
                    "merge it manually." % (old_histfile, new_histfile)
                error_message(message, running_tests=self.app.running_tests)
            else:
                os.rename(old_histfile, new_histfile)
                message = "Moved the old history file %s " \
                    "to the new location %s." % (old_histfile, new_histfile)
                error_message(message, running_tests=self.app.running_tests)
        self.history = read_file(os.path.join(datadir, "history"))

        # Defaults
        self.pos = 0
        self.sub_history = []
        self.search_positions = []
        self.search_case = general["search_case_sensitive"]
        self.incsearch = general["incsearch"]
        if self.incsearch:
            self.entry.connect("changed", self.incremental_search)
        self.last_index = 0
        self.running_processes = []
        self.last_focused = ""
示例#13
0
    def __init__(self, app):
        """Create the necessary objects and settings.

        Args:
            app: The main vimiv application to interact with.
        """
        super(CommandLine, self).__init__()
        self._app = app
        self.commands = None

        # Command line
        self.connect("activate", self._on_activate)
        self.connect("key_press_event", self._app["eventhandler"].on_key_press,
                     "COMMAND")
        self.connect("changed", self._on_text_changed)
        self.set_hexpand(True)

        # Initialize search
        self.search = Search(self)

        # Cmd history from file
        datadir = os.path.join(get_user_data_dir(), "vimiv")
        os.makedirs(datadir, exist_ok=True)
        # If there is a history file in the old location move it and inform the
        # user
        # TODO remove this in a new version, assigned for 0.10
        old_histfile = os.path.expanduser("~/.vimiv/history")
        new_histfile = os.path.join(datadir, "history")
        if os.path.isfile(old_histfile):
            if os.path.isfile(new_histfile):
                message = "There is a history file in the deprecated location" \
                    " %s and the new location %s. Using the new one. If you " \
                    "want the history from the old file you will have to " \
                    "merge it manually." % (old_histfile, new_histfile)
                error_message(message, running_tests=self._app.running_tests)
            else:
                os.rename(old_histfile, new_histfile)
                message = "Moved the old history file %s " \
                    "to the new location %s." % (old_histfile, new_histfile)
                error_message(message, running_tests=self._app.running_tests)
        self._history = read_file(os.path.join(datadir, "history"))

        # Defaults
        self._matching_history = []
        self._last_index = 0
        self._pos = 0
        self.running_processes = []
        self._last_widget = ""
示例#14
0
文件: tags_test.py 项目: sahwar/vimiv
 def test_tag_commandline(self):
     """Tag commands from command line."""
     # Set some marked images
     taglist = ["vimiv/testimages/arch-logo.png",
                "vimiv/testimages/arch_001.jpg"]
     taglist = [os.path.abspath(image) for image in taglist]
     self.vimiv["mark"].marked = list(taglist)
     # Write a tag
     self.run_command("tag_write new_test_tag")
     created_file = os.path.join(self.tagdir, "new_test_tag")
     file_content = read_file(created_file)
     self.assertEqual(taglist, file_content)
     # Load a tag
     self.run_command("tag_load new_test_tag")
     self.assertEqual(self.vimiv.get_paths(), taglist)
     # Delete a tag
     self.run_command("tag_remove new_test_tag")
     self.assertFalse(os.path.isfile(created_file))
示例#15
0
    def __init__(self, vimiv, settings):
        """Create the necessary objects and settings.

        Args:
            vimiv: The main vimiv class to interact with.
            settings: Settings from configfiles to use.
        """
        self.vimiv = vimiv
        general = settings["GENERAL"]

        # Command line
        self.grid = Gtk.Grid()
        self.entry = Gtk.Entry()
        self.entry.connect("activate", self.handler)
        self.entry.connect("key_press_event",
                           self.vimiv.keyhandler.run, "COMMAND")
        self.entry.connect("changed", self.check_close)
        self.entry.connect("changed", self.reset_tab_count)
        self.entry.set_hexpand(True)
        self.info = Gtk.Label()
        self.info.set_hexpand(True)
        self.info.set_valign(Gtk.Align.CENTER)
        self.info.set_halign(Gtk.Align.START)
        self.grid.attach(self.info, 0, 0, 1, 1)
        self.grid.attach(self.entry, 0, 1, 1, 1)
        # Make it nice using CSS
        self.grid.set_name("CommandLine")
        style = self.vimiv.get_style_context()
        color = style.get_background_color(Gtk.StateType.NORMAL)
        color_str = "#CommandLine { background-color: " + color.to_string() \
            + "; }"
        command_provider = Gtk.CssProvider()
        command_css = color_str.encode()
        command_provider.load_from_data(command_css)
        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), command_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        # Alignment and spacing
        self.grid.set_valign(Gtk.Align.END)
        self.info.set_margin_top(6)
        self.info.set_margin_bottom(6)

        # Monospaced font
        self.info.set_name("CompletionInfo")
        completion_provider = Gtk.CssProvider()
        completion_css = "#CompletionInfo { font-family: monospace; }".encode()
        completion_provider.load_from_data(completion_css)
        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), completion_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # Cmd history from file
        self.history = read_file(os.path.expanduser("~/.vimiv/history"))

        # Defaults
        self.pos = 0
        self.sub_history = []
        self.search_positions = []
        self.search_case = general["search_case_sensitive"]
        self.incsearch = general["incsearch"]
        if self.incsearch:
            self.entry.connect("changed", self.incremental_search)
        self.last_filename = ""

        # List of threads
        self.running_threads = []