Beispiel #1
0
    def _add_list_renderers(self):
        list_widget = self.view.get_generic_view()
        list_widget.set_halign(Gtk.Align.CENTER)
        cols = list_widget.get_columns()
        cells = cols[0].get_cells()
        cells[2].set_visible(False)
        now_playing_symbol_renderer = Gtk.CellRendererPixbuf(xpad=0,
                                                             xalign=0.5,
                                                             yalign=0.5)

        column_now_playing = Gtk.TreeViewColumn()
        column_now_playing.set_fixed_width(48)
        column_now_playing.pack_start(now_playing_symbol_renderer, False)
        column_now_playing.set_cell_data_func(now_playing_symbol_renderer,
                                              self._on_list_widget_icon_render,
                                              None)
        list_widget.insert_column(column_now_playing, 0)

        title_renderer = Gtk.CellRendererText(
            xpad=0,
            xalign=0.0,
            yalign=0.5,
            height=48,
            width=300,
            ellipsize=Pango.EllipsizeMode.END)

        list_widget.add_renderer(title_renderer,
                                 self._on_list_widget_title_render, None)
        cols[0].add_attribute(title_renderer, 'text', 2)

        self.star_handler.add_star_renderers(list_widget, cols)

        duration_renderer = Gd.StyledTextRenderer(xpad=32, xalign=1.0)
        duration_renderer.add_class('dim-label')

        col = Gtk.TreeViewColumn()
        col.pack_start(duration_renderer, False)
        col.set_cell_data_func(duration_renderer,
                               self._on_list_widget_duration_render, None)
        list_widget.append_column(col)

        artist_renderer = Gd.StyledTextRenderer(
            xpad=32, width=300, ellipsize=Pango.EllipsizeMode.END)
        artist_renderer.add_class('dim-label')

        col = Gtk.TreeViewColumn()
        col.set_expand(True)
        col.pack_start(artist_renderer, True)
        col.set_cell_data_func(artist_renderer,
                               self._on_list_widget_artist_render, None)
        col.add_attribute(artist_renderer, 'text', 3)
        list_widget.append_column(col)

        type_renderer = Gd.StyledTextRenderer(
            xpad=32, width=300, ellipsize=Pango.EllipsizeMode.END)
        type_renderer.add_class('dim-label')

        col.pack_end(type_renderer, True)
        col.set_cell_data_func(type_renderer, self._on_list_widget_type_render,
                               None)
Beispiel #2
0
    def _add_list_renderers(self):
        list_widget = self.view.get_generic_view()
        cols = list_widget.get_columns()
        cells = cols[0].get_cells()
        cells[2].set_visible(False)
        now_playing_symbol_renderer = Gtk.CellRendererPixbuf(xalign=1.0)

        column_now_playing = Gtk.TreeViewColumn()
        column_now_playing.set_property('fixed_width', 24)
        column_now_playing.pack_start(now_playing_symbol_renderer, False)
        column_now_playing.add_attribute(now_playing_symbol_renderer,
                                         'visible', 10)
        column_now_playing.add_attribute(now_playing_symbol_renderer,
                                         'icon_name', 8)
        list_widget.insert_column(column_now_playing, 0)

        title_renderer = Gtk.CellRendererText(
            xpad=0,
            xalign=0.0,
            yalign=0.5,
            height=48,
            ellipsize=Pango.EllipsizeMode.END)
        list_widget.add_renderer(title_renderer,
                                 self._on_list_widget_title_render, None)
        cols[0].add_attribute(title_renderer, 'text', 2)

        star_renderer = Gtk.CellRendererPixbuf(xpad=32,
                                               icon_name=self.starIconName)
        list_widget.add_renderer(star_renderer,
                                 self._on_list_widget_star_render, None)
        cols[0].add_attribute(star_renderer, 'visible', 9)

        duration_renderer = Gd.StyledTextRenderer(xpad=32, xalign=1.0)
        duration_renderer.add_class('dim-label')
        list_widget.add_renderer(duration_renderer,
                                 self._on_list_widget_duration_render, None)

        artist_renderer = Gd.StyledTextRenderer(
            xpad=32, ellipsize=Pango.EllipsizeMode.END)
        artist_renderer.add_class('dim-label')
        list_widget.add_renderer(artist_renderer,
                                 self._on_list_widget_artist_render, None)
        cols[0].add_attribute(artist_renderer, 'text', 3)

        type_renderer = Gd.StyledTextRenderer(
            xpad=32, ellipsize=Pango.EllipsizeMode.END)
        type_renderer.add_class('dim-label')
        list_widget.add_renderer(type_renderer,
                                 self._on_list_widget_type_render, None)
