Beispiel #1
0
class MusicBar(Frame):
    def __init__(self, parent, music_filepath):
        Frame.__init__(self, parent)
        self.player = Player(music_filepath)
        
        title = os.path.basename(music_filepath) 

        label = tkinter.Label(self, text=title, width=30)
        label.pack(side=LEFT)

        padx = 10
        #image = tkinter.PhotoImage(file=icon_play)
        play_button = Button(self, text="Play")#image=image)
        play_button.pack(side=LEFT, padx=padx)
        play_button.bind("<Button-1>", self.play)
        
        #image = tkinter.PhotoImage(file=icon_pause)
        #pause_button = Button(self, text="Pause")#image=image)
        #pause_button.pack(side=LEFT, padx=padx)
        #pause_button.bind("<Button-1>", self.pause)
        #self.pausing = False
        
        #image = tkinter.PhotoImage(file=icon_stop)
        stop_button = Button(self, text="Stop")#image=image)
        stop_button.pack(side=LEFT, padx=padx)
        stop_button.bind("<Button-1>", self.stop)
 
        #MusicBar(self, music_filepath)

    def play(self, event):
        self.player.play()

    def stop(self, event):
        self.player.stop()
Beispiel #2
0
def reset_music():
    global albumCover
    global songTitle
    global albumTitle
    global totalTime
    global musicData
    global currentMusic
    global durationTime
    global slider
    global anim
    global image
    global start
    global currentValue
    global anim_timeline
    global playedTime
    global player

    if (anim_timeline != None):
        lv.anim_timeline_stop(anim_timeline)
        lv.anim_timeline_del(anim_timeline)
        anim_timeline = None

    albumCover.set_src(musicData[currentMusic]["album_url"])
    songTitle.set_text(musicData[currentMusic]["title"])
    albumTitle.set_text(musicData[currentMusic]["album"])
    durationTime = musicData[currentMusic]["duration"]

    currentValue = 0

    slider.set_range(0, durationTime)
    slider.set_value(0, lv.ANIM.ON)
    anim.set_time(durationTime * 1000)
    anim.set_values(0, durationTime)
    anim_timeline = lv.anim_timeline_create()
    lv.anim_timeline_add(anim_timeline, 0, anim)

    setLabelValue(totalTime, durationTime)
    setLabelValue(playedTime, 0)

    if (player != None):
        player.pause()
        player.close()
        player = None

    if (start == False):
        image[1].set_src(RESOURCES_ROOT + "images/play.png")
    else:
        image[1].set_src(RESOURCES_ROOT + "images/pause.png")
        lv.anim_timeline_start(anim_timeline)
        player = Player()
        player.open()
        player.play(musicData[currentMusic]["url"], sync=False)
        player.on(cb)

    if (musicData[currentMusic]["favorite"] == False):
        image[3].set_src(RESOURCES_ROOT + "images/favorite.png")
    else:
        image[3].set_src(RESOURCES_ROOT + "images/favorited.png")
def init_audio():
    global player
    Snd.install_codec_driver()
    Snd.init()
    player = Player()
    player.create()
    player.set_volume(8)
Beispiel #4
0
    def __init__(self):
        logger.info('Bonjob started')

        # Menu indicator
        self.ind = app3.Indicator.new('Bonjob',
                                      'Bonjob',
                                      app3.IndicatorCategory.APPLICATION_STATUS)
        self.ind.set_status(app3.IndicatorStatus.ACTIVE)
        self.state = 'idle'
        self.ind.set_icon(self.imgpath())

        # init modules
        self.player = Player()
        self.mset = MenuSet()
        # Counter for timer
        self.break_counter = 0

        #####################
        ##### GUI setup #####
        #####################

        self.menu = Gtk.Menu()
        self.item = Gtk.MenuItem('Start')
        self.item.connect('activate', self.control_click)
        self.item.show()
        self.menu.append(self.item)
        # Separator
        separator = Gtk.SeparatorMenuItem()
        separator.show()
        self.menu.append(separator)
        # Settings
        item2 = Gtk.MenuItem('Settings')
        item2.connect('activate', self.pref, None)
        item2.show()
        self.menu.append(item2)
        # A quit item
        item3 = Gtk.MenuItem('Quit')
        item3.connect('activate', self.quit, None)
        item3.show()
        self.menu.append(item3)

        self.menu.show_all()
        self.ind.set_menu(self.menu)
Beispiel #5
0
def init_audio():
    global player
    Snd.init()
    player = Player()
    player.open()
    player.setVolume(8)
