* src/Bookmarks.py: get bookmark menu working

* src/EditPlace.py: menu tracking


svn: r5632
This commit is contained in:
Don Allingham 2005-12-25 04:01:47 +00:00
parent 2d73317658
commit 516230ce2d
5 changed files with 64 additions and 38 deletions

View File

@ -1,4 +1,6 @@
2005-12-24 Don Allingham <don@gramps-project.org> 2005-12-24 Don Allingham <don@gramps-project.org>
* src/Bookmarks.py: get bookmark menu working
* src/EditPlace.py: menu tracking
* src/DisplayState.py: recent file support * src/DisplayState.py: recent file support
* src/ViewManager.py: recent file support * src/ViewManager.py: recent file support

View File

@ -31,6 +31,7 @@ __version__ = "$Revision$"
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gettext import gettext as _ from gettext import gettext as _
from cStringIO import StringIO
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -53,10 +54,16 @@ import ListModel
# Bookmarks # Bookmarks
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
_top = '''<ui><menubar name="MenuBar"><menu action="BookMenu"><menu action="GoToBook">'''
_btm = '''</menu></menu></menubar></ui>'''
DISABLED = -1
class Bookmarks : class Bookmarks :
"Handle the bookmarks interface for Gramps" "Handle the bookmarks interface for Gramps"
def __init__(self,db,bookmarks): def __init__(self,dbstate,uimanager,bookmarks):
""" """
Creates a the bookmark editor. Creates a the bookmark editor.
@ -64,13 +71,40 @@ class Bookmarks :
menu - parent menu to attach users menu - parent menu to attach users
callback - task to connect to the menu item as a callback callback - task to connect to the menu item as a callback
""" """
self.db = db self.dbstate = dbstate
self.uimanager = uimanager
self.bookmarks = bookmarks self.bookmarks = bookmarks
self.active = DISABLED
self.action_group = gtk.ActionGroup('Bookmarks')
self.redraw() self.redraw()
def redraw(self): def redraw(self):
"""Create the pulldown menu""" """Create the pulldown menu"""
pass f = StringIO()
f.write(_top)
count = 0
if self.active != DISABLED:
self.uimanager.remove_ui(self.active)
self.uimanager.remove_action_group(self.action_group)
self.active = DISABLED
actions = []
for item in self.bookmarks:
person = self.dbstate.db.get_person_from_handle(item)
name = NameDisplay.displayer.display(person)
action_id = "BM:%s" % item
f.write('<menuitem action="%s"/>' % action_id)
label = "%s [%s]" % (name,person.gramps_id)
func = make_callback(item,self.dbstate.change_active_handle)
actions.append((action_id,None,label,None,None,func))
count +=1
f.write(_btm)
self.action_group.add_actions(actions)
self.uimanager.insert_action_group(self.action_group,1)
self.active = self.uimanager.add_ui_from_string(f.getvalue())
print f.getvalue()
f.close()
def add(self,person_handle): def add(self,person_handle):
"""appends the person to the bottom of the bookmarks""" """appends the person to the bottom of the bookmarks"""
@ -144,7 +178,7 @@ class Bookmarks :
""" """
self.draw_window() self.draw_window()
for person_handle in self.bookmarks: for person_handle in self.bookmarks:
person = self.db.get_person_from_handle(person_handle) person = self.dbstate.db.get_person_from_handle(person_handle)
if person: if person:
name = NameDisplay.displayer.display(person) name = NameDisplay.displayer.display(person)
gramps_id = person.get_gramps_id() gramps_id = person.get_gramps_id()
@ -193,3 +227,6 @@ class Bookmarks :
"""Display the relevant portion of GRAMPS manual""" """Display the relevant portion of GRAMPS manual"""
GrampsDisplay.help('gramps-nav') GrampsDisplay.help('gramps-nav')
self.response = self.top.run() self.response = self.top.run()
def make_callback(n,f):
return lambda x: f(n)

View File

@ -65,7 +65,7 @@ class History(GrampsDb.GrampsDBCallback):
def clear(self): def clear(self):
self.history = [] self.history = []
self.mistory = [] self.mhistory = []
self.index = -1 self.index = -1
self.lock = False self.lock = False
@ -366,7 +366,6 @@ class RecentDocsMenu:
self.state = state self.state = state
def load(self,item): def load(self,item):
print item
name = item.get_path() name = item.get_path()
dbtype = item.get_mime() dbtype = item.get_mime()
@ -390,7 +389,9 @@ class RecentDocsMenu:
self.active = DISABLED self.active = DISABLED
actions = [] actions = []
for item in gramps_rf.gramps_recent_files: rfiles = gramps_rf.gramps_recent_files
rfiles.sort(by_time)
for item in rfiles:
try: try:
filename = os.path.basename(item.get_path()).replace('_','__') filename = os.path.basename(item.get_path()).replace('_','__')
filetype = get_mime_type(item.get_path()) filetype = get_mime_type(item.get_path())
@ -411,6 +412,9 @@ class RecentDocsMenu:
def make_callback(n,f): def make_callback(n,f):
return lambda x: f(n) return lambda x: f(n)
def by_time(a,b):
return cmp(b.get_time(),a.get_time())
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Gramps Managed Window class # Gramps Managed Window class

View File

