当前位置: 首页>>代码示例>>Python>>正文


Python MPDClient.__getattr__方法代码示例

本文整理汇总了Python中mpd.MPDClient.__getattr__方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.__getattr__方法的具体用法?Python MPDClient.__getattr__怎么用?Python MPDClient.__getattr__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpd.MPDClient的用法示例。


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

示例1: OSC_MPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import __getattr__ [as 别名]
class OSC_MPD(object):
    def __init__(self, osc=('0.0.0.0', 8000), mpd=('127.0.0.1', 6600)):
        self.mpc = MPDClient()
        self.mpc.connect(mpd[0], mpd[1])
        self.server = OSCServer(osc)

        def musicManage(addr, tags, data, client_address):
            cmd = addr.strip('/').split('/')[-1]
            self.mpc.__getattr__(cmd)(*data)

        self.server.addMsgHandler('/bearstech/music/play', musicManage)
        self.server.addMsgHandler('/bearstech/music/pause', musicManage)
        self.server.addMsgHandler('/bearstech/music/next', musicManage)
        self.server.addMsgHandler('/bearstech/music/previous', musicManage)
        self.server.addMsgHandler('/bearstech/music/stop', musicManage)

    def serve_forever(self):
        self.server.serve_forever()
开发者ID:bearstech,项目名称:osc-mpd,代码行数:20,代码来源:__init__.py

示例2: __MPC

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import __getattr__ [as 别名]
class __MPC(object):
    _mpdc   = None
    _host   = DEFAULT_CONFIG['host']
    _port   = DEFAULT_CONFIG['port']
    verbose = bool(int(DEFAULT_CONFIG['verbose']))
    debug   = bool(int(DEFAULT_CONFIG['debug']))

    # Switch automatically to created buffers
    autoswitch = bool(int(DEFAULT_CONFIG['autoswitch']))

    # State symbols
    state_chars = {
            'pause':DEFAULT_CONFIG['ch_pause'],
            'play':DEFAULT_CONFIG['ch_play'],
            'stop':DEFAULT_CONFIG['ch_stop'],
            }

    def __init__(self, wc_buffer=None):
        object.__init__(self)
        self._mpdc = MPDClient()
        self._commands = self._mpdc._commands
        self.wcb = wc_buffer

        self.verbose = bool(int((wc.config_get_plugin("verbose"))))
        self.debug = bool(int((wc.config_get_plugin("debug"))))
        self.autoswitch = bool(int((wc.config_get_plugin("autoswitch"))))

        for k, v in self.state_chars.iteritems():
            self.state_chars[k] = wc.config_get_plugin('ch_' + k)

        self._commands['np'] = None

    @property
    def shortstats(self): return wc.config_get_plugin("shortstats")

    def __getattribute__(self, attr):
        try:
            return object.__getattribute__(self, attr)
        except AttributeError:
            return self._mpdc.__getattr__(attr)

    def _get_status(self, key):
        return self._mpdc.status()[key]

    def _print_current(f):
        """Do `f`, then prints the short_status in the buffer.
        """
        def pf(self, *args, **kwargs):
            robj = f(self, *args, **kwargs)
            if not self.verbose: return robj

            # Show the status in the current buffer
            csong = self._mpdc.currentsong()
            csong.update({'state':self.state_chars[self._get_status('state')]})
            wc.prnt(self.wcb or wc.current_buffer(),
                    Template(self.shortstats).safe_substitute(csong))
            return robj

        return pf

    def connect(self):
        self._host = wc.config_get_plugin("host")
        self._port = int(wc.config_get_plugin("port"))
        self._mpdc.connect(host=self._host, port=self._port)
        pw = wc.config_get_plugin("password")
        if len(pw) > 0: self._mpdc.password(pw)

        if self.debug: wc.prnt(self.wcb or wc.current_buffer(),
                               'mpc debug: Connected')

    def currentsong(self):
        ds = self._mpdc.currentsong()
        itime = int(ds['time'])
        ipos  = int(ds['pos'])
        pct   = int(100 * (ipos / itime))

        ds.update({
            "title_or_file" : ds['title'] or splitext(basename(ds['file']))[0],
            "pos_sec"       : "%02d" % (ipos / 60),
            "pos_min"       : str(ipos / 60),
            "length_sec"    : "%02d" % (itime % 60),
            "length_min"    : str(itime / 60),
            "pct"           : "%2.0f" % pct,
            })

        return ds

    def np(self):
        """Pushes result of np template substitution to current buffer.
        """
        ds  = self.currentsong()
        if len(ds) == 0:
            wc.prnt(wc.current_buffer(), "MPC: ERROR: mpd is stopped")
            return
        wc.command(wc.current_buffer(),
                   Template(wc.config_get_plugin("format")).safe_substitute(ds))

    @_print_current
    def next(self):
        self._mpdc.next()
