コード例 #1
0
class CollectionUiManager:
    def __init__(self, app):
        self._app = app
        self.model = CollectionsModel(app)
        self._id_coll_mapping = {}

    def get(self, identifier):
        return self._id_coll_mapping.get(identifier, None)

    def get_coll_id(self, coll):
        # TODO: 目前还没想好 collection identifier 计算方法,故添加这个函数
        # 现在把 fpath 当作 identifier 使用,但对外透明
        return elfhash(base64.b64encode(bytes(coll.fpath, 'utf-8')))

    def add(self, collection):
        coll_id = self.get_coll_id(collection)
        self._id_coll_mapping[coll_id] = collection
        self.model.add(collection)

    def clear(self):
        self._id_coll_mapping.clear()
        self.model.clear()

    def initialize(self):
        self._scan()

    def refresh(self):
        """重新加载本地收藏列表"""
        self.model.clear()
        self._scan()

    def _scan(self):
        for coll in self._app.coll_mgr.scan():
            self.add(coll)
コード例 #2
0
def attach_attrs(app):
    """初始化 app 属性"""
    app.library = Library()
    app.live_lyric = LiveLyric()
    player_kwargs = dict(
        audio_device=bytes(app.config.MPV_AUDIO_DEVICE, 'utf-8')
    )
    app.player = Player(app=app, **(player_kwargs or {}))
    app.playlist = app.player.playlist
    app.plugin_mgr = PluginsManager(app)
    app.request = Request()
    app._g = {}

    if app.mode & (app.DaemonMode | app.GuiMode):
        app.version_mgr = VersionManager(app)

    if app.mode & app.GuiMode:
        from feeluown.widgets.collections import CollectionsModel
        from feeluown.uimodels.provider import ProviderUiManager
        from feeluown.uimodels.playlist import PlaylistUiManager
        from feeluown.uimodels.my_music import MyMusicUiManager
        from feeluown.collection import CollectionManager

        from .browser import Browser
        from .hotkey import HotkeyManager
        from .image import ImgManager
        from .theme import ThemeManager
        from .tips import TipsManager
        from .ui import Ui

        # GUI 的一些辅助管理模块
        app.coll_mgr = CollectionManager(app)
        app.theme_mgr = ThemeManager(app)
        app.tips_mgr = TipsManager(app)
        app.hotkey_mgr = HotkeyManager(app)
        app.img_mgr = ImgManager(app)

        # GUI 组件的数据管理模块
        app.pvd_uimgr = ProviderUiManager(app)
        app.pl_uimgr = PlaylistUiManager(app)
        app.mymusic_uimgr = MyMusicUiManager(app)

        app.collections = CollectionsModel(parent=app)

        app.browser = Browser(app)
        app.ui = Ui(app)
        app.show_msg = app.ui.magicbox.show_msg
コード例 #3
0
ファイル: app.py プロジェクト: Currylike/FeelUOwn
def attach_attrs(app, **player_kwargs):
    """初始化 app 属性"""
    app.library = Library()
    app.live_lyric = LiveLyric()
    app.protocol = FuoProcotol(app)
    app.plugin_mgr = PluginsManager(app)
    app.version_mgr = VersionManager(app)
    app.request = Request()
    app._g = {}

    app.player = Player(app=app, **(player_kwargs or {}))
    app.playlist = app.player.playlist

    if app.mode & app.GuiMode:
        from feeluown.widgets.collections import CollectionsModel
        from feeluown.uimodels.provider import ProviderUiManager
        from feeluown.uimodels.playlist import PlaylistUiManager
        from feeluown.uimodels.my_music import MyMusicUiManager
        from feeluown.protocol import CollectionManager

        from .browser import Browser
        from .hotkey import HotkeyManager
        from .image import ImgManager
        from .theme import ThemeManager
        from .tips import TipsManager
        from .ui import Ui

        # GUI 的一些辅助管理模块
        app.coll_mgr = CollectionManager(app)
        app.theme_mgr = ThemeManager(app)
        app.tips_mgr = TipsManager(app)
        app.hotkey_mgr = HotkeyManager(app)
        app.img_mgr = ImgManager(app)

        # GUI 组件的数据管理模块
        app.pvd_uimgr = ProviderUiManager(app)
        app.pl_uimgr = PlaylistUiManager(app)
        app.mymusic_uimgr = MyMusicUiManager(app)

        app.collections = CollectionsModel(parent=app)

        app.browser = Browser(app)
        app.ui = Ui(app)
        app.show_msg = app.ui.magicbox.show_msg
コード例 #4
0
class CollectionUiManager:
    def __init__(self, app):
        self._app = app
        self.model = CollectionsModel(app)
        self._id_coll_mapping = {}

    def get(self, identifier):
        return self._id_coll_mapping.get(identifier, None)

    def get_coll_id(self, coll):
        # TODO: 目前还没想好 collection identifier 计算方法,故添加这个函数
        # 现在把 fpath 当作 identifier 使用,但对外透明
        return elfhash(base64.b64encode(bytes(coll.fpath, 'utf-8')))

    def get_coll_library(self):
        for coll in self._id_coll_mapping.values():
            if coll.type == CollectionType.sys_library:
                return coll
        raise Exception('collection library not found')

    def add(self, collection):
        coll_id = self.get_coll_id(collection)
        self._id_coll_mapping[coll_id] = collection
        self.model.add(collection)

    def clear(self):
        self._id_coll_mapping.clear()
        self.model.clear()

    def initialize(self):
        self._scan()

    def refresh(self):
        """重新加载本地收藏列表"""
        self.model.clear()
        self._scan()

    def _scan(self):
        colls = []
        library_coll = None
        for coll in self._app.coll_mgr.scan():
            if coll.type == CollectionType.sys_library:
                library_coll = coll
                continue
            colls.append(coll)
        colls.insert(0, library_coll)
        for coll in colls:
            self.add(coll)
コード例 #5
0
class CollectionUiManager:
    def __init__(self, app):
        self._app = app
        self.model = CollectionsModel(app)
        self._id_coll_mapping = {}

    def get(self, identifier):
        return self._id_coll_mapping.get(identifier, None)

    def get_coll_id(self, coll):
        # TODO: 目前还没想好 collection identifier 计算方法,故添加这个函数
        # 现在把 fpath 当作 identifier 使用,但对外透明
        return elfhash(base64.b64encode(bytes(coll.fpath, 'utf-8')))

    def add(self, collection):
        coll_id = self.get_coll_id(collection)
        self._id_coll_mapping[coll_id] = collection
        self.model.add(collection)

    def clear(self):
        self._id_coll_mapping.clear()
        self.model.clear()

    def initialize(self):
        self._scan()

    def refresh(self):
        """重新加载本地收藏列表"""
        self.model.clear()
        self._scan()

    def _scan(self):
        colls = []
        for coll in self._app.coll_mgr.scan():
            colls.append(coll)
        # put predefined collections on the top
        for coll in colls:
            if coll.type == CollectionType.sys_song:
                colls[0], colls[-1] = colls[-1], colls[0]
            if coll.type == CollectionType.sys_album:
                colls[1], colls[-1] = colls[-1], colls[1]
        for coll in colls:
            self.add(coll)
コード例 #6
0
 def __init__(self, app):
     self._app = app
     self.model = CollectionsModel(app)
     self._id_coll_mapping = {}