Example #1
0
    def __init__(self):
        super(SongTimer, self).__init__()

        self.label_time = Label("00:00/00:00", app_theme.get_color("labelText"), 8, enable_gaussian=True)

        self.bar = HScalebar()
        self.bar.set_draw_value(False)
        self.bar.set_range(0, 1000)
        self.bar.set_value(0)
        self.bar.connect("button_press_event", self.on_bar_press)
        self.bar.connect("button_release_event", self.on_bar_release)
        self.__value_changed_id = self.bar.connect("value-changed", self.on_bar_value_changed)
        self.bar.handler_block(self.__value_changed_id)
        self.pack_start(self.bar, True, True)
        self.update_bar = 1
        self.duration = 0
        self.__idle_release_id = None
        self.delete = False
        self.__need_report = False

        Player.connect("instant-new-song", self.set_duration)

        Player.bin.connect("tick", self.on_tick)
        Player.connect("seeked", self.on_seek)
        Player.connect("stopped", self.set_duration)
        if not Player.song:
            self.bar.set_sensitive(False)
Example #2
0
    def __init__(self, draw_time_callback=None):
        super(SongTimer, self).__init__()

        self.label_time = Label("00:00",
                                app_theme.get_color("labelText"),
                                8,
                                enable_gaussian=True)
        self.draw_time_callback = draw_time_callback
        if draw_time_callback:
            draw_time_callback(self.label_time.get_text())

        self.bar = HScalebar()
        self.bar.set_draw_value(False)
        self.bar.set_range(0, 1000)
        self.bar.set_value(0)
        bar_align = gtk.Alignment()
        bar_align.set_padding(0, 0, 2, 2)
        bar_align.set(1, 1, 1, 1)
        bar_align.add(self.bar)
        self.bar.connect("button-press-event", self.on_bar_press)
        self.bar.connect("button-release-event", self.on_bar_release)
        self.__value_changed_id = self.bar.connect("value-changed",
                                                   self.on_bar_value_changed)

        self.pack_start(bar_align, True, True)
        self.update_bar = 1
        self.duration = 0
        self.__idle_release_id = None
        self.delete = False
        self.__need_report = False
        self.press_flag = False

        Player.connect("instant-new-song", self.set_duration)
        Player.connect("init-status", self.on_player_init_status)

        Player.bin.connect("tick", self.on_tick)
        Player.connect("seeked", self.on_seek)
        Player.connect("stopped", self.set_duration)
        if not Player.song:
            self.bar.set_sensitive(False)
Example #3
0
    def __init__(self, init_value=100, min_value=0, max_value=100):
        
        super(VolumeButton, self).__init__()
        self.set_spacing(2)
        self.volume_progressbar = HScalebar(
            app_theme.get_pixbuf("volume/fg.png"),
            app_theme.get_pixbuf("volume/bg.png"),
            app_theme.get_pixbuf("volume/point_normal.png"),
            )
        
        self.volume_button = ToggleButton(
            app_theme.get_pixbuf("volume/high_normal.png"),
            app_theme.get_pixbuf("volume/mute_normal.png"),
            app_theme.get_pixbuf("volume/high_hover.png"),
            app_theme.get_pixbuf("volume/mute_hover.png"),
            app_theme.get_pixbuf("volume/high_press.png"),
            app_theme.get_pixbuf("volume/mute_press.png"),
            )
        
        # Init widget.
        self.volume_progressbar.set_size_request(58, 11)
        self.volume_progressbar.set_range(min_value, max_value)
        self.volume_progressbar.set_value(init_value)
        self.volume_progressbar.connect("button-release-event", self.release_event)
        
        # Signals.
        self.volume_progressbar.get_adjustment().connect("value-changed", self.moniter_volume_change)
        
        # Pack.
        volume_align = gtk.Alignment()
        volume_align.set(0.5, 0.5, 0, 0)
        volume_align.add(self.volume_progressbar)
        
        button_align = gtk.Alignment()
        # button_align.set(0.5, 0.5, 0, 0)
        button_align.add(self.volume_button)

        self.pack_start(button_align, False, False)
        self.pack_start(volume_align, False, False)