#.........这里部分代码省略.........
开发者ID:sitaktif,项目名称:weechat-scripts,代码行数:103,代码来源:mpc.py

示例3: MPDPrinter

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import __getattr__ [as 别名]

#.........这里部分代码省略.........
                if title:
                    items.append(title)
                songtext = " - ".join(items)
                self.songtext.setText(songtext)
                state = status['state']
                if state == 'play':
                    state = LCD.SYM_PLAY
                elif state == 'pause':
                    state = LCD.SYM_PAUSE
                else:
                    state = LCD.SYM_STOP
                self.statetext.setText(chr(state))
            elif i == 'playlist':
                plstext = ("%d/%d" % (int(status.get('song', '-1'))+1,int(status.get('playlistlength', '-1'))))
                self.plstext.setText( plstext.ljust(self.plstext.width))
            elif i == 'options':
                self.opttext.setList(
                    [
                        'Repeat '.ljust(8) + strswitch(int(status['repeat'])).rjust(3),
                        'Consume'.ljust(8) + strswitch(int(status['consume'])).rjust(3),
                        'Random '.ljust(8) + strswitch(int(status['random'])).rjust(3),
                        'Single '.ljust(8) + strswitch(int(status['single'])).rjust(3),
                        ]
                    )
            elif i == 'mixer':
                volumetext = status['volume']+"%"
                self.volumetext.setText(volumetext.rjust(self.volumetext.width))
            elif i == 'update':
                self.updatestatus.setText( chr(LCD.SYM_CLOCK) if status.get('updating_db', False) else ' ')
            elif i == 'sticker':
                pass
            else:
                self.logger.debug( "%s unhandled event %s" %( type(self).__name__, i))
        
    def call_mpd(self,cmd, *args):
        self._mpd.connect(self.mpdhost, self.mpdport)
        ret = self._mpd.__getattr__(cmd)(*args)
        self._mpd.disconnect()
        return ret

    def toggle_play(self):
        self._mpd.connect(self.mpdhost, self.mpdport)
        status = self._mpd.status()
        if status['state'] == 'play':
            self._mpd.pause()
        else:
            self._mpd.play()
        self._mpd.disconnect()

    def button_clicked(self,btn):
        if self.active == self.PAGE.PLAYER:
            if btn == LCD.RIGHT:
                self.call_mpd('next')
            elif btn == LCD.LEFT:
                self.call_mpd('previous')
        super(MPDPrinter,self).button_clicked(btn)
        
    def button_pressed(self,btn,repeat):
        if self.active == self.PAGE.PLAYER:
            if (btn == LCD.LEFT or btn == LCD.RIGHT) and repeat:
                status = self.call_mpd('status')
                if not status.has_key('elapsed'):
                    return
                secs   = int(float(status['elapsed'])+0.5)
                songid = status['songid']
                if btn == LCD.RIGHT:
                    secs += 10
                    self.call_mpd('seek', songid, str(secs))
                elif btn == LCD.LEFT:
                    secs -= 10
                    self.call_mpd('seek', songid, str(secs))
            elif btn == LCD.DOWN and not repeat:
                self.call_mpd('stop')
            elif btn == LCD.UP and not repeat:
                self.toggle_play()
        elif self.active == self.PAGE.OPTIONS:
            volumetext = self.volumetext.text[:-1]
            if len(volumetext):
                volume = int(volumetext)
                if btn == LCD.RIGHT:
                    volume = min(volume+5,100)
                    self.call_mpd('setvol', volume)
                    self.volumetext.setText("%d%%" % volume)
                elif btn == LCD.LEFT:
                    volume = max(volume-5,0)
                    self.call_mpd('setvol', volume)
                    self.volumetext.setText("%d%%" % volume)
            if btn == LCD.UP and not repeat:
                if self.updatestatus.text == ' ':
                    self.show_splash('Updating all')
                    self.call_mpd('update')
                else:
                    self.show_splash('Update in\nprogress')
            elif btn == LCD.DOWN and not repeat:
                if self.updatestatus.text == ' ':
                    self.show_splash('Updating ramdisk')
                    self.call_mpd('update', 'RAMDISK')
                else:
                    self.show_splash('Update in\nprogress')
        super(MPDPrinter,self).button_pressed(btn,repeat)
开发者ID:jmechnich,项目名称:musicpi_lcd,代码行数:104,代码来源:printer_mpd.py


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