* src/ImageSelect.py: changed display_refs to use find_backlink_handles and updated

GlobalMediaProperties to use new UI model.
	* src/MediaView.py: changed call to GlobalMediaProperties to use new UI params.
	* src/Utils.py: added support for Gtk.labels to bold/unbold/temp label util funcs.


svn: r5617
This commit is contained in:
Richard Taylor 2005-12-22 13:35:37 +00:00
parent b2b6cb0ad5
commit 4d36b334bc
4 changed files with 178 additions and 161 deletions

View File

@ -1,3 +1,9 @@
2005-12-22 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/ImageSelect.py: changed display_refs to use find_backlink_handles and updated
GlobalMediaProperties to use new UI model.
* src/MediaView.py: changed call to GlobalMediaProperties to use new UI params.
* src/Utils.py: added support for Gtk.labels to bold/unbold/temp label util funcs.
2005-12-22 Richard Taylor <rjt-gramps@thegrindstone.me.uk> 2005-12-22 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/EditPlace.py: changed display_references to use find_backlink_handles * src/EditPlace.py: changed display_references to use find_backlink_handles
* src/EditRepository.py: modified to use find_backlink_handles and fixed subtle bug * src/EditRepository.py: modified to use find_backlink_handles and fixed subtle bug

View File

@ -60,6 +60,7 @@ import DateHandler
import Date import Date
import ImgManip import ImgManip
import Spell import Spell
import DisplayState
import GrampsDisplay import GrampsDisplay
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
@ -935,25 +936,38 @@ class LocalMediaProperties:
# GlobalMediaProperties # GlobalMediaProperties
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class GlobalMediaProperties: class GlobalMediaProperties(DisplayState.ManagedWindow):
def __init__(self,db,obj,parent,parent_window=None): def __init__(self,state,uistate,track,obj):
self.parent = parent #self.parent = parent
self.dp = DateHandler.parser self.dp = DateHandler.parser
self.dd = DateHandler.displayer self.dd = DateHandler.displayer
win_menu_label = _("Media Properties")
if obj: if obj:
if self.parent.parent.child_windows.has_key(obj.get_handle()): ## if self.parent.parent.child_windows.has_key(obj.get_handle()):
self.parent.parent.child_windows[obj.get_handle()].present(None) ## self.parent.parent.child_windows[obj.get_handle()].present(None)
return ## return
else: ## else:
self.win_key = obj.get_handle() self.win_key = obj.get_handle()
else: else:
self.win_key = self self.win_key = self
DisplayState.ManagedWindow.__init__(
self, uistate, [], self.win_key, win_menu_label, _('Media Properties'))
if self.already_exist:
return
self.state = state
self.uistate = uistate
self.pdmap = {} self.pdmap = {}
self.child_windows = {} self.child_windows = {}
self.obj = obj self.obj = obj
self.lists_changed = 0 self.lists_changed = 0
self.db = db self.db = self.state.db
self.idle = None self.idle = None
if obj: if obj:
self.date_object = Date.Date(self.obj.get_date_object()) self.date_object = Date.Date(self.obj.get_date_object())
@ -964,6 +978,8 @@ class GlobalMediaProperties:
self.alist = [] self.alist = []
self.refs = 1 self.refs = 1
self.refmodel = None # this becomes the model for the references
self.path = self.db.get_save_path() self.path = self.db.get_save_path()
self.change_dialog = gtk.glade.XML(const.imageselFile, self.change_dialog = gtk.glade.XML(const.imageselFile,
"change_global","gramps") "change_global","gramps")
@ -1073,9 +1089,9 @@ class GlobalMediaProperties:
self.change_dialog.get_widget(name).set_sensitive(mode) self.change_dialog.get_widget(name).set_sensitive(mode)
self.redraw_attr_list() self.redraw_attr_list()
if parent_window: #if parent_window:
self.window.set_transient_for(parent_window) # self.window.set_transient_for(parent_window)
self.add_itself_to_menu() #self.add_itself_to_menu()
self.window.show() self.window.show()
if not self.refs: if not self.refs:
Utils.temp_label(self.refs_label,self.window) Utils.temp_label(self.refs_label,self.window)
@ -1083,41 +1099,41 @@ class GlobalMediaProperties:
self.idle = gobject.idle_add(self.display_refs) self.idle = gobject.idle_add(self.display_refs)
def on_delete_event(self,obj,b): def on_delete_event(self,obj,b):
self.close_child_windows() #self.close_child_windows()
self.remove_itself_from_menu() #self.remove_itself_from_menu()
gc.collect() gc.collect()
def close(self,obj): def close(self,obj):
self.close_child_windows() #self.close_child_windows()
self.remove_itself_from_menu() #self.remove_itself_from_menu()
self.window.destroy() self.window.destroy()
if self.idle != None: if self.idle != None:
gobject.source_remove(self.idle) gobject.source_remove(self.idle)
gc.collect() gc.collect()
def close_child_windows(self): ## def close_child_windows(self):
for child_window in self.child_windows.values(): ## for child_window in self.child_windows.values():
child_window.close(None) ## child_window.close(None)
self.child_windows = {} ## self.child_windows = {}
def add_itself_to_menu(self): ## def add_itself_to_menu(self):
self.parent.parent.child_windows[self.win_key] = self ## self.parent.parent.child_windows[self.win_key] = self
label = _('Media Object') ## label = _('Media Object')
self.parent_menu_item = gtk.MenuItem(label) ## self.parent_menu_item = gtk.MenuItem(label)
self.parent_menu_item.set_submenu(gtk.Menu()) ## self.parent_menu_item.set_submenu(gtk.Menu())
self.parent_menu_item.show() ## self.parent_menu_item.show()
self.parent.parent.winsmenu.append(self.parent_menu_item) ## self.parent.parent.winsmenu.append(self.parent_menu_item)
self.winsmenu = self.parent_menu_item.get_submenu() ## self.winsmenu = self.parent_menu_item.get_submenu()
self.menu_item = gtk.MenuItem(_('Properties Editor')) ## self.menu_item = gtk.MenuItem(_('Properties Editor'))
self.menu_item.connect("activate",self.present) ## self.menu_item.connect("activate",self.present)
self.menu_item.show() ## self.menu_item.show()
self.winsmenu.append(self.menu_item) ## self.winsmenu.append(self.menu_item)
def remove_itself_from_menu(self): ## def remove_itself_from_menu(self):
del self.parent.parent.child_windows[self.win_key] ## del self.parent.parent.child_windows[self.win_key]
self.menu_item.destroy() ## self.menu_item.destroy()
self.winsmenu.destroy() ## self.winsmenu.destroy()
self.parent_menu_item.destroy() ## self.parent_menu_item.destroy()
def present(self,obj): def present(self,obj):
self.window.present() self.window.present()
@ -1189,127 +1205,99 @@ class GlobalMediaProperties:
None,self.db.readonly) None,self.db.readonly)
def display_refs(self): def display_refs(self):
media_handle = self.obj.get_handle()
self.refs = 1
# Initialize things if we're entering this functioin self.refs = 1 # not sure what this does
# for the first time
if not self.cursor_type:
self.cursor_type = 'Person'
self.cursor = self.db.get_person_cursor()
self.data = self.cursor.first()
if not self.refmodel:
self.any_refs = False self.any_refs = False
media_handle = self.obj.get_handle()
titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)] titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)]
self.refmodel = ListModel.ListModel( self.refmodel = ListModel.ListModel(
self.change_dialog.get_widget("refinfo"), self.change_dialog.get_widget("refinfo"),
titles, titles,
event_func=self.button_press) event_func=self.button_press)
if self.cursor_type == 'Person': self.backlink_generator = self.db.find_backlink_handles(media_handle)
while self.data:
handle,val = self.data
person = RelLib.Person()
person.unserialize(val)
if person.has_media_reference(media_handle):
name = NameDisplay.displayer.display(person)
gramps_id = person.get_gramps_id()
self.refmodel.add([_("Person"),gramps_id,name],
(0,handle))
self.any_refs = True
self.data = self.cursor.next()
if gtk.events_pending():
return True
self.cursor.close()
self.cursor_type = 'Family'
self.cursor = self.db.get_family_cursor()
self.data = self.cursor.first()
if self.cursor_type == 'Family': while True: # The loop is broken when the backlink_generator finishes
while self.data:
handle,val = self.data
family = RelLib.Family()
family.unserialize(val)
if family.has_media_reference(media_handle):
name = Utils.family_name(family,self.db)
gramps_id = family.get_gramps_id()
self.refmodel.add([_("Family"),gramps_id,name],
(1,handle))
self.any_refs = True
self.data = self.cursor.next()
if gtk.events_pending():
return True
self.cursor.close()
self.cursor_type = 'Event' try:
self.cursor = self.db.get_event_cursor() reference = self.backlink_generator.next()
self.data = self.cursor.first() except StopIteration:
# Last reference reached.
break
if self.cursor_type == 'Event': # If we make it here then there is at least one reference
while self.data: self.any_refs = True
handle,val = self.data
event = RelLib.Event()
event.unserialize(val)
if event.has_media_reference(media_handle):
name = event.get_name()
gramps_id = event.get_gramps_id()
self.refmodel.add([_("Event"),gramps_id,name],
(2,handle))
self.any_refs = True
self.data = self.cursor.next()
if gtk.events_pending():
return True
self.cursor.close()
self.cursor_type = 'Place' cls_name,handle = reference
self.cursor = self.db.get_place_cursor()
self.data = self.cursor.first()
if self.cursor_type == 'Place': if cls_name == 'Person':
while self.data: person = self.db.get_person_from_handle(handle)
handle,val = self.data name = NameDisplay.displayer.display(person)
place = RelLib.Place() gramps_id = person.get_gramps_id()
place.unserialize(val) self.refmodel.add([_("Person"),gramps_id,name],
if place.has_media_reference(media_handle): (0,handle))
name = place.get_title() self.model.add([_("Person"),gramps_id,name],(0,handle))
gramps_id = place.get_gramps_id()
self.refmodel.add([_("Place"),gramps_id,name], elif cls_name == 'Event':
event = self.db.get_event_from_handle(handle)
name = event.get_name()
gramps_id = event.get_gramps_id()
self.refmodel.add([_("Event"),gramps_id,name],
(2,handle))
elif cls_name == 'Family':
family = self.db.get_family_from_handle(handle)
name = Utils.family_name(family,self.db)
gramps_id = family.get_gramps_id()
self.refmodel.add([_("Family"),gramps_id,name],
(1,handle))
elif cls_name == 'Place':
place = self.db.get_place_from_handle(handle)
name = place.get_title()
gramps_id = place.get_gramps_id()
self.refmodel.add([_("Place"),gramps_id,name],
(3,handle)) (3,handle))
self.any_refs = True
self.data = self.cursor.next()
if gtk.events_pending():
return True
self.cursor.close()
self.cursor_type = 'Source' elif cls_name == 'Source':
self.cursor = self.db.get_source_cursor() source = self.db.get_source_from_handle(handle)
self.data = self.cursor.first() name = source.get_title()
gramps_id = source.get_gramps_id()
self.refmodel.add([_("Source"),gramps_id,name],
(4,handle))
if self.cursor_type == 'Source': elif cls_name == 'Media':
while self.data: obj = self.db.get_object_from_handle(handle)
handle,val = self.data name = obj.get_description()
source = RelLib.Source() gramps_id = obj.get_gramps_id()
source.unserialize(val) self.refmodel.add([_("Media"),gramps_id,name],
if source.has_media_reference(media_handle): (5,handle))
name = source.get_title()
gramps_id = source.get_gramps_id() else:
self.refmodel.add([_("Source"),gramps_id,name], # If we get here it means there is a new Primary object type
(4,handle)) # that has been added to the database. Print a warning
self.any_refs = True # to remind us that this code need updating.
self.data = self.cursor.next() log("WARNING: Unhandled Primary object type returned from "
if gtk.events_pending(): "find_backlink_handles()\n")
return True
self.cursor.close() if gtk.events_pending():
return True
if self.any_refs: if self.any_refs:
Utils.bold_label(self.refs_label,self.window) Utils.bold_label(self.refs_label,self.window)
else: else:
Utils.unbold_label(self.refs_label,self.window) Utils.unbold_label(self.refs_label,self.window)
self.cursor_type = None self.ref_not_loaded = 0
self.backlink_generator = None
return False return False
def on_notebook_switch_page(self,obj,junk,page): def on_notebook_switch_page(self,obj,junk,page):
if page == 3 and not self.refs: if page == 3 and not self.refs:
Utils.temp_label(self.refs_label,self.window) Utils.temp_label(self.refs_label,self.window)

