Add buttons for arrangement of GalleryTab media order

This commit is contained in:
prculley 2019-01-30 11:40:57 -06:00 committed by Nick Hall
parent b765d7eae0
commit 4f14cbc12c
2 changed files with 57 additions and 5 deletions

View File

@ -73,7 +73,10 @@ class ButtonTab(GrampsTab):
'jump' : _('Jump To'), 'jump' : _('Jump To'),
'up' : _('Move Up'), 'up' : _('Move Up'),
'down' : _('Move Down'), 'down' : _('Move Down'),
'left' : _('Move Left'),
'right' : _('Move right')
} }
L_R = 2 # indicator for left/right move buttons
def __init__(self, dbstate, uistate, track, name, share_button=False, def __init__(self, dbstate, uistate, track, name, share_button=False,
move_buttons=False, jump_button=False, top_label=None): move_buttons=False, jump_button=False, top_label=None):
@ -142,10 +145,14 @@ class ButtonTab(GrampsTab):
self.share_btn = None self.share_btn = None
if move_buttons: if move_buttons:
self.up_btn = SimpleButton('go-up', self.up_button_clicked) l_r = move_buttons == self.L_R
self.up_btn.set_tooltip_text(self._MSG['up']) self.up_btn = SimpleButton('go-previous' if l_r else 'go-up',
self.down_btn = SimpleButton('go-down', self.down_button_clicked) self.up_button_clicked)
self.down_btn.set_tooltip_text(self._MSG['down']) self.up_btn.set_tooltip_text(self._MSG['left' if l_r else 'up'])
self.down_btn = SimpleButton('go-next' if l_r else 'go-down',
self.down_button_clicked)
self.down_btn.set_tooltip_text(
self._MSG['right' if l_r else 'down'])
self.track_ref_for_deletion("up_btn") self.track_ref_for_deletion("up_btn")
self.track_ref_for_deletion("down_btn") self.track_ref_for_deletion("down_btn")
else: else:

View File

@ -81,7 +81,8 @@ class GalleryTab(ButtonTab, DbGUIElement):
def __init__(self, dbstate, uistate, track, media_list, update=None): def __init__(self, dbstate, uistate, track, media_list, update=None):
self.iconlist = Gtk.IconView() self.iconlist = Gtk.IconView()
ButtonTab.__init__(self, dbstate, uistate, track, _('_Gallery'), True) ButtonTab.__init__(self, dbstate, uistate, track, _('_Gallery'), True,
move_buttons=ButtonTab.L_R)
DbGUIElement.__init__(self, dbstate.db) DbGUIElement.__init__(self, dbstate.db)
self.track_ref_for_deletion("iconlist") self.track_ref_for_deletion("iconlist")
self.media_list = media_list self.media_list = media_list
@ -398,6 +399,50 @@ class GalleryTab(ButtonTab, DbGUIElement):
self.rebuild() self.rebuild()
break break
def up_button_clicked(self, obj):
""" Deal with up button """
ref = self.get_selected()
if ref:
pos = self.find_index(ref)
if pos > 0 :
self._move_up(pos, ref)
def down_button_clicked(self, obj):
""" Deal with down button """
ref = self.get_selected()
if ref:
pos = self.find_index(ref)
if pos >= 0 and pos < len(self.get_data()) - 1:
self._move_down(pos, ref)
def _move_up(self, row_from, obj):
"""
Move the item a position up in the EmbeddedList.
Eg: 0,1,2,3 needs to become 0,2,1,3, here row_from = 2
"""
dlist = self.get_data()
del dlist[row_from]
dlist.insert(row_from - 1, obj)
self.changed = True
self.rebuild()
#select the row
path = Gtk.TreePath.new_from_string(str(row_from - 1))
self.iconlist.select_path(path)
def _move_down(self, row_from, obj):
"""
Move the item a position down in the EmbeddedList.
Eg: 0,1,2,3 needs to become 0,2,1,3, here row_from = 1
"""
dlist = self.get_data()
del dlist[row_from]
dlist.insert(row_from + 1, obj)
self.changed = True
self.rebuild()
#select the row
path = Gtk.TreePath.new_from_string(str(row_from + 1))
self.iconlist.select_path(path)
def _set_dnd(self): def _set_dnd(self):
""" """
Set up drag-n-drop. The source and destination are set by calling .target() Set up drag-n-drop. The source and destination are set by calling .target()