• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python path.get_home_dir函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_initial

    def test_initial(self):
        paths = ["/", get_home_dir(), "/usr/bin"]
        if os.name == "nt":
            paths = [u"C:\\", get_home_dir()]

        for path in paths:
            dirlist = DirectoryTree(path, folders=self.ROOTS)
            model, rows = dirlist.get_selection().get_selected_rows()
            selected = [model[row][0] for row in rows]
            dirlist.destroy()
            self.failUnlessEqual([path], selected)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:11,代码来源:test_qltk_filesel.py


示例2: __get_themes

    def __get_themes(self):
        # deprecated, but there is no public replacement
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            theme_dir = Gtk.rc_get_theme_dir()

        theme_dirs = [theme_dir, os.path.join(get_home_dir(), ".themes")]

        themes = set()
        for theme_dir in theme_dirs:
            try:
                subdirs = os.listdir(theme_dir)
            except OSError:
                continue
            for dir_ in subdirs:
                gtk_dir = os.path.join(theme_dir, dir_, "gtk-3.0")
                if os.path.isdir(gtk_dir):
                    themes.add(dir_)

        try:
            resource_themes = Gio.resources_enumerate_children(
                "/org/gtk/libgtk/theme", 0)
        except GLib.GError:
            pass
        else:
            themes.update([t.rstrip("/") for t in resource_themes])

        return themes
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:28,代码来源:themeswitcher.py


示例3: get_init_select_dir

def get_init_select_dir():
    scandirs = get_scan_dirs()
    if scandirs and os.path.isdir(scandirs[-1]):
        # start with last added directory
        return scandirs[-1]
    else:
        return get_home_dir()
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:7,代码来源:scanbox.py


示例4: open_chooser

    def open_chooser(self, action):
        last_dir = self.last_dir
        if not os.path.exists(last_dir):
            last_dir = get_home_dir()

        class MusicFolderChooser(FolderChooser):
            def __init__(self, parent, init_dir):
                super(MusicFolderChooser, self).__init__(
                    parent, _("Add Music"), init_dir)

                cb = Gtk.CheckButton(_("Watch this folder for new songs"))
                # enable if no folders are being watched
                cb.set_active(not get_scan_dirs())
                cb.show()
                self.set_extra_widget(cb)

            def run(self):
                fns = super(MusicFolderChooser, self).run()
                cb = self.get_extra_widget()
                return fns, cb.get_active()

        class MusicFileChooser(FileChooser):
            def __init__(self, parent, init_dir):
                super(MusicFileChooser, self).__init__(
                    parent, _("Add Music"), formats.filter, init_dir)

        if action.get_name() == "AddFolders":
            dialog = MusicFolderChooser(self, last_dir)
            fns, do_watch = dialog.run()
            dialog.destroy()
            if fns:
                fns = map(glib2fsnative, fns)
                # scan them
                self.last_dir = fns[0]
                copool.add(self.__library.scan, fns, cofuncid="library",
                           funcid="library")

                # add them as library scan directory
                if do_watch:
                    dirs = get_scan_dirs()
                    for fn in fns:
                        if fn not in dirs:
                            dirs.append(fn)
                    set_scan_dirs(dirs)
        else:
            dialog = MusicFileChooser(self, last_dir)
            fns = dialog.run()
            dialog.destroy()
            if fns:
                fns = map(glib2fsnative, fns)
                self.last_dir = os.path.dirname(fns[0])
                for filename in map(os.path.realpath, fns):
                    self.__library.add_filename(filename)
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:53,代码来源:quodlibetwindow.py


示例5: get_init_select_dir

def get_init_select_dir():
    """Returns a path which might be a good starting point when browsing
    for a path for library scanning.

    Returns:
        fsnative
    """

    scandirs = get_scan_dirs()
    if scandirs and os.path.isdir(scandirs[-1]):
        # start with last added directory
        return scandirs[-1]
    else:
        return get_home_dir()
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:14,代码来源:scanbox.py


