Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
068551db
by wurstsalat at 2021-12-17T23:59:43+01:00
-
e7331833
by wurstsalat at 2021-12-18T00:00:23+01:00
-
c5cc0fe4
by wurstsalat at 2021-12-18T00:16:38+01:00
-
2cb70610
by wurstsalat at 2021-12-18T00:24:36+01:00
4 changed files:
- gajim/common/app.py
- gajim/gtk/emoji_chooser.py
- gajim/gtk/preview_audio.py
- gajim/gtk/workspace_side_bar.py
Changes:
| ... | ... | @@ -206,7 +206,8 @@ def detect_dependencies() -> None: |
| 206 | 206 |
gi.require_version('GstPbutils', '1.0')
|
| 207 | 207 |
from gi.repository import Gst
|
| 208 | 208 |
from gi.repository import GstPbutils # pylint: disable=unused-import
|
| 209 |
- _dependencies['GST'] = True
|
|
| 209 |
+ success, _argv = Gst.init_check(None)
|
|
| 210 |
+ _dependencies['GST'] = success
|
|
| 210 | 211 |
except Exception:
|
| 211 | 212 |
pass
|
| 212 | 213 |
|
| ... | ... | @@ -400,6 +400,7 @@ def _on_emoticon_press(self, flowbox, child): |
| 400 | 400 |
GLib.timeout_add(100, flowbox.unselect_child, child)
|
| 401 | 401 |
codepoint, pixbuf = child.get_emoji()
|
| 402 | 402 |
self._text_widget().insert_emoji(codepoint, pixbuf)
|
| 403 |
+ self._text_widget().grab_focus()
|
|
| 403 | 404 |
|
| 404 | 405 |
def do_destroy(self):
|
| 405 | 406 |
# Remove the references we hold to other objects
|
| ... | ... | @@ -12,6 +12,8 @@ |
| 12 | 12 |
# You should have received a copy of the GNU General Public License
|
| 13 | 13 |
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
| 14 | 14 |
|
| 15 |
+from typing import Optional
|
|
| 16 |
+ |
|
| 15 | 17 |
import logging
|
| 16 | 18 |
from pathlib import Path
|
| 17 | 19 |
|
| ... | ... | @@ -28,22 +30,24 @@ |
| 28 | 30 |
|
| 29 | 31 |
class AudioWidget(Gtk.Box):
|
| 30 | 32 |
def __init__(self, file_path: Path) -> None:
|
| 31 |
- Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL,
|
|
| 33 |
+ Gtk.Box.__init__(self,
|
|
| 34 |
+ orientation=Gtk.Orientation.HORIZONTAL,
|
|
| 32 | 35 |
spacing=6)
|
| 33 |
- self._playbin = Gst.ElementFactory.make('playbin', 'bin')
|
|
| 36 |
+ self._playbin: Optional[Gst.Element] = Gst.ElementFactory.make(
|
|
| 37 |
+ 'playbin', 'bin')
|
|
| 34 | 38 |
if self._playbin is None:
|
| 35 | 39 |
label = Gtk.Label(label=_('Audio preview is not available'))
|
| 36 | 40 |
self.add(label)
|
| 37 | 41 |
log.debug('Could not create GST playbin')
|
| 38 | 42 |
return
|
| 39 | 43 |
|
| 40 |
- self._query = Gst.Query.new_position(Gst.Format.TIME)
|
|
| 44 |
+ self._query: Gst.Query = Gst.Query.new_position(Gst.Format.TIME)
|
|
| 41 | 45 |
self._has_timeout: bool = False
|
| 42 | 46 |
|
| 43 | 47 |
self._build_audio_widget()
|
| 44 | 48 |
self._setup_audio_player(file_path)
|
| 45 | 49 |
|
| 46 |
- def _build_audio_widget(self):
|
|
| 50 |
+ def _build_audio_widget(self) -> None:
|
|
| 47 | 51 |
play_button = Gtk.Button()
|
| 48 | 52 |
play_button.get_style_context().add_class('flat')
|
| 49 | 53 |
play_button.get_style_context().add_class('preview-button')
|
| ... | ... | @@ -81,11 +85,14 @@ def _setup_audio_player(self, file_path: Path) -> None: |
| 81 | 85 |
log.debug('Could not setup GST playbin')
|
| 82 | 86 |
return
|
| 83 | 87 |
|
| 84 |
- bus = self._playbin.get_bus()
|
|
| 88 |
+ bus: Optional[Gst.Bus] = self._playbin.get_bus()
|
|
| 89 |
+ if bus is None:
|
|
| 90 |
+ log.debug('Could not get GST Bus')
|
|
| 91 |
+ return
|
|
| 85 | 92 |
bus.add_signal_watch()
|
| 86 | 93 |
bus.connect('message', self._on_bus_message)
|
| 87 | 94 |
|
| 88 |
- def _on_bus_message(self, _bus, message):
|
|
| 95 |
+ def _on_bus_message(self, _bus: Gst.Bus, message: Gst.Message) -> None:
|
|
| 89 | 96 |
if message.type == Gst.MessageType.EOS:
|
| 90 | 97 |
self._set_pause(True)
|
| 91 | 98 |
self._playbin.seek_simple(
|
| ... | ... | @@ -102,12 +109,16 @@ def _on_bus_message(self, _bus, message): |
| 102 | 109 |
GLib.timeout_add(500, self._update_seek_bar)
|
| 103 | 110 |
self._has_timeout = True
|
| 104 | 111 |
|
| 105 |
- def _on_seek(self, _range, _scroll, value):
|
|
| 112 |
+ def _on_seek(self,
|
|
| 113 |
+ _range: Gtk.Range,
|
|
| 114 |
+ _scroll: Gtk.ScrollType,
|
|
| 115 |
+ value: float
|
|
| 116 |
+ ) -> bool:
|
|
| 106 | 117 |
self._playbin.seek_simple(
|
| 107 | 118 |
Gst.Format.TIME, Gst.SeekFlags.FLUSH, value)
|
| 108 | 119 |
return False
|
| 109 | 120 |
|
| 110 |
- def _on_play_clicked(self, _button):
|
|
| 121 |
+ def _on_play_clicked(self, _button: Gtk.Button) -> None:
|
|
| 111 | 122 |
self._set_pause(not self._get_paused())
|
| 112 | 123 |
|
| 113 | 124 |
def _on_destroy(self, _widget):
|
| ... | ... | @@ -140,7 +151,7 @@ def _update_seek_bar(self) -> bool: |
| 140 | 151 |
return True
|
| 141 | 152 |
|
| 142 | 153 |
@staticmethod
|
| 143 |
- def _format_audio_timestamp(_widget: Gtk.Widget, ns: int) -> str:
|
|
| 154 |
+ def _format_audio_timestamp(_widget: Gtk.Scale, ns: float) -> str:
|
|
| 144 | 155 |
seconds = ns / 1000000000
|
| 145 | 156 |
minutes = seconds / 60
|
| 146 | 157 |
hours = minutes / 60
|
| ... | ... | @@ -154,5 +165,5 @@ def _format_audio_timestamp(_widget: Gtk.Widget, ns: int) -> str: |
| 154 | 165 |
return f'{i_minutes:d}:{i_seconds:02d}'
|
| 155 | 166 |
|
| 156 | 167 |
@staticmethod
|
| 157 |
- def _on_realize(event_box):
|
|
| 168 |
+ def _on_realize(event_box: Gtk.EventBox) -> None:
|
|
| 158 | 169 |
event_box.get_window().set_cursor(get_cursor('pointer'))
|
| ... | ... | @@ -12,8 +12,11 @@ |
| 12 | 12 |
# You should have received a copy of the GNU General Public License
|
| 13 | 13 |
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
| 14 | 14 |
|
| 15 |
+from __future__ import annotations
|
|
| 16 |
+ |
|
| 15 | 17 |
from typing import Any
|
| 16 | 18 |
from typing import List
|
| 19 |
+from typing import Optional
|
|
| 17 | 20 |
|
| 18 | 21 |
import logging
|
| 19 | 22 |
|
| ... | ... | @@ -26,13 +29,15 @@ |
| 26 | 29 |
from gajim.common.const import AvatarSize
|
| 27 | 30 |
from gajim.common.i18n import _
|
| 28 | 31 |
|
| 32 |
+from .chat_list_stack import ChatListStack
|
|
| 33 |
+from .chat_page import ChatPage
|
|
| 29 | 34 |
from .util import open_window
|
| 30 | 35 |
|
| 31 | 36 |
log = logging.getLogger('gajim.gui.workspace_sidebar')
|
| 32 | 37 |
|
| 33 | 38 |
|
| 34 | 39 |
class WorkspaceSideBar(Gtk.ListBox):
|
| 35 |
- def __init__(self, chat_page):
|
|
| 40 |
+ def __init__(self, chat_page: ChatPage) -> None:
|
|
| 36 | 41 |
Gtk.ListBox.__init__(self)
|
| 37 | 42 |
self.set_vexpand(True)
|
| 38 | 43 |
self.set_valign(Gtk.Align.START)
|
| ... | ... | @@ -54,7 +59,7 @@ def __init__(self, chat_page): |
| 54 | 59 |
entries,
|
| 55 | 60 |
Gdk.DragAction.MOVE)
|
| 56 | 61 |
|
| 57 |
- self.drag_row = None
|
|
| 62 |
+ self.drag_row: Optional[Workspace] = None
|
|
| 58 | 63 |
self.row_before = None
|
| 59 | 64 |
self.row_after = None
|
| 60 | 65 |
|
| ... | ... | @@ -152,14 +157,18 @@ def _get_row_before(self, row): |
| 152 | 157 |
def _get_row_after(self, row):
|
| 153 | 158 |
return self.get_row_at_index(row.get_index() + 1)
|
| 154 | 159 |
|
| 155 |
- def _get_last_workspace_row(self):
|
|
| 160 |
+ def _get_last_workspace_row(self) -> Workspace:
|
|
| 156 | 161 |
# Calling len(children) would include AddWorkspace
|
| 157 | 162 |
return self.get_row_at_index(len(self.get_children()) - 1)
|
| 158 | 163 |
|
| 159 |
- def set_drag_row(self, row):
|
|
| 164 |
+ def set_drag_row(self, row: Workspace) -> None:
|
|
| 160 | 165 |
self.drag_row = row
|
| 161 | 166 |
|
| 162 |
- def _on_unread_count_changed(self, _chat_list_stack, workspace_id, count):
|
|
| 167 |
+ def _on_unread_count_changed(self,
|
|
| 168 |
+ _chat_list_stack: ChatListStack,
|
|
| 169 |
+ workspace_id: str,
|
|
| 170 |
+ count: int
|
|
| 171 |
+ ) -> None:
|
|
| 163 | 172 |
workspace = self._workspaces[workspace_id]
|
| 164 | 173 |
workspace.set_unread_count(count)
|
| 165 | 174 |
|
| ... | ... | @@ -173,25 +182,25 @@ def _on_row_activated(_listbox, row): |
| 173 | 182 |
else:
|
| 174 | 183 |
app.window.activate_workspace(row.workspace_id)
|
| 175 | 184 |
|
| 176 |
- def add_workspace(self, workspace_id):
|
|
| 185 |
+ def add_workspace(self, workspace_id: str) -> None:
|
|
| 177 | 186 |
row = Workspace(workspace_id)
|
| 178 | 187 |
self._workspaces[workspace_id] = row
|
| 179 | 188 |
# Insert row before AddWorkspace row
|
| 180 | 189 |
self.insert(row, len(self.get_children()) - 1)
|
| 181 | 190 |
|
| 182 |
- def store_workspace_order(self):
|
|
| 191 |
+ def store_workspace_order(self) -> None:
|
|
| 183 | 192 |
order = [row.workspace_id for row in self.get_children()]
|
| 184 | 193 |
order.remove('add')
|
| 185 | 194 |
app.settings.set_app_setting('workspace_order', order)
|
| 186 | 195 |
|
| 187 |
- def remove_workspace(self, workspace_id):
|
|
| 196 |
+ def remove_workspace(self, workspace_id: str) -> bool:
|
|
| 188 | 197 |
if len(self._workspaces) == 1:
|
| 189 | 198 |
return False
|
| 190 | 199 |
row = self._workspaces.pop(workspace_id)
|
| 191 | 200 |
self.remove(row)
|
| 192 | 201 |
return True
|
| 193 | 202 |
|
| 194 |
- def activate_workspace(self, workspace_id):
|
|
| 203 |
+ def activate_workspace(self, workspace_id: str) -> None:
|
|
| 195 | 204 |
row = self.get_selected_row()
|
| 196 | 205 |
if row is not None and row.workspace_id == workspace_id:
|
| 197 | 206 |
return
|
| ... | ... | @@ -199,23 +208,23 @@ def activate_workspace(self, workspace_id): |
| 199 | 208 |
row = self._workspaces[workspace_id]
|
| 200 | 209 |
self.select_row(row)
|
| 201 | 210 |
|
| 202 |
- def get_active_workspace(self):
|
|
| 211 |
+ def get_active_workspace(self) -> str:
|
|
| 203 | 212 |
row = self.get_selected_row()
|
| 204 | 213 |
if row is None:
|
| 205 | 214 |
return None
|
| 206 | 215 |
return row.workspace_id
|
| 207 | 216 |
|
| 208 |
- def get_first_workspace(self):
|
|
| 217 |
+ def get_first_workspace(self) -> str:
|
|
| 209 | 218 |
for row in self.get_children():
|
| 210 | 219 |
return row.workspace_id
|
| 211 | 220 |
|
| 212 |
- def get_workspace_by_id(self, workspace_id):
|
|
| 221 |
+ def get_workspace_by_id(self, workspace_id: str) -> Optional[Workspace]:
|
|
| 213 | 222 |
for row in self.get_children():
|
| 214 | 223 |
if row.workspace_id == workspace_id:
|
| 215 | 224 |
return row
|
| 216 | 225 |
return None
|
| 217 | 226 |
|
| 218 |
- def update_avatar(self, workspace_id):
|
|
| 227 |
+ def update_avatar(self, workspace_id: str) -> None:
|
|
| 219 | 228 |
row = self._workspaces[workspace_id]
|
| 220 | 229 |
row.update_avatar()
|
| 221 | 230 |
|
| ... | ... | @@ -227,7 +236,7 @@ def __init__(self, workspace_id): |
| 227 | 236 |
|
| 228 | 237 |
|
| 229 | 238 |
class Workspace(CommonWorkspace):
|
| 230 |
- def __init__(self, workspace_id):
|
|
| 239 |
+ def __init__(self, workspace_id: str) -> None:
|
|
| 231 | 240 |
CommonWorkspace.__init__(self, workspace_id)
|
| 232 | 241 |
self.get_style_context().add_class('workspace-sidebar-item')
|
| 233 | 242 |
|
| ... | ... | @@ -270,7 +279,7 @@ def __init__(self, workspace_id): |
| 270 | 279 |
self.add(eventbox)
|
| 271 | 280 |
self.show_all()
|
| 272 | 281 |
|
| 273 |
- def _popup_menu(self, _widget, event):
|
|
| 282 |
+ def _popup_menu(self, _widget: Gtk.Widget, event: Gdk.EventButton) -> None:
|
|
| 274 | 283 |
if event.button != 3: # right click
|
| 275 | 284 |
return
|
| 276 | 285 |
|
| ... | ... | @@ -301,17 +310,20 @@ def _get_workspace_menu(self) -> Gio.Menu: |
| 301 | 310 |
menu.append_item(menuitem)
|
| 302 | 311 |
return menu
|
| 303 | 312 |
|
| 304 |
- def update_avatar(self):
|
|
| 313 |
+ def update_avatar(self) -> None:
|
|
| 305 | 314 |
self._image.update()
|
| 306 | 315 |
|
| 307 |
- def set_unread_count(self, count):
|
|
| 316 |
+ def set_unread_count(self, count: int) -> None:
|
|
| 308 | 317 |
if count < 1000:
|
| 309 | 318 |
self._unread_label.set_text(str(count))
|
| 310 | 319 |
else:
|
| 311 | 320 |
self._unread_label.set_text('999+')
|
| 312 | 321 |
self._unread_label.set_visible(bool(count))
|
| 313 | 322 |
|
| 314 |
- def _on_drag_begin(self, _widget, drag_context):
|
|
| 323 |
+ def _on_drag_begin(self,
|
|
| 324 |
+ _widget: Gtk.Widget,
|
|
| 325 |
+ drag_context: Gdk.DragContext
|
|
| 326 |
+ ) -> None:
|
|
| 315 | 327 |
scale = self.get_scale_factor()
|
| 316 | 328 |
surface = app.interface.avatar_storage.get_workspace_surface(
|
| 317 | 329 |
self.workspace_id, AvatarSize.WORKSPACE, scale)
|
| ... | ... | @@ -320,15 +332,20 @@ def _on_drag_begin(self, _widget, drag_context): |
| 320 | 332 |
listbox = self.get_parent()
|
| 321 | 333 |
listbox.set_drag_row(self)
|
| 322 | 334 |
|
| 323 |
- def _on_drag_data_get(self, _widget, _drag_context, selection_data,
|
|
| 324 |
- _info, _time):
|
|
| 335 |
+ def _on_drag_data_get(self,
|
|
| 336 |
+ _widget: Gtk.Widget,
|
|
| 337 |
+ _drag_context: Gdk.DragContext,
|
|
| 338 |
+ selection_data: Gtk.SelectionData,
|
|
| 339 |
+ _info: int,
|
|
| 340 |
+ _time: int
|
|
| 341 |
+ ) -> None:
|
|
| 325 | 342 |
drop_type = Gdk.Atom.intern_static_string('WORKSPACE_SIDEBAR_ITEM')
|
| 326 | 343 |
data = self.workspace_id.encode('utf-8')
|
| 327 | 344 |
selection_data.set(drop_type, 32, data)
|
| 328 | 345 |
|
| 329 | 346 |
|
| 330 | 347 |
class AddWorkspace(CommonWorkspace):
|
| 331 |
- def __init__(self, workspace_id):
|
|
| 348 |
+ def __init__(self, workspace_id: str) -> None:
|
|
| 332 | 349 |
CommonWorkspace.__init__(self, workspace_id)
|
| 333 | 350 |
self.set_selectable(False)
|
| 334 | 351 |
self.set_tooltip_text(_('Add Workspace'))
|
| ... | ... | @@ -340,17 +357,17 @@ def __init__(self, workspace_id): |
| 340 | 357 |
self.show_all()
|
| 341 | 358 |
|
| 342 | 359 |
@staticmethod
|
| 343 |
- def _on_add_clicked(_button):
|
|
| 360 |
+ def _on_add_clicked(_button: Gtk.Button) -> None:
|
|
| 344 | 361 |
open_window('WorkspaceDialog')
|
| 345 | 362 |
|
| 346 | 363 |
|
| 347 | 364 |
class WorkspaceAvatar(Gtk.Image):
|
| 348 |
- def __init__(self, workspace_id):
|
|
| 365 |
+ def __init__(self, workspace_id: str) -> None:
|
|
| 349 | 366 |
Gtk.Image.__init__(self)
|
| 350 | 367 |
self._workspace_id = workspace_id
|
| 351 | 368 |
self.update()
|
| 352 | 369 |
|
| 353 |
- def update(self):
|
|
| 370 |
+ def update(self) -> None:
|
|
| 354 | 371 |
app.interface.avatar_storage.invalidate_cache(self._workspace_id)
|
| 355 | 372 |
scale = self.get_scale_factor()
|
| 356 | 373 |
surface = app.interface.avatar_storage.get_workspace_surface(
|