Exemplo n.º 1
0
    def __init__(self, extensions):
        # Start threads
        threads_init()

        self.extensions = extensions

        # Create the main Bluemindo window
        self.main_window = Window()
        functions.open_bluemindo(self.main_window)

        # Handling close button
        def close_window(wdg, ka):
            functions.close_bluemindo(self.main_window, True)

        self.main_window.connect('delete_event', close_window)

        # Create the whole Header Bar
        box = HeaderBar()
        box.set_show_close_button(True)
        box.props.title = 'Bluemindo'
        self.main_window.set_titlebar(box)

        # Add an icon to the window
        icon_file = join(functions.datadir, 'image', 'logo_head_small.png')
        pixbuf = Pixbuf.new_from_file(icon_file)
        self.main_window.set_icon(pixbuf)

        # Add the about button
        about_button = Button(relief=2)
        about_button.add(
            Image.new_from_gicon(ThemedIcon(name='help-about-symbolic'),
                                 IconSize.BUTTON))
        box.pack_end(about_button)

        # Add the reload button
        refresh_button = Button(relief=2)
        refresh_button.add(
            Image.new_from_gicon(ThemedIcon(name='view-refresh-symbolic'),
                                 IconSize.BUTTON))
        box.pack_end(refresh_button)

        # Add PREVIOUS/STOP/PLAYPAUSE/NEXT buttons
        player_box = Box(orientation=Orientation.HORIZONTAL)
        StyleContext.add_class(player_box.get_style_context(), 'linked')

        previous_b = Button()
        previous_b.set_size_request(42, -1)
        previous_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-skip-backward-symbolic'),
                IconSize.BUTTON))
        player_box.add(previous_b)

        stop_b = Button()
        stop_b.set_size_request(42, -1)
        stop_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-playback-stop-symbolic'),
                IconSize.BUTTON))
        player_box.add(stop_b)

        playpause_b = Button()
        playpause_b.set_size_request(55, -1)
        playpause_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-playback-start-symbolic'),
                IconSize.BUTTON))
        player_box.add(playpause_b)

        next_b = Button()
        next_b.set_size_request(42, -1)
        next_b.add(
            Image.new_from_gicon(
                ThemedIcon(name='media-skip-forward-symbolic'),
                IconSize.BUTTON))
        player_box.add(next_b)

        box.pack_start(player_box)

        # Create the main window
        glade_main = join(functions.datadir, 'glade', 'mainwindow.ui')
        win = gtk_builder()
        win.set_translation_domain('bluemindo')
        win.add_from_file(glade_main)

        self.main_window.add(win.get_object('box1'))

        # Connect to the about button
        def show_dialog(wdg):
            dialog = AboutDialog()
            dialog.set_transient_for(self.main_window)

            dialog.set_artists(['Thomas Julien <*****@*****.**>'])
            dialog.set_authors([
                'Erwan Briand <*****@*****.**>',
                'Vincent Berset <*****@*****.**>',
                'Thibaut Girka <*****@*****.**>',
                'Ľubomír Remák <*****@*****.**>',
                'Anaël Verrier <*****@*****.**>'
            ])
            dialog.set_translator_credits(
                'Bruno Conde <*****@*****.**>\n' +
                'Niklas Grahn <*****@*****.**>\n' +
                'Ľubomír Remák <*****@*****.**>\n' +
                'Salvatore Tomarchio <*****@*****.**>\n' +
                'Shang Yuanchun <*****@*****.**>')

            dialog.set_copyright('Copyright © 2007-2016 Erwan Briand ' +
                                 '<*****@*****.**>')

            dialog.set_comments(
                _('Ergonomic and modern music player ' +
                  'designed for audiophiles.'))

            dialog.set_license('GNU General Public License (v3)')
            dialog.set_license_type(10)

            dialog.set_program_name('Bluemindo')
            dialog.set_version('1.0RC1')
            dialog.set_website('http://bluemindo.codingteam.net')

            pxbf = Pixbuf.new_from_file_at_scale(
                join(functions.datadir, 'image', 'logo_head_big.png'), 60, 60,
                True)
            dialog.set_logo(pxbf)

            dialog.show_all()

        about_button.connect('clicked', show_dialog)

        # Start main handler
        headerbar_wdg = [
            box, None, about_button, refresh_button, player_box, previous_b,
            stop_b, playpause_b, next_b, None,
            win.get_object('box1'), self.main_window
        ]
        self.wdg = [headerbar_wdg, win]