Beispiel #3
0
    def __init__(self, player, parentview):
        Gtk.EventBox.__init__(self)
        self.player = player
        self.iterToClean = None
        self.parentview = parentview

        self.ui = Gtk.Builder()
        self.ui.add_from_resource('/org/gnome/Music/AlbumWidget.ui')
        self._create_model()
        self.view = Gd.MainView(shadow_type=Gtk.ShadowType.NONE)
        self.view.set_view_type(Gd.MainViewType.LIST)
        self.album = None
        self.header_bar = None
        self.view.connect('item-activated', self._on_item_activated)
        view_box = self.ui.get_object('view')
        self.ui.get_object('scrolledWindow').set_placement(
            Gtk.CornerType.TOP_LEFT)
        self.view.connect('selection-mode-request',
                          self._on_selection_mode_request)
        child_view = self.view.get_children()[0]
        child_view.set_margin_top(64)
        child_view.set_margin_bottom(64)
        child_view.set_margin_end(32)
        self.view.remove(child_view)
        view_box.add(child_view)
        self.add(self.ui.get_object('AlbumWidget'))
        self.star_handler = StarHandler(self, 9)
        self._add_list_renderers()
        self.get_style_context().add_class('view')
        self.get_style_context().add_class('content-view')
        self.view.get_generic_view().get_style_context().remove_class('view')
        self.show_all()
Beispiel #4
0
 def __init__(self, id_, label, entry):
     self._id = id_
     self._label = label
     self.entry = entry
     self._tag = Gd.TaggedEntryTag()
     self._tag.manager = self
     self.values = []
Beispiel #5
0
    def __init__(self, stack_switcher, search_button, dropdown):
        Gtk.Revealer.__init__(self)
        self.timeout = None
        self.stack_switcher = stack_switcher
        self._search_button = search_button
        self.dropdown = dropdown
        self._searchContainer = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, halign=Gtk.Align.CENTER)
        self._searchContainer.get_style_context().add_class('linked')

        self._search_entry = Gd.TaggedEntry(width_request=500, halign=Gtk.Align.CENTER)
        self._search_entry.connect("changed", self.search_entry_timeout)
        self._search_entry.show()
        self._searchContainer.add(self._search_entry)

        arrow = Gtk.Image.new_from_icon_name('pan-down-symbolic',
                                             Gtk.IconSize.BUTTON)
        self._dropDownButton = Gtk.ToggleButton()
        self._dropDownButton.add(arrow)
        self._dropDownButton.get_style_context().add_class('image-button')
        self._dropDownButton.connect("toggled", self._drop_down_button_toggled)
        self._dropDownButton.show_all()
        self._searchContainer.add(self._dropDownButton)

        self._search_entry.connect("tag-button-clicked", self._search_entry_tag_button_clicked)

        self._searchContainer.show_all()
        self.add(self._searchContainer)
Beispiel #6
0
    def _init_playlist_removal_notification(self):
        if self.pl_todelete_notification:
            self.views[3].really_delete = False
            self.pl_todelete_notification.destroy()
            playlist.delete_playlist(self.views[3].pl_todelete)

        self.notification = Gd.Notification()
        self.notification.set_timeout(20)

        grid = Gtk.Grid(valign=Gtk.Align.CENTER, margin_right=8)
        grid.set_column_spacing(8)
        self.notification.add(grid)

        undo_button = Gtk.Button.new_with_mnemonic(_("_Undo"))
        label = _("Playlist %s removed" % (
            self.views[3].current_playlist.get_title()))
        grid.add(Gtk.Label.new(label))
        grid.add(undo_button)

        self.notification.show_all()
        self._overlay.add_overlay(self.notification)
        self.pl_todelete_notification = self.notification

        self.notification.connect("dismissed", self._playlist_removal_notification_dismissed)
        undo_button.connect("clicked", self._undo_deletion)
Beispiel #7
0
 def __init__(self, id, label, entry):
     self.id = id
     self.label = label
     self.entry = entry
     self.tag = Gd.TaggedEntryTag()
     self.tag.set_style('music-entry-tag')
     self.tag.manager = self
     self.values = []
Beispiel #8
0
    def _add_list_renderers(self):
        type_renderer = Gd.StyledTextRenderer(
            xpad=8, ypad=8, ellipsize=Pango.EllipsizeMode.END, xalign=0.0)

        cols = Gtk.TreeViewColumn()
        cols.pack_start(type_renderer, True)
        cols.add_attribute(type_renderer, "text", 0)
        cols.set_cell_data_func(type_renderer, self._on_list_text_render)
        self._view.append_column(cols)
Beispiel #9
0
 def _add_list_renderers(self):
     cols = Gtk.TreeViewColumn()
     type_renderer = Gd.StyledTextRenderer(
         xpad=8, ypad=8, ellipsize=Pango.EllipsizeMode.END, xalign=0.0)
     type_renderer.connect('editing-started', self._on_editing_started,
                           None)
     cols.pack_start(type_renderer, True)
     cols.add_attribute(type_renderer, "text", 0)
     cols.add_attribute(type_renderer, "editable", 1)
     cols.set_cell_data_func(type_renderer, self._on_list_text_render)
     self.view.append_column(cols)
