def gtk_show(self,str,tags,augmentation, start, end): """Internal function: never use it, always use show """ circle_gtk.check_is_gtkthread() self.fterm.lock.acquire() cursor_was_visible = self.fterm.is_cursor_visible() if start != end: self.fterm.buffer.delete( self.fterm.buffer.get_iter_at_offset(start), self.fterm.buffer.get_iter_at_offset(end)) # insert_with_tags_by_name broken, so do it ourselves self.fterm.buffer.insert( self.fterm.buffer.get_iter_at_offset(start),str) self.fterm.buffer.remove_all_tags( self.fterm.buffer.get_iter_at_offset(start), self.fterm.buffer.get_iter_at_offset(start+len(str))) for tag in tags + ['clickable']: self.fterm.buffer.apply_tag_by_name( tag, self.fterm.buffer.get_iter_at_offset(start), self.fterm.buffer.get_iter_at_offset(start+len(str))) if augmentation: _augment(self.fterm.buffer, start, augmentation) #apply(self.fterm.buffer.insert_with_tags_by_name, # [ self.fterm.buffer.get_iter_at_offset(self.start), # str ] + tags) if cursor_was_visible: self.fterm.force_cursor_onscreen() self.fterm.lock.release()
def apply_tags(self,tags): circle_gtk.check_is_gtkthread() for tag in tags + ['clickable']: self.fterm.buffer.apply_tag_by_name( tag, self.fterm.buffer.get_iter_at_offset(self.start), self.fterm.buffer.get_iter_at_offset(self.end))
def remove_tags(self,tags): circle_gtk.check_is_gtkthread() for tag in tags: self.fterm.buffer.remove_tag_by_name( tag, self.fterm.buffer.get_iter_at_offset(self.start), self.fterm.buffer.get_iter_at_offset(self.end))
def reset_tabs(self): circle_gtk.check_is_gtkthread() self.tabs.set_tab(0,pango.TAB_LEFT,50) self.tabs.set_tab(1,pango.TAB_LEFT,60) self.tabs.set_tab(2,pango.TAB_LEFT,80) self.tabs.set_tab(3,pango.TAB_LEFT,70) self.view.set_tabs(self.tabs) self.maxlen=2
def update(self): """called from the main update function""" circle_gtk.check_is_gtkthread() for i in range(len(self.playlist)): player = self.playlist[i] downloader = player.downloader if downloader!=None: if not downloader.success: filename=player.filename if os.path.exists(filename): str = " %d%%" % (float(100*os.path.getsize(filename)) / self.playlist[i].size) self.list.set_text(i,2,str) else: self.list.set_text(i,2,'100%') player.downloader=None if self.player: if self.player.finished: i = self.playlist.index(player) self.list.set_text(i,1,' ') for player in self.playlist: if not player.finished: self.player = player self.playing_row = self.playlist.index(player) self.start_music() break else: self.player= None self.playing_row = -1 if self.player and self.app.running: self.player.update() self.progress.set_fraction(self.player.fraction) if self.player.time: str = "%d:%02d / %d:%02d "\ % (int(self.player.time_elapsed/60), int(self.player.time_elapsed%60),\ int((self.player.time + 0.5 - self.player.time_elapsed)/60),\ int((self.player.time + 0.5 - self.player.time_elapsed)%60) ) else: str = "%d:%02d / ?? "% (int(self.player.time_elapsed/60), int(self.player.time_elapsed%60)) if self.player.stalled : str = str + " (stalled...)" self.progress.set_text(str) else: self.progress.set_fraction(0) self.progress.set_text("") self.update_info()
def set_tabs(self,length): """The first column is the title or filename (variable width) The second is the size for files (width 70) The third is the mimetype (width 90) """ circle_gtk.check_is_gtkthread() if length>self.maxlen: self.maxlen=length if self.maxlen>90: self.maxlen=90 self.tabs.set_tab(0,pango.TAB_LEFT,self.maxlen*7) self.tabs.set_tab(1,pango.TAB_LEFT,self.maxlen*7+70) self.tabs.set_tab(2,pango.TAB_LEFT,self.maxlen*7+70+90) self.view.set_tabs(self.tabs)
def start_music(self): """ start a new song. playing_row must be set and valid """ circle_gtk.check_is_gtkthread() if self.player: if self.player.playing: self.player.stop_playing() if self.playing_row != -1: self.progress.set_fraction(0) self.player = self.playlist[self.playing_row] self.player.finished = 0 self.list.set_text(self.playing_row,1,'*') self.player.start_playing() self.update_info()
def update_info(self): circle_gtk.check_is_gtkthread() if self.playing_row!=-1 and self.playlist: player = self.playlist[self.playing_row] else: player= self.player if player: filename=os.path.basename(player.filename) title = player.info.get('music_title') artist = player.info.get('music_artist') album = player.info.get('music_album') frequency = player.info.get('frequency') bitrate = player.info.get('bitrate') time = player.info.get('time') else: filename='' title='' artist='' album='' frequency='' bitrate='' time='' if title: str = title+' by '+artist else: str = filename self.title_label.set_text(utility.force_unicode(str)) self.title_label.show() str="" if frequency: str= str + "%dHz "%frequency if bitrate: str = str + " %dkb/s"%bitrate if time: str = str + " %dmin%02ds "% ((time/100/60),((time/100)%60)) self.bitstream_label.set_text(str) self.bitstream_label.show()
def show_gtk(self,str,tags=[],augmentation=None): """display text in the field. to be called from gtk thread only""" check.check_has_type(str, types.StringType) circle_gtk.check_is_gtkthread() if self.closed: return if type(tags) != type([]): tags = [tags] if tags == []: tags = [ "black" ] if type(str) == type(''): str = unicode(str,'ascii','replace') self.text = str change = len(str) - (self.end - self.start) self.offset_successors(change) self.gtk_show(str,tags,augmentation,self.start, self.end) self.end = self.end + change
def stop_music(self, e=None): circle_gtk.check_is_gtkthread() if self.player: self.player.stop_playing() self.player.finished = 1 self.progress.set_fraction(0)
def append_song(self, info, play_now, downloader=None, field=None): """ appends song. if play_now, stops current player and starts this one. method called by other classes """ circle_gtk.check_is_gtkthread() if info.get('local_path'): f = info['local_path'] else: f = downloader.filename size = info.get('length') # first check if already in playlist for i in range(len(self.playlist)): if self.playlist[i].filename == f: self.selected_row=i self.playing_row=i self.playlist[i].field=field if play_now: if self.player != self.playlist[i]: self.stop_music() self.player = self.playlist[i] self.play_row() else: if not self.player.playing: self.play_row() return if play_now: self.stop_music() self.player=None mime=info.get('mime') extension = string.split(f, ".")[-1] lext = string.lower(extension) if mime=='audio/x-mp3' or lext == 'mp3': player=Mp3Player(f,downloader,size,field) elif mime=='audio/x-ogg' or lext == 'ogg': try: import ogg.vorbis import linuxaudiodev except: raise error.Error('I do not know how to play ogg files.\n'+ 'Please install the python libraries for Ogg Vorbis:\n'+ 'http://www.andrewchatham.com/pyogg/') try: player=LADPlayer(f,downloader,size,field) except: raise error.Error('Cannot play %s: file not found'%f) else: raise error.Error('Cannot play : unrecognized file format') player.info = info if info.get('time'): player.time = float(info['time'])/100 else: player.time = None if play_now: self.playlist.insert(0,player) self.list.insert(0,[utility.force_unicode(os.path.basename(f)),'*','']) self.list.set_text(0,1,'0') self.selected_row=0 self.playing_row=0 self.play_row() else: self.playlist.append(player) self.list.append([utility.force_unicode(os.path.basename(f)),'-',''])