def __init__(self, window, pluginHelper, query):
        self._window = window
        self.pluginHelper = pluginHelper
        self.pluginHelper.registerSearcher(self)
        self.query = query
        self.files = {}
        self.numMatches = 0
        self.numLines = 0
        self.wasCancelled = False
        self.searchProcess = None
        self._collapseAll = False  # if true, new nodes will be displayed collapsed

        self._createResultPanel()
        self._updateSummary()

        searchSummary = "<span size=\"smaller\">" + \
            _("searching for <i>%(keywords)s</i> in <i>%(folder)s</i>") % \
                {
                    'keywords': escapeMarkup(query.text),
                    'folder': escapeMarkup(GLib.filename_display_name(query.directory))
                } + \
            "</span>"
        it = self.treeStore.append(None, None)
        self.treeStore.set(it, 0, searchSummary, 1, "", 2, 0)

        self.searchProcess = SearchProcess(query, self)
        self._updateSummary()
Beispiel #2
0
    def tags_win_update(self):
        current_tag = self.tags[self.tagnum]
        tag = tagpy.FileRef(current_tag['fullpath']).tag()
        # Update interface:
        for entry_name, entry in self.entries.items():
            # Only retrieve info from the file if the info hasn't changed
            if not current_tag[entry_name + "-changed"]:
                current_tag[entry_name] = getattr(tag, entry_name, '')
            tag_value = current_tag[entry_name]
            if tag_value == 0:
                tag_value = ''
            try:
                entry.set_text(str(tag_value).strip())
            except AttributeError:
                pass

            # Revert text color if this tag wasn't changed by the user
            if not current_tag[entry_name + "-changed"]:
                self.tags_win_entry_revert_color(entry)

        self.curr_mpdpath = GLib.filename_display_name(current_tag['mpdpath'])
        filename = self.curr_mpdpath
        if not self.use_mpdpaths:
            filename = os.path.basename(filename)
        self.file_label.set_text(filename)
        self.entries['title'].grab_focus()
        self.edit_window.set_title(
            _("Edit Tags - %s of %s") % (self.tagnum + 1, len(self.tags)))
Beispiel #3
0
    def tags_win_update(self):
        current_tag = self.tags[self.tagnum]
        tag = tagpy.FileRef(current_tag['fullpath']).tag()
        # Update interface:
        for entry_name, entry in self.entries.items():
            # Only retrieve info from the file if the info hasn't changed
            if not current_tag[entry_name + "-changed"]:
                current_tag[entry_name] = getattr(tag, entry_name, '')
            tag_value = current_tag[entry_name]
            if tag_value == 0:
                tag_value = ''
            try:
                entry.set_text(str(tag_value).strip())
            except AttributeError:
                pass

            # Revert text color if this tag wasn't changed by the user
            if not current_tag[entry_name + "-changed"]:
                self.tags_win_entry_revert_color(entry)

        self.curr_mpdpath = GLib.filename_display_name(current_tag['mpdpath'])
        filename = self.curr_mpdpath
        if not self.use_mpdpaths:
            filename = os.path.basename(filename)
        self.file_label.set_text(filename)
        self.entries['title'].grab_focus()
        self.edit_window.set_title(_("Edit Tags - %s of %s") %
            (self.tagnum + 1, len(self.tags)))
Beispiel #4
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        def glibfsencode(f):
            # the annotations of filename_from_utf8() was changed in
            # https://bugzilla.gnome.org/show_bug.cgi?id=756128
            if isinstance(f, bytes):
                return f
            if os.name == "nt":
                if PY3:
                    return f.encode("utf-8", "surrogatepass")
                else:
                    return f.encode("utf-8")
            else:
                assert PY3
                return os.fsencode(f)

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(u'aäb')
        res = glibfsencode(res)
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        res = GLib.filename_from_utf8(u'aäb', 1)
        res = glibfsencode(res)
        self.assertEqual(res, b'a')
