* src/DataViews/MediaView.py:
* src/DataViews/RepositoryView.py: * src/DataViews/SourceView.py: * src/DataViews/EventView.py: * src/DataViews/PlaceView.py: * src/PageView.py: Remove unused double click procedure * src/plugins/SimpleBookTitle.py: remove use of AddMedia * src/Editors/AddMedia.py: added * src/AddMedia.py: removed * src/Editors/Makefile.am: * src/Makefile.am: * po/POTFILES.in: Move AddMedia to the editors directory * src/Editors/_EditMedia.py: Edit Media now works as other editors, spawning AddMedia when select is clicked. * src/ManagedWindow.py: typo in comment * src/Config/_GrampsConfigKeys.py: Two new keys, rerun ./autogen.sh Still todo: make relative path work 2008-01-06 Benny Malengier <benny.malengier@gramps-project.org> svn: r9722
This commit is contained in:
parent
aabef20651
commit
9664842702
22
ChangeLog
22
ChangeLog
@ -1,3 +1,25 @@
|
||||
2008-01-06 Benny Malengier <benny.malengier@gramps-project.org>
|
||||
* src/DataViews/MediaView.py:
|
||||
* src/DataViews/RepositoryView.py:
|
||||
* src/DataViews/SourceView.py:
|
||||
* src/DataViews/EventView.py:
|
||||
* src/DataViews/PlaceView.py:
|
||||
* src/PageView.py:
|
||||
Remove unused double click procedure
|
||||
* src/plugins/SimpleBookTitle.py: remove use of AddMedia
|
||||
* src/Editors/AddMedia.py: added
|
||||
* src/AddMedia.py: removed
|
||||
* src/Editors/Makefile.am:
|
||||
* src/Makefile.am:
|
||||
* po/POTFILES.in:
|
||||
Move AddMedia to the editors directory
|
||||
* src/Editors/_EditMedia.py:
|
||||
Edit Media now works as other editors, spawning AddMedia when
|
||||
select is clicked.
|
||||
* src/ManagedWindow.py: typo in comment
|
||||
* src/Config/_GrampsConfigKeys.py: Two new keys, rerun ./autogen.sh
|
||||
Still todo: make relative path work
|
||||
|
||||
2008-01-06 Benny Malengier <benny.malengier@gramps-project.org>
|
||||
* src/plugins/DefaultGadgets.py: handle long text in standard way for
|
||||
translation
|
||||
|
@ -3,7 +3,6 @@
|
||||
#
|
||||
# Python files
|
||||
#
|
||||
src/AddMedia.py
|
||||
src/ansel_utf8.py
|
||||
src/ArgHandler.py
|
||||
src/Assistant.py
|
||||
@ -169,6 +168,7 @@ src/DisplayTabs/_WebModel.py
|
||||
src/DisplayTabs/__init__.py
|
||||
|
||||
# Editors package
|
||||
src/Editors/AddMedia.py
|
||||
src/Editors/_EditAddress.py
|
||||
src/Editors/_EditAttribute.py
|
||||
src/Editors/_EditChildRef.py
|
||||
|
@ -164,6 +164,8 @@ MIN_GENERATION_YEARS = ('behavior', 'min-generation-years', 1)
|
||||
AVG_GENERATION_GAP = ('behavior', 'avg-generation-gap', 1)
|
||||
GENERATION_DEPTH = ('behavior', 'generation-depth', 1)
|
||||
DATA_VIEWS = ('interface','data-views', 2)
|
||||
ADDMEDIA_IMGDIR = ('behavior', 'addmedia-image-dir', 2)
|
||||
ADDMEDIA_RELPATH = ('behavior', 'addmedia-relative-path', 0)
|
||||
|
||||
default_value = {
|
||||
DEFAULT_SOURCE : False,
|
||||
@ -283,4 +285,6 @@ default_value = {
|
||||
DATA_VIEWS: ('MyGrampsView,PersonView,RelationshipView,FamilyListView,'
|
||||
'PedigreeView,EventView,SourceView,PlaceView,MediaView,'
|
||||
'RepositoryView,NoteView'),
|
||||
ADDMEDIA_IMGDIR : '',
|
||||
ADDMEDIA_RELPATH : False,
|
||||
}
|
||||
|
@ -214,14 +214,6 @@ class EventView(PageView.ListView):
|
||||
self.dbstate.db.set_event_column_order(clist)
|
||||
self.build_columns()
|
||||
|
||||
def on_double_click(self, obj, event):
|
||||
handle = self.first_selected()
|
||||
the_event = self.dbstate.db.get_event_from_handle(handle)
|
||||
try:
|
||||
EditEvent(self.dbstate, self.uistate, [], the_event)
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
|
||||
def add(self, obj):
|
||||
try:
|
||||
EditEvent(self.dbstate, self.uistate, [], gen.lib.Event())
|
||||
|
@ -378,9 +378,10 @@ class MediaView(PageView.ListView):
|
||||
|
||||
def add(self, obj):
|
||||
"""Add a new media object to the media list"""
|
||||
import AddMedia
|
||||
am = AddMedia.AddMediaObject(self.dbstate, self.uistate, [])
|
||||
am.run()
|
||||
try:
|
||||
EditMedia(self.dbstate, self.uistate, [], gen.lib.MediaObject())
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
|
||||
def remove(self, obj):
|
||||
"""
|
||||
|
@ -217,14 +217,6 @@ class PlaceView(PageView.ListView):
|
||||
</popup>
|
||||
</ui>'''
|
||||
|
||||
def on_double_click(self, obj, event):
|
||||
handle = self.first_selected()
|
||||
place = self.dbstate.db.get_place_from_handle(handle)
|
||||
try:
|
||||
EditPlace(self.dbstate, self.uistate, [], place)
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
|
||||
def add(self, obj):
|
||||
try:
|
||||
EditPlace(self.dbstate, self.uistate, [], gen.lib.Place())
|
||||
|
@ -182,14 +182,6 @@ class RepositoryView(PageView.ListView):
|
||||
</popup>
|
||||
</ui>'''
|
||||
|
||||
def on_double_click(self, obj, event):
|
||||
handle = self.first_selected()
|
||||
repos = self.dbstate.db.get_repository_from_handle(handle)
|
||||
try:
|
||||
EditRepository(self.dbstate, self.uistate, [], repos)
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
|
||||
def add(self, obj):
|
||||
EditRepository(self.dbstate, self.uistate, [], gen.lib.Repository())
|
||||
|
||||
|
@ -180,14 +180,6 @@ class SourceView(PageView.ListView):
|
||||
</popup>
|
||||
</ui>'''
|
||||
|
||||
def on_double_click(self, obj, event):
|
||||
handle = self.first_selected()
|
||||
source = self.dbstate.db.get_source_from_handle(handle)
|
||||
try:
|
||||
EditSource(self.dbstate, self.uistate, [], source)
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
|
||||
def add(self, obj):
|
||||
EditSource(self.dbstate, self.uistate, [], gen.lib.Source())
|
||||
|
||||
|
@ -53,6 +53,7 @@ import gtk.glade
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import Config
|
||||
import Utils
|
||||
import gen.lib
|
||||
import Mime
|
||||
@ -65,8 +66,7 @@ import ManagedWindow
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
_last_directory = None
|
||||
_relative_path = False
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -76,19 +76,26 @@ _relative_path = False
|
||||
class AddMediaObject(ManagedWindow.ManagedWindow):
|
||||
"""
|
||||
Displays the Add Media Dialog window, allowing the user to select
|
||||
a media object from the file system, while providing a description.
|
||||
a file from the file system, while providing a description.
|
||||
"""
|
||||
|
||||
def __init__(self, dbstate, uistate, track):
|
||||
def __init__(self, dbstate, uistate, track, mediaobj, callback=None):
|
||||
"""
|
||||
Creates and displays the dialog box
|
||||
|
||||
db - the database in which the new object is to be stored
|
||||
The mediaobject is updated with the information, and on save, the
|
||||
callback function is called
|
||||
"""
|
||||
|
||||
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
|
||||
|
||||
self.dbase = dbstate.db
|
||||
self.obj = mediaobj
|
||||
self.callback = callback
|
||||
|
||||
self.last_directory = Config.get(Config.ADDMEDIA_IMGDIR)
|
||||
self.relative_path = Config.get(Config.ADDMEDIA_RELPATH)
|
||||
|
||||
self.glade = gtk.glade.XML(const.GLADE_FILE, "imageSelect", "gramps")
|
||||
|
||||
self.set_window(
|
||||
@ -99,37 +106,40 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
|
||||
self.description = self.glade.get_widget("photoDescription")
|
||||
self.image = self.glade.get_widget("image")
|
||||
self.file_text = self.glade.get_widget("fname")
|
||||
if _last_directory and os.path.isdir(_last_directory):
|
||||
self.file_text.set_current_folder(_last_directory)
|
||||
if not(self.last_directory and os.path.isdir(self.last_directory)):
|
||||
self.last_directory = const.HOME_DIR
|
||||
print 'test', self.last_directory
|
||||
self.file_text.set_current_folder(self.last_directory)
|
||||
|
||||
self.relpath = self.glade.get_widget('relpath')
|
||||
self.relpath.set_active(_relative_path)
|
||||
self.relpath.set_active(self.relative_path)
|
||||
self.temp_name = ""
|
||||
self.object = None
|
||||
|
||||
self.glade.get_widget('fname').connect('update_preview',
|
||||
self.on_name_changed)
|
||||
self.ok_button = self.glade.get_widget('button79')
|
||||
self.help_button = self.glade.get_widget('button103')
|
||||
self.cancel_button = self.glade.get_widget('button81')
|
||||
self.ok_button.connect('clicked',self.save)
|
||||
self.ok_button.set_sensitive(not self.dbase.readonly)
|
||||
self.help_button.connect('clicked', lambda x: GrampsDisplay.help(
|
||||
'gramps-edit-quick'))
|
||||
self.cancel_button.connect('clicked', self.close)
|
||||
self.show()
|
||||
self.modal_call()
|
||||
|
||||
def build_menu_names(self, obj):
|
||||
"""
|
||||
Build the menu name for the window manager
|
||||
"""
|
||||
return(_('Select media object'), None)
|
||||
|
||||
def on_help_imagesel_clicked(self, obj):
|
||||
"""Display the relevant portion of GRAMPS manual"""
|
||||
GrampsDisplay.help('gramps-edit-quick')
|
||||
self.window.run()
|
||||
|
||||
def save(self):
|
||||
def save(self, *obj):
|
||||
"""
|
||||
Callback function called with the save button is pressed.
|
||||
A new media object is created, and added to the database.
|
||||
The media object is updated, and callback called
|
||||
"""
|
||||
|
||||
global _last_directory, _relative_path
|
||||
|
||||
description = unicode(self.description.get_text())
|
||||
|
||||
if self.file_text.get_filename() is None:
|
||||
@ -141,13 +151,14 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
|
||||
filename = Utils.get_unicode_path(self.file_text.get_filename())
|
||||
full_file = filename
|
||||
|
||||
pname = self.dbase.get_save_path()
|
||||
if not os.path.isdir(pname):
|
||||
pname = os.path.dirname(pname)
|
||||
|
||||
if self.relpath.get_active():
|
||||
pname = self.dbase.get_save_path()
|
||||
if not os.path.isdir(pname):
|
||||
pname = os.path.dirname(pname)
|
||||
filename = Utils.relative_path(filename, pname)
|
||||
|
||||
if os.path.exists(filename) == 0:
|
||||
if os.path.exists(pname) == 0:
|
||||
msgstr = _("Cannot import %s")
|
||||
msgstr2 = _("The filename supplied could not be found.")
|
||||
ErrorDialog(msgstr % filename, msgstr2)
|
||||
@ -157,21 +168,17 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
|
||||
if description == "":
|
||||
description = os.path.basename(filename)
|
||||
|
||||
mobj = gen.lib.MediaObject()
|
||||
mobj.set_description(description)
|
||||
mobj.set_mime_type(mtype)
|
||||
self.obj.set_description(description)
|
||||
self.obj.set_mime_type(mtype)
|
||||
name = filename
|
||||
mobj.set_path(name)
|
||||
_last_directory = os.path.dirname(full_file)
|
||||
_relative_path = self.relpath.get_active()
|
||||
self.obj.set_path(name)
|
||||
|
||||
self.last_directory = os.path.dirname(full_file)
|
||||
self.relative_path = self.relpath.get_active()
|
||||
|
||||
mobj.set_handle(Utils.create_id())
|
||||
if not mobj.get_gramps_id():
|
||||
mobj.set_gramps_id(self.dbase.find_next_object_gramps_id())
|
||||
trans = self.dbase.transaction_begin()
|
||||
self.object = mobj
|
||||
self.dbase.commit_media_object(mobj, trans)
|
||||
self.dbase.transaction_commit(trans, _("Add Media Object"))
|
||||
self._cleanup_on_exit()
|
||||
if self.callback:
|
||||
self.callback(self.obj)
|
||||
|
||||
def on_name_changed(self, *obj):
|
||||
"""
|
||||
@ -200,23 +207,10 @@ class AddMediaObject(ManagedWindow.ManagedWindow):
|
||||
image = Mime.find_mime_type_pixbuf(mtype)
|
||||
self.image.set_from_pixbuf(image)
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Run the dialog, returning the selected object.
|
||||
"""
|
||||
while True:
|
||||
val = self.window.run()
|
||||
|
||||
if val == gtk.RESPONSE_OK:
|
||||
self.save()
|
||||
self.close()
|
||||
return self.object
|
||||
elif val == gtk.RESPONSE_HELP:
|
||||
self.on_help_imagesel_clicked(None)
|
||||
else:
|
||||
self.close()
|
||||
return None
|
||||
return None
|
||||
def _cleanup_on_exit(self):
|
||||
Config.set(Config.ADDMEDIA_IMGDIR, self.last_directory)
|
||||
Config.set(Config.ADDMEDIA_RELPATH, self.relative_path)
|
||||
Config.sync()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
@ -6,6 +6,7 @@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@/Editors
|
||||
|
||||
pkgdata_PYTHON = \
|
||||
AddMedia.py\
|
||||
__init__.py\
|
||||
_EditAddress.py \
|
||||
_EditAttribute.py \
|
||||
|
@ -48,6 +48,7 @@ import Mime
|
||||
import ThumbNails
|
||||
import Utils
|
||||
from _EditPrimary import EditPrimary
|
||||
from AddMedia import AddMediaObject
|
||||
|
||||
from GrampsWidgets import *
|
||||
from DisplayTabs import SourceEmbedList,AttrEmbedList,NoteTab,MediaBackRefList
|
||||
@ -59,10 +60,14 @@ from DisplayTabs import SourceEmbedList,AttrEmbedList,NoteTab,MediaBackRefList
|
||||
#-------------------------------------------------------------------------
|
||||
class EditMedia(EditPrimary):
|
||||
|
||||
def __init__(self,state,uistate,track,obj):
|
||||
def __init__(self, state, uistate, track, obj, callback=None):
|
||||
|
||||
EditPrimary.__init__(self, state, uistate, track, obj,
|
||||
state.db.get_object_from_handle)
|
||||
state.db.get_object_from_handle, callback)
|
||||
if not self.obj.get_handle():
|
||||
#show the addmedia dialog immediately, with track of parent.
|
||||
AddMediaObject(state, self.uistate, self.track, self.obj,
|
||||
self._update_addmedia)
|
||||
|
||||
def empty_object(self):
|
||||
return gen.lib.MediaObject()
|
||||
@ -94,8 +99,9 @@ class EditMedia(EditPrimary):
|
||||
|
||||
def _connect_signals(self):
|
||||
self.define_cancel_button(self.glade.get_widget('button91'))
|
||||
self.define_ok_button(self.glade.get_widget('ok'),self.save)
|
||||
self.define_help_button(self.glade.get_widget('button102'),'adv-media')
|
||||
self.define_ok_button(self.glade.get_widget('ok'), self.save)
|
||||
self.define_help_button(self.glade.get_widget('button102'),
|
||||
'adv-media')
|
||||
|
||||
def _setup_fields(self):
|
||||
self.date_field = MonitoredDate(
|
||||
@ -122,25 +128,36 @@ class EditMedia(EditPrimary):
|
||||
self.glade.get_widget("private"),
|
||||
self.obj, self.db.readonly)
|
||||
|
||||
pixmap = self.glade.get_widget("pixmap")
|
||||
self.pixmap = self.glade.get_widget("pixmap")
|
||||
ebox = self.glade.get_widget('eventbox')
|
||||
ebox.connect('button-press-event', self.button_press_event)
|
||||
|
||||
self.mimetext = self.glade.get_widget("type")
|
||||
self.draw_preview()
|
||||
self.setup_filepath()
|
||||
|
||||
def draw_preview(self):
|
||||
mtype = self.obj.get_mime_type()
|
||||
if mtype:
|
||||
pb = ThumbNails.get_thumbnail_image(
|
||||
Utils.find_file(self.obj.get_path()),mtype)
|
||||
pixmap.set_from_pixbuf(pb)
|
||||
Utils.find_file(self.obj.get_path()), mtype)
|
||||
self.pixmap.set_from_pixbuf(pb)
|
||||
descr = Mime.get_description(mtype)
|
||||
if descr:
|
||||
self.glade.get_widget("type").set_text(descr)
|
||||
self.mimetext.set_text(descr)
|
||||
else:
|
||||
pb = Mime.find_mime_type_pixbuf('text/plain')
|
||||
pixmap.set_from_pixbuf(pb)
|
||||
self.glade.get_widget("type").set_text(_('Note'))
|
||||
self.pixmap.set_from_pixbuf(pb)
|
||||
self.mimetext.set_text(_('Note'))
|
||||
|
||||
def setup_filepath(self):
|
||||
self.select = self.glade.get_widget('file_select')
|
||||
self.file_path = self.glade.get_widget("path")
|
||||
|
||||
fname = self.obj.get_path()
|
||||
self.file_path.set_text(fname)
|
||||
self.select.connect('clicked', self.select_file)
|
||||
|
||||
self.setup_filepath()
|
||||
|
||||
def _create_tabbed_pages(self):
|
||||
notebook = gtk.Notebook()
|
||||
|
||||
@ -176,7 +193,6 @@ class EditMedia(EditPrimary):
|
||||
self.view_media(obj)
|
||||
|
||||
def view_media(self, obj):
|
||||
|
||||
ref_obj = self.dbstate.db.get_object_from_handle(self.obj.handle)
|
||||
mime_type = ref_obj.get_mime_type()
|
||||
app = Mime.get_application(mime_type)
|
||||
@ -184,34 +200,24 @@ class EditMedia(EditPrimary):
|
||||
import Utils
|
||||
Utils.launch(app[0],ref_obj.get_path())
|
||||
|
||||
def select_file(self,obj):
|
||||
f = gtk.FileChooserDialog(
|
||||
_('Select Media Object'),
|
||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(gtk.STOCK_CANCEL,
|
||||
gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OPEN,
|
||||
gtk.RESPONSE_OK))
|
||||
def select_file(self, val):
|
||||
AddMediaObject(self.dbstate, self.uistate, self.track, self.obj,
|
||||
self._update_addmedia)
|
||||
|
||||
text = self.file_path.get_text()
|
||||
path = os.path.dirname(text)
|
||||
|
||||
f.set_filename(path)
|
||||
|
||||
status = f.run()
|
||||
if status == gtk.RESPONSE_OK:
|
||||
self.file_path.set_text(Utils.get_unicode_path(f.get_filename()))
|
||||
f.destroy()
|
||||
|
||||
def setup_filepath(self):
|
||||
self.select = self.glade.get_widget('file_select')
|
||||
self.file_path = self.glade.get_widget("path")
|
||||
|
||||
def _update_addmedia(self, obj):
|
||||
"""
|
||||
Called when the add media dialog has been called.
|
||||
This allows us to update the main form in response to
|
||||
any changes: Redraw relevant fields: description, mimetype and path
|
||||
"""
|
||||
for obj in (self.descr_window, ):
|
||||
obj.update()
|
||||
fname = self.obj.get_path()
|
||||
self.file_path.set_text(fname)
|
||||
self.select.connect('clicked', self.select_file)
|
||||
|
||||
self.draw_preview()
|
||||
|
||||
def save(self, *obj):
|
||||
self.ok_button.set_sensitive(False)
|
||||
path = self.glade.get_widget('path').get_text()
|
||||
|
||||
if path != self.obj.get_path():
|
||||
@ -221,8 +227,15 @@ class EditMedia(EditPrimary):
|
||||
self.obj.set_path(Utils.get_unicode_path(path))
|
||||
|
||||
trans = self.db.transaction_begin()
|
||||
self.db.commit_media_object(self.obj,trans)
|
||||
self.db.transaction_commit(trans,_("Edit Media Object"))
|
||||
if self.obj.get_handle():
|
||||
self.db.commit_media_object(self.obj, trans)
|
||||
else:
|
||||
self.db.add_object(self.obj, trans)
|
||||
self.db.transaction_commit(trans, _("Edit Media Object (%s)"
|
||||
) % self.obj.get_description())
|
||||
|
||||
if self.callback:
|
||||
self.callback(self.obj)
|
||||
self.close()
|
||||
|
||||
def _cleanup_on_exit(self):
|
||||
|
@ -30,7 +30,6 @@ SUBDIRS = \
|
||||
gdirdir=$(prefix)/share/gramps
|
||||
|
||||
gdir_PYTHON = \
|
||||
AddMedia.py\
|
||||
ansel_utf8.py\
|
||||
ArgHandler.py\
|
||||
Assistant.py\
|
||||
|
@ -437,7 +437,7 @@ class ManagedWindow:
|
||||
while True:
|
||||
response = self.window.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
# dialog will be close by connect, now continue work while
|
||||
# dialog will be closed by connect, now continue work while
|
||||
# rest of dialog is unresponsive, release when finished
|
||||
self.close()
|
||||
if after_ok_func is not None:
|
||||
|
@ -993,9 +993,6 @@ class ListView(BookMarkView):
|
||||
return True
|
||||
return False
|
||||
|
||||
def double_click(self, obj, event):
|
||||
return False
|
||||
|
||||
def change_page(self):
|
||||
if self.model:
|
||||
self.uistate.show_filter_results(self.dbstate,
|
||||
|
@ -45,7 +45,7 @@ from ReportBase import Report, ReportOptions, CATEGORY_TEXT, MODE_BKI
|
||||
import BaseDoc
|
||||
from Selectors import selector_factory
|
||||
SelectObject = selector_factory('MediaObject')
|
||||
import AddMedia
|
||||
#import AddMedia
|
||||
import ThumbNails
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
@ -241,10 +241,12 @@ class SimpleBookTitleOptions(ReportOptions):
|
||||
self.setup_object(dialog.db,the_object)
|
||||
|
||||
def select_file(self,obj,dialog):
|
||||
a_o = AddMedia.AddMediaObject(dialog.dbstate,dialog.uistate,
|
||||
dialog.track)
|
||||
a_o.run()
|
||||
self.setup_object(dialog.db,a_o.object)
|
||||
print 'Deprecated use, this must be removed'
|
||||
|
||||
#a_o = AddMedia.AddMediaObject(dialog.dbstate,dialog.uistate,
|
||||
# dialog.track)
|
||||
#a_o.run()
|
||||
#self.setup_object(dialog.db,a_o.object)
|
||||
|
||||
def setup_object(self,database,the_object):
|
||||
if not the_object:
|
||||
|
Loading…
Reference in New Issue
Block a user