示例6: __get_themes

    def __get_themes(self):
        # deprecated, but there is no public replacement
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            theme_dir = Gtk.rc_get_theme_dir()

        theme_dirs = [theme_dir, os.path.join(get_home_dir(), ".themes")]

        themes = set()
        for theme_dir in theme_dirs:
            try:
                subdirs = os.listdir(theme_dir)
            except OSError:
                continue
            for dir_ in subdirs:
                gtk_dir = os.path.join(theme_dir, dir_, "gtk-3.0")
                if os.path.isdir(gtk_dir):
                    themes.add(dir_)
        return themes
开发者ID:MikeiLL,项目名称:quodlibet,代码行数:19,代码来源:themeswitcher.py


示例7: get_favorites

def get_favorites():
    """A list of paths of commonly used folders (Desktop,..)

    Paths don't have to exist.
    """

    if os.name == "nt":
        return _get_win_favorites()
    else:
        paths = [get_home_dir()]

        xfg_user_dirs = xdg_get_user_dirs()
        for key in ["XDG_DESKTOP_DIR", "XDG_DOWNLOAD_DIR", "XDG_MUSIC_DIR"]:
            if key in xfg_user_dirs:
                path = xfg_user_dirs[key]
                if path not in paths:
                    paths.append(path)

        return paths
开发者ID:qwence,项目名称:quodlibet,代码行数:19,代码来源:filesel.py


示例8: __import

 def __import(self, activator, library):
     filt = lambda fn: fn.endswith(".pls") or fn.endswith(".m3u")
     from quodlibet.qltk.chooser import FileChooser
     chooser = FileChooser(self, _("Import Playlist"), filt, get_home_dir())
     files = chooser.run()
     chooser.destroy()
     for filename in files:
         if filename.endswith(".m3u"):
             playlist = parse_m3u(filename, library=library)
         elif filename.endswith(".pls"):
             playlist = parse_pls(filename, library=library)
         else:
             qltk.ErrorMessage(
                 qltk.get_top_parent(self),
                 _("Unable to import playlist"),
                 _("Quod Libet can only import playlists in the M3U "
                   "and PLS formats.")).run()
             return
         PlaylistsBrowser.changed(playlist)
         library.add(playlist)
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:20,代码来源:main.py


示例9: get_gtk_bookmarks

def get_gtk_bookmarks():
    """A list of paths from the GTK+ bookmarks.
    The paths don't have to exist.

    Returns:
        List[fsnative]
    """

    if os.name == "nt":
        return []

    path = os.path.join(get_home_dir(), ".gtk-bookmarks")
    folders = []
    try:
        with open(path, "rb") as f:
            folders = parse_gtk_bookmarks(f.read())
    except (EnvironmentError, ValueError):
        pass

    return folders
开发者ID:elfalem,项目名称:quodlibet,代码行数:20,代码来源:filesel.py


示例10: test_lyric_filename_search_order_priority

 def test_lyric_filename_search_order_priority(self):
     """test custom lyrics order priority"""
     with self.lyric_filename_test_setup() as ts:
         root2 = os.path.join(get_home_dir(), ".lyrics") # built-in default
         fp2 = os.path.join(root2, ts["artist"] + " - " +
                                   ts["title"] + ".lyric")
         p2 = os.path.dirname(fp2)
         mkdir(p2)
         with io.open(fp2, "w", encoding='utf-8') as f:
             f.write(u"")
         fp = os.path.join(ts.root, ts["artist"] + " - " +
                                    ts["title"] + ".lyric")
         with io.open(fp, "w", encoding='utf-8') as f:
             f.write(u"")
         mkdir(p2)
         search = ts.lyric_filename
         os.remove(fp2)
         os.rmdir(p2)
         os.remove(fp)
         self.assertEqual(search, fp)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:20,代码来源:test_formats__audio.py


