Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ReckonPrimer.tests/exstore/test_collection_WW091215.py
blob: b8008c849589e0d98bbe7aaa16477daf6e1cb3aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# -*- coding: utf-8 -*-
"""tests on collection class"""



class Task(object):

    # constructor
    def __init__(self, name):
        self.name = name
        self.obj = object
    # destructor
    #def __del__(self):
    #    print "in destructor"

    # methods

    # returns string representation of object
    def __str__(self):
        return "task: { name: ", self._name , " }"



class Collection(object):
    
    # constructor
    def __init__(self, name):
        self.name = name
        self.pic = object
        self._coll = []
        self._tasks = []
    # destructor
    #def __del__(self):
    #    print "in destructor"
        
    # methods

    # adds collection or task to collection
    def add(self, obj):
        # if obj.instanceOf(Collection)
        self._coll.append(obj)
        #else
        #self._tasks.append(obj)

    # deletes collection or task from collection
    def delete(self,sel):
        # if obj.instanceOf(Collection)                 ?????
            # find object
            # if obj empty: delete
            print "collection deleted"
            # else error: collection not empty
            # error: collection not found
        # else # =task
            # find object
            print "task deletet"
            # error: task not found
    
    # returns string representation of object
    def __str__(self): #mit for schleife definieren!!!
        return 'collection: { name: ' , self.name , ', tasks: [' , self._tasks.__str__ , '], collections: [' , self._coll.__str__ , '] }'
    
################################
    def delete(self, n):
        del self._data[n]

    def pick(self, coords):
        """ coords is a list of numbers (n-tupel), wich tells, which element
        of the collection to select. The selected element will be returned """
        if len(coords) == 0:
            return self  # emty coordinates: return this element
        elif len(coords) == 1:
            return self._data[coords[0]]  # end of recursion
        # go to next level
        #self._data[coords[0]].show()
        self._data[coords[0]].pick(coords[1:])

    def show(self, top):
        """ prints recursively all elements of this collection """
        print("**********")
        print "collection: ", self._name
        print "elements:"
        for el in self._data:
            el.show(False)
        print "---- end of ", self._name
        if top:
            print  # print an empty line after the last element
##################################



class Data(object):     # inherit from gtk tree???

    # constructor
    def __init__(self):
        self._collRoot = Collection("")
        self._co=[0,2]   # selction coordiantes: testing only ???
    # destructor
    #def __del__(self):
    #    print "in destructor"
        
    # methods
    
    # adds collection to selected collection or root
    def addCollection(self, obj):
        # if selection = null
            self._collRoot.add(obj)
        # else
        # selCollection.add(obj)

    # adds task to selected collection
    def addTask(self, obj):
        print "add task"   #avoid syntax error
        # if selection = null
        # Error: please selct a collection to add a new task
        # else
        # selCollection.add(obj)
        
    # edit selected object: task or collection
    def edit(self):
        # if selection = null
        # Error: please select a task or collection
        # find object
        # if sel obj instance of task
        # loadTask.. ???
        # else
        # loadCollection.. ???
        print "edit object"
    
    # deletes selected collection or task
    def delete(self):
        print "delete"      #avoid syntax error
        #if self._co = [0,2] and self._collRoot = []
        #   del self._collRoot
        #else
        self._collRoot.delete(sel)
        
        
    # saves _collRoot to file
    def _saveToFile(self):
        print "save"
        
    # loads _collRoot from file
    def _loadFromFile(self):
        print "load"
        
    # update treeView
    def _updateTree(self):
        print "update treeView"
        
    # returns string representation of object
    def __str__(self):
        return self._collRoot.__str__()






# test

fs = Data()

c1 = Collection("c1")
c2 = Collection("c2")
t1 = Task("t1")
t2 = Task("t2")
c1.add(t1)
c1.add(t2)
c3 = Collection("c3")
c3.add(t2)
c3.add(t1)
c1.add(c2.add(c3))
fs.addCollection(c1)

# created: [[t1, t2, [t2, t1]]]
print fs.__str__()
#print fs.__dict__
#print fs.collRoot.__dict__


# Versuch in einer Schleife dynamisch auf ein mit Koordinaten spezifiertes Object zuzugreifen
#co=[0,2]  # Koordinaten
#print "pick element ", co
#el = root
#for n in co:
#    el = el._data[n]
#el.show(True)

#p1=task("res")
#p1.show(True)
#p1=root.pick([0,1])
#p1.show(True)

#root.pick([0,2,1]).show(True)
#print "should be t1"