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


Python Ui.notifySend方法代码示例

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


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

示例1: __init__

# 需要导入模块: from ui import Ui [as 别名]
# 或者: from ui.Ui import notifySend [as 别名]
class Player:

    def __init__(self):
        self.ui = Ui()
        self.datatype = 'songs'
        self.popen_handler = None
        # flag stop, prevent thread start
        self.playing_flag = False
        self.pause_flag = False
        self.songs = []
        self.idx = 0
        self.next_music_p=False  #播放下一曲标志
        self.stop_sub=False  #结束自动播放下一曲,手动选择播放``
        self.mplayer_controller=os.path.join(tempfile.mkdtemp(),'mplayer_controller')
        os.mkfifo(self.mplayer_controller)  #临时文件``

        

    def return_idx(self):
        return self.idx,self.playing_flag#,self.next_music_p

    def popen_recall(self, onExit, popenArgs):
        """
        Runs the given args in a subprocess.Popen, and then calls the function
        onExit when the subprocess completes.
        onExit is a callable object, and popenArgs is a lists/tuple of args that 
        would give to subprocess.Popen.
        """
        def runInThread(onExit, popenArgs):
            self.ui.notifySend(name=self.songs[self.idx]['song_name'],artist=self.songs[self.idx]['artist'])
            play_s='mplayer -quiet -slave -input file={fifo} \'{song_url}\' 2>&1'
            self.popen_handler = subprocess.Popen(play_s.format(fifo=self.mplayer_controller,song_url=popenArgs),shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,bufsize=1)
            self.popen_handler.wait()
            if self.playing_flag and self.stop_sub==False:
                self.idx = carousel(0, len(self.songs)-1, self.idx+1 )
                #self.next_music_p= not self.next_music_p #对下一曲标志取反
                onExit()
            else:
                self.stop_sub=False
            return
        thread = threading.Thread(target=runInThread, args=(onExit, popenArgs))
        thread.start()
        # returns immediately after the thread starts
        return thread

    def recall(self):
        self.playing_flag = True
        item = self.songs[ self.idx ]
        self.ui.build_playinfo(item['song_name'], item['artist'], item['album_name'])
        self.popen_recall(self.recall, item['mp3_url'])

    def play(self, datatype, songs, idx):
        # if same playlists && idx --> same song :: pause/resume it
        self.datatype = datatype

        if datatype == 'songs' or datatype == 'djchannels':
            if idx == self.idx and songs == self.songs:
                if self.pause_flag:
                    self.resume()        
                else:
                    self.pause()

            else:    
                if datatype == 'songs' or datatype == 'djchannels':
                    self.songs = songs
                    self.idx = idx

                # if it's playing
                if self.playing_flag:
                    self.switch()

                # start new play
                else:
                    self.recall()
        # if current menu is not song, pause/resume
        else:
            if self.playing_flag:
                if self.pause_flag:
                    self.resume()
                else:
                    self.pause()
            else:
                pass

    # play another   
    def switch(self):
        self.stop()
        # wait process be killed
        time.sleep(0.01)
        self.recall()

    def stop(self):
        if self.playing_flag and self.popen_handler:
            self.playing_flag = False
            self.stop_sub=True
            subprocess.Popen('echo "quit" > {fifo}'.format(fifo=self.mplayer_controller),shell=True,stdin=subprocess.PIPE).wait()
            #self.popen_handler.kill()

    def pause(self):
        self.pause_flag = True
#.........这里部分代码省略.........
开发者ID:dream1986,项目名称:musicbox-1,代码行数:103,代码来源:player.py


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