Added delete gadget; finished menus

svn: r9609
This commit is contained in:
Doug Blank 2007-12-28 06:48:45 +00:00
parent b98e1ef9c7
commit c0d16ee50b

View File

@ -768,13 +768,14 @@ class MyGrampsView(PageView.PageView):
self.action = gtk.ActionGroup(self.title + "/Gadgets") self.action = gtk.ActionGroup(self.title + "/Gadgets")
self.action.add_actions([('AddGadget',gtk.STOCK_ADD,_("_Add a gadget")), self.action.add_actions([('AddGadget',gtk.STOCK_ADD,_("_Add a gadget")),
('RestoreGadget',None,_("_Restore a gadget")), ('RestoreGadget',None,_("_Restore a gadget")),
('Columns1',None,_("Set columns to 1"), ('DeleteGadget',None,_("_Delete a gadget")),
('Columns1',None,_("Set columns to _1"),
None,None, None,None,
lambda obj:self.set_columns(1)), lambda obj:self.set_columns(1)),
('Columns2',None,_("Set columns to 2"), ('Columns2',None,_("Set columns to _2"),
None,None, None,None,
lambda obj:self.set_columns(2)), lambda obj:self.set_columns(2)),
('Columns3',None,_("Set columns to 3"), ('Columns3',None,_("Set columns to _3"),
None,None, None,None,
lambda obj:self.set_columns(3)), lambda obj:self.set_columns(3)),
]) ])
@ -799,6 +800,22 @@ class MyGrampsView(PageView.PageView):
self.place_gadgets() self.place_gadgets()
self.widget.show() self.widget.show()
def delete_gadget(self, obj):
name = obj.get_child().get_label()
############### First kind: from current session
for gadget in self.closed_gadgets:
if gadget.title == name:
self.closed_gadgets.remove(gadget)
self.gadget_map[gadget.title]
self.frame_map[str(gadget.mainframe)]
del gadget
return
################ Second kind: from options
for opts in self.closed_opts:
if opts["title"] == name:
self.closed_opts.remove(opts)
return
def restore_gadget(self, obj): def restore_gadget(self, obj):
name = obj.get_child().get_label() name = obj.get_child().get_label()
############### First kind: from current session ############### First kind: from current session
@ -890,9 +907,6 @@ class MyGrampsView(PageView.PageView):
<ui> <ui>
<menubar name="MenuBar"> <menubar name="MenuBar">
<menu action="ViewMenu"> <menu action="ViewMenu">
<menuitem action="AddGadget"/>
<menuitem action="RestoreGadget"/>
<separator/>
<menuitem action="Columns1"/> <menuitem action="Columns1"/>
<menuitem action="Columns2"/> <menuitem action="Columns2"/>
<menuitem action="Columns3"/> <menuitem action="Columns3"/>
@ -901,6 +915,7 @@ class MyGrampsView(PageView.PageView):
<popup name="Popup"> <popup name="Popup">
<menuitem action="AddGadget"/> <menuitem action="AddGadget"/>
<menuitem action="RestoreGadget"/> <menuitem action="RestoreGadget"/>
<menuitem action="DeleteGadget"/>
<separator/> <separator/>
<menuitem action="Columns1"/> <menuitem action="Columns1"/>
<menuitem action="Columns2"/> <menuitem action="Columns2"/>
@ -925,10 +940,14 @@ class MyGrampsView(PageView.PageView):
None, self.add_gadget) None, self.add_gadget)
self.uistate.uimanager.get_widget('/Popup/AddGadget').set_submenu(qr_menu) self.uistate.uimanager.get_widget('/Popup/AddGadget').set_submenu(qr_menu)
rg_menu = self.uistate.uimanager.get_widget('/Popup/RestoreGadget') rg_menu = self.uistate.uimanager.get_widget('/Popup/RestoreGadget')
dg_menu = self.uistate.uimanager.get_widget('/Popup/DeleteGadget')
if rg_menu: if rg_menu:
qr_menu = rg_menu.get_submenu() qr_menu = rg_menu.get_submenu()
if qr_menu != None: if qr_menu != None:
rg_menu.remove_submenu() rg_menu.remove_submenu()
qr2_menu = dg_menu.get_submenu()
if qr2_menu != None:
dg_menu.remove_submenu()
names = [] names = []
for gadget in self.closed_gadgets: for gadget in self.closed_gadgets:
names.append(gadget.title) names.append(gadget.title)
@ -937,10 +956,14 @@ class MyGrampsView(PageView.PageView):
names.sort() names.sort()
if len(names) > 0: if len(names) > 0:
qr_menu = gtk.Menu() qr_menu = gtk.Menu()
qr2_menu = gtk.Menu()
for name in names: for name in names:
Utils.add_menuitem(qr_menu, name, Utils.add_menuitem(qr_menu, name,
None, self.restore_gadget) None, self.restore_gadget)
Utils.add_menuitem(qr2_menu, name,
None, self.delete_gadget)
self.uistate.uimanager.get_widget('/Popup/RestoreGadget').set_submenu(qr_menu) self.uistate.uimanager.get_widget('/Popup/RestoreGadget').set_submenu(qr_menu)
self.uistate.uimanager.get_widget('/Popup/DeleteGadget').set_submenu(qr2_menu)
if menu: if menu:
menu.popup(None, None, None, event.button, event.time) menu.popup(None, None, None, event.button, event.time)
return True return True