Example #4
0
    def __init__(self, draw_time_callback=None):
        super(SongTimer, self).__init__()

        self.label_time = Label("00:00", app_theme.get_color("labelText"), 8, enable_gaussian=True)
        self.draw_time_callback = draw_time_callback
        if draw_time_callback:
            draw_time_callback(self.label_time.get_text())
            
        self.bar = HScalebar()
        self.bar.set_draw_value(False)
        self.bar.set_range(0, 1000)
        self.bar.set_value(0)
        bar_align = gtk.Alignment()
        bar_align.set_padding(0, 0, 2, 2)
        bar_align.set(1, 1, 1, 1)
        bar_align.add(self.bar)
        self.bar.connect("button-press-event", self.on_bar_press)
        self.bar.connect("button-release-event", self.on_bar_release)
        self.__value_changed_id = self.bar.connect("value-changed", self.on_bar_value_changed)
        self.bar.handler_block(self.__value_changed_id)
        self.pack_start(bar_align, True, True)
        self.update_bar = 1
        self.duration = 0
        self.__idle_release_id = None
        self.delete = False
        self.__need_report = False
        self.press_flag = False

        Player.connect("instant-new-song", self.set_duration)
        Player.connect("init-status", self.on_player_init_status)

        Player.bin.connect("tick", self.on_tick)
        Player.connect("seeked", self.on_seek)
        Player.connect("stopped", self.set_duration)
        if not Player.song:
            self.bar.set_sensitive(False)
Example #5
0
class VolumeButton(gtk.HBox):
    
    def __init__(self, init_value=100, min_value=0, max_value=100):
        
        super(VolumeButton, self).__init__()
        self.set_spacing(2)
        self.volume_progressbar = HScalebar(
            app_theme.get_pixbuf("volume/fg.png"),
            app_theme.get_pixbuf("volume/bg.png"),
            app_theme.get_pixbuf("volume/point_normal.png"),
            )
        
        self.volume_button = ToggleButton(
            app_theme.get_pixbuf("volume/high_normal.png"),
            app_theme.get_pixbuf("volume/mute_normal.png"),
            app_theme.get_pixbuf("volume/high_hover.png"),
            app_theme.get_pixbuf("volume/mute_hover.png"),
            app_theme.get_pixbuf("volume/high_press.png"),
            app_theme.get_pixbuf("volume/mute_press.png"),
            )
        
        # Init widget.
        self.volume_progressbar.set_size_request(58, 11)
        self.volume_progressbar.set_range(min_value, max_value)
        self.volume_progressbar.set_value(init_value)
        self.volume_progressbar.connect("button-release-event", self.release_event)
        
        # Signals.
        self.volume_progressbar.get_adjustment().connect("value-changed", self.moniter_volume_change)
        
        # Pack.
        volume_align = gtk.Alignment()
        volume_align.set(0.5, 0.5, 0, 0)
        volume_align.add(self.volume_progressbar)
        
        button_align = gtk.Alignment()
        # button_align.set(0.5, 0.5, 0, 0)
        button_align.add(self.volume_button)

        self.pack_start(button_align, False, False)
        self.pack_start(volume_align, False, False)
            
    def release_event(self, widget, event):    
        pass
        
    def update_volume_button_pixbuf(self, name):
        group = (
            app_theme.get_pixbuf("volume/%s_normal.png" % name),
            app_theme.get_pixbuf("volume/%s_hover.png" % name),
            app_theme.get_pixbuf("volume/%s_press.png" % name),
            app_theme.get_pixbuf("volume/%s_press.png" % name)
            )
        self.volume_button.set_inactive_pixbuf_group(group)
        self.queue_draw()
        
    
    def moniter_volume_change(self, adjustment):
        high_value = adjustment.get_upper()
        lower_value = adjustment.get_lower()
        total_value = high_value - lower_value
        current_value = adjustment.get_value() - lower_value
        
        if current_value > 0:
            if self.volume_button.get_active():
                self.volume_button.set_active(False)
        if current_value == 0:
            self.update_volume_button_pixbuf("zero")
        elif 0 < current_value  <= total_value * 0.3: 
            self.update_volume_button_pixbuf("lower")
        elif total_value * 0.3 < current_value <= total_value * 0.6:
            self.update_volume_button_pixbuf("middle")
        elif total_value * 0.6 < current_value <= total_value:
            self.update_volume_button_pixbuf("high")