Beispiel #6
0
def controller_click_cb(e, func):
    global anim
    global start
    global anim_timeline
    global durationTime
    global player
    global image
    global currentValue
    global musicData
    global currentMusic

    print(func, anim_timeline)
    if (func == "play"):
        if (start == False):
            start = True

            if (currentValue == durationTime):
                currentValue = 0
                anim.set_time((durationTime - currentValue) * 1000)
                anim.set_values(currentValue, durationTime)
                anim_timeline = lv.anim_timeline_create()
                lv.anim_timeline_add(anim_timeline, 0, anim)

            lv.anim_timeline_start(anim_timeline)
            image[1].set_src(RESOURCES_ROOT + "images/pause.png")

            if (player == None):
                player = Player()
                player.open()
                player.play(musicData[currentMusic]["url"], sync=False)
                player.on(cb)

            else:
                player.resume()
                # state = player.getState()
                # print(state)
                # if (state == 2):
                #     player.resume()
                #     image[1].set_src(RESOURCES_ROOT + "images/pause.png")
                # else:
                #     player.pause()
                #     image[1].set_src(RESOURCES_ROOT + "images/play.png")
        else:
            start = False

            image[1].set_src(RESOURCES_ROOT + "images/play.png")

            lv.anim_timeline_stop(anim_timeline)
            lv.anim_timeline_del(anim_timeline)
            anim_timeline = None

            anim.set_time((durationTime - currentValue) * 1000)
            anim.set_values(currentValue, durationTime)
            anim_timeline = lv.anim_timeline_create()
            lv.anim_timeline_add(anim_timeline, 0, anim)
            player.pause()
    elif (func == "fav"):
        if (musicData[currentMusic]["favorite"] == False):
            image[3].set_src(RESOURCES_ROOT + "images/favorited.png")
            musicData[currentMusic]["favorite"] = True
        else:
            musicData[currentMusic]["favorite"] = False
            image[3].set_src(RESOURCES_ROOT + "images/favorite.png")

    elif (func == "next"):
        currentMusic += 1
        if (len(musicData) == currentMusic):
            currentMusic = 0

        reset_music()

    elif (func == "prev"):
        currentMusic -= 1
        if (currentMusic < 0):
            currentMusic = len(musicData) - 1

        reset_music()
Beispiel #7
0
class Bonjob:
    def __init__(self):
        logger.info('Bonjob started')

        # Menu indicator
        self.ind = app3.Indicator.new('Bonjob',
                                      'Bonjob',
                                      app3.IndicatorCategory.APPLICATION_STATUS)
        self.ind.set_status(app3.IndicatorStatus.ACTIVE)
        self.state = 'idle'
        self.ind.set_icon(self.imgpath())

        # init modules
        self.player = Player()
        self.mset = MenuSet()
        # Counter for timer
        self.break_counter = 0

        #####################
        ##### GUI setup #####
        #####################

        self.menu = Gtk.Menu()
        self.item = Gtk.MenuItem('Start')
        self.item.connect('activate', self.control_click)
        self.item.show()
        self.menu.append(self.item)
        # Separator
        separator = Gtk.SeparatorMenuItem()
        separator.show()
        self.menu.append(separator)
        # Settings
        item2 = Gtk.MenuItem('Settings')
        item2.connect('activate', self.pref, None)
        item2.show()
        self.menu.append(item2)
        # A quit item
        item3 = Gtk.MenuItem('Quit')
        item3.connect('activate', self.quit, None)
        item3.show()
        self.menu.append(item3)

        self.menu.show_all()
        self.ind.set_menu(self.menu)

    def quit(self, widget, args):
        """ Stop all and quit program """
        # Exit timer
        self.break_timer = True
        # Kill music
        self.player.kill()
        # Exit GUI
        Gtk.main_quit()

    def imgpath(self):
        """ Get absolute path for current state img """
        dirname = os.path.dirname(__file__)
        real = os.path.join(dirname, 'images', self.state + '.png')
        abs_path = os.path.abspath(real)

        return abs_path

    def change_icon(self):
        """ Change menu app icon """
        icon_path = self.imgpath()
        self.ind.set_icon(icon_path)

    def pref(self, *args):
        """ Open window with settings """
        win = prefs.SettingsWindow()
        win.show_all()
        prefs.Gtk.main()

        # Get object with changed settings
        self.mset = MenuSet()

    def control_click(self, *args):
        """ Start/Stop menu click """

        logger.info('Leave %s state' % self.state)

        if self.state == 'idle':
            self.item.get_child().set_text('Stop')
            self.break_timer = False
            self.timer()
        elif self.state == 'break':
            self.item.get_child().set_text('Start')
            self.break_timer = True
            self.state = 'idle'
            self.notify('Stop')
            logger.info('Start %s state' % self.state)
        else:
            self.item.get_child().set_text('Start')
            self.break_timer = True
            self.state = 'idle'
            self.notify('Stop')
            logger.info('Start %s state' % self.state)

    def timer(self):
        """
        Main status control method
        based on time settings from config.ini file.
        break_counter - counter of the short breaks
        """
        # Exit if stopped
        if self.break_timer is True:
            return

        if self.state == 'working':
            self.state = 'break'
            logger.info('Start %s state' % self.state)

            if self.break_counter == float(self.mset.maxshort_break):
                self.break_counter = 0
                self.notify('Time for long break')
                time = float(self.mset.long_break) * 60000
                GObject.timeout_add(time, self.timer)
            else:
                self.break_counter += 1
                self.notify('Time for short break')
                time = float(self.mset.short_break) * 60000
                GObject.timeout_add(time, self.timer)
        else:
            self.state = 'working'
            logger.info('Start %s state' % self.state)
            self.notify('Time to work')
            time = float(self.mset.pub_time) * 60000
            GObject.timeout_add(time, self.timer)

    def notify(self, message):
        """
        Notify about timeout signals.
        Change icon, play mausic, show message.
        """
        # Change menu icon
        self.change_icon()

        if self.state == 'break':
            # Play single file
            if self.mset.song_switch == 'on':
                self.player.play_single(self.mset.filename)

            # Play files from folder
            if self.mset.songs_switch == 'on':
                self.player.play_list(self.mset.foldername)
        else:
            if self.mset.song_switch == 'on' or self.mset.songs_switch == 'on':
                self.player.kill()

        # Show window message
        if self.mset.tooltip_switch == 'on':
            task = 'notify-send -u normal "%s" -i %s' % (message, self.imgpath())
            subprocess.Popen(task, shell=True)

    def main(self):
        Gtk.main()