Mercurial > libervia-backend
comparison sat_frontends/tools/misc.py @ 2562:26edcf3a30eb
core, setup: huge cleaning:
- moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention
- move twisted directory to root
- removed all hacks from setup.py, and added missing dependencies, it is now clean
- use https URL for website in setup.py
- removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed
- renamed sat.sh to sat and fixed its installation
- added python_requires to specify Python version needed
- replaced glib2reactor which use deprecated code by gtk3reactor
sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2018 19:44:50 +0200 |
parents | frontends/src/tools/misc.py@1dfc5516dead |
children | b4ecbcc2fd08 |
comparison
equal
deleted
inserted
replaced
2561:bd30dc3ffe5a | 2562:26edcf3a30eb |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT helpers methods for plugins | |
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 InputHistory(object): | |
22 | |
23 def _updateInputHistory(self, text=None, step=None, callback=None, mode=""): | |
24 """Update the lists of previously sent messages. Several lists can be | |
25 handled as they are stored in a dictionary, the argument "mode" being | |
26 used as the entry key. There's also a temporary list to allow you play | |
27 with previous entries before sending a new message. Parameters values | |
28 can be combined: text is None and step is None to initialize a main | |
29 list and the temporary one, step is None to update a list and | |
30 reinitialize the temporary one, step is not None to update | |
31 the temporary list between two messages. | |
32 @param text: text to be saved. | |
33 @param step: step to move the temporary index. | |
34 @param callback: method to display temporary entries. | |
35 @param mode: the dictionary key for main lists. | |
36 """ | |
37 if not hasattr(self, "input_histories"): | |
38 self.input_histories = {} | |
39 history = self.input_histories.setdefault(mode, []) | |
40 if step is None and text is not None: | |
41 # update the main list | |
42 if text in history: | |
43 history.remove(text) | |
44 history.append(text) | |
45 length = len(history) | |
46 if step is None or length == 0: | |
47 # prepare the temporary list and index | |
48 self.input_history_tmp = history[:] | |
49 self.input_history_tmp.append("") | |
50 self.input_history_index = length | |
51 if step is None: | |
52 return | |
53 # update the temporary list | |
54 if text is not None: | |
55 # save the current entry | |
56 self.input_history_tmp[self.input_history_index] = text | |
57 # move to another entry if possible | |
58 index_tmp = self.input_history_index + step | |
59 if index_tmp >= 0 and index_tmp < len(self.input_history_tmp): | |
60 if callback is not None: | |
61 callback(self.input_history_tmp[index_tmp]) | |
62 self.input_history_index = index_tmp | |
63 | |
64 | |
65 class FlagsHandler(object): | |
66 """Small class to handle easily option flags | |
67 | |
68 the instance is initialized with an iterable | |
69 then attribute return True if flag is set, False else. | |
70 WARNING: If a flag is checked, it is removed (i.e. unset) | |
71 this is done to use bool(flags_handler) to check if all flags | |
72 have been used | |
73 """ | |
74 | |
75 def __init__(self, flags): | |
76 self.flags = set(flags or []) | |
77 | |
78 def __getattr__(self, flag): | |
79 try: | |
80 self.flags.remove(flag) | |
81 except KeyError: | |
82 return False | |
83 else: | |
84 return True | |
85 | |
86 def __len__(self): | |
87 return len(self.flags) | |
88 | |
89 def __iter__(self): | |
90 return self.flags.__iter__() |