Example #6
0
class SongTimer(gtk.HBox):
    __gsignals__ = {
        "play-end": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
    }

    def __init__(self, draw_time_callback=None):
        super(SongTimer, self).__init__()

        self.label_time = Label("00:00",
                                app_theme.get_color("labelText"),
                                8,
                                enable_gaussian=True)
        self.draw_time_callback = draw_time_callback
        if draw_time_callback:
            draw_time_callback(self.label_time.get_text())

        self.bar = HScalebar()
        self.bar.set_draw_value(False)
        self.bar.set_range(0, 1000)
        self.bar.set_value(0)
        bar_align = gtk.Alignment()
        bar_align.set_padding(0, 0, 2, 2)
        bar_align.set(1, 1, 1, 1)
        bar_align.add(self.bar)
        self.bar.connect("button-press-event", self.on_bar_press)
        self.bar.connect("button-release-event", self.on_bar_release)
        self.__value_changed_id = self.bar.connect("value-changed",
                                                   self.on_bar_value_changed)

        self.pack_start(bar_align, True, True)
        self.update_bar = 1
        self.duration = 0
        self.__idle_release_id = None
        self.delete = False
        self.__need_report = False
        self.press_flag = False

        Player.connect("instant-new-song", self.set_duration)
        Player.connect("init-status", self.on_player_init_status)

        Player.bin.connect("tick", self.on_tick)
        Player.connect("seeked", self.on_seek)
        Player.connect("stopped", self.set_duration)
        if not Player.song:
            self.bar.set_sensitive(False)

    def on_player_init_status(self, player):
        self.label_time.set_text("00:00")
        self.bar.set_value(0)
        self.bar.set_sensitive(True)
        if self.draw_time_callback:
            self.draw_time_callback(self.label_time.get_text())

    def get_label(self):
        return self.label_time

    def stop(self):
        self.delete = True

    def set_duration(self, player, song=None):
        if not song:
            if player.song: song = player.song
            else: return
        else:
            self.__need_report = True

        self.duration = song.get("#duration", 0) / 1000
        self.set_current_time(0, self.duration)

    def on_tick(self, bin, pos, duration):
        if Player.song:
            if Player.song.get_type() == "webcast":
                duration = 0

        pos /= 1000.0
        duration /= 1000.0

        if Player.song and Player.song.get_type() == "cue":
            duration = Player.song.get("#duration") / 1000
            pos = pos - Player.song.get("seek", 0)

        self.duration = duration
        if self.update_bar == 1:
            self.set_current_time(pos, duration)
        return not self.delete

    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)

    def on_seek(self, *args, **kwargs):
        self.__need_report = False

    def on_bar_value_changed(self, widget):
        pos = self.bar.get_value()
        self.set_current_time(pos, self.duration)

    def on_bar_press(self, widget, event):
        if not self.press_flag:
            if self.__idle_release_id:
                gobject.source_remove(self.__idle_release_id)
                self.__idle_release_id = None
            self.update_bar = 0
            self.__need_report = False

            self.bar.disconnect(self.__value_changed_id)
            self.press_flag = True

    def __idle_release(self):
        self.update_bar = 1
        self.__idle_release_id = None

    def on_bar_release(self, widget, event):
        if self.press_flag:
            self.__value_changed_id = self.bar.connect(
                "value-changed", self.on_bar_value_changed)

            s = Player.song
            if not s:
                return
            if s.get_type() in [
                    "webcast",
            ]:
                return

            if s.get_type() == "cue":
                Player.seek(s.get("seek", 0) + self.bar.get_value())
            else:
                Player.seek(self.bar.get_value())

            # wait a bit that the player are really seek to update the progress bar
            # if not self.__idle_release_id:
            self.__idle_release()
            self.__idle_release_id = gobject.idle_add(self.__idle_release)
            self.press_flag = False
