Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: dcf0ed9f by wurstsalat at 2021-12-26T17:44:55+01:00 WorkspaceSidebar: Typing
- - - - - 0f72a7d2 by wurstsalat at 2021-12-26T17:57:07+01:00 ResourceSelector: Typing
- - - - -
2 changed files:
- gajim/gtk/resource_selector.py - gajim/gtk/workspace_side_bar.py
Changes:
===================================== gajim/gtk/resource_selector.py ===================================== @@ -12,7 +12,7 @@ # 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 List +from __future__ import annotations from typing import Optional from typing import Tuple
@@ -27,6 +27,7 @@ from nbxmpp.structs import DiscoInfo
from gajim.common import app +from gajim.common import types from gajim.common.i18n import _ from gajim.common.modules.contacts import BareContact from gajim.common.modules.contacts import ResourceContact @@ -43,8 +44,9 @@ class ResourceSelector(Gtk.ScrolledWindow): (bool, )), }
- def __init__(self, contact: BareContact, - constraints: List[_Namespaces] = None) -> None: + def __init__(self, + contact: BareContact, + constraints: Optional[list[_Namespaces]] = None) -> None: Gtk.ScrolledWindow.__init__(self) self.set_shadow_type(Gtk.ShadowType.IN) self.set_size_request(-1, 200) @@ -68,11 +70,14 @@ def __init__(self, contact: BareContact, self.show_all()
@staticmethod - def _sort_func(row1, row2): + def _sort_func(row1: ResourceRow, row2: ResourceRow) -> int: return locale.strcoll( row1.device_text.lower(), row2.device_text.lower())
- def _on_row_selected(self, _listbox, row): + def _on_row_selected(self, + _listbox: Gtk.ListBox, + row: ResourceRow + ) -> None: state = bool(row is not None) self.emit('selection-changed', state)
@@ -92,7 +97,10 @@ def _add_entries(self) -> None: for resource in self._contact.iter_resources(): self._listbox.add(ResourceRow(resource, self._constraints))
- def _on_update(self, _contact, _signal_name): + def _on_update(self, + _contact: types.ResourceContact, + _signal_name: str + ) -> None: for child in self._listbox.get_children(): self._listbox.remove(child) self._add_entries() @@ -102,15 +110,17 @@ def get_jid(self) -> JID:
class ResourceRow(Gtk.ListBoxRow): - def __init__(self, resource_contact: ResourceContact, - constraints: List[_Namespaces]) -> None: + def __init__(self, + resource_contact: ResourceContact, + constraints: list[_Namespaces] + ) -> None: Gtk.ListBoxRow.__init__(self)
self.jid = resource_contact.jid
icon_name = 'computer-symbolic' tooltip_text = _('Computer') - self.device_text = resource_contact.jid.resource + self.device_text = resource_contact.jid.resource or ''
disco_info = app.storage.cache.get_last_disco_info( resource_contact.jid) @@ -135,7 +145,7 @@ def __init__(self, resource_contact: ResourceContact, box.add(name_label)
for constraint in constraints: - if not resource_contact.supports(constraint): + if not resource_contact.supports(str(constraint)): self.set_sensitive(False) self.set_tooltip_text(_('This devices is not compatible.'))
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -17,6 +17,7 @@ from typing import Any from typing import List from typing import Optional +from typing import Union
import logging
@@ -60,8 +61,8 @@ def __init__(self, chat_page: ChatPage) -> None: Gdk.DragAction.MOVE)
self.drag_row: Optional[Workspace] = None - self.row_before = None - self.row_after = None + self.row_before: Optional[Workspace] = None + self.row_after: Union[Workspace, AddWorkspace, None] = None
self.connect('drag-motion', self._on_drag_motion) self.connect('drag-data-received', self._on_drag_data_received) @@ -74,7 +75,7 @@ def __init__(self, chat_page: ChatPage) -> None: self._on_unread_count_changed) chat_list_stack.connect('chat-selected', self._on_chat_selected) - self._workspaces = {} + self._workspaces: dict[str, Workspace] = {}
def _on_drag_motion(self, _widget: Gtk.Widget, @@ -82,7 +83,7 @@ def _on_drag_motion(self, _x_coord: int, y_coord: int, _time: int - ) -> None: + ) -> bool: row = self.get_row_at_y(y_coord)
if row: @@ -172,11 +173,16 @@ def _on_unread_count_changed(self, workspace = self._workspaces[workspace_id] workspace.set_unread_count(count)
- def _on_chat_selected(self, _chat_list_stack, workspace_id, *args): + def _on_chat_selected(self, + _chat_list_stack: ChatListStack, + workspace_id: str, + *args: Any) -> None: self.activate_workspace(workspace_id)
@staticmethod - def _on_row_activated(_listbox, row): + def _on_row_activated(_listbox: Gtk.ListBox, + row: Union[Workspace, AddWorkspace] + ) -> None: if row.workspace_id == 'add': open_window('WorkspaceDialog') else: @@ -208,7 +214,7 @@ def activate_workspace(self, workspace_id: str) -> None: row = self._workspaces[workspace_id] self.select_row(row)
- def get_active_workspace(self) -> str: + def get_active_workspace(self) -> Optional[str]: row = self.get_selected_row() if row is None: return None @@ -230,7 +236,7 @@ def update_avatar(self, workspace_id: str) -> None:
class CommonWorkspace(Gtk.ListBoxRow): - def __init__(self, workspace_id): + def __init__(self, workspace_id: str) -> None: Gtk.ListBoxRow.__init__(self) self.workspace_id = workspace_id
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/f03998805709844034b4065f3145b27e...