Ejemplo n.º 1
0
    def set_current_time(self, pos, duration):
        if self.update_bar == 1:
            if duration == 0 or pos >= duration:
                self.bar.set_range(0, 1000)
                self.bar.set_value(0)
                self.bar.set_sensitive(False)
            else:
                self.bar.set_sensitive(True)
                self.bar.set_range(0, duration)
                self.bar.set_value(pos)

        # total = utils.duration_to_string(duration * 1000, "00:00")
        if pos > 0 and pos < duration:
            current = utils.duration_to_string(pos, "00:00", 1)
        else:
            current = "00:00"

        if pos > 0 and Player.song and Player.song.get_type() == "webcast":
            current = utils.duration_to_string(pos, "00:00", 1)
            # total = "--:--"
        # text = "%s/%s" % (current, total)
        text = current
        self.label_time.set_text(text)
        if self.draw_time_callback:
            self.draw_time_callback(text)
Ejemplo n.º 2
0
    def set_current_time(self, pos, duration):
        if self.update_bar == 1:
            if duration == 0 or pos >= duration:
                self.bar.set_range(0, 1000)
                self.bar.set_value(0)
                self.bar.set_sensitive(False)
            else :
                self.bar.set_sensitive(True)
                self.bar.set_range(0, duration)
                self.bar.set_value(pos)

        # total = utils.duration_to_string(duration * 1000, "00:00")                
        if pos > 0 and pos < duration:
            current = utils.duration_to_string(pos, "00:00", 1) 
        else:    
            current = "00:00"
            
        if pos >0 and Player.song and Player.song.get_type() == "webcast":    
            current = utils.duration_to_string(pos, "00:00", 1) 
            # total = "--:--"
        # text = "%s/%s" % (current, total)
        text = current
        self.label_time.set_text(text)
        if self.draw_time_callback:
            self.draw_time_callback(text)
Ejemplo n.º 3
0
    def update(self, song, redraw=False):
        '''update'''
        self.song = song
        self.title = song.get_str("name")
        self.artist = ','.join([artist['name'] for artist in song['artists']])
        self.album = song["album"]["name"]
        self.length = utils.duration_to_string(int(song.get_str("duration")))

        self.tooltip_text = "曲名:" + self.title + "\n歌手:" + self.artist + "\n时长:" + self.length + "\n专辑:" + self.album

        # Calculate item size.
        self.title_padding_x = 15
        self.title_padding_y = 5
        (self.title_width,
         self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE)

        self.artist_padding_x = 10
        self.artist_padding_y = 5
        (self.artist_width,
         self.artist_height) = get_content_size(self.artist, DEFAULT_FONT_SIZE)

        self.length_padding_x = 2
        self.length_padding_y = 5
        (self.length_width,
         self.length_height) = get_content_size(self.length, DEFAULT_FONT_SIZE)

        if redraw:
            self.emit_redraw_request()
    def update(self, song, redraw=False):
        '''update'''
        self.song = song
        self.title = song.get_str("name")
        self.artist = ','.join([artist['name'] for artist in
            song['artists']])
        self.album = song["album"]["name"]
        self.length = utils.duration_to_string(int(song.get_str("duration")))

        self.tooltip_text = "曲名:" + self.title + "\n歌手:" + self.artist + "\n时长:" + self.length + "\n专辑:" + self.album

        # Calculate item size.
        self.title_padding_x = 15
        self.title_padding_y = 5
        (self.title_width, self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE)

        self.artist_padding_x = 10
        self.artist_padding_y = 5
        (self.artist_width, self.artist_height) = get_content_size(self.artist, DEFAULT_FONT_SIZE)

        self.length_padding_x = 2
        self.length_padding_y = 5
        (self.length_width, self.length_height) = get_content_size(self.length, DEFAULT_FONT_SIZE)

        if redraw:
            self.emit_redraw_request()
