comparison frontends/src/tools/misc.py @ 719:56aa0e98c92e

frontends tools: moved src/tools/frontends to frontends/src/tools
author souliane <souliane@mailoo.org>
date Thu, 21 Nov 2013 18:57:10 +0100
parents src/tools/frontends/misc.py@f610864eb7a5
children 1fe00f0c9a91
comparison
equal deleted inserted replaced
718:074970227bc0 719:56aa0e98c92e
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # SAT helpers methods for plugins
5 # Copyright (C) 2013 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 # Default value for the "New discussion room" user input
22 DEFAULT_MUC = 'sat@chat.jabberfr.org'
23
24
25 class InputHistory(object):
26
27 def _updateInputHistory(self, text=None, step=None, callback=None, mode=""):
28 """Update the lists of previously sent messages. Several lists can be
29 handled as they are stored in a dictionary, the argument "mode" being
30 used as the entry key. There's also a temporary list to allow you play
31 with previous entries before sending a new message. Parameters values
32 can be combined: text is None and step is None to initialize a main
33 list and the temporary one, step is None to update a list and
34 reinitialize the temporary one, step is not None to update
35 the temporary list between two messages.
36 @param text: text to be saved.
37 @param step: step to move the temporary index.
38 @param callback: method to display temporary entries.
39 @param mode: the dictionary key for main lists.
40 """
41 if not hasattr(self, "input_histories"):
42 self.input_histories = {}
43 history = self.input_histories.setdefault(mode, [])
44 if step is None and text is not None:
45 # update the main list
46 if text in history:
47 history.remove(text)
48 history.append(text)
49 length = len(history)
50 if step is None or length == 0:
51 # prepare the temporary list and index
52 self.input_history_tmp = history[:]
53 self.input_history_tmp.append("")
54 self.input_history_index = length
55 if step is None:
56 return
57 # update the temporary list
58 if text is not None:
59 # save the current entry
60 self.input_history_tmp[self.input_history_index] = text
61 # move to another entry if possible
62 index_tmp = self.input_history_index + step
63 if index_tmp >= 0 and index_tmp < len(self.input_history_tmp):
64 if callback is not None:
65 callback(self.input_history_tmp[index_tmp])
66 self.input_history_index = index_tmp