Beispiel #5
0
def get_display_path_for_bytestring(filepath):
    """Return a unicode path for display for bytestring @filepath

    Will use glib's filename decoding functions, and will
    format nicely (denote home by ~/ etc)
    """
    desc = GLib.filename_display_name(filepath)
    homedir = os.path.expanduser("~/")
    if desc.startswith(homedir) and homedir != desc:
        desc = desc.replace(homedir, "~/", 1)
    return desc
Beispiel #6
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(_unicode('aäb'))
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        self.assertEqual(GLib.filename_from_utf8(_unicode('aäb'), 1), b'a')
Beispiel #7
0
def get_display_path_for_bytestring(filepath):
    """Return a unicode path for display for bytestring @filepath

    Will use glib's filename decoding functions, and will
    format nicely (denote home by ~/ etc)
    """
    desc = GLib.filename_display_name(filepath)
    homedir = os.path.expanduser("~/")
    if desc.startswith(homedir) and homedir != desc:
        desc = desc.replace(homedir, "~/", 1)
    return desc
Beispiel #8
0
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(_unicode('aäb'))
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        self.assertEqual(GLib.filename_from_utf8(_unicode('aäb'), 1), b'a')
Beispiel #9
0
    def get_basename_display(self):
        """
            Return the track basename for display purposes (invalid characters
            are replaced).

            :rtype: unicode
        """
        gfile = Gio.File.new_for_uri(self.get_loc_for_io())
        path = gfile.get_path()
        if path:  # Local
            path = GLib.filename_display_basename(path)
        else:  # Non-local
            path = GLib.filename_display_name(gfile.get_basename())
        return path.decode('utf-8')
Beispiel #10
0
    def get_basename_display(self):
        """
            Return the track basename for display purposes (invalid characters
            are replaced).

            :rtype: unicode
        """
        gfile = Gio.File.new_for_uri(self.get_loc_for_io())
        path = gfile.get_path()
        if path:  # Local
            path = GLib.filename_display_basename(path)
        else:  # Non-local
            path = GLib.filename_display_name(gfile.get_basename())
        return path.decode('utf-8')
Beispiel #11
0
 def set_filename(self, f):
     try:
         disp = GLib.filename_display_name(f)
         pb = GdkPixbuf.Pixbuf.new_from_file_at_size(f, 16, 16)
     except (GLib.GError, TypeError):
         # TC: Text reads as /path/to/file.ext or this when no file is chosen.
         self._label.set_text(_("(None)"))
         self._image.clear()
         self._filename = None
     else:
         self._label.set_text(disp)
         self._image.set_from_pixbuf(pb)
         self._filename = f
         self._dialog.set_filename(f)
     self.emit("filename-changed", self._filename)
    def test_filenames(self):
        self.assertEqual(GLib.filename_display_name('foo'), 'foo')
        self.assertEqual(GLib.filename_display_basename('bar/foo'), 'foo')

        def glibfsencode(f):
            # the annotations of filename_from_utf8() was changed in
            # https://bugzilla.gnome.org/show_bug.cgi?id=756128
            if isinstance(f, bytes):
                return f
            if os.name == "nt":
                return f.encode("utf-8", "surrogatepass")
            else:
                return os.fsencode(f)

        # this is locale dependent, so we cannot completely verify the result
        res = GLib.filename_from_utf8(u'aäb')
        res = glibfsencode(res)
        self.assertTrue(isinstance(res, bytes))
        self.assertGreaterEqual(len(res), 3)

        # with explicit length argument
        res = GLib.filename_from_utf8(u'aäb', 1)
        res = glibfsencode(res)
        self.assertEqual(res, b'a')
Beispiel #13
0
 def get_text_representation(self):
     return GLib.filename_display_name(self.object)
Beispiel #14
0
 def get_text_representation(self):
     return GLib.filename_display_name(self.object)