Exemplo n.º 2
0
        def start_playback(wdg):
            # Create GStreamer instance
            self.gst = GStreamer()
            self.gst.set_playback('gapless')
            self.gst.player.connect('about-to-finish', self.song_nearly_ended)
            self.gst.stop()

            self.current_song = False
            self.current_album = False

            # Prepare buttons
            self.btn_playpause = wdg[0][7]
            self.btn_previous = wdg[0][5]
            self.btn_next = wdg[0][8]
            self.btn_stop = wdg[0][6]

            self.btn_previous.connect('clicked', self.previous_pressed)
            self.btn_stop.connect('clicked', self.stop_pressed)
            self.btn_playpause.connect('clicked', self.play_pressed)
            self.btn_next.connect('clicked', self.next_pressed)

            self.btn_player = wdg[0][9]
            self.headerbar = wdg[0][0]

            # Create the player box and popover
            gtkpla = join(self.functions.datadir, 'glade', 'playerbar.ui')
            win = gtk_builder()
            win.set_translation_domain('bluemindo')
            win.add_from_file(gtkpla)
            basebox = win.get_object('playerbox')
            wdg[0][0].add(basebox)

            self.player_event = win.get_object('player_event')
            self.player_event.set_size_request(32, 32)
            self.player_button_img = win.get_object('image_cover')
            self.player_event.connect('button-press-event', self.show_player)
            default = join(self.functions.datadir, 'image', 'logo_head_big.png')
            cover_px = Pixbuf.new_from_file_at_scale(default, 20, 20, True)
            self.player_button_img.set_from_pixbuf(cover_px)
            self.player_event.set_sensitive(False)

            self.player_scalab = win.get_object('label_scale')
            self.player_scalab.set_markup('<span size="small">00:00</span>')
            self.player_sca = win.get_object('scale')
            self.player_sca.connect('change-value', self.on_change_value)
            self.player_sca.set_sensitive(False)

            # Create the player popover
            gtkpla = join(self.functions.datadir, 'glade', 'playerpopover.ui')
            win = gtk_builder()
            win.add_from_file(gtkpla)
            hbox = win.get_object('box-player')

            self.player_img = win.get_object('image')
            self.player_pop = Popover.new(self.player_event)
            self.player_pop.set_size_request(200, 200)
            self.player_pop.add(hbox)

            self.lyrics_button = wdg[1].get_object('tool-lyrics')
            self.lyrics_pop = Popover.new(self.lyrics_button)
            self.lyrics_pop.set_size_request(400, 600)
            box = Box(1, 0)
            self.lyrics_swin = ScrolledWindow()
            lyrics_tview = TextView()
            lyrics_tview.set_editable(False)
            self.lyrics_buffer = TextBuffer()
            lyrics_tview.set_buffer(self.lyrics_buffer)
            self.lyrics_swin.add(lyrics_tview)
            box.add(self.lyrics_swin)
            self.lyrics_wait = Spinner()
            self.lyrics_wait.props.active = True
            box.add(self.lyrics_wait)
            self.lyrics_pop.add(box)

            def show_lyrics(widget):
                if self.current_song:
                    title = self.current_song.title
                    artist = self.current_song.artist
                    album = self.current_song.album
                    filename = self.current_song.filename

                    sn = self.functions.get_hash(title, artist)
                    lyrics_file = join(self.userconf.datadir, '%s.lyrics' % sn)

                    lyrics = self.lyrics_downloader.get_lyrics(title,
                                                               artist,
                                                               True)

                    self.lyrics_pop.show_all()

                    if lyrics is not None:
                        self.lyrics_wait.hide()
                        self.lyrics_swin.show()
                        self.lyrics_buffer.set_text(lyrics)
                    else:
                        self.lyrics_swin.hide()
                        self.lyrics_wait.show()
                        self.lyrics_buffer.set_text('')

            self.lyrics_button.connect('clicked', show_lyrics)
            self.lyrics_button.set_sensitive(False)
