annotate frontends/src/primitivus/progress.py @ 1963:a2bc5089c2eb

backend, frontends: message refactoring (huge commit): /!\ several features are temporarily disabled, like notifications in frontends next step in refactoring, with the following changes: - jp: updated jp message to follow changes in backend/bridge - jp: added --lang, --subject, --subject_lang, and --type options to jp message + fixed unicode handling for jid - quick_frontend (QuickApp, QuickChat): - follow backend changes - refactored chat, message are now handled in OrderedDict and uid are kept so they can be updated - Message and Occupant classes handle metadata, so frontend just have to display them - Primitivus (Chat): - follow backend/QuickFrontend changes - info & standard messages are handled in the same MessageWidget class - improved/simplified handling of messages, removed update() method - user joined/left messages are merged when next to each other - a separator is shown when message is received while widget is out of focus, so user can quickly see the new messages - affiliation/role are shown (in a basic way for now) in occupants panel - removed "/me" messages handling, as it will be done by a backend plugin - message language is displayed when available (only one language per message for now) - fixed :history and :search commands - core (constants): new constants for messages type, XML namespace, entity type - core: *Message methods renamed to follow new code sytle (e.g. sendMessageToBridge => messageSendToBridge) - core (messages handling): fixed handling of language - core (messages handling): mes_data['from'] and ['to'] are now jid.JID - core (core.xmpp): reorganised message methods, added getNick() method to client.roster - plugin text commands: fixed plugin and adapted to new messages behaviour. client is now used in arguments instead of profile - plugins: added information for cancellation reason in CancelError calls - plugin XEP-0045: various improvments, but this plugin still need work: - trigger is used to avoid message already handled by the plugin to be handled a second time - changed the way to handle history, the last message from DB is checked and we request only messages since this one, in seconds (thanks Poezio folks :)) - subject reception is waited before sending the roomJoined signal, this way we are sure that everything including history is ready - cmd_* method now follow the new convention with client instead of profile - roomUserJoined and roomUserLeft messages are removed, the events are now handled with info message with a "ROOM_USER_JOINED" info subtype - probably other forgotten stuffs :p
author Goffi <goffi@goffi.org>
date Mon, 20 Jun 2016 18:41:53 +0200
parents 2daf7b4c6756
children 8b37a62336c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
4 # Primitivus: a SAT frontend
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1636
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
10 # (at your option) any later version.
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
15 # GNU Affero General Public License for more details.
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
20 from sat.core.i18n import _
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import urwid
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 180
diff changeset
22 from urwid_satext import sat_widgets
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 811
diff changeset
23 from sat_frontends.quick_frontend import quick_widgets
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
24
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
25
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 811
diff changeset
26 class Progress(urwid.WidgetWrap, quick_widgets.QuickWidget):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 811
diff changeset
27 PROFILES_ALLOW_NONE = True
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
28
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 811
diff changeset
29 def __init__(self, host, target, profiles):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 811
diff changeset
30 assert target is None and profiles is None
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 811
diff changeset
31 quick_widgets.QuickWidget.__init__(self, host, target)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self.host = host
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
33 self.progress_list = urwid.SimpleListWalker([])
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
34 self.progress_dict = {}
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
35 listbox = urwid.ListBox(self.progress_list)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
36 buttons = []
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
37 buttons.append(sat_widgets.CustomButton(_('Clear progress list'), self._onClear))
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
38 max_len = max([button.getSize() for button in buttons])
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
39 buttons_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 180
diff changeset
40 main_wid = sat_widgets.FocusFrame(listbox, footer=buttons_wid)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
41 urwid.WidgetWrap.__init__(self, main_wid)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
42
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
43 def add(self, progress_id, message, profile):
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
44 mess_wid = urwid.Text(message)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
45 progr_wid = urwid.ProgressBar('progress_normal', 'progress_complete')
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
46 column = urwid.Columns([mess_wid, progr_wid])
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
47 self.progress_dict[(progress_id, profile)] = {'full':column,'progress':progr_wid,'state':'init'}
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.progress_list.append(column)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
49 self.progressCB(self.host.loop, (progress_id, message, profile))
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
50
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def progressCB(self, loop, data):
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
52 progress_id, message, profile = data
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
53 data = self.host.bridge.progressGet(progress_id, profile)
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
54 pbar = self.progress_dict[(progress_id, profile)]['progress']
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
55 if data:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
56 if self.progress_dict[(progress_id, profile)]['state'] == 'init':
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
57 #first answer, we must construct the bar
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
58 self.progress_dict[(progress_id, profile)]['state'] = 'progress'
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
59 pbar.done = float(data['size'])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
60
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
61 pbar.set_completion(float(data['position']))
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.updateNotBar()
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
63 else:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
64 if self.progress_dict[(progress_id, profile)]['state'] == 'progress':
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
65 self.progress_dict[(progress_id, profile)]['state'] = 'done'
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
66 pbar.set_completion(pbar.done)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self.updateNotBar()
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
68 return
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
69
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
70 loop.set_alarm_in(0.2,self.progressCB, (progress_id, message, profile))
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
71
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
72 def _removeBar(self, progress_id, profile):
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
73 wid = self.progress_dict[(progress_id, profile)]['full']
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.progress_list.remove(wid)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
75 del(self.progress_dict[(progress_id, profile)])
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
76
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
77 def _onClear(self, button):
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
78 to_remove = []
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
79 for progress_id, profile in self.progress_dict:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
80 if self.progress_dict[(progress_id, profile)]['state'] == 'done':
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
81 to_remove.append((progress_id, profile))
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
82 for progress_id, profile in to_remove:
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
83 self._removeBar(progress_id, profile)
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.updateNotBar()
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
85
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def updateNotBar(self):
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
87 if not self.progress_dict:
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.host.setProgress(None)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
89 return
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
90 progress = 0
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
91 nb_bars = 0
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
92 for progress_id, profile in self.progress_dict:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
93 pbar = self.progress_dict[(progress_id, profile)]['progress']
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
94 progress += pbar.current/pbar.done*100
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
95 nb_bars+=1
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
96 av_progress = progress/float(nb_bars)
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
diff changeset
97 self.host.setProgress(av_progress)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
98