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


Python Popen.flush方法代码示例

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


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

示例1: set_clipboard

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import flush [as 别名]
def set_clipboard(text):
    from subprocess import Popen, PIPE

    pipe = Popen(['xsel', '--primary --input'], shell=True, stdin=PIPE).stdin
    pipe.write(bytes(text, 'ascii'))
    pipe.flush()
    pipe.close()
开发者ID:mkalinowski,项目名称:climgur,代码行数:9,代码来源:climgur.py

示例2: __init__

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import flush [as 别名]
class AudioPlayer:

    song = None
    state = States.INITIAL
    startup = -1

    def __init__(self):
        self.mplayer = None

    def play(self, song=None):
        if self.state == States.INITIAL or self.state == States.STOPPED:
            self.song = song
            index = configurations.BUFFERED_TEMP_LOCATION + "-" + self.song['artist'].replace(" ", "_") + "-" + self.song['title'].replace(" ", "_")
            available = list(glob.glob(index + "*"))
            if len(available) > 0:
                location = available.pop(0)
            else:
                stream = pafy.new(song['youtube_link']).getbestaudio()
                location = index+"."+stream.extension
                stream.download(filepath=location)
            self.mplayer = Popen(["mplayer", "-slave", "-really-quiet", location], stdin=PIPE)
            self.startup = int(time.time())
            self.state = States.PLAYING
        elif self.state == States.PAUSED:
            self.mplayer.stdin.write(b"p\n")
            self.mplayer.stdin.flush()
            self.state = States.PLAYING

    def pause(self):
        self.mplayer.write(b"p\n")
        self.mplayer.flush()
        self.state = States.PAUSED

    def stop(self):
        self.mplayer.kill()
        self.state = States.STOPPED

    def is_dying(self):
        return time.time() > (self.song.duration-5+self.startup)

    def is_stopped(self):
        if self.state == States.STOPPED:
            return True
        elif self.state == States.INITIAL:
            return False
        elif self.mplayer.poll() is not None:
            self.state = States.STOPPED

        return self.state == States.STOPPED

    def is_initial(self):
        return self.state == States.INITIAL
开发者ID:Nixon-,项目名称:LeninAudio,代码行数:54,代码来源:AudioPlayer.py


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