comparison libervia/frontends/quick_frontend/quick_list_manager.py @ 4074:26b7ed2817da

refactoring: rename `sat_frontends` to `libervia.frontends`
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 14:12:38 +0200
parents sat_frontends/quick_frontend/quick_list_manager.py@559a625a236b
children 0d7bb4df2343
comparison
equal deleted inserted replaced
4073:7c5654c54fed 4074:26b7ed2817da
1 #!/usr/bin/env python3
2
3
4 # Libervia: a Salut à Toi frontend
5 # Copyright (C) 2013-2016 Adrien Cossa <souliane@mailoo.org>
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21 class QuickTagList(object):
22 """This class manages a sorted list of tagged items, and a complementary sorted list of suggested but non tagged items."""
23
24 def __init__(self, items=None):
25 """
26
27 @param items (list): the suggested list of non tagged items
28 """
29 self.tagged = []
30 self.original = (
31 items[:] if items else []
32 ) # XXX: copy the list! It will be modified
33 self.untagged = (
34 items[:] if items else []
35 ) # XXX: copy the list! It will be modified
36 self.untagged.sort()
37
38 @property
39 def items(self):
40 """Return a sorted list of all items, tagged or untagged.
41
42 @return list
43 """
44 res = list(set(self.tagged).union(self.untagged))
45 res.sort()
46 return res
47
48 def tag(self, items):
49 """Tag some items.
50
51 @param items (list): items to be tagged
52 """
53 for item in items:
54 if item not in self.tagged:
55 self.tagged.append(item)
56 if item in self.untagged:
57 self.untagged.remove(item)
58 self.tagged.sort()
59 self.untagged.sort()
60
61 def untag(self, items):
62 """Untag some items.
63
64 @param items (list): items to be untagged
65 """
66 for item in items:
67 if item not in self.untagged and item in self.original:
68 self.untagged.append(item)
69 if item in self.tagged:
70 self.tagged.remove(item)
71 self.tagged.sort()
72 self.untagged.sort()