Example #7
0
class SongTimer(gtk.HBox):
    __gsignals__ = {
        "play-end" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
    }
    def __init__(self, draw_time_callback=None):
        super(SongTimer, self).__init__()

        self.label_time = Label("00:00", app_theme.get_color("labelText"), 8, enable_gaussian=True)
        self.draw_time_callback = draw_time_callback
        if draw_time_callback:
            draw_time_callback(self.label_time.get_text())
            
        self.bar = HScalebar()
        self.bar.set_draw_value(False)
        self.bar.set_range(0, 1000)
        self.bar.set_value(0)
        bar_align = gtk.Alignment()
        bar_align.set_padding(0, 0, 2, 2)
        bar_align.set(1, 1, 1, 1)
        bar_align.add(self.bar)
        self.bar.connect("button-press-event", self.on_bar_press)
        self.bar.connect("button-release-event", self.on_bar_release)
        self.__value_changed_id = self.bar.connect("value-changed", self.on_bar_value_changed)
        self.bar.handler_block(self.__value_changed_id)
        self.pack_start(bar_align, True, True)
        self.update_bar = 1
        self.duration = 0
        self.__idle_release_id = None
        self.delete = False
        self.__need_report = False
        self.press_flag = False

        Player.connect("instant-new-song", self.set_duration)
        Player.connect("init-status", self.on_player_init_status)

        Player.bin.connect("tick", self.on_tick)
        Player.connect("seeked", self.on_seek)
        Player.connect("stopped", self.set_duration)
        if not Player.song:
            self.bar.set_sensitive(False)
            
    def on_player_init_status(self, player):        
        self.label_time.set_text("00:00")
        self.bar.set_value(0)
        self.bar.set_sensitive(True)
        if self.draw_time_callback:
            self.draw_time_callback(self.label_time.get_text())
            

    def get_label(self):
        return self.label_time
    
    def stop(self):
        self.delete = True

    def set_duration(self, player, song=None):
        if not song:
            if player.song: song = player.song
            else: return
        else:
            self.__need_report = True
        
        self.duration = song.get("#duration", 0) / 1000
        self.set_current_time(0, self.duration)
        
    def on_tick(self, bin, pos, duration):
        if Player.song:
            if Player.song.get_type() == "webcast":
                duration = 0
        
        pos /= 1000.0
        duration /= 1000.0
        
        if Player.song and Player.song.get_type() == "cue":
            duration = Player.song.get("#duration") / 1000
            pos = pos - Player.song.get("seek", 0)
            
        self.duration = duration
        if self.update_bar == 1:
            self.set_current_time(pos, duration)
        return not self.delete

    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)

    def on_seek(self, *args, **kwargs):
        self.__need_report = False
    
    def on_bar_value_changed(self, widget):        
        pos = self.bar.get_value()
        self.set_current_time(pos, self.duration)

    def on_bar_press(self, widget, event):
        if not self.press_flag:
            if self.__idle_release_id:
                gobject.source_remove(self.__idle_release_id)
                self.__idle_release_id = None
            self.update_bar = 0
            self.__need_report = False
            
            try:
                self.bar.handler_unblock(self.__value_changed_id)
            except: pass
            
            self.press_flag = True

    def __idle_release(self):
        self.update_bar = 1
        self.__idle_release_id = None

    def on_bar_release(self, widget, event):
        if self.press_flag:
            try:
                self.bar.handler_block(self.__value_changed_id)
            except:    
                pass
            
            s = Player.song
            if not s :
                return
            if s.get_type() in [ "webcast",]:
                return
            
            if s.get_type() == "cue":
                Player.seek(s.get("seek", 0) + self.bar.get_value())
            else:    
                Player.seek(self.bar.get_value())
            
            # wait a bit that the player are really seek to update the progress bar
            # if not self.__idle_release_id:
            self.__idle_release()
            self.__idle_release_id = gobject.idle_add(self.__idle_release)
            self.press_flag = False
Example #8
0
class SongTimer(gtk.HBox):
    __gsignals__ = {
        "play-end" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
    }
    def __init__(self):
        super(SongTimer, self).__init__()

        self.label_time = Label("00:00/00:00", app_theme.get_color("labelText"), 8, enable_gaussian=True)

        self.bar = HScalebar()
        self.bar.set_draw_value(False)
        self.bar.set_range(0, 1000)
        self.bar.set_value(0)
        self.bar.connect("button_press_event", self.on_bar_press)
        self.bar.connect("button_release_event", self.on_bar_release)
        self.__value_changed_id = self.bar.connect("value-changed", self.on_bar_value_changed)
        self.bar.handler_block(self.__value_changed_id)
        self.pack_start(self.bar, True, True)
        self.update_bar = 1
        self.duration = 0
        self.__idle_release_id = None
        self.delete = False
        self.__need_report = False

        Player.connect("instant-new-song", self.set_duration)

        Player.bin.connect("tick", self.on_tick)
        Player.connect("seeked", self.on_seek)
        Player.connect("stopped", self.set_duration)
        if not Player.song:
            self.bar.set_sensitive(False)

    def get_label(self):
        return self.label_time
    
    def stop(self):
        self.delete = True

    def set_duration(self, player, song=None):
        if not song:
            if player.song: song = player.song
            else: return
        else:
            self.__need_report = True
        
        self.duration = song.get("#duration", 0) / 1000
        self.set_current_time(0, self.duration)
        
    def on_tick(self, bin, pos, duration):
        self.duration = duration
        if self.update_bar == 1:
            self.set_current_time(pos, duration)
        return not self.delete

    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)

    def on_seek(self, *args, **kwargs):
        self.__need_report = False
    
    def on_bar_value_changed(self, widget):        
        pos = self.bar.get_value()
        self.set_current_time(pos, self.duration)

    def on_bar_press(self, widget, event):
        if self.__idle_release_id:
            gobject.source_remove(self.__idle_release_id)
            self.__idle_release_id = None
        self.update_bar = 0
        self.__need_report = False

        self.bar.handler_unblock(self.__value_changed_id)

    def __idle_release(self):
        self.update_bar = 1
        self.__idle_release_id = None

    def on_bar_release(self, widget, event):
        self.bar.handler_block(self.__value_changed_id)
        
        s = Player.song
        if s is not None and s.get_type() in [ "webradio", "volatile_webradio"]:
            return
        Player.seek(self.bar.get_value())

        # wait a bit that the player are really seek to update the progress bar
        if not self.__idle_release_id:
            self.__idle_release()
            self.__idle_release_id = gobject.idle_add(self.__idle_release)