Beispiel #10
0
    def _add_list_renderers(self):
        list_widget = self.view.get_generic_view()

        cols = list_widget.get_columns()
        cols[0].set_min_width(100)
        cols[0].set_max_width(200)
        cells = cols[0].get_cells()
        cells[2].set_visible(False)
        cells[1].set_visible(False)

        now_playing_symbol_renderer = Gtk.CellRendererPixbuf(xpad=0,
                                                             xalign=1.0,
                                                             yalign=0.5)

        column_now_playing = Gtk.TreeViewColumn()
        column_now_playing.set_fixed_width(24)
        column_now_playing.pack_start(now_playing_symbol_renderer, False)
        column_now_playing.add_attribute(now_playing_symbol_renderer,
                                         'visible', 9)
        column_now_playing.add_attribute(now_playing_symbol_renderer,
                                         'icon_name', 7)
        list_widget.insert_column(column_now_playing, 0)

        type_renderer = Gd.StyledTextRenderer(
            xpad=16, ellipsize=Pango.EllipsizeMode.END, xalign=0.0)
        list_widget.add_renderer(type_renderer, lambda *args: None, None)
        cols[0].clear_attributes(type_renderer)
        cols[0].add_attribute(type_renderer, 'markup', 0)

        durationRenderer = Gd.StyledTextRenderer(
            xpad=16, ellipsize=Pango.EllipsizeMode.END, xalign=1.0)
        durationRenderer.add_class('dim-label')
        list_widget.add_renderer(durationRenderer, lambda *args: None, None)
        cols[0].clear_attributes(durationRenderer)
        cols[0].add_attribute(durationRenderer, 'markup', 1)

        star_renderer = CellRendererClickablePixbuf(self.view)
        star_renderer.connect("clicked", self._on_star_toggled)
        list_widget.add_renderer(star_renderer, lambda *args: None, None)
        cols[0].clear_attributes(star_renderer)
        cols[0].add_attribute(star_renderer, 'show_star', 10)
Beispiel #11
0
    def _add_list_renderers(self):
        list_widget = self.view.get_generic_view()

        cols = list_widget.get_columns()
        cols[0].set_min_width(100)
        cols[0].set_max_width(200)
        cells = cols[0].get_cells()
        cells[2].set_visible(False)
        cells[1].set_visible(False)

        now_playing_symbol_renderer = Gtk.CellRendererPixbuf(xpad=0,
                                                             xalign=0.5,
                                                             yalign=0.5)

        column_now_playing = Gtk.TreeViewColumn()
        column_now_playing.set_fixed_width(48)
        column_now_playing.pack_start(now_playing_symbol_renderer, False)
        column_now_playing.set_cell_data_func(now_playing_symbol_renderer,
                                              self._on_list_widget_icon_render, None)
        list_widget.insert_column(column_now_playing, 0)

        type_renderer = Gd.StyledTextRenderer(
            xpad=16,
            ellipsize=Pango.EllipsizeMode.END,
            xalign=0.0
        )
        list_widget.add_renderer(type_renderer, lambda *args: None, None)
        cols[0].clear_attributes(type_renderer)
        cols[0].add_attribute(type_renderer, 'markup', 0)

        durationRenderer = Gd.StyledTextRenderer(
            xpad=16,
            ellipsize=Pango.EllipsizeMode.END,
            xalign=1.0
        )
        durationRenderer.add_class('dim-label')
        list_widget.add_renderer(durationRenderer, lambda *args: None, None)
        cols[0].clear_attributes(durationRenderer)
        cols[0].add_attribute(durationRenderer, 'markup', 1)

        self.star_handler._add_star_renderers(list_widget, cols)
Beispiel #12
0
    def _add_list_renderers(self):
        column = Gtk.TreeViewColumn()

        # Add our own surface renderer, instead of the one provided by
        # Gd. This avoids us having to set the model to a cairo.Surface
        # which is currently not a working solution in pygobject.
        # https://gitlab.gnome.org/GNOME/pygobject/issues/155
        pixbuf_renderer = Gtk.CellRendererPixbuf(xalign=0.5,
                                                 yalign=0.5,
                                                 xpad=12,
                                                 ypad=2)
        column.pack_start(pixbuf_renderer, False)
        column.set_cell_data_func(pixbuf_renderer,
                                  self._on_list_widget_pixbuf_renderer)
        column.add_attribute(pixbuf_renderer, 'surface', 13)

        # With the bugfix in libgd 9117650bda, the search results
        # stopped aligning at the top. With the artists results not
        # having a second line of text, this looks off.
        # Revert to old behaviour by forcing the alignment to be top.
        two_lines_renderer = Gd.TwoLinesRenderer(
            wrap_mode=Pango.WrapMode.WORD_CHAR,
            xpad=12,
            xalign=0.0,
            yalign=0,
            text_lines=2)
        column.pack_start(two_lines_renderer, True)
        column.set_cell_data_func(two_lines_renderer,
                                  self._on_list_widget_two_lines_renderer)
        column.add_attribute(two_lines_renderer, 'text', 2)
        column.add_attribute(two_lines_renderer, 'line_two', 3)

        title_renderer = Gtk.CellRendererText(
            xpad=12,
            xalign=0.0,
            yalign=0.5,
            height=32,
            ellipsize=Pango.EllipsizeMode.END,
            weight=Pango.Weight.BOLD)
        column.pack_start(title_renderer, False)
        column.set_cell_data_func(title_renderer,
                                  self._on_list_widget_title_renderer)
        column.add_attribute(title_renderer, 'text', 2)

        self._star_handler.add_star_renderers(column)

        selection_renderer = Gtk.CellRendererToggle(xpad=12, xalign=1.0)
        column.pack_start(selection_renderer, False)
        column.set_cell_data_func(selection_renderer,
                                  self._on_list_widget_selection_renderer)
        column.add_attribute(selection_renderer, 'active', 6)

        self._view.append_column(column)
Beispiel #13
0
 def _add_list_renderers(self):
     list_widget = self._view.get_generic_view()
     cols = list_widget.get_columns()
     cells = cols[0].get_cells()
     cells[1].set_visible(False)
     cells[2].set_visible(False)
     self.text_renderer = Gd.StyledTextRenderer(
         xpad=16, ypad=16, ellipsize=Pango.EllipsizeMode.END, xalign=0.0,
         width=220)
     list_widget.add_renderer(self.text_renderer, lambda *args: None, None)
     cols[0].clear_attributes(self.text_renderer)
     cols[0].add_attribute(self.text_renderer, 'text', 2)
Beispiel #14
0
    def __send_notification(self, message):
        notification = Gd.Notification()
        notification.set_timeout(5)
        container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)

        notification_lbl = Gtk.Label()
        notification_lbl.set_text(message)
        container.pack_start(notification_lbl, False, False, 3)

        notification.add(container)
        notification_parent = self.get_children()[-1]
        notification_parent.add(notification)
        notification_parent.reorder_child(notification, 0)
        self.show_all()
Beispiel #15
0
    def _setup_view(self, view_type):
        self.view = Gd.MainView(shadow_type=Gtk.ShadowType.NONE)
        self.view.set_view_type(view_type)

        self.view.click_handler = self.view.connect('item-activated',
                                                    self._on_item_activated)
        self.view.connect('selection-mode-request',
                          self._on_selection_mode_request)

        self.view.bind_property('selection-mode', self, 'selection_mode',
                                GObject.BindingFlags.BIDIRECTIONAL)

        self.view.connect('view-selection-changed',
                          self._on_view_selection_changed)

        self._box.pack_start(self.view, True, True, 0)
Beispiel #16
0
 def _init_loading_notification(self):
     self.notification = Gd.Notification()
     self.notification.set_timeout(5)
     grid = Gtk.Grid(valign=Gtk.Align.CENTER, margin_end=8)
     grid.set_column_spacing(8)
     spinner = Gtk.Spinner()
     spinner.start()
     grid.add(spinner)
     label = Gtk.Label.new(_("Loading"))
     grid.add(label)
     self.notification.add(grid)
     self._overlay.add_overlay(self.notification)
     if self.notification_handler:
         GLib.Source.remove(self.notification_handler)
         self.notification_handler = None
     self.notification_handler = GLib.timeout_add(1000, self._show_notification)
Beispiel #17
0
    def __init__(self, application):
        super().__init__()

        self._coregrilo = application.props.coregrilo
        self._selection_mode = False
        self._timeout = None

        self._entry = Gd.TaggedEntry()
        self._entry.props.halign = Gtk.Align.CENTER
        self._entry.props.visible = True
        self._entry.props.width_request = 500

        self._selection_menu = SelectionBarMenuButton()

        self.bind_property(
            "selection-mode", self, "show-close-button",
            GObject.BindingFlags.INVERT_BOOLEAN
            | GObject.BindingFlags.SYNC_CREATE)
        self.bind_property(
            "selection-mode", self._cancel_button, "visible")
        self.bind_property(
            "selection-mode", self._select_button, "visible",
            GObject.BindingFlags.INVERT_BOOLEAN)
        self.bind_property(
            "selection-mode", self._select_button, "active",
            GObject.BindingFlags.BIDIRECTIONAL)
        self.bind_property(
            "selected-songs-count", self._selection_menu,
            "selected-songs-count")
        self.bind_property(
            "search-mode-active", self._search_button, "active",
            GObject.BindingFlags.BIDIRECTIONAL
            | GObject.BindingFlags.SYNC_CREATE)
        self.bind_property(
            "selection-mode", self._search_button, "visible",
            GObject.BindingFlags.INVERT_BOOLEAN
            | GObject.BindingFlags.SYNC_CREATE)

        self.connect(
            "notify::selection-mode-allowed",
            self._on_selection_mode_allowed_changed)

        self.connect(
            "notify::search-mode-active", self._on_search_mode_changed)
        self.connect("notify::search-state", self._search_state_changed)

        self._entry.connect("changed", self._search_entry_timeout)
Beispiel #18
0
    def __send_notification(self, message):
        """
            Show a notification using Gd.Notification.
            :param message: the notification message
            :type message: str
        """
        notification = Gd.Notification()
        notification.set_show_close_button(True)
        notification.set_timeout(5)

        notification_lbl = Gtk.Label()
        notification_lbl.set_text(message)

        notification.add(notification_lbl)

        self.add(notification)
        self.reorder_child(notification, 0)
        self.show_all()
    def __init__(self, player, parent_view):
        """Initialize the AlbumWidget.

        :param player: The player object
        :param parent_view: The view this widget is part of
        """
        Gtk.EventBox.__init__(self)

        scale = self.get_scale_factor()
        self._cache = AlbumArtCache(scale)
        self._loading_icon_surface = DefaultIcon(scale).get(
            DefaultIcon.Type.loading, ArtSize.large)

        self._player = player
        self._iter_to_clean = None

        self._ui = Gtk.Builder()
        self._ui.add_from_resource('/org/gnome/Music/AlbumWidget.ui')
        self._create_model()
        self.view = Gd.MainView(shadow_type=Gtk.ShadowType.NONE)
        self.view.set_view_type(Gd.MainViewType.LIST)
        self._album = None
        self._header_bar = None
        self.view.connect('item-activated', self._on_item_activated)

        view_box = self._ui.get_object('view')
        self._ui.get_object('scrolledWindow').set_placement(
            Gtk.CornerType.TOP_LEFT)
        self.view.connect('selection-mode-request',
                          self._on_selection_mode_request)
        child_view = self.view.get_children()[0]
        child_view.set_margin_top(64)
        child_view.set_margin_bottom(64)
        child_view.set_margin_end(32)
        self.view.remove(child_view)
        view_box.add(child_view)

        self.add(self._ui.get_object('AlbumWidget'))
        self._star_handler = StarHandlerWidget(self, 9)
        self._add_list_renderers()
        self.get_style_context().add_class('view')
        self.get_style_context().add_class('content-view')
        self.view.get_generic_view().get_style_context().remove_class('view')
        self.show_all()
Beispiel #20
0
    def __on_clear_database_clicked(self, *__):
        notification = Gd.Notification()
        notification.set_timeout(5)
        notification.connect("dismissed", self.__clear_database)
        container = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)

        notification_lbl = Gtk.Label()
        notification_lbl.set_text(
            _("The existing accounts will be erased in 5 seconds"))
        container.pack_start(notification_lbl, False, False, 3)

        undo_btn = Gtk.Button()
        undo_btn.set_label(_("Undo"))
        undo_btn.connect("clicked", lambda widget: notification.hide())
        container.pack_end(undo_btn, False, False, 3)

        notification.add(container)
        notification_parent = self.stack.get_child_by_name("behaviour")
        notification_parent.add(notification)
        notification_parent.reorder_child(notification, 0)
        self.show_all()
Beispiel #21
0
    def __init__(self, stack_switcher, search_button, dropdown):
        Gtk.Revealer.__init__(self)
        self.timeout = None
        self.stack_switcher = stack_switcher
        self._search_button = search_button
        self.dropdown = dropdown
        self._searchContainer = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
                                        halign=Gtk.Align.CENTER)
        self._searchContainer.get_style_context().add_class('linked')

        self._search_entry = Gd.TaggedEntry(width_request=500,
                                            halign=Gtk.Align.CENTER)
        self._search_entry.connect("changed", self.search_entry_timeout)
        self._search_entry.show()
        self._searchContainer.add(self._search_entry)

        self._dropDownButtonArrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN,
                                              shadow_type=Gtk.ShadowType.NONE)
        self._dropDownButton = Gtk.ToggleButton()
        self._dropDownButton.add(self._dropDownButtonArrow)
        self._dropDownButton.get_style_context().add_class('raised')
        self._dropDownButton.get_style_context().add_class('image-button')
        self._dropDownButton.connect("toggled", self._drop_down_button_toggled)
        self._dropDownButton.show_all()
        self._searchContainer.add(self._dropDownButton)

        self._search_entry.connect("tag-button-clicked",
                                   self._search_entry_tag_button_clicked)

        self._searchContainer.show_all()
        toolbar = Gtk.Toolbar()
        toolbar.get_style_context().add_class("search-bar")
        toolbar.show()
        self.add(toolbar)

        item = Gtk.ToolItem()
        item.set_expand(True)
        item.show()
        toolbar.insert(item, 0)
        item.add(self._searchContainer)
Beispiel #22
0
    def __init__(self, title, header_bar):
        Stack.__init__(self, transition_type=StackTransitionType.CROSSFADE)
        self.grid = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL)

        self.view = Gd.MainView(shadow_type=Gtk.ShadowType.NONE)
        self.title = title
        self.header_bar = header_bar

        if hasattr(self, "model"):
            self.view.set_model(self.model)
            self.filter = self.model.filter_new(None)
            self.view.set_model(self.filter)
        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        box.pack_start(self.view, True, True, 0)
        button = Gtk.Button(label=title)
        #self.add(button)
        self.grid.add(box)
        self.add(self.grid)

        if hasattr(self, "on_item_activated"):
            self.view.connect('item-activated', self.on_item_activated)

        self.show_all()
Beispiel #23
0
    def __init__(self, title, header_bar, selection_toolbar, useStack=False):
        Stack.__init__(self, transition_type=StackTransitionType.CROSSFADE)
        self._grid = Gtk.Grid(orientation=Gtk.Orientation.VERTICAL)
        self._iconWidth = -1
        self._iconHeight = 128
        self._offset = 0
        self._adjustmentValueId = 0
        self._adjustmentChangedId = 0
        self._scrollbarVisibleId = 0
        self._model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING,
                                    GObject.TYPE_STRING, GObject.TYPE_STRING,
                                    GdkPixbuf.Pixbuf, GObject.TYPE_OBJECT,
                                    GObject.TYPE_BOOLEAN, GObject.TYPE_INT,
                                    GObject.TYPE_STRING, GObject.TYPE_BOOLEAN,
                                    GObject.TYPE_BOOLEAN)
        self.view = Gd.MainView(shadow_type=Gtk.ShadowType.NONE)
        self.view.set_view_type(Gd.MainViewType.ICON)
        self.view.set_model(self._model)
        self.filter = self._model.filter_new(None)
        self.view.set_model(self.filter)
        self.vadjustment = self.view.get_vadjustment()
        self.selection_toolbar = selection_toolbar
        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        box.pack_start(self.view, True, True, 0)
        if useStack:
            self.stack = Stack(
                transition_type=StackTransitionType.SLIDE_RIGHT, )
            dummy = Gtk.Frame(visible=False)
            self.stack.add_named(dummy, 'dummy')
            self.stack.add_named(box, 'artists')
            self.stack.set_visible_child_name('dummy')
            self._grid.add(self.stack)
        else:
            self._grid.add(box)

        self._cached_count = -1
        self._loadMore = Widgets.LoadMoreButton(self._get_remaining_item_count)
        box.pack_end(self._loadMore.widget, False, False, 0)
        self._loadMore.widget.connect('clicked', self._populate)
        self.view.connect('item-activated', self._on_item_activated)
        self.view.connect('selection-mode-request',
                          self._on_selection_mode_request)
        self._cursor = None
        self.header_bar = header_bar
        self.header_bar._select_button.connect('toggled',
                                               self._on_header_bar_toggled)
        self.header_bar._cancel_button.connect('clicked',
                                               self._on_cancel_button_clicked)

        self.title = title
        self.add(self._grid)

        self.show_all()
        self._items = []
        self._loadMore.widget.hide()
        self._connect_view()
        self.cache = albumArtCache.get_default()
        self._symbolicIcon = self.cache.make_default_icon(
            self._iconHeight, self._iconWidth)

        self._init = False
        grilo.connect('ready', self._on_grilo_ready)
        self.header_bar.header_bar.connect('state-changed',
                                           self._on_state_changed)
        self.view.connect('view-selection-changed',
                          self._on_view_selection_changed)

        self._discovering_urls = {}
