2005-08-09 10:11:20 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-16 03:20:14 +05:30
|
|
|
from cStringIO import StringIO
|
2005-08-09 10:11:20 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-21 16:57:05 +05:30
|
|
|
import GrampsDb
|
2005-08-09 10:11:20 +05:30
|
|
|
import GrampsKeys
|
|
|
|
import NameDisplay
|
2005-12-29 04:28:26 +05:30
|
|
|
import GrampsMime
|
2006-01-24 03:18:34 +05:30
|
|
|
import const
|
2005-08-09 10:11:20 +05:30
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# History manager
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-21 16:57:05 +05:30
|
|
|
class History(GrampsDb.GrampsDBCallback):
|
2005-08-11 05:23:24 +05:30
|
|
|
|
|
|
|
__signals__ = {
|
|
|
|
'changed' : (list,),
|
|
|
|
'menu-changed' : (list,),
|
|
|
|
}
|
2005-08-09 10:11:20 +05:30
|
|
|
|
|
|
|
def __init__(self):
|
2005-12-21 16:57:05 +05:30
|
|
|
GrampsDb.GrampsDBCallback.__init__(self)
|
2005-08-09 10:11:20 +05:30
|
|
|
self.history = []
|
|
|
|
self.mhistory = []
|
|
|
|
self.index = -1
|
|
|
|
self.lock = False
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self.history = []
|
2005-12-25 09:31:47 +05:30
|
|
|
self.mhistory = []
|
2005-08-09 10:11:20 +05:30
|
|
|
self.index = -1
|
|
|
|
self.lock = False
|
|
|
|
|
|
|
|
def remove(self,person_handle,old_id=None):
|
|
|
|
"""Removes a person from the history list"""
|
|
|
|
if old_id:
|
|
|
|
del_id = old_id
|
|
|
|
else:
|
|
|
|
del_id = person_handle
|
|
|
|
|
|
|
|
hc = self.history.count(del_id)
|
|
|
|
for c in range(hc):
|
|
|
|
self.history.remove(del_id)
|
|
|
|
self.index -= 1
|
|
|
|
|
|
|
|
mhc = self.mhistory.count(del_id)
|
|
|
|
for c in range(mhc):
|
|
|
|
self.mhistory.remove(del_id)
|
2005-08-11 05:23:24 +05:30
|
|
|
self.emit('changed',(self.history,))
|
|
|
|
self.emit('menu-changed',(self.mhistory,))
|
2005-08-09 10:11:20 +05:30
|
|
|
|
2005-08-10 19:58:16 +05:30
|
|
|
def push(self,person_handle):
|
|
|
|
self.prune()
|
|
|
|
if len(self.history) == 0 or person_handle != self.history[-1]:
|
|
|
|
self.history.append(person_handle)
|
2006-01-04 05:21:20 +05:30
|
|
|
if person_handle in self.mhistory:
|
2005-08-20 03:40:35 +05:30
|
|
|
self.mhistory.remove(person_handle)
|
2006-01-04 05:21:20 +05:30
|
|
|
self.mhistory.append(person_handle)
|
2005-08-10 19:58:16 +05:30
|
|
|
self.index += 1
|
2005-08-20 03:40:35 +05:30
|
|
|
self.emit('menu-changed',(self.mhistory,))
|
2005-08-11 05:23:24 +05:30
|
|
|
self.emit('changed',(self.history,))
|
2005-08-10 19:58:16 +05:30
|
|
|
|
|
|
|
def forward(self,step=1):
|
|
|
|
self.index += step
|
2005-08-11 05:23:24 +05:30
|
|
|
person_handle = self.history[self.index]
|
|
|
|
if person_handle not in self.mhistory:
|
|
|
|
self.mhistory.append(person_handle)
|
|
|
|
self.emit('menu-changed',(self.mhistory,))
|
2005-08-10 19:58:16 +05:30
|
|
|
return str(self.history[self.index])
|
|
|
|
|
|
|
|
def back(self,step=1):
|
|
|
|
self.index -= step
|
2005-08-11 05:23:24 +05:30
|
|
|
person_handle = self.history[self.index]
|
|
|
|
if person_handle not in self.mhistory:
|
|
|
|
self.mhistory.append(person_handle)
|
|
|
|
self.emit('menu-changed',(self.mhistory,))
|
2005-08-10 19:58:16 +05:30
|
|
|
return str(self.history[self.index])
|
|
|
|
|
|
|
|
def at_end(self):
|
|
|
|
return self.index+1 == len(self.history)
|
|
|
|
|
|
|
|
def at_front(self):
|
2005-08-11 22:49:03 +05:30
|
|
|
return self.index <= 0
|
2005-08-10 19:58:16 +05:30
|
|
|
|
|
|
|
def prune(self):
|
|
|
|
if not self.at_end():
|
|
|
|
self.history = self.history[0:self.index+1]
|
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Window manager
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-15 10:15:20 +05:30
|
|
|
|
2005-12-23 11:05:32 +05:30
|
|
|
_win_top = '<ui><menubar name="MenuBar"><menu action="WindowsMenu">'
|
2005-12-16 03:20:14 +05:30
|
|
|
_win_btm = '</menu></menubar></ui>'
|
|
|
|
DISABLED = -1
|
2005-12-15 10:15:20 +05:30
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
class GrampsWindowManager:
|
2005-12-14 09:36:42 +05:30
|
|
|
"""
|
|
|
|
Manage hierarchy of open GRAMPS windows.
|
|
|
|
|
|
|
|
This class's purpose is to manage the hierarchy of open windows.
|
|
|
|
The idea is to maintain the tree of branches and leaves.
|
|
|
|
A leaf does not have children and corresponds to a single open window.
|
|
|
|
A branch has children and corresponds to a group of windows.
|
|
|
|
|
|
|
|
We will follow the convention of having first leaf in any given
|
|
|
|
branch represent a parent window of the group, and the rest of the
|
|
|
|
children leaves/branches represent windows spawned from the parent.
|
|
|
|
|
|
|
|
The tree structure is maintained as a list of items.
|
|
|
|
Items which are lists are branches.
|
|
|
|
Items which are not lists are leaves.
|
|
|
|
|
|
|
|
Lookup of an item is done via track sequence. The elements of
|
|
|
|
the track sequence specify the lookup order: [2,3,1] means
|
|
|
|
'take the second item of the tree, take its third child, and
|
|
|
|
then the first child of that child'.
|
|
|
|
|
|
|
|
Lookup can be also done by ID for windows that are identifiable.
|
|
|
|
"""
|
2005-08-15 09:15:16 +05:30
|
|
|
|
2005-12-16 03:20:14 +05:30
|
|
|
def __init__(self,uimanager):
|
2005-12-14 09:36:42 +05:30
|
|
|
# initialize empty tree and lookup dictionary
|
2005-12-16 03:20:14 +05:30
|
|
|
self.uimanager = uimanager
|
2005-08-15 09:15:16 +05:30
|
|
|
self.window_tree = []
|
|
|
|
self.id2item = {}
|
2005-12-16 03:20:14 +05:30
|
|
|
self.action_group = gtk.ActionGroup('WindowManger')
|
|
|
|
self.active = DISABLED
|
|
|
|
self.ui = _win_top + _win_btm
|
|
|
|
|
|
|
|
def disable(self):
|
|
|
|
"""
|
|
|
|
Removes the UI and action groups if the navigation is enabled
|
|
|
|
"""
|
|
|
|
if self.active != DISABLED:
|
|
|
|
self.uimanager.remove_ui(self.active)
|
|
|
|
self.uimanager.remove_action_group(self.action_group)
|
|
|
|
self.active = DISABLED
|
|
|
|
|
|
|
|
def enable(self):
|
|
|
|
"""
|
|
|
|
Enables the UI and action groups
|
|
|
|
"""
|
|
|
|
self.uimanager.insert_action_group(self.action_group, 1)
|
|
|
|
self.active = self.uimanager.add_ui_from_string(self.ui)
|
2005-08-15 09:15:16 +05:30
|
|
|
|
2005-12-14 09:36:42 +05:30
|
|
|
def get_item_from_track(self,track):
|
|
|
|
# Recursively find an item given track sequence
|
2005-08-15 09:15:16 +05:30
|
|
|
item = self.window_tree
|
2005-12-14 09:36:42 +05:30
|
|
|
for index in track:
|
2005-08-15 09:15:16 +05:30
|
|
|
item = item[index]
|
|
|
|
return item
|
|
|
|
|
2005-12-14 09:36:42 +05:30
|
|
|
def get_item_from_id(self,item_id):
|
|
|
|
# Find an item given its ID
|
|
|
|
# Return None if the ID is not found
|
|
|
|
return self.id2item.get(item_id,None)
|
2005-08-15 09:15:16 +05:30
|
|
|
|
2005-12-14 12:24:02 +05:30
|
|
|
def close_track(self,track):
|
2005-12-14 09:36:42 +05:30
|
|
|
# This is called when item needs to be closed
|
|
|
|
# Closes all its children and then removes the item from the tree.
|
|
|
|
item = self.get_item_from_track(track)
|
2005-12-22 01:18:18 +05:30
|
|
|
self.recursive_action(item,self.close_item)
|
2005-12-14 12:24:02 +05:30
|
|
|
# This only needs to be run once for the highest level point
|
|
|
|
# to remove.
|
2005-12-14 09:36:42 +05:30
|
|
|
self.remove_item(track)
|
2005-08-15 09:15:16 +05:30
|
|
|
|
2005-12-22 01:18:18 +05:30
|
|
|
def recursive_action(self,item,func,*args):
|
|
|
|
# This function recursively calls itself over the child items
|
|
|
|
# starting with the given item.
|
|
|
|
# Eventualy, every non-list item (leaf) will be reached
|
|
|
|
# and the func(item,*args) will be called on that item.
|
2005-08-15 09:15:16 +05:30
|
|
|
if type(item) == list:
|
2005-12-14 09:36:42 +05:30
|
|
|
# If this item is a branch
|
|
|
|
# close the children except for the first one
|
2005-08-15 09:15:16 +05:30
|
|
|
for sub_item in item[1:]:
|
2005-12-22 01:18:18 +05:30
|
|
|
self.recursive_action(sub_item,func,*args)
|
2005-12-14 09:36:42 +05:30
|
|
|
# return the first child
|
2005-12-14 12:24:02 +05:30
|
|
|
last_item = item[0]
|
2005-08-15 09:15:16 +05:30
|
|
|
else:
|
2005-12-14 09:36:42 +05:30
|
|
|
# This item is a leaf -- no children to close
|
|
|
|
# return itself
|
2005-12-14 12:24:02 +05:30
|
|
|
last_item = item
|
2005-12-22 01:18:18 +05:30
|
|
|
func(last_item,*args)
|
|
|
|
|
|
|
|
def close_item(self,item,*args):
|
|
|
|
# Given an item, close its window and remove it's ID from the dict
|
|
|
|
if item.window_id:
|
|
|
|
del self.id2item[item.window_id]
|
2006-02-06 03:53:53 +05:30
|
|
|
if item.window:
|
|
|
|
item.window.destroy()
|
2005-12-14 09:36:42 +05:30
|
|
|
|
|
|
|
def remove_item(self,track):
|
|
|
|
# We need the whole gymnastics below because our item
|
|
|
|
# may actually be a list consisting of a single real
|
|
|
|
# item and empty lists.
|
|
|
|
|
|
|
|
# find the track corresponding to the parent item
|
|
|
|
parent_track = track[:-1]
|
|
|
|
# find index of our item in parent
|
|
|
|
child_in_parent = track[-1:][0]
|
|
|
|
# obtain parent item and remove our item from it
|
|
|
|
parent_item = self.get_item_from_track(parent_track)
|
|
|
|
parent_item.pop(child_in_parent)
|
2005-12-21 12:37:12 +05:30
|
|
|
# Adjust each item following the removed one
|
|
|
|
# so that it's track is down by one on this level
|
2005-12-21 23:54:38 +05:30
|
|
|
for ix in range(child_in_parent,len(parent_item)):
|
|
|
|
item = parent_item[ix]
|
2005-12-22 01:18:18 +05:30
|
|
|
self.recursive_action(item,self.move_item_down,len(track)-1)
|
2005-12-14 09:36:42 +05:30
|
|
|
# Rebuild menu
|
|
|
|
self.build_windows_menu()
|
|
|
|
|
2005-12-22 01:18:18 +05:30
|
|
|
def move_item_down(self,item,*args):
|
|
|
|
# Given an item and an index, adjust the item's track
|
|
|
|
# by subtracting 1 from that index's level
|
|
|
|
index = args[0]
|
|
|
|
item.track[index] -= 1
|
2005-12-21 23:54:38 +05:30
|
|
|
|
2005-12-14 09:36:42 +05:30
|
|
|
def add_item(self,track,item):
|
|
|
|
# if the item is identifiable then we need to remember
|
|
|
|
# its id so that in the future we recall this window
|
|
|
|
# instead of spawning a new one
|
2005-08-15 09:15:16 +05:30
|
|
|
if item.window_id:
|
2005-08-20 03:40:35 +05:30
|
|
|
self.id2item[item.window_id] = item
|
2005-08-15 09:15:16 +05:30
|
|
|
|
2005-12-14 09:36:42 +05:30
|
|
|
# Make sure we have a track
|
|
|
|
parent_item = self.get_item_from_track(track)
|
|
|
|
assert type(parent_item) == list or track == [], \
|
|
|
|
"Gwm: add_item: Incorrect track."
|
|
|
|
|
|
|
|
# Prepare a new item, depending on whether it is branch or leaf
|
2005-08-15 09:15:16 +05:30
|
|
|
if item.submenu_label:
|
2005-12-14 09:36:42 +05:30
|
|
|
# This is an item with potential children -- branch
|
2005-08-15 09:15:16 +05:30
|
|
|
new_item = [item]
|
|
|
|
else:
|
2005-12-14 09:36:42 +05:30
|
|
|
# This is an item without children -- leaf
|
2005-08-15 09:15:16 +05:30
|
|
|
new_item = item
|
2005-12-14 09:36:42 +05:30
|
|
|
|
|
|
|
# append new item to the parent
|
2005-08-15 09:15:16 +05:30
|
|
|
parent_item.append(new_item)
|
|
|
|
|
2005-12-14 09:36:42 +05:30
|
|
|
# rebuild the Windows menu based on the new tree
|
2005-08-20 03:40:35 +05:30
|
|
|
self.build_windows_menu()
|
2005-08-15 09:15:16 +05:30
|
|
|
|
2005-12-14 09:36:42 +05:30
|
|
|
# prepare new track corresponding to the added item and return it
|
|
|
|
new_track = track + [len(parent_item)-1]
|
|
|
|
return new_track
|
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
def call_back_factory(self,item):
|
|
|
|
if type(item) != list:
|
|
|
|
def f(obj):
|
2005-12-16 03:20:14 +05:30
|
|
|
if item.window_id and self.id2item.get(item.window_id):
|
|
|
|
self.id2item[item.window_id].present()
|
2005-08-15 09:15:16 +05:30
|
|
|
else:
|
|
|
|
def f(obj):
|
|
|
|
pass
|
|
|
|
return f
|
|
|
|
|
2005-12-24 01:39:02 +05:30
|
|
|
def generate_id(self,item):
|
|
|
|
return str(item.window_id)
|
2005-12-16 03:20:14 +05:30
|
|
|
|
|
|
|
def display_menu_list(self,data,action_data,mlist):
|
|
|
|
i = mlist[0]
|
2005-12-24 01:39:02 +05:30
|
|
|
idval = self.generate_id(i)
|
2005-12-16 03:20:14 +05:30
|
|
|
data.write('<menu action="M:%s">' % idval)
|
2005-12-24 01:39:02 +05:30
|
|
|
data.write('<menuitem action="%s"/>' % idval)
|
2005-12-16 03:20:14 +05:30
|
|
|
|
|
|
|
action_data.append(("M:"+idval,None,i.submenu_label,None,None,None))
|
2005-12-21 12:37:12 +05:30
|
|
|
action_data.append((idval,None,i.menu_label,None,None,
|
|
|
|
self.call_back_factory(i)))
|
2005-12-16 03:20:14 +05:30
|
|
|
|
|
|
|
if len(mlist) > 1:
|
|
|
|
for i in mlist[1:]:
|
|
|
|
if type(i) == list:
|
|
|
|
self.display_menu_list(data,action_data,i)
|
|
|
|
else:
|
2005-12-24 01:39:02 +05:30
|
|
|
idval = self.generate_id(i)
|
2005-12-21 12:37:12 +05:30
|
|
|
data.write('<menuitem action="%s"/>'
|
2005-12-24 01:39:02 +05:30
|
|
|
% self.generate_id(i))
|
2005-12-21 12:37:12 +05:30
|
|
|
action_data.append((idval,None,i.menu_label,None,None,
|
|
|
|
self.call_back_factory(i)))
|
2005-12-16 03:20:14 +05:30
|
|
|
data.write('</menu>')
|
|
|
|
|
2005-08-20 03:40:35 +05:30
|
|
|
def build_windows_menu(self):
|
2005-12-16 03:20:14 +05:30
|
|
|
if self.active != DISABLED:
|
|
|
|
self.uimanager.remove_ui(self.active)
|
|
|
|
self.uimanager.remove_action_group(self.action_group)
|
|
|
|
|
|
|
|
self.action_group = gtk.ActionGroup('WindowManger')
|
|
|
|
action_data = []
|
|
|
|
|
|
|
|
data = StringIO()
|
|
|
|
data.write(_win_top)
|
|
|
|
for i in self.window_tree:
|
|
|
|
self.display_menu_list(data,action_data,i)
|
|
|
|
data.write(_win_btm)
|
|
|
|
self.ui = data.getvalue()
|
|
|
|
data.close()
|
|
|
|
self.action_group.add_actions(action_data)
|
|
|
|
self.enable()
|
2005-08-15 09:15:16 +05:30
|
|
|
|
2005-12-24 05:39:04 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Recent Docs Menu
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
_rct_top = '<ui><menubar name="MenuBar"><menu action="FileMenu"><menu action="OpenRecent">'
|
|
|
|
_rct_btm = '</menu></menu></menubar></ui>'
|
|
|
|
|
|
|
|
import RecentFiles
|
|
|
|
import os
|
|
|
|
|
|
|
|
class RecentDocsMenu:
|
2006-01-05 02:36:28 +05:30
|
|
|
def __init__(self,uistate, state, fileopen):
|
2005-12-24 05:39:04 +05:30
|
|
|
self.action_group = gtk.ActionGroup('RecentFiles')
|
|
|
|
self.active = DISABLED
|
2006-01-05 02:36:28 +05:30
|
|
|
self.uistate = uistate
|
|
|
|
self.uimanager = uistate.uimanager
|
2005-12-25 00:48:18 +05:30
|
|
|
self.fileopen = fileopen
|
|
|
|
self.state = state
|
|
|
|
|
2006-01-05 02:36:28 +05:30
|
|
|
menu_item = self.uimanager.get_widget('/MenuBar/FileMenu/OpenRecent')
|
|
|
|
self.uistate.set_open_recent_menu(menu_item.get_submenu())
|
|
|
|
|
2005-12-25 00:48:18 +05:30
|
|
|
def load(self,item):
|
|
|
|
name = item.get_path()
|
|
|
|
dbtype = item.get_mime()
|
|
|
|
|
|
|
|
db = GrampsDb.gramps_db_factory(dbtype)()
|
|
|
|
self.state.change_database(db)
|
|
|
|
self.fileopen(name)
|
|
|
|
RecentFiles.recent_files(name,dbtype)
|
|
|
|
self.build()
|
2005-12-24 05:39:04 +05:30
|
|
|
|
|
|
|
def build(self):
|
|
|
|
f = StringIO()
|
|
|
|
f.write(_rct_top)
|
|
|
|
gramps_rf = RecentFiles.GrampsRecentFiles()
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
|
|
|
|
if self.active != DISABLED:
|
|
|
|
self.uimanager.remove_ui(self.active)
|
|
|
|
self.uimanager.remove_action_group(self.action_group)
|
|
|
|
self.active = DISABLED
|
|
|
|
|
|
|
|
actions = []
|
2005-12-25 09:31:47 +05:30
|
|
|
rfiles = gramps_rf.gramps_recent_files
|
|
|
|
rfiles.sort(by_time)
|
|
|
|
for item in rfiles:
|
2005-12-24 05:39:04 +05:30
|
|
|
try:
|
|
|
|
filename = os.path.basename(item.get_path()).replace('_','__')
|
2005-12-29 04:28:26 +05:30
|
|
|
filetype = GrampsMime.get_type(item.get_path())
|
2005-12-24 05:39:04 +05:30
|
|
|
action_id = "RecentMenu%d" % count
|
|
|
|
f.write('<menuitem action="%s"/>' % action_id)
|
2005-12-25 00:48:18 +05:30
|
|
|
actions.append((action_id,None,filename,None,None,
|
|
|
|
make_callback(item,self.load)))
|
2005-12-24 05:39:04 +05:30
|
|
|
except RuntimeError:
|
|
|
|
pass # ignore no longer existing files
|
|
|
|
|
|
|
|
count +=1
|
|
|
|
f.write(_rct_btm)
|
|
|
|
self.action_group.add_actions(actions)
|
|
|
|
self.uimanager.insert_action_group(self.action_group,1)
|
2005-12-25 00:48:18 +05:30
|
|
|
self.active = self.uimanager.add_ui_from_string(f.getvalue())
|
2005-12-24 05:39:04 +05:30
|
|
|
f.close()
|
|
|
|
|
2006-01-05 02:36:28 +05:30
|
|
|
menu_item = self.uistate.uimanager.get_widget('/MenuBar/FileMenu/OpenRecent')
|
|
|
|
self.uistate.set_open_recent_menu(menu_item.get_submenu())
|
|
|
|
|
2005-12-25 00:48:18 +05:30
|
|
|
def make_callback(n,f):
|
|
|
|
return lambda x: f(n)
|
|
|
|
|
2005-12-25 09:31:47 +05:30
|
|
|
def by_time(a,b):
|
|
|
|
return cmp(b.get_time(),a.get_time())
|
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps Managed Window class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class ManagedWindow:
|
|
|
|
"""
|
|
|
|
Managed window base class.
|
|
|
|
|
|
|
|
This class provides all the goodies necessary for user-friendly window
|
|
|
|
management in GRAMPS: registering the menu item under the Windows
|
|
|
|
menu, keeping track of child windows, closing them on close/delete
|
|
|
|
event, and presenting itself when selected or attempted to create again.
|
|
|
|
"""
|
|
|
|
|
2005-12-23 05:13:32 +05:30
|
|
|
def __init__(self,uistate,track,obj):
|
2005-08-15 09:15:16 +05:30
|
|
|
"""
|
|
|
|
Create child windows and add itself to menu, if not there already.
|
2005-12-22 11:38:33 +05:30
|
|
|
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
The usage from derived classes is envisioned as follows:
|
2005-12-23 05:13:32 +05:30
|
|
|
|
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
import DisplayState
|
|
|
|
class SomeWindowClass(DisplayState.ManagedWindow):
|
2005-12-14 09:36:42 +05:30
|
|
|
def __init__(self,uistate,dbstate,track):
|
2005-08-15 09:15:16 +05:30
|
|
|
window_id = self # Or e.g. window_id = person.handle
|
|
|
|
submenu_label = None # This window cannot have children
|
|
|
|
menu_label = 'Menu label for this window'
|
|
|
|
DisplayState.ManagedWindow.__init__(self,
|
|
|
|
uistate,
|
2005-12-14 09:36:42 +05:30
|
|
|
track,
|
2005-08-15 09:15:16 +05:30
|
|
|
window_id,
|
|
|
|
submenu_label,
|
|
|
|
menu_label)
|
|
|
|
if self.already_exist:
|
|
|
|
return
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
# Proceed with the class.
|
|
|
|
...
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2005-08-15 09:15:16 +05:30
|
|
|
"""
|
2005-12-23 05:13:32 +05:30
|
|
|
|
|
|
|
window_key = self.build_window_key(obj)
|
2005-12-24 01:46:43 +05:30
|
|
|
menu_label,submenu_label = self.build_menu_names(obj)
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2005-12-14 09:36:42 +05:30
|
|
|
if uistate.gwm.get_item_from_id(window_key):
|
|
|
|
uistate.gwm.get_item_from_id(window_key).present()
|
2005-08-15 09:15:16 +05:30
|
|
|
self.already_exist = True
|
|
|
|
else:
|
|
|
|
self.already_exist = False
|
2005-08-20 03:40:35 +05:30
|
|
|
self.window_id = window_key
|
2005-08-15 09:15:16 +05:30
|
|
|
self.submenu_label = submenu_label
|
|
|
|
self.menu_label = menu_label
|
|
|
|
self.uistate = uistate
|
2005-12-14 09:36:42 +05:30
|
|
|
self.track = self.uistate.gwm.add_item(track,self)
|
2005-12-22 11:38:33 +05:30
|
|
|
# Work out parent_window
|
|
|
|
if len(self.track) > 1:
|
|
|
|
# We don't belong to the lop level
|
|
|
|
if self.track[-1] > 0:
|
|
|
|
# If we are not the first in the group,
|
|
|
|
# then first in that same group is our parent
|
|
|
|
parent_item_track = self.track[:-1]
|
|
|
|
parent_item_track.append(0)
|
|
|
|
else:
|
|
|
|
# If we're first in the group, then our parent
|
|
|
|
# is the first in the group one level up
|
|
|
|
parent_item_track = self.track[:-2]
|
|
|
|
parent_item_track.append(0)
|
|
|
|
|
|
|
|
# Based on the track, get item and then window object
|
|
|
|
self.parent_window = self.uistate.gwm.get_item_from_track(
|
|
|
|
parent_item_track).window
|
|
|
|
else:
|
|
|
|
# On the top level: we use gramps top window
|
|
|
|
self.parent_window = self.uistate.window
|
2005-08-15 09:15:16 +05:30
|
|
|
|
2005-12-23 05:13:32 +05:30
|
|
|
def build_menu_names(self,obj):
|
2005-12-24 01:46:43 +05:30
|
|
|
return ('Undefined Menu','Undefined Submenu')
|
2005-12-23 05:13:32 +05:30
|
|
|
|
|
|
|
def build_window_key(self,obj):
|
2005-12-24 01:46:43 +05:30
|
|
|
return id(self)
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
self.window.set_transient_for(self.parent_window)
|
|
|
|
self.window.show()
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2005-12-22 11:38:33 +05:30
|
|
|
def close(self,obj=None,obj2=None):
|
2005-08-15 09:15:16 +05:30
|
|
|
"""
|
|
|
|
Close itself.
|
|
|
|
|
|
|
|
Takes care of closing children and removing itself from menu.
|
|
|
|
"""
|
2005-12-14 12:24:02 +05:30
|
|
|
self.uistate.gwm.close_track(self.track)
|
2005-08-15 09:15:16 +05:30
|
|
|
|
|
|
|
def present(self):
|
|
|
|
"""
|
|
|
|
Present window (unroll/unminimize/bring to top).
|
|
|
|
"""
|
|
|
|
self.window.present()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps Display State class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-01-24 03:18:34 +05:30
|
|
|
|
|
|
|
import logging
|
|
|
|
from GrampsLogger import RotateHandler
|
|
|
|
|
|
|
|
class WarnHandler(RotateHandler):
|
|
|
|
def __init__(self,capacity,button):
|
|
|
|
RotateHandler.__init__(self,capacity)
|
|
|
|
self.setLevel(logging.WARN)
|
|
|
|
self.button = button
|
|
|
|
button.on_clicked(self.display)
|
2006-01-24 04:06:34 +05:30
|
|
|
self.timer = None
|
2006-01-24 03:18:34 +05:30
|
|
|
|
|
|
|
def emit(self,record):
|
2006-01-24 04:06:34 +05:30
|
|
|
if self.timer:
|
|
|
|
gobject.source_remove(self.timer)
|
|
|
|
gobject.timeout_add(180*1000,self._clear)
|
2006-01-24 03:18:34 +05:30
|
|
|
RotateHandler.emit(self,record)
|
|
|
|
self.button.show()
|
|
|
|
|
2006-01-24 04:06:34 +05:30
|
|
|
def _clear(self):
|
|
|
|
self.button.hide()
|
|
|
|
self.set_capacity(self._capacity)
|
|
|
|
self.timer = None
|
|
|
|
return False
|
|
|
|
|
2006-01-24 03:18:34 +05:30
|
|
|
def display(self,obj):
|
|
|
|
obj.hide()
|
|
|
|
g = gtk.glade.XML(const.gladeFile,'scrollmsg')
|
|
|
|
top = g.get_widget('scrollmsg')
|
|
|
|
msg = g.get_widget('msg')
|
|
|
|
buf = msg.get_buffer()
|
|
|
|
for i in self.get_formatted_log():
|
|
|
|
buf.insert_at_cursor(i + '\n')
|
2006-01-24 04:06:34 +05:30
|
|
|
self.set_capacity(self._capacity)
|
2006-01-24 03:18:34 +05:30
|
|
|
top.run()
|
2006-01-24 04:06:34 +05:30
|
|
|
top.destroy()
|
2006-01-24 03:18:34 +05:30
|
|
|
|
2005-12-21 16:57:05 +05:30
|
|
|
class DisplayState(GrampsDb.GrampsDBCallback):
|
2005-08-11 05:23:24 +05:30
|
|
|
|
|
|
|
__signals__ = {
|
|
|
|
}
|
|
|
|
|
2006-01-23 09:39:20 +05:30
|
|
|
def __init__(self,window,status,warnbtn,uimanager,dbstate):
|
2005-08-11 05:23:24 +05:30
|
|
|
self.dbstate = dbstate
|
|
|
|
self.uimanager = uimanager
|
|
|
|
self.window = window
|
2005-12-21 16:57:05 +05:30
|
|
|
GrampsDb.GrampsDBCallback.__init__(self)
|
2005-08-11 05:23:24 +05:30
|
|
|
self.status = status
|
|
|
|
self.status_id = status.get_context_id('GRAMPS')
|
|
|
|
self.phistory = History()
|
2005-12-16 03:20:14 +05:30
|
|
|
self.gwm = GrampsWindowManager(uimanager)
|
2006-01-05 02:36:28 +05:30
|
|
|
self.widget = None
|
2006-01-23 09:39:20 +05:30
|
|
|
self.warnbtn = warnbtn
|
2006-01-05 02:36:28 +05:30
|
|
|
|
2006-01-24 04:06:34 +05:30
|
|
|
formatter = logging.Formatter('%(levelname)s %(name)s: %(message)s')
|
2006-01-24 03:18:34 +05:30
|
|
|
self.rh = WarnHandler(capacity=400,button=warnbtn)
|
2006-01-24 04:06:34 +05:30
|
|
|
self.rh.setFormatter(formatter)
|
2006-01-24 03:18:34 +05:30
|
|
|
self.log = logging.getLogger()
|
|
|
|
self.log.setLevel(logging.WARN)
|
|
|
|
self.log.addHandler(self.rh)
|
|
|
|
|
2006-02-02 22:30:37 +05:30
|
|
|
def set_busy_cursor(self,value):
|
|
|
|
if value:
|
|
|
|
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
|
|
|
else:
|
|
|
|
self.window.window.set_cursor(None)
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
|
|
|
|
2006-01-05 02:36:28 +05:30
|
|
|
def set_open_widget(self,widget):
|
|
|
|
self.widget = widget
|
|
|
|
|
|
|
|
def set_open_recent_menu(self,menu):
|
|
|
|
self.widget.set_menu(menu)
|
2005-08-11 05:23:24 +05:30
|
|
|
|
2005-12-23 11:05:32 +05:30
|
|
|
def push_message(self, text):
|
|
|
|
self.status_text(text)
|
|
|
|
gobject.timeout_add(5000,self.modify_statusbar)
|
|
|
|
|
2005-08-11 05:23:24 +05:30
|
|
|
def modify_statusbar(self,active=None):
|
2005-08-09 10:11:20 +05:30
|
|
|
self.status.pop(self.status_id)
|
2005-08-11 05:23:24 +05:30
|
|
|
if self.dbstate.active == None:
|
2005-08-09 10:11:20 +05:30
|
|
|
self.status.push(self.status_id,"")
|
|
|
|
else:
|
|
|
|
if GrampsKeys.get_statusbar() <= 1:
|
2005-08-11 05:23:24 +05:30
|
|
|
pname = NameDisplay.displayer.display(self.dbstate.active)
|
|
|
|
name = "[%s] %s" % (self.dbstate.active.get_gramps_id(),pname)
|
2005-12-08 09:57:53 +05:30
|
|
|
else:
|
|
|
|
name = "" #self.display_relationship()
|
2005-08-09 10:11:20 +05:30
|
|
|
self.status.push(self.status_id,name)
|
|
|
|
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
|
|
|
|
|
|
|
def status_text(self,text):
|
|
|
|
self.status.pop(self.status_id)
|
|
|
|
self.status.push(self.status_id,text)
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
2006-01-23 09:39:20 +05:30
|
|
|
|
2006-01-24 03:18:34 +05:30
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
import GrampsWidgets
|
|
|
|
|
|
|
|
rh = WarnHandler(capacity=400,button=GrampsWidgets.WarnButton())
|
|
|
|
log = logging.getLogger()
|
|
|
|
log.setLevel(logging.WARN)
|
|
|
|
log.addHandler(rh)
|
|
|
|
|