示例11: get_gtk_bookmarks

def get_gtk_bookmarks():
    """A list of paths from the GTK+ bookmarks.

    The paths don't have to exist.
    """

    if os.name == "nt":
        return []

    path = os.path.join(get_home_dir(), ".gtk-bookmarks")
    folders = []
    try:
        with open(path, "rb") as f:
            for line in f.readlines():
                parts = line.split()
                if not parts:
                    continue
                folder_url = parts[0]
                folders.append(urlparse.urlsplit(folder_url)[2])
    except EnvironmentError:
        pass

    return folders
开发者ID:qwence,项目名称:quodlibet,代码行数:23,代码来源:filesel.py


示例12: get_current_dir

def get_current_dir():
    """Returns the currently active chooser directory path.
    The path might not actually exist.

    Returns:
        fsnative
    """

    data = config.getbytes("memory", "chooser_dir", b"")
    try:
        path = bytes2fsn(data, "utf-8") or None
    except ValueError:
        path = None

    # the last user dir might not be there any more, try showing a parent
    # instead
    if path is not None:
        path = find_nearest_dir(path)

    if path is None:
        path = get_home_dir()

    return path
开发者ID:zsau,项目名称:quodlibet,代码行数:23,代码来源:chooser.py


示例13: test_get_home_dir

 def test_get_home_dir(self):
     self.assertTrue(isinstance(get_home_dir(), fsnative))
     self.assertTrue(os.path.isabs(get_home_dir()))
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:3,代码来源:test_util_path.py


示例14: test_get_scan_dirs

    def test_get_scan_dirs(self):
        some_path = os.path.join(unexpand(get_home_dir()), "foo")
        config.set('settings', 'scan', some_path)
        assert expanduser(some_path) in get_scan_dirs()

        assert all([isinstance(p, fsnative) for p in get_scan_dirs()])
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:6,代码来源:test_util_library.py


示例15: test_get_exclude_dirs

    def test_get_exclude_dirs(self):
        some_path = os.path.join(unexpand(get_home_dir()), "foo")
        config.set('library', 'exclude', some_path)
        assert expanduser(some_path) in get_exclude_dirs()

        assert all([isinstance(p, fsnative) for p in get_exclude_dirs()])
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:6,代码来源:test_util_library.py


示例16: get_home_dir

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation

from gi.repository import Gtk
from os.path import splitext, extsep, dirname

from quodlibet import app
from quodlibet.qltk import ErrorMessage
from quodlibet.util.path import get_home_dir
from quodlibet.plugins.songsmenu import SongsMenuPlugin

__all__ = ['Export', 'Import']


lastfolder = get_home_dir()


def filechooser(save, title):
    chooser = Gtk.FileChooserDialog(
        title=(save and "Export %s Metadata to ..." or
               "Import %s Metadata from ...") % title,
        action=(save and Gtk.FileChooserAction.SAVE or
                Gtk.FileChooserAction.OPEN),
        buttons=(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT,
                 Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT))

    for name, pattern in [('Tag files (*.tags)', '*.tags'),
                          ('All Files', '*')]:
        filter = Gtk.FileFilter()
        filter.set_name(name)
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:31,代码来源:importexport.py


示例17: test_get_home_dir

 def test_get_home_dir(self):
     self.assertTrue(is_fsnative(get_home_dir()))
     self.assertTrue(os.path.isabs(get_home_dir()))
开发者ID:gbtami,项目名称:quodlibet,代码行数:3,代码来源:test_util_path.py


