2007-09-12 Don Allingham <don@gramps-project.org>
* src/DataViews/_MediaView.py: update thumbnail on data update (#1226) svn: r8968
This commit is contained in:
parent
6665df0a3e
commit
ca2942e133
@ -1,3 +1,6 @@
|
|||||||
|
2007-09-12 Don Allingham <don@gramps-project.org>
|
||||||
|
* src/DataViews/_MediaView.py: update thumbnail on data update (#1226)
|
||||||
|
|
||||||
2007-09-12 Benny Malengier <benny.malengier@gramps-project.org>
|
2007-09-12 Benny Malengier <benny.malengier@gramps-project.org>
|
||||||
* src/plugins/lineage.py: Improvements
|
* src/plugins/lineage.py: Improvements
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
@ -64,13 +64,13 @@ from QuestionDialog import QuestionDialog, ErrorDialog
|
|||||||
from Filters.SideBar import MediaSidebarFilter
|
from Filters.SideBar import MediaSidebarFilter
|
||||||
from DdTargets import DdTargets
|
from DdTargets import DdTargets
|
||||||
|
|
||||||
column_names = [
|
COLUMN_NAMES = [
|
||||||
_('Title'),
|
_('Title'),
|
||||||
_('ID'),
|
_('ID'),
|
||||||
_('Type'),
|
_('Type'),
|
||||||
_('Path'),
|
_('Path'),
|
||||||
_('Last Changed'),
|
_('Last Changed'),
|
||||||
_('Date'),
|
_('Date'),
|
||||||
]
|
]
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -79,6 +79,13 @@ column_names = [
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class MediaView(PageView.ListView):
|
class MediaView(PageView.ListView):
|
||||||
|
"""
|
||||||
|
Provides the Media View interface on the GRAMPS main window. This allows
|
||||||
|
people to manage all media items in their database. This is very similar
|
||||||
|
to the other list based views, with the exeception that it also has a
|
||||||
|
thumbnail image at the top of the view that must be updated when the
|
||||||
|
selection changes or when the selected media object changes.
|
||||||
|
"""
|
||||||
|
|
||||||
ADD_MSG = _("Add a new media object")
|
ADD_MSG = _("Add a new media object")
|
||||||
EDIT_MSG = _("Edit the selected media object")
|
EDIT_MSG = _("Edit the selected media object")
|
||||||
@ -90,24 +97,24 @@ class MediaView(PageView.ListView):
|
|||||||
def __init__(self, dbstate, uistate):
|
def __init__(self, dbstate, uistate):
|
||||||
|
|
||||||
signal_map = {
|
signal_map = {
|
||||||
'media-add' : self.row_add,
|
'media-add' : self.row_add,
|
||||||
'media-update' : self.row_update,
|
'media-update' : self.row_update,
|
||||||
'media-delete' : self.row_delete,
|
'media-delete' : self.row_delete,
|
||||||
'media-rebuild' : self.build_tree,
|
'media-rebuild' : self.build_tree,
|
||||||
}
|
}
|
||||||
|
|
||||||
PageView.ListView.__init__(
|
PageView.ListView.__init__(
|
||||||
self, _('Media'), dbstate, uistate,
|
self, _('Media'), dbstate, uistate,
|
||||||
column_names,len(column_names), DisplayModels.MediaModel,
|
COLUMN_NAMES, len(COLUMN_NAMES), DisplayModels.MediaModel,
|
||||||
signal_map, dbstate.db.get_media_bookmarks(),
|
signal_map, dbstate.db.get_media_bookmarks(),
|
||||||
Bookmarks.MediaBookmarks, filter_class=MediaSidebarFilter)
|
Bookmarks.MediaBookmarks, filter_class=MediaSidebarFilter)
|
||||||
|
|
||||||
self.func_list = {
|
self.func_list = {
|
||||||
'<CONTROL>J' : self.jump,
|
'<CONTROL>J' : self.jump,
|
||||||
'<CONTROL>BackSpace' : self.key_delete,
|
'<CONTROL>BackSpace' : self.key_delete,
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.client.notify_add("/apps/gramps/interface/filter",
|
Config.client.notify_add("/apps/gramps/interface/filter",
|
||||||
self.filter_toggle)
|
self.filter_toggle)
|
||||||
|
|
||||||
def _set_dnd(self):
|
def _set_dnd(self):
|
||||||
@ -119,10 +126,10 @@ class MediaView(PageView.ListView):
|
|||||||
|
|
||||||
dnd_types = [ self._DND_TYPE.target() ]
|
dnd_types = [ self._DND_TYPE.target() ]
|
||||||
|
|
||||||
self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, dnd_types,
|
self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, dnd_types,
|
||||||
gtk.gdk.ACTION_COPY)
|
gtk.gdk.ACTION_COPY)
|
||||||
self.list.drag_source_set(gtk.gdk.BUTTON1_MASK,
|
self.list.drag_source_set(gtk.gdk.BUTTON1_MASK,
|
||||||
[self._DND_TYPE.target()],
|
[self._DND_TYPE.target()],
|
||||||
gtk.gdk.ACTION_COPY)
|
gtk.gdk.ACTION_COPY)
|
||||||
self.list.connect('drag_data_get', self.drag_data_get)
|
self.list.connect('drag_data_get', self.drag_data_get)
|
||||||
self.list.connect('drag_data_received', self.drag_data_received)
|
self.list.connect('drag_data_received', self.drag_data_received)
|
||||||
@ -148,6 +155,10 @@ class MediaView(PageView.ListView):
|
|||||||
sel_data.set(sel_data.target, 8, pickle.dumps(data))
|
sel_data.set(sel_data.target, 8, pickle.dumps(data))
|
||||||
|
|
||||||
def drag_info(self):
|
def drag_info(self):
|
||||||
|
"""
|
||||||
|
Returns the type of DND targetst that this view will accept. For Media
|
||||||
|
View, we will accept media objects.
|
||||||
|
"""
|
||||||
return DdTargets.MEDIAOBJ
|
return DdTargets.MEDIAOBJ
|
||||||
|
|
||||||
def find_index(self, obj):
|
def find_index(self, obj):
|
||||||
@ -160,12 +171,12 @@ class MediaView(PageView.ListView):
|
|||||||
"""
|
"""
|
||||||
Handle the standard gtk interface for drag_data_received.
|
Handle the standard gtk interface for drag_data_received.
|
||||||
|
|
||||||
If the selection data is define, extract the value from sel_data.data,
|
If the selection data is define, extract the value from sel_data.data,
|
||||||
and decide if this is a move or a reorder.
|
and decide if this is a move or a reorder.
|
||||||
"""
|
"""
|
||||||
if sel_data and sel_data.data:
|
if sel_data and sel_data.data:
|
||||||
cleaned_string = sel_data.data.replace('\0',' ')
|
cleaned_string = sel_data.data.replace('\0', ' ')
|
||||||
cleaned_string = cleaned_string.replace("\r"," ").strip()
|
cleaned_string = cleaned_string.replace("\r", " ").strip()
|
||||||
data_list = Utils.fix_encoding(cleaned_string).split('\n')
|
data_list = Utils.fix_encoding(cleaned_string).split('\n')
|
||||||
for d in [item.strip() for item in data_list]:
|
for d in [item.strip() for item in data_list]:
|
||||||
protocol, site, mfile, j, k, l = urlparse.urlparse(d)
|
protocol, site, mfile, j, k, l = urlparse.urlparse(d)
|
||||||
@ -182,24 +193,36 @@ class MediaView(PageView.ListView):
|
|||||||
photo.set_description(root)
|
photo.set_description(root)
|
||||||
trans = self.dbstate.db.transaction_begin()
|
trans = self.dbstate.db.transaction_begin()
|
||||||
self.dbstate.db.add_object(photo, trans)
|
self.dbstate.db.add_object(photo, trans)
|
||||||
self.dbstate.db.transaction_commit(trans,
|
self.dbstate.db.transaction_commit(trans,
|
||||||
_("Drag Media Object"))
|
_("Drag Media Object"))
|
||||||
widget.emit_stop_by_name('drag_data_received')
|
widget.emit_stop_by_name('drag_data_received')
|
||||||
|
|
||||||
def get_bookmarks(self):
|
def get_bookmarks(self):
|
||||||
|
"""
|
||||||
|
Returns the booksmarks associated with this view
|
||||||
|
"""
|
||||||
return self.dbstate.db.get_media_bookmarks()
|
return self.dbstate.db.get_media_bookmarks()
|
||||||
|
|
||||||
def define_actions(self):
|
def define_actions(self):
|
||||||
|
"""
|
||||||
|
Defines the UIManager actions specific to Media View. We need to make
|
||||||
|
sure that the common List View actions are defined as well, so we
|
||||||
|
call the parent function.
|
||||||
|
"""
|
||||||
PageView.ListView.define_actions(self)
|
PageView.ListView.define_actions(self)
|
||||||
|
|
||||||
self.add_action('ColumnEdit', gtk.STOCK_PROPERTIES,
|
self.add_action('ColumnEdit', gtk.STOCK_PROPERTIES,
|
||||||
_('_Column Editor'), callback=self.column_editor)
|
_('_Column Editor'), callback=self.column_editor)
|
||||||
self.add_action('FilterEdit', None, _('Media Filter Editor'),
|
self.add_action('FilterEdit', None, _('Media Filter Editor'),
|
||||||
callback=self.filter_editor)
|
callback=self.filter_editor)
|
||||||
self.add_action('OpenMedia', 'gramps-viewmedia', _('View'),
|
self.add_action('OpenMedia', 'gramps-viewmedia', _('View'),
|
||||||
tip=_("View in the default viewer"), callback=self.view_media)
|
tip=_("View in the default viewer"),
|
||||||
|
callback=self.view_media)
|
||||||
|
|
||||||
def view_media(self, obj):
|
def view_media(self, obj):
|
||||||
|
"""
|
||||||
|
Launch external viewers based of mime types for the selected objects.
|
||||||
|
"""
|
||||||
mlist = []
|
mlist = []
|
||||||
self.selection.selected_foreach(self.blist, mlist)
|
self.selection.selected_foreach(self.blist, mlist)
|
||||||
|
|
||||||
@ -209,39 +232,54 @@ class MediaView(PageView.ListView):
|
|||||||
app = Mime.get_application(mime_type)
|
app = Mime.get_application(mime_type)
|
||||||
if app:
|
if app:
|
||||||
Utils.launch(app[0], ref_obj.get_path())
|
Utils.launch(app[0], ref_obj.get_path())
|
||||||
else:
|
else:
|
||||||
ErrorDialog(_("Cannot view %s") % ref_obj.get_path(),
|
ErrorDialog(_("Cannot view %s") % ref_obj.get_path(),
|
||||||
_("GRAMPS cannot find an application that can view "
|
_("GRAMPS cannot find an application that can view "
|
||||||
"a file type of %s.") % mime_type)
|
"a file type of %s.") % mime_type)
|
||||||
|
|
||||||
def column_editor(self, obj):
|
def column_editor(self, obj):
|
||||||
|
"""
|
||||||
|
Start the column editor dialog
|
||||||
|
"""
|
||||||
import ColumnOrder
|
import ColumnOrder
|
||||||
|
|
||||||
ColumnOrder.ColumnOrder(
|
ColumnOrder.ColumnOrder(
|
||||||
_('Select Media Columns'),
|
_('Select Media Columns'),
|
||||||
self.uistate,
|
self.uistate,
|
||||||
self.dbstate.db.get_media_column_order(),
|
self.dbstate.db.get_media_column_order(),
|
||||||
column_names,
|
COLUMN_NAMES,
|
||||||
self.set_column_order)
|
self.set_column_order)
|
||||||
|
|
||||||
def set_column_order(self, clist):
|
def set_column_order(self, clist):
|
||||||
|
"""
|
||||||
|
Saves the column order to the database
|
||||||
|
"""
|
||||||
self.dbstate.db.set_media_column_order(clist)
|
self.dbstate.db.set_media_column_order(clist)
|
||||||
self.build_columns()
|
self.build_columns()
|
||||||
|
|
||||||
def column_order(self):
|
def column_order(self):
|
||||||
|
"""
|
||||||
|
Gets the column order from the database
|
||||||
|
"""
|
||||||
return self.dbstate.db.get_media_column_order()
|
return self.dbstate.db.get_media_column_order()
|
||||||
|
|
||||||
def get_stock(self):
|
def get_stock(self):
|
||||||
|
"""
|
||||||
|
Return the icon for this view
|
||||||
|
"""
|
||||||
return 'gramps-media'
|
return 'gramps-media'
|
||||||
|
|
||||||
def build_widget(self):
|
def build_widget(self):
|
||||||
|
"""
|
||||||
|
Builds the View from GTK components
|
||||||
|
"""
|
||||||
base = PageView.ListView.build_widget(self)
|
base = PageView.ListView.build_widget(self)
|
||||||
vbox = gtk.VBox()
|
vbox = gtk.VBox()
|
||||||
vbox.set_border_width(0)
|
vbox.set_border_width(0)
|
||||||
vbox.set_spacing(4)
|
vbox.set_spacing(4)
|
||||||
|
|
||||||
self.image = gtk.Image()
|
self.image = gtk.Image()
|
||||||
self.image.set_size_request(int(const.THUMBSCALE),
|
self.image.set_size_request(int(const.THUMBSCALE),
|
||||||
int(const.THUMBSCALE))
|
int(const.THUMBSCALE))
|
||||||
ebox = gtk.EventBox()
|
ebox = gtk.EventBox()
|
||||||
ebox.add(self.image)
|
ebox.add(self.image)
|
||||||
@ -249,36 +287,53 @@ class MediaView(PageView.ListView):
|
|||||||
vbox.pack_start(ebox, False)
|
vbox.pack_start(ebox, False)
|
||||||
vbox.pack_start(base, True)
|
vbox.pack_start(base, True)
|
||||||
|
|
||||||
self.tt = gtk.Tooltips()
|
self.ttips = gtk.Tooltips()
|
||||||
self.tt.set_tip(ebox,
|
self.ttips.set_tip(
|
||||||
_('Double click image to view in an external viewer'))
|
ebox, _('Double click image to view in an external viewer'))
|
||||||
|
|
||||||
self.selection.connect('changed', self.row_change)
|
self.selection.connect('changed', self.row_change)
|
||||||
self._set_dnd()
|
self._set_dnd()
|
||||||
return vbox
|
return vbox
|
||||||
|
|
||||||
def button_press_event(self, obj, event):
|
def button_press_event(self, obj, event):
|
||||||
|
"""
|
||||||
|
Event handler that catches a double click, and and launches a viewer for
|
||||||
|
the selected object.
|
||||||
|
"""
|
||||||
if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
|
if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
|
||||||
self.view_media(obj)
|
self.view_media(obj)
|
||||||
|
|
||||||
|
def row_update(self, obj):
|
||||||
|
"""
|
||||||
|
Update the data in the row. we override this because the Media View adds
|
||||||
|
additional functionality to the normal List View. The Media View may
|
||||||
|
have to update the thumbnail image. So, we call the parent task to
|
||||||
|
handle the normal operation, then call row_change to make sure that
|
||||||
|
the thumbnail is updated properly if needed.
|
||||||
|
"""
|
||||||
|
PageView.ListView.row_update(self, obj)
|
||||||
|
if self.active:
|
||||||
|
self.row_change(obj)
|
||||||
|
|
||||||
def row_change(self, obj):
|
def row_change(self, obj):
|
||||||
|
"""
|
||||||
|
Update the thumbnail on a row change. If nothing is selected, clear
|
||||||
|
the thumbnail image.
|
||||||
|
"""
|
||||||
handle = self.first_selected()
|
handle = self.first_selected()
|
||||||
if not handle:
|
if not handle:
|
||||||
try:
|
self.image.clear()
|
||||||
self.image.clear()
|
self.ttips.disable()
|
||||||
self.tt.disable()
|
|
||||||
except AttributeError:
|
|
||||||
# Working around the older pygtk
|
|
||||||
# that lacks clear() method for gtk.Image()
|
|
||||||
self.image.set_from_file(None)
|
|
||||||
self.tt.enable()
|
|
||||||
else:
|
else:
|
||||||
obj = self.dbstate.db.get_object_from_handle(handle)
|
obj = self.dbstate.db.get_object_from_handle(handle)
|
||||||
pix = ThumbNails.get_thumbnail_image(obj.get_path())
|
pix = ThumbNails.get_thumbnail_image(obj.get_path())
|
||||||
self.image.set_from_pixbuf(pix)
|
self.image.set_from_pixbuf(pix)
|
||||||
self.tt.enable()
|
self.ttips.enable()
|
||||||
|
|
||||||
def ui_definition(self):
|
def ui_definition(self):
|
||||||
|
"""
|
||||||
|
Returns the UIManager XML description of the menus
|
||||||
|
"""
|
||||||
return '''<ui>
|
return '''<ui>
|
||||||
<menubar name="MenuBar">
|
<menubar name="MenuBar">
|
||||||
<menu action="FileMenu">
|
<menu action="FileMenu">
|
||||||
@ -308,8 +363,8 @@ class MediaView(PageView.ListView):
|
|||||||
<toolitem action="Edit"/>
|
<toolitem action="Edit"/>
|
||||||
<toolitem action="Remove"/>
|
<toolitem action="Remove"/>
|
||||||
</placeholder>
|
</placeholder>
|
||||||
<separator/>
|
<separator/>
|
||||||
<toolitem action="OpenMedia"/>
|
<toolitem action="OpenMedia"/>
|
||||||
</toolbar>
|
</toolbar>
|
||||||
<popup name="Popup">
|
<popup name="Popup">
|
||||||
<menuitem action="Add"/>
|
<menuitem action="Add"/>
|
||||||
@ -326,12 +381,16 @@ class MediaView(PageView.ListView):
|
|||||||
am.run()
|
am.run()
|
||||||
|
|
||||||
def remove(self, obj):
|
def remove(self, obj):
|
||||||
|
"""
|
||||||
|
Removes the selected object from the database after getting
|
||||||
|
user verification.
|
||||||
|
"""
|
||||||
handle = self.first_selected()
|
handle = self.first_selected()
|
||||||
if not handle:
|
if not handle:
|
||||||
return
|
return
|
||||||
the_lists = Utils.get_media_referents(handle, self.dbstate.db)
|
the_lists = Utils.get_media_referents(handle, self.dbstate.db)
|
||||||
|
|
||||||
ans = DeleteMediaQuery(self.dbstate,self.uistate,handle,the_lists)
|
ans = DeleteMediaQuery(self.dbstate, self.uistate, handle, the_lists)
|
||||||
if filter(None, the_lists): # quick test for non-emptiness
|
if filter(None, the_lists): # quick test for non-emptiness
|
||||||
msg = _('This media object is currently being used. '
|
msg = _('This media object is currently being used. '
|
||||||
'If you delete this object, it will be removed from '
|
'If you delete this object, it will be removed from '
|
||||||
@ -341,11 +400,14 @@ class MediaView(PageView.ListView):
|
|||||||
|
|
||||||
msg = "%s %s" % (msg, Utils.data_recover_msg)
|
msg = "%s %s" % (msg, Utils.data_recover_msg)
|
||||||
self.uistate.set_busy_cursor(1)
|
self.uistate.set_busy_cursor(1)
|
||||||
QuestionDialog(_('Delete Media Object?'), msg,
|
QuestionDialog(_('Delete Media Object?'), msg,
|
||||||
_('_Delete Media Object'), ans.query_response)
|
_('_Delete Media Object'), ans.query_response)
|
||||||
self.uistate.set_busy_cursor(0)
|
self.uistate.set_busy_cursor(0)
|
||||||
|
|
||||||
def edit(self, obj):
|
def edit(self, obj):
|
||||||
|
"""
|
||||||
|
Edit the selected object in the EditMedia dialog
|
||||||
|
"""
|
||||||
handle = self.first_selected()
|
handle = self.first_selected()
|
||||||
if not handle:
|
if not handle:
|
||||||
return
|
return
|
||||||
@ -357,6 +419,9 @@ class MediaView(PageView.ListView):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def get_handle_from_gramps_id(self, gid):
|
def get_handle_from_gramps_id(self, gid):
|
||||||
|
"""
|
||||||
|
returns the handle of the specified object
|
||||||
|
"""
|
||||||
obj = self.dbstate.db.get_object_from_gramps_id(gid)
|
obj = self.dbstate.db.get_object_from_gramps_id(gid)
|
||||||
if obj:
|
if obj:
|
||||||
return obj.get_handle()
|
return obj.get_handle()
|
||||||
|
Loading…
Reference in New Issue
Block a user