Exemplo n.º 3
0
    def _init_tab(self, notebook_page: Gtk.Box):
        assert self.builder
        layers_box = self.builder.get_object('bg_layers')

        toolbox_box = self.builder.get_object('bg_layers_toolbox')
        toolbox_box_child_layers = self.builder.get_object(
            'bg_layers_toolbox_layers')
        toolbox_box_child_collision = self.builder.get_object(
            'bg_layers_toolbox_collision')
        toolbox_box_child_data = self.builder.get_object(
            'bg_layers_toolbox_data')

        if Gtk.Buildable.get_name(notebook_page) != 'metadata':
            for child in notebook_page.get_children():
                notebook_page.remove(child)
            for child in toolbox_box.get_children():
                toolbox_box.remove(child)

        page_name = Gtk.Buildable.get_name(notebook_page)
        if page_name == 'bg_layer2' and self.bma.number_of_layers < 2:
            # Layer 2: Does not exist
            label: Gtk.Label = Gtk.Label.new(
                _('This map only has one layer.\n'
                  'You can add a second layer at Map > Settings.'))
            label.set_vexpand(True)
            label.show()
            notebook_page.add(label)
        elif page_name in ['bg_layer1', 'bg_layer2']:
            # Layer 1 / 2
            if layers_box.get_parent():
                layers_box.get_parent().remove(layers_box)
            notebook_page.pack_start(layers_box, True, True, 0)

            if toolbox_box_child_layers.get_parent():
                toolbox_box_child_layers.get_parent().remove(
                    toolbox_box_child_layers)
            toolbox_box.pack_start(toolbox_box_child_layers, True, True, 0)

            self._init_chunks_icon_view(0 if page_name == 'bg_layer1' else 1)
            self._init_drawer_layer_selected()
        elif page_name == 'bg_col1' and self.bma.number_of_collision_layers < 1:
            # Collision 1: Does not exist
            label = Gtk.Label.new(
                _('This map has no collision.\n'
                  'You can add collision at Map > Settings.'))
            label.set_vexpand(True)
            label.show()
            notebook_page.add(label)
        elif page_name == 'bg_col2' and self.bma.number_of_collision_layers < 2:
            # Collision 2: Does not exist
            label = Gtk.Label.new(
                _('This map has no second collision layer.\n'
                  'You can add a second collision layer at Map > Settings.'))
            label.set_vexpand(True)
            label.show()
            notebook_page.add(label)
        elif page_name in ['bg_col1', 'bg_col2']:
            # Collision 1 / 2
            if layers_box.get_parent():
                layers_box.get_parent().remove(layers_box)
            notebook_page.pack_start(layers_box, True, True, 0)

            if toolbox_box_child_collision.get_parent():
                toolbox_box_child_collision.get_parent().remove(
                    toolbox_box_child_collision)
            toolbox_box.pack_start(toolbox_box_child_collision, True, True, 0)

            self._init_drawer_collision_selected(0 if page_name ==
                                                 'bg_col1' else 1)
        elif page_name == 'bg_data' and self.bma.unk6 < 1:
            # Data Layer: Does not exist
            label = Gtk.Label.new(
                _('This map has no data layer.\n'
                  'You can add a data layer at Map > Settings.'))
            label.set_vexpand(True)
            label.show()
            notebook_page.add(label)
        elif page_name == 'bg_data':
            # Data Layer
            if layers_box.get_parent():
                layers_box.get_parent().remove(layers_box)
            notebook_page.pack_start(layers_box, True, True, 0)

            if toolbox_box_child_data.get_parent():
                toolbox_box_child_data.get_parent().remove(
                    toolbox_box_child_data)
            toolbox_box.pack_start(toolbox_box_child_data, True, True, 0)

            self._init_data_layer_combobox()
            self._init_drawer_data_layer_selected()
        else:
            # Metadata
            # Nothing to do, tab is already finished.
            pass

        self._update_scales()