Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 068551db by wurstsalat at 2021-12-17T23:59:43+01:00 AudioPreview: Typing
- - - - - e7331833 by wurstsalat at 2021-12-18T00:00:23+01:00 App: Init Gst while checking dependencies
- - - - - c5cc0fe4 by wurstsalat at 2021-12-18T00:16:38+01:00 WorkspaceSidebar: Typing
- - - - - 2cb70610 by wurstsalat at 2021-12-18T00:24:36+01:00 Windows: Let message input grab focus after inserting Emoji
- - - - -
4 changed files:
- gajim/common/app.py - gajim/gtk/emoji_chooser.py - gajim/gtk/preview_audio.py - gajim/gtk/workspace_side_bar.py
Changes:
===================================== gajim/common/app.py ===================================== @@ -206,7 +206,8 @@ def detect_dependencies() -> None: gi.require_version('GstPbutils', '1.0') from gi.repository import Gst from gi.repository import GstPbutils # pylint: disable=unused-import - _dependencies['GST'] = True + success, _argv = Gst.init_check(None) + _dependencies['GST'] = success except Exception: pass
===================================== gajim/gtk/emoji_chooser.py ===================================== @@ -400,6 +400,7 @@ def _on_emoticon_press(self, flowbox, child): GLib.timeout_add(100, flowbox.unselect_child, child) codepoint, pixbuf = child.get_emoji() self._text_widget().insert_emoji(codepoint, pixbuf) + self._text_widget().grab_focus()
def do_destroy(self): # Remove the references we hold to other objects
===================================== gajim/gtk/preview_audio.py ===================================== @@ -12,6 +12,8 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from typing import Optional + import logging from pathlib import Path
@@ -28,22 +30,24 @@
class AudioWidget(Gtk.Box): def __init__(self, file_path: Path) -> None: - Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, + Gtk.Box.__init__(self, + orientation=Gtk.Orientation.HORIZONTAL, spacing=6) - self._playbin = Gst.ElementFactory.make('playbin', 'bin') + self._playbin: Optional[Gst.Element] = Gst.ElementFactory.make( + 'playbin', 'bin') if self._playbin is None: label = Gtk.Label(label=_('Audio preview is not available')) self.add(label) log.debug('Could not create GST playbin') return
- self._query = Gst.Query.new_position(Gst.Format.TIME) + self._query: Gst.Query = Gst.Query.new_position(Gst.Format.TIME) self._has_timeout: bool = False
self._build_audio_widget() self._setup_audio_player(file_path)
- def _build_audio_widget(self): + def _build_audio_widget(self) -> None: play_button = Gtk.Button() play_button.get_style_context().add_class('flat') play_button.get_style_context().add_class('preview-button') @@ -81,11 +85,14 @@ def _setup_audio_player(self, file_path: Path) -> None: log.debug('Could not setup GST playbin') return
- bus = self._playbin.get_bus() + bus: Optional[Gst.Bus] = self._playbin.get_bus() + if bus is None: + log.debug('Could not get GST Bus') + return bus.add_signal_watch() bus.connect('message', self._on_bus_message)
- def _on_bus_message(self, _bus, message): + def _on_bus_message(self, _bus: Gst.Bus, message: Gst.Message) -> None: if message.type == Gst.MessageType.EOS: self._set_pause(True) self._playbin.seek_simple( @@ -102,12 +109,16 @@ def _on_bus_message(self, _bus, message): GLib.timeout_add(500, self._update_seek_bar) self._has_timeout = True
- def _on_seek(self, _range, _scroll, value): + def _on_seek(self, + _range: Gtk.Range, + _scroll: Gtk.ScrollType, + value: float + ) -> bool: self._playbin.seek_simple( Gst.Format.TIME, Gst.SeekFlags.FLUSH, value) return False
- def _on_play_clicked(self, _button): + def _on_play_clicked(self, _button: Gtk.Button) -> None: self._set_pause(not self._get_paused())
def _on_destroy(self, _widget): @@ -140,7 +151,7 @@ def _update_seek_bar(self) -> bool: return True
@staticmethod - def _format_audio_timestamp(_widget: Gtk.Widget, ns: int) -> str: + def _format_audio_timestamp(_widget: Gtk.Scale, ns: float) -> str: seconds = ns / 1000000000 minutes = seconds / 60 hours = minutes / 60 @@ -154,5 +165,5 @@ def _format_audio_timestamp(_widget: Gtk.Widget, ns: int) -> str: return f'{i_minutes:d}:{i_seconds:02d}'
@staticmethod - def _on_realize(event_box): + def _on_realize(event_box: Gtk.EventBox) -> None: event_box.get_window().set_cursor(get_cursor('pointer'))
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -12,8 +12,11 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from __future__ import annotations + from typing import Any from typing import List +from typing import Optional
import logging
@@ -26,13 +29,15 @@ from gajim.common.const import AvatarSize from gajim.common.i18n import _
+from .chat_list_stack import ChatListStack +from .chat_page import ChatPage from .util import open_window
log = logging.getLogger('gajim.gui.workspace_sidebar')
class WorkspaceSideBar(Gtk.ListBox): - def __init__(self, chat_page): + def __init__(self, chat_page: ChatPage) -> None: Gtk.ListBox.__init__(self) self.set_vexpand(True) self.set_valign(Gtk.Align.START) @@ -54,7 +59,7 @@ def __init__(self, chat_page): entries, Gdk.DragAction.MOVE)
- self.drag_row = None + self.drag_row: Optional[Workspace] = None self.row_before = None self.row_after = None
@@ -152,14 +157,18 @@ def _get_row_before(self, row): def _get_row_after(self, row): return self.get_row_at_index(row.get_index() + 1)
- def _get_last_workspace_row(self): + def _get_last_workspace_row(self) -> Workspace: # Calling len(children) would include AddWorkspace return self.get_row_at_index(len(self.get_children()) - 1)
- def set_drag_row(self, row): + def set_drag_row(self, row: Workspace) -> None: self.drag_row = row
- def _on_unread_count_changed(self, _chat_list_stack, workspace_id, count): + def _on_unread_count_changed(self, + _chat_list_stack: ChatListStack, + workspace_id: str, + count: int + ) -> None: workspace = self._workspaces[workspace_id] workspace.set_unread_count(count)
@@ -173,25 +182,25 @@ def _on_row_activated(_listbox, row): else: app.window.activate_workspace(row.workspace_id)
- def add_workspace(self, workspace_id): + def add_workspace(self, workspace_id: str) -> None: row = Workspace(workspace_id) self._workspaces[workspace_id] = row # Insert row before AddWorkspace row self.insert(row, len(self.get_children()) - 1)
- def store_workspace_order(self): + def store_workspace_order(self) -> None: order = [row.workspace_id for row in self.get_children()] order.remove('add') app.settings.set_app_setting('workspace_order', order)
- def remove_workspace(self, workspace_id): + def remove_workspace(self, workspace_id: str) -> bool: if len(self._workspaces) == 1: return False row = self._workspaces.pop(workspace_id) self.remove(row) return True
- def activate_workspace(self, workspace_id): + def activate_workspace(self, workspace_id: str) -> None: row = self.get_selected_row() if row is not None and row.workspace_id == workspace_id: return @@ -199,23 +208,23 @@ def activate_workspace(self, workspace_id): row = self._workspaces[workspace_id] self.select_row(row)
- def get_active_workspace(self): + def get_active_workspace(self) -> str: row = self.get_selected_row() if row is None: return None return row.workspace_id
- def get_first_workspace(self): + def get_first_workspace(self) -> str: for row in self.get_children(): return row.workspace_id
- def get_workspace_by_id(self, workspace_id): + def get_workspace_by_id(self, workspace_id: str) -> Optional[Workspace]: for row in self.get_children(): if row.workspace_id == workspace_id: return row return None
- def update_avatar(self, workspace_id): + def update_avatar(self, workspace_id: str) -> None: row = self._workspaces[workspace_id] row.update_avatar()
@@ -227,7 +236,7 @@ def __init__(self, workspace_id):
class Workspace(CommonWorkspace): - def __init__(self, workspace_id): + def __init__(self, workspace_id: str) -> None: CommonWorkspace.__init__(self, workspace_id) self.get_style_context().add_class('workspace-sidebar-item')
@@ -270,7 +279,7 @@ def __init__(self, workspace_id): self.add(eventbox) self.show_all()
- def _popup_menu(self, _widget, event): + def _popup_menu(self, _widget: Gtk.Widget, event: Gdk.EventButton) -> None: if event.button != 3: # right click return
@@ -301,17 +310,20 @@ def _get_workspace_menu(self) -> Gio.Menu: menu.append_item(menuitem) return menu
- def update_avatar(self): + def update_avatar(self) -> None: self._image.update()
- def set_unread_count(self, count): + def set_unread_count(self, count: int) -> None: if count < 1000: self._unread_label.set_text(str(count)) else: self._unread_label.set_text('999+') self._unread_label.set_visible(bool(count))
- def _on_drag_begin(self, _widget, drag_context): + def _on_drag_begin(self, + _widget: Gtk.Widget, + drag_context: Gdk.DragContext + ) -> None: scale = self.get_scale_factor() surface = app.interface.avatar_storage.get_workspace_surface( self.workspace_id, AvatarSize.WORKSPACE, scale) @@ -320,15 +332,20 @@ def _on_drag_begin(self, _widget, drag_context): listbox = self.get_parent() listbox.set_drag_row(self)
- def _on_drag_data_get(self, _widget, _drag_context, selection_data, - _info, _time): + def _on_drag_data_get(self, + _widget: Gtk.Widget, + _drag_context: Gdk.DragContext, + selection_data: Gtk.SelectionData, + _info: int, + _time: int + ) -> None: drop_type = Gdk.Atom.intern_static_string('WORKSPACE_SIDEBAR_ITEM') data = self.workspace_id.encode('utf-8') selection_data.set(drop_type, 32, data)
class AddWorkspace(CommonWorkspace): - def __init__(self, workspace_id): + def __init__(self, workspace_id: str) -> None: CommonWorkspace.__init__(self, workspace_id) self.set_selectable(False) self.set_tooltip_text(_('Add Workspace')) @@ -340,17 +357,17 @@ def __init__(self, workspace_id): self.show_all()
@staticmethod - def _on_add_clicked(_button): + def _on_add_clicked(_button: Gtk.Button) -> None: open_window('WorkspaceDialog')
class WorkspaceAvatar(Gtk.Image): - def __init__(self, workspace_id): + def __init__(self, workspace_id: str) -> None: Gtk.Image.__init__(self) self._workspace_id = workspace_id self.update()
- def update(self): + def update(self) -> None: app.interface.avatar_storage.invalidate_cache(self._workspace_id) scale = self.get_scale_factor() surface = app.interface.avatar_storage.get_workspace_surface(
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/d345f92fbdfa78afd6e0c000044962ae...