Exemplo n.º 1
0
def box_add(
    box: Gtk.Box,
    widget: Gtk.Widget,
    expand: bool = True,
    fill: bool = True,
    padding: int = 0,
):
    box.pack_start(widget, expand, fill, padding)
    box.show_all()
Exemplo n.º 2
0
    def add_button_if_pos_mark(self, box: Gtk.Box, buffer: Gtk.TextBuffer):
        textiter = buffer.get_iter_at_offset(buffer.props.cursor_position)
        pos = self._get_start_pos_mark(textiter)
        if pos is None or pos != self._active_pos:
            self.reset(box)

        if pos is not None and pos != self._active_pos:
            self._active_pos = pos
            self._active_widget: Gtk.Button = Gtk.Button.new_with_label('Edit Position Mark')
            self._active_widget.connect('clicked', self.on_clicked)
            box.pack_start(self._active_widget, True, False, 0)

        return True
Exemplo n.º 3
0
    def on_load(self, container: Gtk.Box) -> None:

        self._builder = Builder("services-transfer.ui")
        self.widget = self._builder.get_widget("transfer", Gtk.Widget)

        container.pack_start(self.widget, True, True, 0)
        a = AppletService()
        if "TransferService" in a.QueryPlugins():
            self._setup_transfer()
        else:
            self.widget.props.sensitive = False
            self.widget.props.tooltip_text = _(
                "Applet's transfer service plugin is disabled")
Exemplo n.º 4
0
    def on_load(self, container: Gtk.Box) -> None:

        self.Builder = Gtk.Builder()
        self.Builder.set_translation_domain("blueman")
        self.Builder.add_from_file(UI_PATH + "/services-transfer.ui")
        self.widget = self.Builder.get_object("transfer")

        container.pack_start(self.widget, True, True, 0)
        a = AppletService()
        if "TransferService" in a.QueryPlugins():
            self._setup_transfer()
        else:
            self.widget.props.sensitive = False
            self.widget.props.tooltip_text = _("Applet's transfer service plugin is disabled")
Exemplo n.º 5
0
    def on_load(self, container: Gtk.Box) -> None:

        self._builder = Builder("services-network.ui")
        self.widget = self._builder.get_widget("network_frame", Gtk.Widget)

        container.pack_start(self.widget, True, True, 0)

        self.interfaces: List[Tuple[str, ipaddress.IPv4Interface]] = []
        netifs = get_local_interfaces()
        for iface in netifs:
            if iface != "lo" and iface != "pan1":
                logging.info(iface)
                ipiface = ipaddress.ip_interface('/'.join(
                    cast(Tuple[str, str], netifs[iface])))
                self.interfaces.append((iface, ipiface))

        self.setup_network()
        try:
            self.ip_check()
        except (ValueError, ipaddress.AddressValueError) as e:
            logging.exception(e)
Exemplo n.º 6
0
class ReaderWindow(ApplicationWindow):

    __gtype_name__ = 'ReaderWindow'

    def __init__(self, **kwargs):
        super(ReaderWindow, self).__init__(
            title='Eearth Reader',
            **kwargs
        )
        app = self.get_application()
        assert isinstance(app, EarthReaderApp)
        self.set_wmclass('Earth Reader', 'Earth Reader')
        self.set_icon_list(ICON_LIST)
        self.box = Box(spacing=0)
        self.add(self.box)
        subscriptions = SubscriptionTreeModel(app.stage)
        self.subscriptions_sidebar = ScrolledWindow()
        self.subscription_list = TreeView(subscriptions)
        cell_renderer = CellRendererText()
        subscription_column = TreeViewColumn('Title', cell_renderer, text=0)

        def cell_data_func(column, renderer, model, tree_iter, *args):
            if isinstance(model[tree_iter], Category):
                renderer.set_property('cell-background', 'silver')
            else:
                renderer.set_property('cell-background', None)

        subscription_column.set_cell_data_func(cell_renderer, cell_data_func)
        self.subscription_list.append_column(subscription_column)
        self.subscriptions_sidebar.add(self.subscription_list)
        self.box.pack_start(self.subscriptions_sidebar,
                            expand=True, fill=True, padding=0)
        entries_store = dummy_entries()
        entry_column = TreeViewColumn('Title', CellRendererText(), text=0)
        self.entry_list_box = ScrolledWindow()
        self.entry_list = TreeView(entries_store)
        self.entry_list.append_column(entry_column)
        self.entry_list_box.add(self.entry_list)
        self.box.pack_start(self.entry_list_box,
                            expand=True, fill=True, padding=0)
        self.content_view = WebView()
        self.box.pack_start(self.content_view,
                            expand=True, fill=True, padding=0)
Exemplo n.º 7
0
    def on_selection_changed(self, icon_view, album=None):
        popup = Popover.new(self.albumview)
        popup.set_size_request(810, 240)

        if album is None:
            selection = icon_view.get_selected_items()
            if len(selection) != 1:
                return

            path = selection[0]
            treeiter = self.albumfilter.get_iter(path)

            isset, path, cell = icon_view.get_cursor()
            isset, rect = icon_view.get_cell_rect(path, cell)
            popup.set_pointing_to(rect)

            album_id = self.albumfilter.get_value(treeiter, 4)
            album_obj = self.albums[album_id]
        else:
            album_obj = album
            popup.set_relative_to(self.search_entry)

        # Handle double clicks
        def empty_dblclick():
            self.dblclick = None

        if self.dblclick is None:
            self.dblclick = album_obj
            timeout_add(1000, empty_dblclick)
        elif self.dblclick == album_obj:
            self.play(album_obj)
            return

        album = album_obj.name
        artist = album_obj.artist

        glade_album = join(self.functions.datadir, 'glade', 'albumview.ui')
        box = gtk_builder()
        box.set_translation_domain('bluemindo')
        box.add_from_file(glade_album)
        popup.add(box.get_object('box1'))

        box.get_object('label_album').set_text(album)
        box.get_object('label_artist').set_text(artist)

        bdir = join(self.userconf.datadir, 'modules', 'player', 'covers')
        cover = join(bdir, self.functions.get_hash(album, artist))
        if isfile(cover):
            cover_px = Pixbuf.new_from_file_at_scale(cover, 180, 180, True)
        else:
            cover_px = Pixbuf.new_from_file(join(self.functions.datadir,
                                            'image', 'logo_head_big.png'))

        box.get_object('album_cover').set_from_pixbuf(cover_px)

        def play_album(wdg, album):
            self.play(album)

        def queue_album(wdg, album):
            self.queue(album)

        def change_cover(wdg, ka, album):
            artist_name = album.artist
            album_name = album.name

            fcdialog = FileChooserDialog(
                        title=_('Change the cover picture for this album'),
                        buttons=(_('Select'), ResponseType.OK))

            fcdialog.set_transient_for(self.widgets[0][11])
            response = fcdialog.run()
            if response == ResponseType.OK:
                filename = fcdialog.get_filename()

                datadir = self.userconf.datadir
                hash_a = self.functions.get_hash(album_name, artist_name)
                pictures_dir = join(datadir, 'modules', 'player', 'covers')
                album_file = join(pictures_dir, hash_a)

                copyfile(filename, album_file)

                new = Pixbuf.new_from_file_at_scale(album_file, 180, 180, True)
                box.get_object('album_cover').set_from_pixbuf(new)

            fcdialog.destroy()

        box.get_object('button_play').connect('clicked', play_album, album_obj)

        box.get_object('button_add').connect('clicked', queue_album, album_obj)

        box.get_object('coverevent').connect('button-press-event',
                                             change_cover, album_obj)

        i = 0
        a = -1
        previous_column = 0

        grid_songs = box.get_object('grid_songs')
        grid_songs.set_size_request(-1, 200)
        grid_songs.set_column_spacing(5)

        try:
            kids = grid_songs.get_children()
            for kid in kids:
                grid_songs.remove(kid)
        except IndexError:
            pass

        for song in album_obj.tracks:
            i += 1
            a += 1

            def queue(wdg, song):
                self.queue(song)

            def play(wdg, song):
                self.play(song)

            song_wdg = Box(spacing=0)
            song_btr = Button()
            song_btr.connect('clicked', play, song)
            song_btr.set_relief(ReliefStyle.NONE)
            song_btr_content = Box(spacing=0)
            song_btr.add(song_btr_content)

            song_tr = Label()
            song_tr.set_markup('<span foreground="grey">' + str(song.track)
                               + '</span>')
            song_tr.set_width_chars(3)
            song_btr_content.pack_start(song_tr, False, True, 0)
            song_ti = Label()
            song_ti.set_markup('<b>' + self.functions.view_encode(song.title, 22)
                               + '</b>')
            song_ti.set_alignment(0.0, 0.5)
            song_ti.set_size_request(190, -1)
            song_btr_content.pack_start(song_ti, False, False, 0)

            length = self.functions.human_length(song.length)
            song_le = Label()
            song_le.set_markup('<span foreground="grey">' + length
                               + '</span>')
            song_le.set_width_chars(5)
            song_btr_content.pack_start(song_le, False, True, 0)

            song_wdg.pack_start(song_btr, False, False, 0)

            song_add = Button.new_from_icon_name('list-add-symbolic', 0)
            song_add.set_property('relief', 2)
            song_add.set_size_request(14, 14)
            song_add.connect('clicked', queue, song)
            song_wdg.pack_start(song_add, False, False, 0)

            if i <= len(album_obj.tracks)/2:
                column = 0
                previous_column = 0
                row = a
            else:
                if previous_column == 0:
                    a = 0
                column = 1
                previous_column = 1
                row = a

            grid_songs.attach(song_wdg, column, row, 1, 1)
        popup.show_all()
Exemplo n.º 8
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()