Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
008d137f
by wurstsalat at 2022-01-11T19:06:16+01:00
-
60b577d6
by wurstsalat at 2022-01-11T19:13:34+01:00
3 changed files:
Changes:
| ... | ... | @@ -14,6 +14,7 @@ |
| 14 | 14 |
|
| 15 | 15 |
from typing import Dict
|
| 16 | 16 |
from typing import Optional
|
| 17 |
+from typing import cast
|
|
| 17 | 18 |
|
| 18 | 19 |
from gi.repository import Gtk
|
| 19 | 20 |
from gi.repository import GObject
|
| ... | ... | @@ -101,9 +102,12 @@ def _on_visible_child_name(self, _stack: Gtk.Stack, _param: str) -> None: |
| 101 | 102 |
return
|
| 102 | 103 |
|
| 103 | 104 |
if self._last_visible_child_name != 'default':
|
| 104 |
- child = self.get_child_by_name(self._last_visible_child_name)
|
|
| 105 |
- child.set_filter_text('')
|
|
| 106 |
- self._last_visible_child_name = self.get_visible_child_name()
|
|
| 105 |
+ chat_list = cast(
|
|
| 106 |
+ ChatList,
|
|
| 107 |
+ self.get_child_by_name(self._last_visible_child_name))
|
|
| 108 |
+ chat_list.set_filter_text('')
|
|
| 109 |
+ last_child = self.get_visible_child_name() or 'default'
|
|
| 110 |
+ self._last_visible_child_name = last_child
|
|
| 107 | 111 |
|
| 108 | 112 |
def get_chatlist(self, workspace_id: str) -> ChatList:
|
| 109 | 113 |
return self._chat_lists[workspace_id]
|
| ... | ... | @@ -116,7 +120,7 @@ def get_selected_chat(self) -> Optional[ChatRow]: |
| 116 | 120 |
|
| 117 | 121 |
def get_current_chat_list(self) -> Optional[ChatList]:
|
| 118 | 122 |
workspace_id = self.get_visible_child_name()
|
| 119 |
- if workspace_id == 'empty':
|
|
| 123 |
+ if workspace_id == 'empty' or workspace_id is None:
|
|
| 120 | 124 |
return None
|
| 121 | 125 |
|
| 122 | 126 |
return self._chat_lists[workspace_id]
|
| ... | ... | @@ -130,11 +134,11 @@ def is_chat_active(self, account: str, jid: JID) -> bool: |
| 130 | 134 |
return chat.is_active
|
| 131 | 135 |
|
| 132 | 136 |
def _on_filter_changed(self, _filter: ChatFilter, name: str) -> None:
|
| 133 |
- chat_list = self.get_visible_child()
|
|
| 137 |
+ chat_list = cast(ChatList, self.get_visible_child())
|
|
| 134 | 138 |
chat_list.set_filter(name)
|
| 135 | 139 |
|
| 136 | 140 |
def _on_search_changed(self, search_entry: Gtk.SearchEntry) -> None:
|
| 137 |
- chat_list = self.get_visible_child()
|
|
| 141 |
+ chat_list = cast(ChatList, self.get_visible_child())
|
|
| 138 | 142 |
chat_list.set_filter_text(search_entry.get_text())
|
| 139 | 143 |
|
| 140 | 144 |
def add_chat_list(self, workspace_id: str) -> ChatList:
|
| ... | ... | @@ -165,12 +169,12 @@ def _on_row_selected(self, |
| 165 | 169 |
self.emit('chat-selected', row.workspace_id, row.account, row.jid)
|
| 166 | 170 |
|
| 167 | 171 |
def show_chat_list(self, workspace_id: str) -> None:
|
| 168 |
- current_workspace_id = self.get_visible_child_name()
|
|
| 169 |
- if current_workspace_id == workspace_id:
|
|
| 172 |
+ cur_workspace_id = self.get_visible_child_name()
|
|
| 173 |
+ if cur_workspace_id == workspace_id:
|
|
| 170 | 174 |
return
|
| 171 | 175 |
|
| 172 |
- if current_workspace_id != 'default':
|
|
| 173 |
- self._chat_lists[current_workspace_id].unselect_all()
|
|
| 176 |
+ if cur_workspace_id != 'default' and cur_workspace_id is not None:
|
|
| 177 |
+ self._chat_lists[cur_workspace_id].unselect_all()
|
|
| 174 | 178 |
|
| 175 | 179 |
self.set_visible_child_name(workspace_id)
|
| 176 | 180 |
|
| ... | ... | @@ -213,8 +217,10 @@ def _move_chat_to_workspace(self, |
| 213 | 217 |
new_workspace_id, account, jid = param.unpack()
|
| 214 | 218 |
jid = JID.from_string(jid)
|
| 215 | 219 |
|
| 216 |
- current_chatlist = self.get_visible_child()
|
|
| 220 |
+ current_chatlist = cast(ChatList, self.get_visible_child())
|
|
| 217 | 221 |
type_ = current_chatlist.get_chat_type(account, jid)
|
| 222 |
+ if type_ is None:
|
|
| 223 |
+ return
|
|
| 218 | 224 |
current_chatlist.remove_chat(account, jid)
|
| 219 | 225 |
|
| 220 | 226 |
new_chatlist = self.get_chatlist(new_workspace_id)
|
| ... | ... | @@ -12,8 +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 Dict
|
|
| 16 |
-from typing import Tuple
|
|
| 15 |
+from typing import Any
|
|
| 17 | 16 |
from typing import Optional
|
| 18 | 17 |
from typing import Generator
|
| 19 | 18 |
|
| ... | ... | @@ -55,7 +54,7 @@ def __init__(self): |
| 55 | 54 |
])
|
| 56 | 55 |
|
| 57 | 56 |
self.show_all()
|
| 58 |
- self._controls: Dict[Tuple[str, JID], ControlType] = {}
|
|
| 57 |
+ self._controls: dict[tuple[str, JID], ControlType] = {}
|
|
| 59 | 58 |
|
| 60 | 59 |
def get_control(self, account: str, jid: JID) -> Optional[ControlType]:
|
| 61 | 60 |
try:
|
| ... | ... | @@ -138,7 +137,7 @@ def remove_chats_for_account(self, account: str) -> None: |
| 138 | 137 |
continue
|
| 139 | 138 |
self.remove_chat(account, jid)
|
| 140 | 139 |
|
| 141 |
- def _on_account_changed(self, *args):
|
|
| 140 |
+ def _on_account_changed(self, *args: Any) -> None:
|
|
| 142 | 141 |
for control in self._controls.values():
|
| 143 | 142 |
control.update_account_badge()
|
| 144 | 143 |
|
| ... | ... | @@ -153,7 +152,7 @@ def __init__(self): |
| 153 | 152 |
'org.gajim.Gajim-symbolic',
|
| 154 | 153 |
100,
|
| 155 | 154 |
self.get_scale_factor(),
|
| 156 |
- 0)
|
|
| 155 |
+ Gtk.IconLookupFlags.FORCE_SIZE)
|
|
| 157 | 156 |
image = Gtk.Image.new_from_pixbuf(pixbuf)
|
| 158 | 157 |
image.get_style_context().add_class('dim-label')
|
| 159 | 158 |
self.add(image)
|
| ... | ... | @@ -163,5 +162,5 @@ def __init__(self): |
| 163 | 162 |
button.connect('clicked', self._on_start_chatting)
|
| 164 | 163 |
self.add(button)
|
| 165 | 164 |
|
| 166 |
- def _on_start_chatting(self, _button):
|
|
| 165 |
+ def _on_start_chatting(self, _button: Gtk.Button) -> None:
|
|
| 167 | 166 |
app.app.activate_action('start-chat', GLib.Variant('s', ''))
|
| ... | ... | @@ -147,7 +147,7 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None: |
| 147 | 147 |
|
| 148 | 148 |
self.xml = get_builder(f'{widget_name}.ui')
|
| 149 | 149 |
self.xml.connect_signals(self)
|
| 150 |
- self.widget = self.xml.get_object(f'{widget_name}_hbox')
|
|
| 150 |
+ self.widget: Gtk.Box = self.xml.get_object(f'{widget_name}_hbox')
|
|
| 151 | 151 |
|
| 152 | 152 |
self._account_badge = AccountBadge(self.account)
|
| 153 | 153 |
self.xml.account_badge_box.add(self._account_badge)
|