View File

@ -166,8 +166,8 @@ class MediaView(PageView.ListView):
obj = self.dbstate.db.get_object_from_handle(handle) obj = self.dbstate.db.get_object_from_handle(handle)
if obj.get_mime_type(): if obj.get_mime_type():
ImageSelect.GlobalMediaProperties(self.dbstate.db, ImageSelect.GlobalMediaProperties(self.dbstate,self.uistate, [],
obj,self,self.topWindow) obj)
else: else:
import NoteEdit import NoteEdit
NoteEdit.NoteEditor(obj,self.parent,self.topWindow, NoteEdit.NoteEditor(obj,self.parent,self.topWindow,

View File

@ -717,37 +717,60 @@ def search_for(name):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def bold_label(label,widget=None): def bold_label(label,widget=None):
clist = label.get_children() if label.__class__ == gtk.Label:
text = unicode(clist[1].get_text()) text = unicode(label.get_text())
text = text.replace('<i>','') text = text.replace('<i>','')
text = text.replace('</i>','') text = text.replace('</i>','')
clist[0].show() label.set_text("<b>%s</b>" % text )
clist[1].set_text("<b>%s</b>" % text ) label.set_use_markup(True)
clist[1].set_use_markup(True) else:
clist = label.get_children()
text = unicode(clist[1].get_text())
text = text.replace('<i>','')
text = text.replace('</i>','')
clist[0].show()
clist[1].set_text("<b>%s</b>" % text )
clist[1].set_use_markup(True)
if widget: if widget:
widget.window.set_cursor(None) widget.window.set_cursor(None)
def unbold_label(label,widget=None): def unbold_label(label,widget=None):
clist = label.get_children() if label.__class__ == gtk.Label:
text = unicode(clist[1].get_text()) text = unicode(label.get_text())
text = text.replace('<b>','') text = text.replace('<b>','')
text = text.replace('</b>','') text = text.replace('</b>','')
text = text.replace('<i>','') text = text.replace('<i>','')
text = text.replace('</i>','') text = text.replace('</i>','')
clist[0].hide() label.set_text(text)
clist[1].set_text(text) label.set_use_markup(False)
clist[1].set_use_markup(False) else:
clist = label.get_children()
text = unicode(clist[1].get_text())
text = text.replace('<b>','')
text = text.replace('</b>','')
text = text.replace('<i>','')
text = text.replace('</i>','')
clist[0].hide()
clist[1].set_text(text)
clist[1].set_use_markup(False)
if widget: if widget:
widget.window.set_cursor(None) widget.window.set_cursor(None)
def temp_label(label,widget=None): def temp_label(label,widget=None):
clist = label.get_children() if label.__class__ == gtk.Label:
text = unicode(clist[1].get_text()) text = unicode(label.get_text())
text = text.replace('<b>','') text = text.replace('<b>','')
text = text.replace('</b>','') text = text.replace('</b>','')
clist[0].hide() label.set_text("<i>%s</i>" % text )
clist[1].set_text("<i>%s</i>" % text ) label.set_use_markup(True)
clist[1].set_use_markup(True) else:
clist = label.get_children()
text = unicode(clist[1].get_text())
text = text.replace('<b>','')
text = text.replace('</b>','')
clist[0].hide()
clist[1].set_text("<i>%s</i>" % text )
clist[1].set_use_markup(True)
if widget: if widget:
widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))