restore attr_edit in glade file
svn: r6286
This commit is contained in:
@ -18,15 +18,47 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
_top = '<ui><menubar name="MenuBar"><menu action="GoMenu"><placeholder name="CommonHistory">'
|
||||
_btm = '</placeholder></menu></menubar></ui>'
|
||||
"""
|
||||
Base history navigation class. Builds the action group and ui for the
|
||||
uimanager. Changes to the associated history objects are tracked. When
|
||||
the history changes, the UI XML string and the action groups are updated.
|
||||
|
||||
"""
|
||||
|
||||
__author__ = "Donald N. Allingham"
|
||||
__revision__ = "$Revision:$"
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
#
|
||||
# constants
|
||||
#
|
||||
#-------------------------------------------------------------------
|
||||
import gtk
|
||||
import sys
|
||||
import NameDisplay
|
||||
|
||||
DISABLED = -1
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
#
|
||||
# UI Manager XML code
|
||||
#
|
||||
#-------------------------------------------------------------------
|
||||
_top = [
|
||||
'<ui>'
|
||||
'<menubar name="MenuBar">'
|
||||
'<menu action="GoMenu">'
|
||||
'<placeholder name="CommonHistory">'
|
||||
]
|
||||
|
||||
_btm = [
|
||||
'</placeholder>'
|
||||
'</menu>'
|
||||
'</menubar>'
|
||||
'</ui>'
|
||||
]
|
||||
|
||||
|
||||
class BaseNavigation:
|
||||
"""
|
||||
Base history navigation class. Builds the action group and ui for the
|
||||
@ -43,16 +75,20 @@ class BaseNavigation:
|
||||
self.func - array of functions to take action based off of.
|
||||
|
||||
"""
|
||||
def __init__(self,uistate,history,title):
|
||||
def __init__(self, uistate, history, title):
|
||||
self.title = title
|
||||
self.ui = _top+_btm
|
||||
self.ui = "".join(_top) + "".join(_btm)
|
||||
self.uistate = uistate
|
||||
self.action_group = gtk.ActionGroup(self.title)
|
||||
self.active = DISABLED
|
||||
self.items = []
|
||||
self.func = []
|
||||
self.history = history
|
||||
|
||||
def clear(self):
|
||||
"""
|
||||
Clears out the specified history
|
||||
"""
|
||||
self.history.clear()
|
||||
|
||||
def disable(self):
|
||||
@ -72,23 +108,24 @@ class BaseNavigation:
|
||||
self.uistate.uimanager.insert_action_group(self.action_group, 1)
|
||||
self.active = self.uistate.uimanager.add_ui_from_string(self.ui)
|
||||
|
||||
def build_item_name(self,handle):
|
||||
def build_item_name(self, handle):
|
||||
"""
|
||||
Builds a string from the passed handle. Must be overridden by the
|
||||
derrived class.
|
||||
"""
|
||||
return "ERROR"
|
||||
|
||||
def update_menu(self,items):
|
||||
def update_menu(self, items):
|
||||
"""
|
||||
Builds the UI and action group.
|
||||
"""
|
||||
self.items = items
|
||||
self.disable()
|
||||
menu_len = min(len(items),10)
|
||||
|
||||
data = map(lambda x: '<menuitem action="%s%02d"/>' % (self.title,x), range(0,menu_len))
|
||||
self.ui = _top + "".join(data) + _btm
|
||||
menu_len = min(len(items), 10)
|
||||
entry = '<menuitem action="%s%02d"/>'
|
||||
|
||||
data = [ entry % (self.title, index) for index in range(0, menu_len) ]
|
||||
self.ui = "".join(_top) + "".join(data) + "".join(_btm)
|
||||
self.action_group = gtk.ActionGroup(self.title)
|
||||
data = []
|
||||
index = 0
|
||||
@ -97,9 +134,9 @@ class BaseNavigation:
|
||||
mitems.reverse()
|
||||
for item in mitems[:10]:
|
||||
name = self.build_item_name(item)
|
||||
f = self.func[index]
|
||||
data.append(('%s%02d'%(self.title,index), None, name,
|
||||
"<alt>%d" % index, None, f))
|
||||
func = self.func[index]
|
||||
data.append(('%s%02d'%(self.title, index), None, name,
|
||||
"<alt>%d" % index, None, func))
|
||||
index += 1
|
||||
|
||||
self.action_group.add_actions(data)
|
||||
@ -110,15 +147,17 @@ class PersonNavigation(BaseNavigation):
|
||||
"""
|
||||
Builds a navigation item for the Person class.
|
||||
"""
|
||||
def __init__(self,uistate):
|
||||
def __init__(self, uistate):
|
||||
"""
|
||||
Associates the functions with the associated items. Builds the function
|
||||
array so that there are unique functions for each possible index (0-9)
|
||||
The callback simply calls change_active_handle
|
||||
"""
|
||||
BaseNavigation.__init__(self,uistate,uistate.phistory,'PersonHistory')
|
||||
self.func = [ self.f0, self.f1, self.f2, self.f3, self.f4,
|
||||
self.f5, self.f6, self.f7, self.f8, self.f9 ]
|
||||
BaseNavigation.__init__(self, uistate, uistate.phistory, 'PersonHistory')
|
||||
fcn_ptr = self.uistate.dbstate.change_active_handle
|
||||
|
||||
self.func = [ generate(fcn_ptr, self.items, index) \
|
||||
for index in range(0, 10) ]
|
||||
|
||||
def build_item_name(self, item):
|
||||
"""
|
||||
@ -128,33 +167,8 @@ class PersonNavigation(BaseNavigation):
|
||||
return "%s [%s]" % (NameDisplay.displayer.display(person),
|
||||
person.gramps_id)
|
||||
|
||||
def f0(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[0])
|
||||
|
||||
def f1(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[1])
|
||||
|
||||
def f2(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[2])
|
||||
|
||||
def f3(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[3])
|
||||
|
||||
def f4(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[4])
|
||||
|
||||
def f5(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[5])
|
||||
|
||||
def f6(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[6])
|
||||
|
||||
def f7(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[7])
|
||||
|
||||
def f8(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[8])
|
||||
|
||||
def f9(self,obj):
|
||||
self.uistate.dbstate.change_active_handle(self.items[9])
|
||||
|
||||
def generate(func, items, index):
|
||||
"""
|
||||
Generates a callback function based off the passed arguments
|
||||
"""
|
||||
return lambda x: func(items[index])
|
||||
|
Reference in New Issue
Block a user