Beispiel #24
0
class FindAndReplaceWindow(Gtk.Window):
    __gtype_name__ = "FindAndReplaceWindow"

    # Child widgets. Keep them alphabetically sorted
    btn_find_previous = GtkTemplate.Child()
    btn_find_or_replace_all = GtkTemplate.Child()
    btn_replace = GtkTemplate.Child()
    btn_skip = GtkTemplate.Child()
    btnbox_existing_text = GtkTemplate.Child()
    btnbox_replace_with = GtkTemplate.Child()
    chkbtn_use_regex = GtkTemplate.Child()
    chkbtn_use_similarity_srch = GtkTemplate.Child()
    chkbtn_whole_word = GtkTemplate.Child()
    img_search_notif = GtkTemplate.Child()
    lbl_search_notif = GtkTemplate.Child()
    menubtn_existing_text = GtkTemplate.Child()
    menubtn_replace_with = GtkTemplate.Child()
    menubtn_sound_like = GtkTemplate.Child()
    menubtn_use_similarity_srch = GtkTemplate.Child()
    rvlr_advanced_options = GtkTemplate.Child()
    rvlr_replace_with = GtkTemplate.Child()
    rvlr_search_notif = GtkTemplate.Child()
    stk_find_or_replace = GtkTemplate.Child()
    tglbtn_replace = GtkTemplate.Child()

    # Custom non-buildable widgets
    tagent_existing_text = Gd.TaggedEntry()
    tagent_replace_with = Gd.TaggedEntry()

    # Null objects. Keep them alphabetically sorted
    #
    # Don't forget to disconnect all the external widget signals
    # on this object destroy
    parent = Gtk.ApplicationWindow()

    # Other variables. Keep them alphabetically sorted
    search_flag = Gtk.TextSearchFlags.CASE_INSENSITIVE

    # Properties' storage. Keep them alphabetically sorted
    _replace_mode = True
    _advanced_mode = False

    #---------------------------------
    # The init function
    #
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.init_template()

        # Set null variables
        self.parent = self.get_transient_for()
        self.parent_handler = self.parent.txtbfr_buffer.connect(
            "mark-set", self.on_parent_text_buffer_mark_set)

        # We've to set these properties manually because GtkTemplate
        # doesn't do it well. Keep them alphabetically sorted
        self.btnbox_existing_text.set_homogeneous(False)
        self.btnbox_replace_with.set_homogeneous(False)
        self.menubtn_sound_like.set_sensitive(False)
        self.menubtn_use_similarity_srch.set_sensitive(False)

        # Init widgets
        parent_selected_text = \
            self.match_parent_selected_text(self.search_flag)[2]

        if parent_selected_text:
            self.tagent_existing_text.set_text(parent_selected_text)

        # Init custom widgets. Keep in mind that we don't use "show_all()"
        # since it can break the GTK Template "visible" property
        self.btnbox_existing_text.pack_start(self.tagent_existing_text, True,
                                             True, 0)
        self.tagent_existing_text.connect("changed",
                                          self.on_tagent_existing_text_changed)
        self.tagent_existing_text.show()

        self.btnbox_replace_with.pack_start(self.tagent_replace_with, True,
                                            True, 0)
        self.tagent_replace_with.set_icon_from_icon_name(
            Gtk.EntryIconPosition.PRIMARY, "edit-find-replace-symbolic")
        self.tagent_replace_with.show()

    #-----------------------------------
    # Properties. Keep them alphabetically sorted
    #
    # Advanced Mode property
    def get_advanced_mode(self):
        return self._advanced_mode

    def set_advanced_mode(self, value):
        # Save the value first
        self._advanced_mode = value

        # Refresh the integrations
        self.rvlr_advanced_options.set_reveal_child(value)
        self.menubtn_existing_text.set_visible(value)
        self.menubtn_replace_with.set_visible(value)

    # Replace Mode property
    def get_replace_mode(self):
        return self._replace_mode

    def set_replace_mode(self, value):
        widget = self.btn_find_or_replace_all
        stylectx = widget.get_style_context()

        # Save the value first
        self._replace_mode = value

        # Refresh the integrations
        self.rvlr_replace_with.set_reveal_child(value)
        if value:
            stylectx.add_class("destructive-action")
            widget.set_label("Replace All")
        else:
            stylectx.remove_class("destructive-action")
            widget.set_label("Find All")
        self.refresh_match_integration()

    #---------------------------------------------
    # Integration refreshment functions / procedures. Keep them
    # alphabetically sorted
    #
    def refresh_match_integration(self):
        matching, keyword = \
            self.match_parent_selected_text(self.search_flag)[0:2]
        widget = self.stk_find_or_replace

        widget.set_sensitive(keyword != "")
        if matching:
            if self.get_replace_mode():
                widget.set_visible_child_name("replace_act")
            else:
                widget.set_visible_child_name("main_act")
        else:
            widget.set_visible_child_name("main_act")

    #-----------------------------------
    # Other functions / procedures. Keep them alphabetically sorted
    #
    def find_and_select(self, direction):
        selected_text_matching, keyword, y, _buffer, selection_bounds = \
            self.match_parent_selected_text(self.search_flag)
        search_options = keyword, self.search_flag, None
        cursor_iter = Gtk.TextIter()
        found = False
        match = None
        icon = ""
        label = ""

        if selected_text_matching:
            if direction == Direction.FORWARD:
                cursor_iter = selection_bounds[1]
            elif direction == Direction.BACKWARD:
                cursor_iter = selection_bounds[0]
        else:
            cursor_iter = _buffer.get_iter_at_mark(_buffer.get_insert())

        for x in range(2):
            # Search once more from the start or the end of the documents
            # if nothing matching at first trial
            if direction == Direction.FORWARD:
                if x == 1:
                    cursor_iter = _buffer.get_start_iter()
                match = cursor_iter.forward_search(*search_options)
            elif direction == Direction.BACKWARD:
                if x == 1:
                    cursor_iter = _buffer.get_end_iter()
                match = cursor_iter.backward_search(*search_options)

            if match:
                found = True
                if x == 1:
                    icon = "dialog-information-symbolic"
                    if direction == Direction.FORWARD:
                        label = "Reached the end of the document"
                    elif direction == Direction.BACKWARD:
                        label = "Reached the beginning of the document"
                break

        if found:
            _buffer.select_range(*match)
        else:
            icon = "dialog-error-symbolic"
            label = "Search key not found"

        if label:
            self.lbl_search_notif.set_label(label)
            self.img_search_notif.set_from_icon_name(
                icon, Gtk.IconSize.LARGE_TOOLBAR)
            self.rvlr_search_notif.set_reveal_child(True)

    def match_parent_selected_text(self, flag):
        _buffer = self.parent.txtbfr_buffer
        selection_bounds = _buffer.get_selection_bounds()
        selected_text = ""
        keyword = self.tagent_existing_text.get_text()
        matching = False

        if selection_bounds:
            selected_text = _buffer.get_text(*selection_bounds, True)
            if keyword:  # don't merge this "if" statement to the parent "if"
                if flag == Gtk.TextSearchFlags.CASE_INSENSITIVE:
                    if selected_text.lower() == keyword.lower():
                        matching = True
                elif selected_text == keyword:
                    matching = True

        return matching, keyword, selected_text, _buffer, selection_bounds

    #--------------------------------------
    # Callbacks functions / procedures. Keep them alphabetically sorted
    #
    @GtkTemplate.Callback
    def on_btn_close_search_notif_clicked(self, widget):
        self.rvlr_search_notif.set_reveal_child(False)

    @GtkTemplate.Callback
    def on_btn_find_next_clicked(self, widget):
        self.rvlr_search_notif.set_reveal_child(False)
        self.find_and_select(Direction.FORWARD)

    @GtkTemplate.Callback
    def on_btn_find_previous_clicked(self, widget):
        self.rvlr_search_notif.set_reveal_child(False)
        self.find_and_select(Direction.BACKWARD)

    @GtkTemplate.Callback
    def on_btn_replace_clicked(self, widget):
        matching, x, y, _buffer, z = \
            self.match_parent_selected_text(self.search_flag)

        self.rvlr_search_notif.set_reveal_child(False)
        if matching:
            _buffer.delete_selection(False, False)
            _buffer.insert_at_cursor(self.tagent_replace_with.get_text(), -1)
        self.stk_find_or_replace.set_visible_child_name("main_act")

    @GtkTemplate.Callback
    def on_btn_skip_clicked(self, widget):
        self.rvlr_search_notif.set_reveal_child(False)
        self.stk_find_or_replace.set_visible_child_name("main_act")

    @GtkTemplate.Callback
    def on_chkbtn_sound_like_toggled(self, widget):
        self.menubtn_sound_like.set_sensitive(widget.get_active())

    @GtkTemplate.Callback
    def on_chkbtn_use_regex_toggled(self, widget):
        active = widget.get_active()

        self.chkbtn_use_similarity_srch.set_sensitive(not active)
        self.chkbtn_whole_word.set_sensitive(not active)
        self.chkbtn_whole_word.set_inconsistent(active)

    @GtkTemplate.Callback
    def on_chkbtn_use_similarity_srch_toggled(self, widget):
        active = widget.get_active()

        self.menubtn_use_similarity_srch.set_sensitive(active)
        self.chkbtn_use_regex.set_sensitive(not active)

    @GtkTemplate.Callback
    def on_FindAndReplaceWindow_destroy(self, widget):
        self.parent.txtbfr_buffer.disconnect(self.parent_handler)

    @GtkTemplate.Callback
    def on_tglbtn_replace_toggled(self, widget):
        self.set_replace_mode(widget.get_active())

    def on_parent_text_buffer_mark_set(self, location, mark, widget):
        self.refresh_match_integration()

    @GtkTemplate.Callback
    def on_rdbtn_options_mode_toggled(self, widget):
        self.set_advanced_mode(widget.get_name() == "advanced_mode")

    @GtkTemplate.Callback
    def on_tagent_existing_text_changed(self, widget):
        self.refresh_match_integration()
    def __init__(self, window, player):
        self.playlists_sidebar = Gd.MainView()

        BaseView.__init__(self, 'playlists', _("Playlists"), window,
                          Gd.MainViewType.LIST, True, self.playlists_sidebar)

        self.view.get_generic_view().get_style_context()\
            .add_class('songs-list')
        self._add_list_renderers()
        self.view.get_generic_view().get_style_context().remove_class(
            'content-view')

        builder = Gtk.Builder()
        builder.add_from_resource('/org/gnome/Music/PlaylistControls.ui')
        self.headerbar = builder.get_object('grid')
        self.name_label = builder.get_object('playlist_name')
        self.songs_count_label = builder.get_object('songs_count')
        self.menubutton = builder.get_object('playlist_menubutton')
        playlistPlayAction = Gio.SimpleAction.new('playlist_play', None)
        playlistPlayAction.connect('activate', self._on_play_activate)
        window.add_action(playlistPlayAction)
        self.playlistDeleteAction = Gio.SimpleAction.new(
            'playlist_delete', None)
        self.playlistDeleteAction.connect('activate', self._on_delete_activate)
        window.add_action(self.playlistDeleteAction)
        self._grid.insert_row(0)
        self._grid.attach(self.headerbar, 1, 0, 1, 1)

        self.playlists_model = Gtk.ListStore(
            GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING,
            GObject.TYPE_STRING, GdkPixbuf.Pixbuf, GObject.TYPE_OBJECT,
            GObject.TYPE_BOOLEAN, GObject.TYPE_INT, GObject.TYPE_STRING,
            GObject.TYPE_INT, GObject.TYPE_BOOLEAN, GObject.TYPE_INT)

        self.playlists_sidebar.set_view_type(Gd.MainViewType.LIST)
        self.playlists_sidebar.set_model(self.playlists_model)
        self.playlists_sidebar.set_hexpand(False)
        self.playlists_sidebar.get_style_context().add_class('side-panel')
        self.playlists_sidebar.get_generic_view().get_selection().set_mode(
            Gtk.SelectionMode.SINGLE)
        self.playlists_sidebar.connect('item-activated',
                                       self._on_playlist_activated)
        self._grid.insert_column(0)
        self._grid.child_set_property(self.stack, 'top-attach', 0)
        self._grid.child_set_property(self.stack, 'height', 2)
        self._add_sidebar_renderers()
        self.playlists_sidebar.get_generic_view().get_style_context(
        ).remove_class('content-view')

        self.iter_to_clean = None
        self.iter_to_clean_model = None
        self.current_playlist = None
        self.current_playlist_index = None
        self.pl_todelete = None
        self.pl_todelete_index = None
        self.really_delete = True
        self.songs_count = 0
        self.window = window
        self._update_songs_count()
        self.player = player
        self.player.connect('playlist-item-changed', self.update_model)
        playlists.connect('playlist-created', self._on_playlist_created)
        playlists.connect('playlist-updated', self.on_playlist_update)
        playlists.connect('song-added-to-playlist',
                          self._on_song_added_to_playlist)
        playlists.connect('song-removed-from-playlist',
                          self._on_song_removed_from_playlist)
        self.show_all()