@ -67,10 +67,10 @@ from WindowUtils import GladeIf
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class EditPlace(DisplayState.ManagedWindow): class EditPlace(DisplayState.ManagedWindow):
def __init__(self,place,dbstate,uistate,trace=[]): def __init__(self,place,dbstate,uistate,track=[]):
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.trace = [] self.track = []
self.ref_not_loaded = place and place.get_handle() self.ref_not_loaded = place and place.get_handle()
self.idle = None self.idle = None
@ -219,7 +219,7 @@ class EditPlace(DisplayState.ManagedWindow):
self.gladeif.connect('del_url', 'clicked', self.on_delete_url_clicked) self.gladeif.connect('del_url', 'clicked', self.on_delete_url_clicked)
self.sourcetab = Sources.SourceTab( self.sourcetab = Sources.SourceTab(
self.state, self.ui_state, self.track, self.state, self.uistate, self.track,
self.srcreflist,self, self.srcreflist,self,
self.top_window,self.top,self.slist, self.top_window,self.top,self.slist,
self.top_window.get_widget('add_src'), self.top_window.get_widget('add_src'),
@ -252,7 +252,7 @@ class EditPlace(DisplayState.ManagedWindow):
self.top.show() self.top.show()
DisplayState.ManagedWindow.__init__(self, uistate, [], place) DisplayState.ManagedWindow.__init__(self, uistate, self.track, place)
self.pdmap = {} self.pdmap = {}
self.build_pdmap() self.build_pdmap()

View File

@ -62,6 +62,7 @@ import Navigation
import TipOfDay import TipOfDay
import Bookmarks import Bookmarks
import RecentFiles import RecentFiles
import NameDisplay
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -110,7 +111,7 @@ uidefault = '''<ui>
<menu action="BookMenu"> <menu action="BookMenu">
<menuitem action="AddBook"/> <menuitem action="AddBook"/>
<menuitem action="EditBook"/> <menuitem action="EditBook"/>
<menuitem action="GoToBook"/> <menu action="GoToBook"/>
</menu> </menu>
<menu action="ReportsMenu"> <menu action="ReportsMenu">
</menu> </menu>
@ -271,7 +272,7 @@ class ViewManager:
('EditMenu', None, '_Edit'), ('EditMenu', None, '_Edit'),
('GoMenu', None, '_Go'), ('GoMenu', None, '_Go'),
('BookMenu', None, '_Bookmarks'), ('BookMenu', None, '_Bookmarks'),
('AddBook', gtk.STOCK_INDEX, '_Add bookmark', '<control>d'), ('AddBook', gtk.STOCK_INDEX, '_Add bookmark', '<control>d', None, self.add_bookmark),
('EditBook', None, '_Edit bookmarks', '<control>b'), ('EditBook', None, '_Edit bookmarks', '<control>b'),
('GoToBook', gtk.STOCK_JUMP_TO, '_Go to bookmark'), ('GoToBook', gtk.STOCK_JUMP_TO, '_Go to bookmark'),
('ReportsMenu',None, '_Reports'), ('ReportsMenu',None, '_Reports'),
@ -643,7 +644,6 @@ class ViewManager:
'to the selected file.')) 'to the selected file.'))
try: try:
print self.load_database, filename, callback, mode
if self.load_database(filename,callback,mode=mode): if self.load_database(filename,callback,mode=mode):
if filename[-1] == '/': if filename[-1] == '/':
filename = filename[:-1] filename = filename[:-1]
@ -716,15 +716,14 @@ class ViewManager:
return True return True
def setup_bookmarks(self): def setup_bookmarks(self):
self.bookmarks = Bookmarks.Bookmarks(self.state.db,self.state.db.get_bookmarks()) self.bookmarks = Bookmarks.Bookmarks(self.state,self.uimanager,
self.state.db.get_bookmarks())
def on_add_bookmark_activate(self,obj): def add_bookmark(self,obj):
return if self.state.active:
if self.active_person: self.bookmarks.add(self.state.active.get_handle())
self.bookmarks.add(self.active_person.get_handle()) name = NameDisplay.displayer.display(self.state.active)
name = NameDisplay.displayer.display(self.active_person) self.uistate.push_message(_("%s has been bookmarked") % name)
self.status_text(_("%s has been bookmarked") % name)
gobject.timeout_add(5000,self.modify_statusbar)
else: else:
WarningDialog(_("Could Not Set a Bookmark"), WarningDialog(_("Could Not Set a Bookmark"),
_("A bookmark could not be set because " _("A bookmark could not be set because "
@ -733,22 +732,6 @@ class ViewManager:
def on_edit_bookmarks_activate(self,obj): def on_edit_bookmarks_activate(self,obj):
self.bookmarks.edit() self.bookmarks.edit()
def bookmark_callback(self,obj,person_handle):
old_person = self.active_person
person = self.state.db.get_person_from_handle(person_handle)
try:
self.change_active_person(person)
self.update_display(0)
self.goto_active_person()
except TypeError:
WarningDialog(_("Could not go to a Person"),
_("Either stale bookmark or broken history "
"caused by IDs reorder."))
self.clear_history()
self.change_active_person(old_person)
self.update_display(0)
self.goto_active_person()
def find_initial_person(self): def find_initial_person(self):
person = self.state.db.get_default_person() person = self.state.db.get_default_person()
if not person: if not person: