~bryce/gtg/dbus-service-name

« back to all changes in this revision

Viewing changes to GTG/tools/larch/__init__.py

  • Committer: Lionel Dricot
  • Date: 2010-06-22 09:43:55 UTC
  • mto: (825.1.1 gtg)
  • mto: This revision was merged to the branch mainline in revision 822.
  • Revision ID: ploum@ploum.net-20100622094355-nw1zubdpk4ro8dpd
starting liblarch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
#
 
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
 
9
# version.
 
10
#
 
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
 
14
# details.
 
15
#
 
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
# -----------------------------------------------------------------------------
 
19
 
 
20
import gobject
 
21
 
 
22
from GTG.tools.larch.tree import MainTree
 
23
from GTG.tools.larch.filteredtree import FilteredTree
 
24
 
 
25
class Tree():
 
26
    def __init__(self):
 
27
        self.tree = MainTree()
 
28
 
 
29
    ###### nodes handling ######
 
30
    def get_node(self,nid):
 
31
        return self.tree.get_node(nid)
 
32
    
 
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)
 
36
 
 
37
    def del_node(self,nid):
 
38
        return
 
39
 
 
40
    def modify_node(self,nid):
 
41
        return
 
42
        
 
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):
 
46
        return
 
47
 
 
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):
 
51
        return
 
52
 
 
53
    ############ Views ############
 
54
    def get_viewtree(self):
 
55
 
 
56
    ########### Filters bank ######
 
57
    def list_filters(self):
 
58
    """ List, by name, all available filters """
 
59
 
 
60
    def add_filter(self,filter_name,filter_func):
 
61
        """
 
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
 
65
        """
 
66
 
 
67
    def remove_filter(self,filter_name):
 
68
        """
 
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
 
72
        """
 
73
 
 
74
################### ViewTree #####################
 
75
 
 
76
class ViewTree(gobject.GObject):
 
77
 
 
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, )),}
 
86
                                            
 
87
    def __init(self,maintree,filters_bank):
 
88
        self.__maintree = maintree
 
89
        self.__ft = FilteredTree(maintree,filters_bank)
 
90
 
 
91
    #only by commodities
 
92
    def get_node(self,nid):
 
93
        return self.__maintree.get_node(nid)
 
94
 
 
95
    def print_tree(self):
 
96
 
 
97
    #return a list of nid of displayed nodes
 
98
    def get_all_nodes(self):
 
99
 
 
100
 
 
101
    def get_n_nodes(self,withfilters=[],transparent_filters=True):
 
102
        """
 
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
 
107
        account.
 
108
        If transparent_filters = False, we only take into account 
 
109
        the applied filters that doesn't have the transparent parameters.
 
110
        """
 
111
 
 
112
    def get_node_for_path(self, path):
 
113
 
 
114
    def get_paths_for_node(self, node):
 
115
 
 
116
    def next_node(self, node,parent):
 
117
 
 
118
    def node_has_child(self, node):
 
119
 
 
120
    def node_n_children(self, node):
 
121
 
 
122
    def node_nth_child(self, node, n):
 
123
 
 
124
    def node_parents(self, node):
 
125
 
 
126
    def is_displayed(self,tid):
 
127
 
 
128
    ####### Change filters #################
 
129
    def apply_filter(self,filter_name,parameters=None,\
 
130
                     reset=False,refresh=True):
 
131
        """
 
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 ?
 
137
        """
 
138
 
 
139
    def unapply_filter(self,filter_name,refresh=True):
 
140
        """
 
141
        Removes a filter from the tree.
 
142
        @param filter_name: The name of an already added filter to remove
 
143
        """
 
144
 
 
145
    def reset_filters(self,refresh=True):
 
146
        """
 
147
        Clears all filters currently set on the tree.
 
148
        """