示例18: __init__

    def __init__(self, library, player, headless=False, restore_cb=None):
        super(QuodLibetWindow, self).__init__(dialog=False)
        self.last_dir = get_home_dir()

        self.__destroyed = False
        self.__update_title(player)
        self.set_default_size(550, 450)

        main_box = Gtk.VBox()
        self.add(main_box)

        # create main menubar, load/restore accelerator groups
        self.__library = library
        ui = self.__create_menu(player, library)
        accel_group = ui.get_accel_group()
        self.add_accel_group(accel_group)

        def scroll_and_jump(*args):
            self.__jump_to_current(True, True)

        keyval, mod = Gtk.accelerator_parse("<control><shift>J")
        accel_group.connect(keyval, mod, 0, scroll_and_jump)

        # dbus app menu
        # Unity puts the app menu next to our menu bar. Since it only contains
        # menu items also available in the menu bar itself, don't add it.
        if not util.is_unity():
            AppMenu(self, ui.get_action_groups()[0])

        # custom accel map
        accel_fn = os.path.join(quodlibet.get_user_dir(), "accels")
        Gtk.AccelMap.load(accel_fn)
        # save right away so we fill the file with example comments of all
        # accels
        Gtk.AccelMap.save(accel_fn)

        menubar = ui.get_widget("/Menu")

        # Since https://git.gnome.org/browse/gtk+/commit/?id=b44df22895c79
        # toplevel menu items show an empty 16x16 image. While we don't
        # need image items there UIManager creates them by default.
        # Work around by removing the empty GtkImages
        for child in menubar.get_children():
            if isinstance(child, Gtk.ImageMenuItem):
                child.set_image(None)

        main_box.pack_start(menubar, False, True, 0)

        # get the playlist up before other stuff
        self.songlist = MainSongList(library, player)
        self.songlist.show_all()
        self.songlist.connect("key-press-event", self.__songlist_key_press)
        self.songlist.connect_after(
            'drag-data-received', self.__songlist_drag_data_recv)
        self.song_scroller = SongListScroller(
            ui.get_widget("/Menu/View/SongList"))
        self.song_scroller.add(self.songlist)
        self.qexpander = QueueExpander(
            ui.get_widget("/Menu/View/Queue"), library, player)
        self.playlist = PlaylistMux(
            player, self.qexpander.model, self.songlist.model)

        top_bar = TopBar(self, player, library)
        main_box.pack_start(top_bar, False, True, 0)
        self.top_bar = top_bar

        self.__browserbox = Align(bottom=3)
        main_box.pack_start(self.__browserbox, True, True, 0)

        statusbox = StatusBarBox(self.songlist.model, player)
        self.order = statusbox.order
        self.repeat = statusbox.repeat
        self.statusbar = statusbox.statusbar

        main_box.pack_start(
            Align(statusbox, border=3, top=-3, right=3),
            False, True, 0)

        self.songpane = ConfigRVPaned("memory", "queue_position", 0.75)
        self.songpane.pack1(self.song_scroller, resize=True, shrink=False)
        self.songpane.pack2(self.qexpander, resize=True, shrink=False)
        self.__handle_position = self.songpane.get_property("position")

        def songpane_button_press_cb(pane, event):
            """If we start to drag the pane handle while the
            queue expander is unexpanded, expand it and move the handle
            to the bottom, so we can 'drag' the queue out
            """

            if event.window != pane.get_handle_window():
                return False

            if not self.qexpander.get_expanded():
                self.qexpander.set_expanded(True)
                pane.set_relative(1.0)
            return False

        self.songpane.connect("button-press-event", songpane_button_press_cb)

        self.song_scroller.connect('notify::visible', self.__show_or)
#.........这里部分代码省略.........
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:101,代码来源:quodlibetwindow.py


