Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
dcf0ed9f
by wurstsalat at 2021-12-26T17:44:55+01:00
-
0f72a7d2
by wurstsalat at 2021-12-26T17:57:07+01:00
2 changed files:
Changes:
| ... | ... | @@ -12,7 +12,7 @@ |
| 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 List
|
|
| 15 |
+from __future__ import annotations
|
|
| 16 | 16 |
from typing import Optional
|
| 17 | 17 |
from typing import Tuple
|
| 18 | 18 |
|
| ... | ... | @@ -27,6 +27,7 @@ |
| 27 | 27 |
from nbxmpp.structs import DiscoInfo
|
| 28 | 28 |
|
| 29 | 29 |
from gajim.common import app
|
| 30 |
+from gajim.common import types
|
|
| 30 | 31 |
from gajim.common.i18n import _
|
| 31 | 32 |
from gajim.common.modules.contacts import BareContact
|
| 32 | 33 |
from gajim.common.modules.contacts import ResourceContact
|
| ... | ... | @@ -43,8 +44,9 @@ class ResourceSelector(Gtk.ScrolledWindow): |
| 43 | 44 |
(bool, )),
|
| 44 | 45 |
}
|
| 45 | 46 |
|
| 46 |
- def __init__(self, contact: BareContact,
|
|
| 47 |
- constraints: List[_Namespaces] = None) -> None:
|
|
| 47 |
+ def __init__(self,
|
|
| 48 |
+ contact: BareContact,
|
|
| 49 |
+ constraints: Optional[list[_Namespaces]] = None) -> None:
|
|
| 48 | 50 |
Gtk.ScrolledWindow.__init__(self)
|
| 49 | 51 |
self.set_shadow_type(Gtk.ShadowType.IN)
|
| 50 | 52 |
self.set_size_request(-1, 200)
|
| ... | ... | @@ -68,11 +70,14 @@ def __init__(self, contact: BareContact, |
| 68 | 70 |
self.show_all()
|
| 69 | 71 |
|
| 70 | 72 |
@staticmethod
|
| 71 |
- def _sort_func(row1, row2):
|
|
| 73 |
+ def _sort_func(row1: ResourceRow, row2: ResourceRow) -> int:
|
|
| 72 | 74 |
return locale.strcoll(
|
| 73 | 75 |
row1.device_text.lower(), row2.device_text.lower())
|
| 74 | 76 |
|
| 75 |
- def _on_row_selected(self, _listbox, row):
|
|
| 77 |
+ def _on_row_selected(self,
|
|
| 78 |
+ _listbox: Gtk.ListBox,
|
|
| 79 |
+ row: ResourceRow
|
|
| 80 |
+ ) -> None:
|
|
| 76 | 81 |
state = bool(row is not None)
|
| 77 | 82 |
self.emit('selection-changed', state)
|
| 78 | 83 |
|
| ... | ... | @@ -92,7 +97,10 @@ def _add_entries(self) -> None: |
| 92 | 97 |
for resource in self._contact.iter_resources():
|
| 93 | 98 |
self._listbox.add(ResourceRow(resource, self._constraints))
|
| 94 | 99 |
|
| 95 |
- def _on_update(self, _contact, _signal_name):
|
|
| 100 |
+ def _on_update(self,
|
|
| 101 |
+ _contact: types.ResourceContact,
|
|
| 102 |
+ _signal_name: str
|
|
| 103 |
+ ) -> None:
|
|
| 96 | 104 |
for child in self._listbox.get_children():
|
| 97 | 105 |
self._listbox.remove(child)
|
| 98 | 106 |
self._add_entries()
|
| ... | ... | @@ -102,15 +110,17 @@ def get_jid(self) -> JID: |
| 102 | 110 |
|
| 103 | 111 |
|
| 104 | 112 |
class ResourceRow(Gtk.ListBoxRow):
|
| 105 |
- def __init__(self, resource_contact: ResourceContact,
|
|
| 106 |
- constraints: List[_Namespaces]) -> None:
|
|
| 113 |
+ def __init__(self,
|
|
| 114 |
+ resource_contact: ResourceContact,
|
|
| 115 |
+ constraints: list[_Namespaces]
|
|
| 116 |
+ ) -> None:
|
|
| 107 | 117 |
Gtk.ListBoxRow.__init__(self)
|
| 108 | 118 |
|
| 109 | 119 |
self.jid = resource_contact.jid
|
| 110 | 120 |
|
| 111 | 121 |
icon_name = 'computer-symbolic'
|
| 112 | 122 |
tooltip_text = _('Computer')
|
| 113 |
- self.device_text = resource_contact.jid.resource
|
|
| 123 |
+ self.device_text = resource_contact.jid.resource or ''
|
|
| 114 | 124 |
|
| 115 | 125 |
disco_info = app.storage.cache.get_last_disco_info(
|
| 116 | 126 |
resource_contact.jid)
|
| ... | ... | @@ -135,7 +145,7 @@ def __init__(self, resource_contact: ResourceContact, |
| 135 | 145 |
box.add(name_label)
|
| 136 | 146 |
|
| 137 | 147 |
for constraint in constraints:
|
| 138 |
- if not resource_contact.supports(constraint):
|
|
| 148 |
+ if not resource_contact.supports(str(constraint)):
|
|
| 139 | 149 |
self.set_sensitive(False)
|
| 140 | 150 |
self.set_tooltip_text(_('This devices is not compatible.'))
|
| 141 | 151 |
|
| ... | ... | @@ -17,6 +17,7 @@ |
| 17 | 17 |
from typing import Any
|
| 18 | 18 |
from typing import List
|
| 19 | 19 |
from typing import Optional
|
| 20 |
+from typing import Union
|
|
| 20 | 21 |
|
| 21 | 22 |
import logging
|
| 22 | 23 |
|
| ... | ... | @@ -60,8 +61,8 @@ def __init__(self, chat_page: ChatPage) -> None: |
| 60 | 61 |
Gdk.DragAction.MOVE)
|
| 61 | 62 |
|
| 62 | 63 |
self.drag_row: Optional[Workspace] = None
|
| 63 |
- self.row_before = None
|
|
| 64 |
- self.row_after = None
|
|
| 64 |
+ self.row_before: Optional[Workspace] = None
|
|
| 65 |
+ self.row_after: Union[Workspace, AddWorkspace, None] = None
|
|
| 65 | 66 |
|
| 66 | 67 |
self.connect('drag-motion', self._on_drag_motion)
|
| 67 | 68 |
self.connect('drag-data-received', self._on_drag_data_received)
|
| ... | ... | @@ -74,7 +75,7 @@ def __init__(self, chat_page: ChatPage) -> None: |
| 74 | 75 |
self._on_unread_count_changed)
|
| 75 | 76 |
chat_list_stack.connect('chat-selected',
|
| 76 | 77 |
self._on_chat_selected)
|
| 77 |
- self._workspaces = {}
|
|
| 78 |
+ self._workspaces: dict[str, Workspace] = {}
|
|
| 78 | 79 |
|
| 79 | 80 |
def _on_drag_motion(self,
|
| 80 | 81 |
_widget: Gtk.Widget,
|
| ... | ... | @@ -82,7 +83,7 @@ def _on_drag_motion(self, |
| 82 | 83 |
_x_coord: int,
|
| 83 | 84 |
y_coord: int,
|
| 84 | 85 |
_time: int
|
| 85 |
- ) -> None:
|
|
| 86 |
+ ) -> bool:
|
|
| 86 | 87 |
row = self.get_row_at_y(y_coord)
|
| 87 | 88 |
|
| 88 | 89 |
if row:
|
| ... | ... | @@ -172,11 +173,16 @@ def _on_unread_count_changed(self, |
| 172 | 173 |
workspace = self._workspaces[workspace_id]
|
| 173 | 174 |
workspace.set_unread_count(count)
|
| 174 | 175 |
|
| 175 |
- def _on_chat_selected(self, _chat_list_stack, workspace_id, *args):
|
|
| 176 |
+ def _on_chat_selected(self,
|
|
| 177 |
+ _chat_list_stack: ChatListStack,
|
|
| 178 |
+ workspace_id: str,
|
|
| 179 |
+ *args: Any) -> None:
|
|
| 176 | 180 |
self.activate_workspace(workspace_id)
|
| 177 | 181 |
|
| 178 | 182 |
@staticmethod
|
| 179 |
- def _on_row_activated(_listbox, row):
|
|
| 183 |
+ def _on_row_activated(_listbox: Gtk.ListBox,
|
|
| 184 |
+ row: Union[Workspace, AddWorkspace]
|
|
| 185 |
+ ) -> None:
|
|
| 180 | 186 |
if row.workspace_id == 'add':
|
| 181 | 187 |
open_window('WorkspaceDialog')
|
| 182 | 188 |
else:
|
| ... | ... | @@ -208,7 +214,7 @@ def activate_workspace(self, workspace_id: str) -> None: |
| 208 | 214 |
row = self._workspaces[workspace_id]
|
| 209 | 215 |
self.select_row(row)
|
| 210 | 216 |
|
| 211 |
- def get_active_workspace(self) -> str:
|
|
| 217 |
+ def get_active_workspace(self) -> Optional[str]:
|
|
| 212 | 218 |
row = self.get_selected_row()
|
| 213 | 219 |
if row is None:
|
| 214 | 220 |
return None
|
| ... | ... | @@ -230,7 +236,7 @@ def update_avatar(self, workspace_id: str) -> None: |
| 230 | 236 |
|
| 231 | 237 |
|
| 232 | 238 |
class CommonWorkspace(Gtk.ListBoxRow):
|
| 233 |
- def __init__(self, workspace_id):
|
|
| 239 |
+ def __init__(self, workspace_id: str) -> None:
|
|
| 234 | 240 |
Gtk.ListBoxRow.__init__(self)
|
| 235 | 241 |
self.workspace_id = workspace_id
|
| 236 | 242 |
|