Ejemplo n.º 5
0
    def get_str(self, key, xml=False):
        '''Get a formated version of the tag information.'''
        if key == "uri":
            value = utils.unescape_string_for_display(self.get("uri"))
        elif key == "title":
            value = self.get("title")
            if not value:
                value = self.get_filename()

        elif key == "#size":
            value = utils.str_size(self.get("#size"))
        elif key == "#bitrate":
            value = self.get("#bitrate")
            if value:
                if isinstance(value, (int, float)):
                    test_v = value / 1000
                    if test_v > 1:
                        value = "%dk" % test_v

        elif key == "#duration":
            value = utils.duration_to_string(self.get(key))
        elif key == "#lastplayed":
            value = self.get(key)
            if value:
                value = datetime.fromtimestamp(int(value)).strftime("%Y-%m-%d")
            else:
                value = "Never"
        elif key == "#playcount":
            value = self.get(key) or "0"
        elif key in ["#date", "#added"]:
            value = self.get(key)
            if value:
                value = datetime.fromtimestamp(int(value)).strftime("%Y-%m-%d")
        elif key == "#rate":
            rate = self.get("rate")
            if rate in [0, 1, 2, 3, 4, 5, "0", "1", "2", "3", "4", "5"]:
                value = "rate-" + str(rate)
            else:
                value = "rate-0"
        elif key == "date":
            try:
                value = self.get("date", "")[:4]
            except (ValueError, TypeError, KeyError):
                pass
            if not value:
                value = self.get("#date")
                if value:
                    value = datetime.fromtimestamp(int(value)).strftime("%Y")
                else:
                    value = ""
        else:
            value = None
        if not value: value = self.get(key, "")
        if isinstance(value, int) or isinstance(value, float):
            value = "%d" % value
        if value is None: value = ""
        return str(value)
Ejemplo n.º 6
0
    def set_current_time(self, pos, duration):
        if self.update_bar == 1:
            if duration == 0 or pos >= duration:
                self.bar.set_range(0, 1000)
                self.bar.set_value(0)
                self.bar.set_sensitive(False)
            else :
                self.bar.set_sensitive(True)
                self.bar.set_range(0, duration)
                self.bar.set_value(pos)

        total = utils.duration_to_string(duration * 1000, "00:00")                
        if pos > 0 and pos < duration:
            current = utils.duration_to_string(pos, "00:00", 1) 
        else:    
            current = "00:00"
        text = "%s/%s" % (current, total)
        self.label_time.set_text(text)
Ejemplo n.º 7
0
 def get_str(self, key, xml=False):    
     '''Get a formated version of the tag information.'''
     if key == "uri":
         value = utils.unescape_string_for_display(self.get("uri"))
     elif key == "title":    
         value = self.get("title")
         if not value:
             value = self.get_filename()
             
     elif key == "#size":        
         value = utils.str_size(self.get("#size"))
     elif key == "#bitrate":
         value = self.get("#bitrate")
         if value: 
             if isinstance(value, (int, float)):
                 test_v = value / 1000
                 if test_v > 1:
                     value = "%dk" % test_v
             
     elif key == "#duration":    
         value = utils.duration_to_string(self.get(key))
     elif key == "#lastplayed":    
         value = self.get(key)
         if value:
             value = datetime.fromtimestamp(int(value)).strftime("%Y-%m-%d")
         else:    
             value = "Never"
     elif key == "#playcount":        
         value = self.get(key) or "0"
     elif key in ["#date", "#added"]:
         value = self.get(key)
         if value:
             value = datetime.fromtimestamp(int(value)).strftime("%Y-%m-%d")
     elif key == "#rate":        
         rate = self.get("rate")
         if rate in [0,1,2,3,4,5,"0","1","2","3","4","5"]:
             value = "rate-" + str(rate)
         else: value = "rate-0"    
     elif key == "date":    
         try:
             value = self.get("date", "")[:4]
         except (ValueError, TypeError, KeyError):    
             pass
         if not value:
             value = self.get("#date")
             if value:
                 value = datetime.fromtimestamp(int(value)).strftime("%Y")
             else:    
                 value = ""
     else:            
         value = None
     if not value: value = self.get(key, "")    
     if isinstance(value, int) or isinstance(value, float): value = "%d" % value
     if value is None: value = ""
     return str(value)