1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# Gettings Things Gnome! - a personal organizer for the GNOME desktop
4
# Copyright (c) 2008-2010- Lionel Dricot & Bertrand Rousseau
6
# This program is free software: you can redistribute it and/or modify it under
7
# the terms of the GNU General Public License as published by the Free Software
8
# Foundation, either version 3 of the License, or (at your option) any later
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
# You should have received a copy of the GNU General Public License along with
17
# this program. If not, see <http://www.gnu.org/licenses/>.
18
# -----------------------------------------------------------------------------
22
from GTG.tools.larch.tree import MainTree
23
from GTG.tools.larch.filteredtree import FilteredTree
27
self.tree = MainTree()
29
###### nodes handling ######
30
def get_node(self,nid):
31
return self.tree.get_node(nid)
33
def add_node(self,node,parent_id=None):
34
node.set_tree(self.tree)
35
self.tree.add_node(node,parent_id=parent_id)
37
def del_node(self,nid):
40
def modify_node(self,nid):
43
#move the node to a new parent (dismissing all other parents)
44
#use pid None to move it to the root
45
def move_node(self,nid,new_parent_id=None):
48
#if pid is None, the rood is added but, then,
49
#all other parents are dismissed
50
def add_parent(self,nid,new_parent_id=None):
53
############ Views ############
54
def get_viewtree(self):
56
########### Filters bank ######
57
def list_filters(self):
58
""" List, by name, all available filters """
60
def add_filter(self,filter_name,filter_func):
62
Adds a filter to the filter bank
63
Return True if the filter was added
64
Return False if the filter_name was already in the bank
67
def remove_filter(self,filter_name):
69
Remove a filter from the bank.
70
Only custom filters that were added here can be removed
71
Return False if the filter was not removed
74
################### ViewTree #####################
76
class ViewTree(gobject.GObject):
78
#Those are the three signals you want to catch if displaying
79
#a filteredtree. The argument of all signals is the tid of the task
80
__gsignals__ = {'task-added-inview': (gobject.SIGNAL_RUN_FIRST, \
81
gobject.TYPE_NONE, (str, )),
82
'task-deleted-inview': (gobject.SIGNAL_RUN_FIRST, \
83
gobject.TYPE_NONE, (str, )),
84
'task-modified-inview': (gobject.SIGNAL_RUN_FIRST, \
85
gobject.TYPE_NONE, (str, )),}
87
def __init(self,maintree,filters_bank):
88
self.__maintree = maintree
89
self.__ft = FilteredTree(maintree,filters_bank)
92
def get_node(self,nid):
93
return self.__maintree.get_node(nid)
97
#return a list of nid of displayed nodes
98
def get_all_nodes(self):
101
def get_n_nodes(self,withfilters=[],transparent_filters=True):
103
returns quantity of displayed nodes in this tree
104
if the withfilters is set, returns the quantity of nodes
105
that will be displayed if we apply those filters to the current
106
tree. It means that the currently applied filters are also taken into
108
If transparent_filters = False, we only take into account
109
the applied filters that doesn't have the transparent parameters.
112
def get_node_for_path(self, path):
114
def get_paths_for_node(self, node):
116
def next_node(self, node,parent):
118
def node_has_child(self, node):
120
def node_n_children(self, node):
122
def node_nth_child(self, node, n):
124
def node_parents(self, node):
126
def is_displayed(self,tid):
128
####### Change filters #################
129
def apply_filter(self,filter_name,parameters=None,\
130
reset=False,refresh=True):
132
Applies a new filter to the tree.
133
@param filter_name: The name of an already registered filter to apply
134
@param parameters: Optional parameters to pass to the filter
135
@param reset : optional boolean. Should we remove other filters?
136
@param refresh : should we refresh after applying this filter ?
139
def unapply_filter(self,filter_name,refresh=True):
141
Removes a filter from the tree.
142
@param filter_name: The name of an already added filter to remove
145
def reset_filters(self,refresh=True):
147
Clears all filters currently set on the tree.