示例19: lyric_filename

    def lyric_filename(self):
        """Returns the validated, or default, lyrics filename for this
        file. User defined '[memory] lyric_rootpaths' and
        '[memory] lyric_filenames' matches take precedence"""

        from quodlibet.pattern \
            import ArbitraryExtensionFileFromPattern as expand_patterns

        rx_params = re.compile(r'[^\\]<[^' + re.escape(os.sep) + r']*[^\\]>')

        def expand_pathfile(rpf):
            """Return the expanded RootPathFile"""
            expanded = []
            root = expanduser(rpf.root)
            pathfile = expanduser(rpf.pathfile)
            if rx_params.search(pathfile):
                root = expand_patterns(root).format(self)
                pathfile = expand_patterns(pathfile).format(self)
            rpf = RootPathFile(root, pathfile)
            expanded.append(rpf)
            if not os.path.exists(pathfile) and is_windows():
                # prioritise a special character encoded version
                #
                # most 'alien' chars are supported for 'nix fs paths, and we
                # only pass the proposed path through 'escape_filename' (which
                # apparently doesn't respect case) if we don't care about case!
                #
                # FIX: assumes 'nix build used on a case-sensitive fs, nt case
                # insensitive. clearly this is not biting anyone though (yet!)
                pathfile = os.path.sep.join([rpf.root, rpf.end_escaped])
                rpf = RootPathFile(rpf.root, pathfile)
                expanded.insert(len(expanded) - 1, rpf)
            return expanded

        def sanitise(sep, parts):
            """Return a santisied version of a path's parts"""
            return sep.join(part.replace(os.path.sep, u'')[:128]
                                for part in parts)

        # setup defaults (user-defined take precedence)
        # root search paths
        lyric_paths = \
            config.getstringlist("memory", "lyric_rootpaths", [])
        # ensure default paths
        lyric_paths.append(os.path.join(get_home_dir(), ".lyrics"))
        lyric_paths.append(
            os.path.join(os.path.dirname(self.comma('~filename'))))
        # search pathfile names
        lyric_filenames = \
            config.getstringlist("memory", "lyric_filenames", [])
        # ensure some default pathfile names
        lyric_filenames.append(
            sanitise(os.sep, [(self.comma("lyricist") or
                              self.comma("artist")),
                              self.comma("title")]) + u'.lyric')
        lyric_filenames.append(
            sanitise(' - ', [(self.comma("lyricist") or
                             self.comma("artist")),
                             self.comma("title")]) + u'.lyric')

        # generate all potential paths (unresolved/unexpanded)
        pathfiles = OrderedDict()
        for r in lyric_paths:
            for f in lyric_filenames:
                pathfile = os.path.join(r, os.path.dirname(f),
                                        fsnative(os.path.basename(f)))
                rpf = RootPathFile(r, pathfile)
                if not pathfile in pathfiles:
                    pathfiles[pathfile] = rpf

        #print_d("searching for lyrics in:\n%s" % '\n'.join(pathfiles.keys()))

        # expand each raw pathfile in turn and test for existence
        match_ = ""
        pathfiles_expanded = OrderedDict()
        for pf, rpf in pathfiles.items():
            for rpf in expand_pathfile(rpf):  # resolved as late as possible
                pathfile = rpf.pathfile
                pathfiles_expanded[pathfile] = rpf
                if os.path.exists(pathfile):
                    match_ = pathfile
                    break
            if match_ != "":
                break

        if not match_:
            # search even harder!
            lyric_extensions = ['lyric', 'lyrics', '', 'txt']
            #print_d("extending search to extensions: %s" % lyric_extensions)

            def generate_mod_ext_paths(pathfile):
                # separate pathfile's extension (if any)
                ext = os.path.splitext(pathfile)[1][1:]
                path = pathfile[:-1 * len(ext)].strip('.') if ext else pathfile
                # skip the proposed lyric extension if it is the same as
                # the original for a given search pathfile stub - it has
                # already been tested without success!
                extra_extensions = [x for x in lyric_extensions if x != ext]

                # join valid new extensions to pathfile stub and return
#.........这里部分代码省略.........
开发者ID:zsau,项目名称:quodlibet,代码行数:101,代码来源:_audio.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python path.get_temp_cover_file函数代码示例发布时间:2022-05-26
下一篇:
Python path.fsnative函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap