Changing the item size of the cover grid implemented
This commit is contained in:
parent
c09cb3755f
commit
237e8d3757
1 changed files with 101 additions and 12 deletions
113
mcgGtk.py
113
mcgGtk.py
|
@ -42,6 +42,8 @@ class MCGGtk(Gtk.Window):
|
||||||
self._toolbar.connect_signal(Toolbar.SIGNAL_PLAYPAUSE, self.toolbar_playpause_cb)
|
self._toolbar.connect_signal(Toolbar.SIGNAL_PLAYPAUSE, self.toolbar_playpause_cb)
|
||||||
self._toolbar.connect_signal(Toolbar.SIGNAL_NEXT, self.toolbar_next_cb)
|
self._toolbar.connect_signal(Toolbar.SIGNAL_NEXT, self.toolbar_next_cb)
|
||||||
self._toolbar.connect_signal(Toolbar.SIGNAL_FILTER, self.toolbar_filter_cb)
|
self._toolbar.connect_signal(Toolbar.SIGNAL_FILTER, self.toolbar_filter_cb)
|
||||||
|
self._toolbar.connect_signal(Toolbar.SIGNAL_GRID_SIZE_TEMP, self.toolbar_grid_size_temp_cb)
|
||||||
|
self._toolbar.connect_signal(Toolbar.SIGNAL_GRID_SIZE, self.toolbar_grid_size_cb)
|
||||||
self._cover_panel.connect_signal(CoverPanel.SIGNAL_PLAY, self.cover_panel_play_cb)
|
self._cover_panel.connect_signal(CoverPanel.SIGNAL_PLAY, self.cover_panel_play_cb)
|
||||||
self._cover_panel.connect_signal(CoverPanel.SIGNAL_UPDATE_START, self.cover_panel_update_start_cb)
|
self._cover_panel.connect_signal(CoverPanel.SIGNAL_UPDATE_START, self.cover_panel_update_start_cb)
|
||||||
self._cover_panel.connect_signal(CoverPanel.SIGNAL_UPDATE_END, self.cover_panel_update_end_cb)
|
self._cover_panel.connect_signal(CoverPanel.SIGNAL_UPDATE_END, self.cover_panel_update_end_cb)
|
||||||
|
@ -105,6 +107,16 @@ class MCGGtk(Gtk.Window):
|
||||||
self._cover_panel.filter(filter_string)
|
self._cover_panel.filter(filter_string)
|
||||||
|
|
||||||
|
|
||||||
|
def toolbar_grid_size_temp_cb(self, size):
|
||||||
|
self._cover_panel.set_grid_size(size)
|
||||||
|
|
||||||
|
|
||||||
|
def toolbar_grid_size_cb(self, size):
|
||||||
|
self._cover_panel.set_grid_size(size)
|
||||||
|
self._toolbar.lock()
|
||||||
|
self._mcg.update()
|
||||||
|
|
||||||
|
|
||||||
# Cover panel callbacks
|
# Cover panel callbacks
|
||||||
|
|
||||||
def cover_panel_play_cb(self, album):
|
def cover_panel_play_cb(self, album):
|
||||||
|
@ -210,6 +222,8 @@ class Toolbar(Gtk.Toolbar):
|
||||||
SIGNAL_PLAYPAUSE = 'playpause'
|
SIGNAL_PLAYPAUSE = 'playpause'
|
||||||
SIGNAL_NEXT = 'next'
|
SIGNAL_NEXT = 'next'
|
||||||
SIGNAL_FILTER = 'filter'
|
SIGNAL_FILTER = 'filter'
|
||||||
|
SIGNAL_GRID_SIZE_TEMP = 'grid-size-temp'
|
||||||
|
SIGNAL_GRID_SIZE = 'grid-size'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Gtk.Toolbar.__init__(self)
|
Gtk.Toolbar.__init__(self)
|
||||||
|
@ -235,13 +249,24 @@ class Toolbar(Gtk.Toolbar):
|
||||||
self._filter_entry = Gtk.Entry()
|
self._filter_entry = Gtk.Entry()
|
||||||
self._filter_item.add(self._filter_entry)
|
self._filter_item.add(self._filter_entry)
|
||||||
self.add(self._filter_item)
|
self.add(self._filter_item)
|
||||||
|
self._grid_size_item = Gtk.ToolItem()
|
||||||
|
self._grid_size_scale = Gtk.HScale()
|
||||||
|
self._grid_size_scale.set_range(100,500)
|
||||||
|
self._grid_size_scale.set_round_digits(0)
|
||||||
|
self._grid_size_scale.set_value(128)
|
||||||
|
self._grid_size_scale.set_size_request(100, -1)
|
||||||
|
self._grid_size_scale.set_draw_value(False)
|
||||||
|
self._grid_size_item.add(self._grid_size_scale)
|
||||||
|
self.add(self._grid_size_item)
|
||||||
|
|
||||||
# Signals
|
# Signals
|
||||||
self._connection_button.connect('clicked', self._callback, self.SIGNAL_CONNECT)
|
self._connection_button.connect('clicked', self._callback_with_function, self.SIGNAL_CONNECT)
|
||||||
self._update_button.connect('clicked', self._callback, self.SIGNAL_UPDATE)
|
self._update_button.connect('clicked', self._callback_with_function, self.SIGNAL_UPDATE)
|
||||||
self._playpause_button.connect('clicked', self._callback, self.SIGNAL_PLAYPAUSE)
|
self._playpause_button.connect('clicked', self._callback_with_function, self.SIGNAL_PLAYPAUSE)
|
||||||
self._next_button.connect('clicked', self._callback, self.SIGNAL_NEXT)
|
self._next_button.connect('clicked', self._callback_with_function, self.SIGNAL_NEXT)
|
||||||
self._filter_entry.connect('changed', self._callback, self.SIGNAL_FILTER, self._filter_entry.get_text)
|
self._filter_entry.connect('changed', self._callback_with_function, self.SIGNAL_FILTER, self._filter_entry.get_text)
|
||||||
|
self._grid_size_scale.connect('change-value', self.grid_size_temp_cb)
|
||||||
|
self._grid_size_scale.connect('button-release-event', self.grid_size_cb)
|
||||||
|
|
||||||
|
|
||||||
def connect_signal(self, signal, callback):
|
def connect_signal(self, signal, callback):
|
||||||
|
@ -277,16 +302,35 @@ class Toolbar(Gtk.Toolbar):
|
||||||
self._playpause_button.set_sensitive(False);
|
self._playpause_button.set_sensitive(False);
|
||||||
|
|
||||||
|
|
||||||
def _callback(self, widget, signal, data_function=None):
|
def grid_size_temp_cb(self, widget, scroll, value):
|
||||||
|
value = round(value)
|
||||||
|
range = self._grid_size_scale.get_adjustment()
|
||||||
|
if value < range.get_lower() or value > range.get_upper():
|
||||||
|
return
|
||||||
|
self._callback(self.SIGNAL_GRID_SIZE_TEMP, value)
|
||||||
|
|
||||||
|
|
||||||
|
def grid_size_cb(self, widget, event):
|
||||||
|
value = round(self._grid_size_scale.get_value())
|
||||||
|
range = self._grid_size_scale.get_adjustment()
|
||||||
|
if value < range.get_lower() or value > range.get_upper():
|
||||||
|
return
|
||||||
|
self._callback(self.SIGNAL_GRID_SIZE, value)
|
||||||
|
|
||||||
|
|
||||||
|
def _callback(self, signal, *data):
|
||||||
if signal in self._callbacks:
|
if signal in self._callbacks:
|
||||||
callback = self._callbacks[signal]
|
callback = self._callbacks[signal]
|
||||||
|
|
||||||
data = []
|
|
||||||
if data_function is not None:
|
|
||||||
data = {data_function()}
|
|
||||||
callback(*data)
|
callback(*data)
|
||||||
|
|
||||||
|
|
||||||
|
def _callback_with_function(self, widget, signal, data_function=None):
|
||||||
|
data = []
|
||||||
|
if data_function is not None:
|
||||||
|
data = {data_function()}
|
||||||
|
self._callback(signal, *data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionPanel(Gtk.Box):
|
class ConnectionPanel(Gtk.Box):
|
||||||
|
@ -392,13 +436,13 @@ class ConnectionPanel(Gtk.Box):
|
||||||
|
|
||||||
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
import math
|
||||||
|
|
||||||
class CoverPanel(Gtk.HPaned):
|
class CoverPanel(Gtk.HPaned):
|
||||||
SIGNAL_UPDATE_START = 'update-start'
|
SIGNAL_UPDATE_START = 'update-start'
|
||||||
SIGNAL_UPDATE_END = 'update-end'
|
SIGNAL_UPDATE_END = 'update-end'
|
||||||
SIGNAL_PLAY = 'play'
|
SIGNAL_PLAY = 'play'
|
||||||
SIGNAL_TOGGLE_FULLSCREEN = 'toggle-fullscreen'
|
SIGNAL_TOGGLE_FULLSCREEN = 'toggle-fullscreen'
|
||||||
_default_cover_size = 128
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
|
@ -407,8 +451,10 @@ class CoverPanel(Gtk.HPaned):
|
||||||
self._callbacks = {}
|
self._callbacks = {}
|
||||||
self._albums = []
|
self._albums = []
|
||||||
self._cover_pixbuf = None
|
self._cover_pixbuf = None
|
||||||
|
self._grid_pixbufs = {}
|
||||||
self._filter_string = ""
|
self._filter_string = ""
|
||||||
self._is_fullscreen = False
|
self._is_fullscreen = False
|
||||||
|
self._old_range = None
|
||||||
|
|
||||||
# Image
|
# Image
|
||||||
self._cover_image = Gtk.Image()
|
self._cover_image = Gtk.Image()
|
||||||
|
@ -542,9 +588,10 @@ class CoverPanel(Gtk.HPaned):
|
||||||
file = album.get_cover()
|
file = album.get_cover()
|
||||||
if file is None:
|
if file is None:
|
||||||
continue
|
continue
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, self._default_cover_size, self._default_cover_size)
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(file, self._config.grid_item_size, self._config.grid_item_size)
|
||||||
if pixbuf is None:
|
if pixbuf is None:
|
||||||
continue
|
continue
|
||||||
|
self._grid_pixbufs[album.get_hash()] = pixbuf
|
||||||
self._cover_grid_model.append([pixbuf, album.get_title(), GObject.markup_escape_text("\n".join([album.get_title(), album.get_artist()])), hash])
|
self._cover_grid_model.append([pixbuf, album.get_title(), GObject.markup_escape_text("\n".join([album.get_title(), album.get_artist()])), hash])
|
||||||
i += 1
|
i += 1
|
||||||
GObject.idle_add(self._progress_bar.set_fraction, i/n)
|
GObject.idle_add(self._progress_bar.set_fraction, i/n)
|
||||||
|
@ -554,6 +601,8 @@ class CoverPanel(Gtk.HPaned):
|
||||||
self._cover_grid.thaw_child_notify()
|
self._cover_grid.thaw_child_notify()
|
||||||
self.remove(self._progress_box)
|
self.remove(self._progress_box)
|
||||||
self.pack2(self._cover_grid_scroll, False)
|
self.pack2(self._cover_grid_scroll, False)
|
||||||
|
self._dummy_pixbuf = None
|
||||||
|
self._old_range = None
|
||||||
Gdk.threads_leave()
|
Gdk.threads_leave()
|
||||||
self._callback(self.SIGNAL_UPDATE_END)
|
self._callback(self.SIGNAL_UPDATE_END)
|
||||||
|
|
||||||
|
@ -570,6 +619,38 @@ class CoverPanel(Gtk.HPaned):
|
||||||
self._cover_image.clear()
|
self._cover_image.clear()
|
||||||
|
|
||||||
|
|
||||||
|
def set_grid_size(self, size):
|
||||||
|
self._config.grid_item_size = size
|
||||||
|
self._cover_grid.set_item_width(self._config.grid_item_size)
|
||||||
|
|
||||||
|
if self._old_range is None:
|
||||||
|
self._old_range = range(0, len(self._cover_grid_model))
|
||||||
|
old_start = self._old_range[0]
|
||||||
|
old_end = self._old_range[len(self._old_range)-1]
|
||||||
|
|
||||||
|
vis_range = self._cover_grid.get_visible_range()
|
||||||
|
(vis_start,), (vis_end,) = vis_range
|
||||||
|
vis_range = range(vis_start, vis_end+1)
|
||||||
|
self._old_range = vis_range
|
||||||
|
|
||||||
|
cur_range = range(min(vis_start, old_start), max(vis_end+1, old_end+1))
|
||||||
|
for path in cur_range:
|
||||||
|
iter = self._cover_grid_model.get_iter(path)
|
||||||
|
hash = self._cover_grid_model.get_value(iter, 3)
|
||||||
|
if path in vis_range:
|
||||||
|
pixbuf = self._grid_pixbufs[hash]
|
||||||
|
self._cover_grid_model.set_value(iter, 0, pixbuf.scale_simple(self._config.grid_item_size, self._config.grid_item_size, GdkPixbuf.InterpType.NEAREST))
|
||||||
|
|
||||||
|
vis_range = self._cover_grid.get_visible_range()
|
||||||
|
(vis_start,), (vis_end,) = vis_range
|
||||||
|
vis_range = range(vis_start, vis_end+1)
|
||||||
|
else:
|
||||||
|
pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, 1, 1)
|
||||||
|
self._cover_grid_model.set_value(iter, 0, pixbuf)
|
||||||
|
|
||||||
|
self._cover_grid.set_item_width(self._config.grid_item_size)
|
||||||
|
|
||||||
|
|
||||||
def resize_pane_callback(self, widget, allocation):
|
def resize_pane_callback(self, widget, allocation):
|
||||||
self._config.pane_position = self.get_position()
|
self._config.pane_position = self.get_position()
|
||||||
|
|
||||||
|
@ -629,6 +710,8 @@ class CoverPanel(Gtk.HPaned):
|
||||||
|
|
||||||
def filter_visible_cb(self, model, iter, data):
|
def filter_visible_cb(self, model, iter, data):
|
||||||
hash = model.get_value(iter, 3)
|
hash = model.get_value(iter, 3)
|
||||||
|
if hash == "":
|
||||||
|
return
|
||||||
album = self._albums[hash]
|
album = self._albums[hash]
|
||||||
return album.filter(self._filter_string)
|
return album.filter(self._filter_string)
|
||||||
|
|
||||||
|
@ -641,6 +724,8 @@ class CoverPanel(Gtk.HPaned):
|
||||||
hash1 = model.get_value(row1, 3)
|
hash1 = model.get_value(row1, 3)
|
||||||
hash2 = model.get_value(row2, 3)
|
hash2 = model.get_value(row2, 3)
|
||||||
|
|
||||||
|
if hash1 == "" or hash2 == "":
|
||||||
|
return
|
||||||
return mcg.MCGAlbum.compare(self._albums[hash1], self._albums[hash2], criterion)
|
return mcg.MCGAlbum.compare(self._albums[hash1], self._albums[hash2], criterion)
|
||||||
|
|
||||||
|
|
||||||
|
@ -663,6 +748,7 @@ class Configuration:
|
||||||
self.window_height = 400
|
self.window_height = 400
|
||||||
self.window_maximized = False
|
self.window_maximized = False
|
||||||
self.pane_position = 300
|
self.pane_position = 300
|
||||||
|
self.grid_item_size = 128
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
|
|
||||||
|
@ -687,6 +773,8 @@ class Configuration:
|
||||||
self.window_maximized = self._config.getboolean('gui', 'window_maximized')
|
self.window_maximized = self._config.getboolean('gui', 'window_maximized')
|
||||||
if self._config.has_option('gui', 'pane_position'):
|
if self._config.has_option('gui', 'pane_position'):
|
||||||
self.pane_position = self._config.getint('gui', 'pane_position')
|
self.pane_position = self._config.getint('gui', 'pane_position')
|
||||||
|
if self._config.has_option('gui', 'grid_item_size'):
|
||||||
|
self.grid_item_size = self._config.getint('gui', 'grid_item_size')
|
||||||
|
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
@ -703,6 +791,7 @@ class Configuration:
|
||||||
self._config.set('gui', 'window_height', self.window_height)
|
self._config.set('gui', 'window_height', self.window_height)
|
||||||
self._config.set('gui', 'window_maximized', self.window_maximized)
|
self._config.set('gui', 'window_maximized', self.window_maximized)
|
||||||
self._config.set('gui', 'pane_position', self.pane_position)
|
self._config.set('gui', 'pane_position', self.pane_position)
|
||||||
|
self._config.set('gui', 'grid_item_size', self.grid_item_size)
|
||||||
|
|
||||||
|
|
||||||
with open(self._get_filename(), 'w') as configfile:
|
with open(self._get_filename(), 'w') as configfile:
|
||||||
|
|
Loading…
Reference in a new issue