2007-04-18 Benny Malengier <bm@cage.ugent.be>
* src/DisplayTabs/_EmbeddedList.py * src/DisplayTabs/_BackRefList.py * src/DisplayTabs/_NoteTab.py * src/DisplayTabs/_ButtonTab.py Added move up and move down buttons to the EmbeddedList, use them only for now in NoteTab svn: r8402
This commit is contained in:
parent
44b6c47171
commit
44321f2c89
@ -1,3 +1,11 @@
|
||||
2007-04-18 Benny Malengier <bm@cage.ugent.be>
|
||||
* src/DisplayTabs/_EmbeddedList.py
|
||||
* src/DisplayTabs/_BackRefList.py
|
||||
* src/DisplayTabs/_NoteTab.py
|
||||
* src/DisplayTabs/_ButtonTab.py
|
||||
Added move up and move down buttons to the EmbeddedList, use them only
|
||||
for now in NoteTab
|
||||
|
||||
2007-04-18 Brian Matherly <brian@gramps-project.org>
|
||||
* src/DbManager.py: generate DEFAULT_DIR for databases from const.home_dir
|
||||
|
||||
|
@ -80,7 +80,12 @@ class BackRefList(EmbeddedList):
|
||||
def is_empty(self):
|
||||
return self.model.count == 0
|
||||
|
||||
def create_buttons(self, share=False):
|
||||
def create_buttons(self, share=False, move=False):
|
||||
'''
|
||||
Creates a button box consisting of one button: Edit.
|
||||
This button box is then appended hbox (self).
|
||||
Method has signature of, and overrides create_buttons from _ButtonTab.py
|
||||
'''
|
||||
self.edit_btn = SimpleButton(gtk.STOCK_EDIT, self.edit_button_clicked)
|
||||
self.tooltips = gtk.Tooltips()
|
||||
self.tooltips.set_tip(self.edit_btn, _('Edit reference'))
|
||||
|
@ -60,9 +60,12 @@ class ButtonTab(GrampsTab):
|
||||
'del' : _('Remove'),
|
||||
'edit' : _('Edit'),
|
||||
'share' : _('Share'),
|
||||
'up' : _('Move Up'),
|
||||
'down' : _('Move Down'),
|
||||
}
|
||||
|
||||
def __init__(self, dbstate, uistate, track, name, share_button=False):
|
||||
def __init__(self, dbstate, uistate, track, name, share_button=False,
|
||||
move_buttons=False):
|
||||
"""
|
||||
Similar to the base class, except after Build
|
||||
@param dbstate: The database state. Contains a reference to
|
||||
@ -78,12 +81,16 @@ class ButtonTab(GrampsTab):
|
||||
@type track: list
|
||||
@param name: Notebook label name
|
||||
@type name: str/unicode
|
||||
@param share_button: Add a share button to the Notebook tab or not
|
||||
@type name: bool
|
||||
@param move_buttons: Add up and down button to the Notebook tab or not
|
||||
@type name: bool
|
||||
"""
|
||||
GrampsTab.__init__(self,dbstate, uistate, track, name)
|
||||
self.tooltips = gtk.Tooltips()
|
||||
self.create_buttons(share_button)
|
||||
self.create_buttons(share_button, move_buttons)
|
||||
|
||||
def create_buttons(self, share_button=False):
|
||||
def create_buttons(self, share_button=False, move_buttons=False):
|
||||
"""
|
||||
Creates a button box consisting of three buttons, one for Add,
|
||||
one for Edit, and one for Delete. This button box is then appended
|
||||
@ -102,12 +109,25 @@ class ButtonTab(GrampsTab):
|
||||
self.tooltips.set_tip(self.share_btn, self._MSG['share'])
|
||||
else:
|
||||
self.share_btn = None
|
||||
|
||||
if move_buttons:
|
||||
self.up_btn = SimpleButton(gtk.STOCK_GO_UP, self.up_button_clicked)
|
||||
self.tooltips.set_tip(self.up_btn, self._MSG['up'])
|
||||
self.down_btn = SimpleButton(gtk.STOCK_GO_DOWN,
|
||||
self.down_button_clicked)
|
||||
self.tooltips.set_tip(self.down_btn, self._MSG['down'])
|
||||
else:
|
||||
self.up_btn = None
|
||||
self.down_btn = None
|
||||
|
||||
if self.dbstate.db.readonly:
|
||||
self.add_btn.set_sensitive(False)
|
||||
self.del_btn.set_sensitive(False)
|
||||
if share_button:
|
||||
self.share_btn.set_sensitive(False)
|
||||
if move_buttons:
|
||||
self.up_btn.set_sensitive(False)
|
||||
self.down_btn.set_sensitive(False)
|
||||
|
||||
vbox = gtk.VBox()
|
||||
vbox.set_spacing(6)
|
||||
@ -116,6 +136,9 @@ class ButtonTab(GrampsTab):
|
||||
vbox.pack_start(self.share_btn, False)
|
||||
vbox.pack_start(self.edit_btn, False)
|
||||
vbox.pack_start(self.del_btn, False)
|
||||
if move_buttons:
|
||||
vbox.pack_start(self.up_btn, False)
|
||||
vbox.pack_start(self.down_btn, False)
|
||||
vbox.show_all()
|
||||
self.pack_start(vbox, False)
|
||||
|
||||
@ -158,6 +181,20 @@ class ButtonTab(GrampsTab):
|
||||
class.
|
||||
"""
|
||||
print "Uncaught Edit clicked"
|
||||
|
||||
def up_button_clicked(self, obj):
|
||||
"""
|
||||
Function called with the Up button is clicked.
|
||||
This function should be overridden by the derived class.
|
||||
"""
|
||||
print "Uncaught Up clicked"
|
||||
|
||||
def down_button_clicked(self, obj):
|
||||
"""
|
||||
Function called with the Down button is clicked.
|
||||
This function should be overridden by the derived class.
|
||||
"""
|
||||
print "Uncaught Down clicked"
|
||||
|
||||
def _selection_changed(self, obj=None):
|
||||
"""
|
||||
@ -171,7 +208,17 @@ class ButtonTab(GrampsTab):
|
||||
self.edit_btn.set_sensitive(True)
|
||||
if not self.dbstate.db.readonly:
|
||||
self.del_btn.set_sensitive(True)
|
||||
# note: up and down cannot be set unsensitive after clicked
|
||||
# or they do not respond to a next click
|
||||
#if self.up_btn :
|
||||
# self.up_btn.set_sensitive(True)
|
||||
# self.down_btn.set_sensitive(True)
|
||||
else:
|
||||
self.edit_btn.set_sensitive(False)
|
||||
if not self.dbstate.db.readonly:
|
||||
self.del_btn.set_sensitive(False)
|
||||
# note: up and down cannot be set unsensitive after clicked
|
||||
# or they do not respond to a next click
|
||||
#if self.up_btn :
|
||||
# self.up_btn.set_sensitive(False)
|
||||
# self.down_btn.set_sensitive(False)
|
||||
|
@ -60,12 +60,12 @@ class EmbeddedList(ButtonTab):
|
||||
_DND_EXTRA = None
|
||||
|
||||
def __init__(self, dbstate, uistate, track, name, build_model,
|
||||
share=False):
|
||||
share=False, move=False):
|
||||
"""
|
||||
Creates a new list, using the passed build_model to
|
||||
populate the list.
|
||||
"""
|
||||
ButtonTab.__init__(self, dbstate, uistate, track, name, share)
|
||||
ButtonTab.__init__(self, dbstate, uistate, track, name, share, move)
|
||||
|
||||
|
||||
self.changed = False
|
||||
@ -232,11 +232,39 @@ class EmbeddedList(ButtonTab):
|
||||
dlist.insert(row_to-1, obj)
|
||||
self.changed = True
|
||||
self.rebuild()
|
||||
|
||||
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 = '%d' % (row_from-1)
|
||||
self.tree.get_selection().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 = '%d' % (row_from+1)
|
||||
self.tree.get_selection().select_path(path)
|
||||
|
||||
def get_icon_name(self):
|
||||
"""
|
||||
Specifies the basic icon used for a generic list. Typically,
|
||||
a derived class will override this. The icon chose is the
|
||||
a derived class will override this. The icon chosen is the
|
||||
STOCK_JUSTIFY_FILL icon, which in the default GTK style
|
||||
looks kind of like a list.
|
||||
"""
|
||||
@ -249,6 +277,20 @@ class EmbeddedList(ButtonTab):
|
||||
ref_list.remove(ref)
|
||||
self.changed = True
|
||||
self.rebuild()
|
||||
|
||||
def up_button_clicked(self, obj):
|
||||
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):
|
||||
ref = self.get_selected()
|
||||
if ref:
|
||||
pos = self.find_index(ref)
|
||||
if pos < len(self.get_data())-1:
|
||||
self._move_down(pos,ref)
|
||||
|
||||
def build_interface(self):
|
||||
"""
|
||||
|
@ -62,6 +62,8 @@ class NoteTab(EmbeddedList):
|
||||
'add' : _('Create and add a new note'),
|
||||
'del' : _('Remove the existing note'),
|
||||
'edit' : _('Edit the selected note'),
|
||||
'up' : _('Move the selected note upwards'),
|
||||
'down' : _('Move the selected note downwards'),
|
||||
}
|
||||
|
||||
_column_names = [
|
||||
@ -72,7 +74,7 @@ class NoteTab(EmbeddedList):
|
||||
def __init__(self, dbstate, uistate, track, data):
|
||||
self.data = data
|
||||
EmbeddedList.__init__(self, dbstate, uistate, track,
|
||||
_("Notes"), NoteModel)
|
||||
_("Notes"), NoteModel, move=True)
|
||||
|
||||
self.tree.drag_dest_set(gtk.DEST_DEFAULT_ALL,
|
||||
[DdTargets.NOTE_LINK.target()],
|
||||
|
Loading…
Reference in New Issue
Block a user