Beispiel #1
0
 def __restore_position(self):
     if self.__is_main_window:
         position = blacfg.getlistint("general", "position")
         if position is not None:
             self.__position = position
     x, y = self.__position
     if x >= 0 and y >= 0:
         self.move(x, y)
Beispiel #2
0
 def __restore_size(self):
     if self.__is_main_window:
         size = blacfg.getlistint("general", "size")
         if size is not None:
             self.__size = size
     w, h = self.__size
     screen = self.get_screen()
     w = min(w, screen.get_width())
     h = min(h, screen.get_height())
     if w >= 0 and h >= 0:
         self.resize(w, h)
Beispiel #3
0
def _header_popup(button, event, view_id):
    if not (hasattr(event, "button") and event.button == 3):
        return False

    def column_selected(m, column_id, view_id, view):
        if m.get_active():
            if column_id not in columns:
                columns.append(column_id)
        else:
            try:
                columns.remove(column_id)
            except ValueError:
                pass

        blacfg.set("general",
                   "columns.%s" % view, ", ".join(map(str, columns)))
        if view_id == blaconst.VIEW_PLAYLISTS:
            for treeview in BlaTreeView.playlist_instances:
                update_columns(treeview, view_id)
        else:
            update_columns(BlaTreeView.queue_instance, view_id)

    menu = gtk.Menu()

    if view_id == blaconst.VIEW_PLAYLISTS:
        default = COLUMNS_DEFAULT_PLAYLIST
        view = "playlist"
    elif view_id == blaconst.VIEW_QUEUE:
        default = COLUMNS_DEFAULT_QUEUE
        view = "queue"

    columns = blacfg.getlistint("general", "columns.%s" % view)
    if columns is None:
        columns = default

    for column_id, label in enumerate(COLUMN_TITLES):
        if ((column_id == COLUMN_PLAYING and view_id == blaconst.VIEW_QUEUE) or
            (column_id == COLUMN_QUEUE_POSITION and
            view_id == blaconst.VIEW_PLAYLISTS)):
            continue

        m = gtk.CheckMenuItem(label)
        if column_id in columns:
            m.set_active(True)
            if len(columns) == 1:
                m.set_sensitive(False)
        m.connect("toggled", column_selected, column_id, view_id, view)
        menu.append(m)

    menu.show_all()
    menu.popup(None, None, None, event.button, event.time)

    return True
Beispiel #4
0
def update_columns(treeview, view_id):
    treeview.disconnect_changed_signal()

    if view_id == blaconst.VIEW_PLAYLISTS:
        default = COLUMNS_DEFAULT_PLAYLIST
        view = "playlist"
    elif view_id == blaconst.VIEW_QUEUE:
        default = COLUMNS_DEFAULT_QUEUE
        view = "queue"

    map(treeview.remove_column, treeview.get_columns())
    columns = blacfg.getlistint("general", "columns.%s" % view)

    if columns is None:
        columns = default
        blacfg.set(
            "general", "columns.%s" % view, ", ".join(map(str, columns)))

    xpad = gtk.CellRendererText().get_property("xpad")
    for column_id in columns:
        column = BlaColumn(column_id)
        title = COLUMN_TITLES[column_id]
        label = gtk.Label(title)
        width = label.create_pango_layout(title).get_pixel_size()[0]
        column.set_widget(label)

        if column_id not in [COLUMN_QUEUE_POSITION, COLUMN_PLAYING,
                             COLUMN_TRACK, COLUMN_DURATION]:
            column.set_expand(True)
            column.set_resizable(True)
            column.set_fixed_width(1)
        else:
            column.set_min_width(width + 12 + xpad)

        widget = column.get_widget()
        widget.show()
        treeview.append_column(column)
        widget.get_ancestor(gtk.Button).connect(
            "button_press_event", _header_popup, view_id)
        column.connect(
            "clicked",
            lambda c=column, i=column_id: treeview.sort_column(c, i))

    treeview.connect_changed_signal()