Daniel Brötzmann pushed to branch master at gajim / gajim


Commits:
008d137f by wurstsalat at 2022-01-11T19:06:16+01:00
ChatListStack: Typing

- - - - -
60b577d6 by wurstsalat at 2022-01-11T19:13:34+01:00
ChatStack: Typing

- - - - -


3 changed files:

- gajim/gtk/chat_list_stack.py
- gajim/gtk/chat_stack.py
- gajim/gtk/controls/base.py


Changes:

=====================================
gajim/gtk/chat_list_stack.py
=====================================
@@ -14,6 +14,7 @@
 
 from typing import Dict
 from typing import Optional
+from typing import cast
 
 from gi.repository import Gtk
 from gi.repository import GObject
@@ -101,9 +102,12 @@ def _on_visible_child_name(self, _stack: Gtk.Stack, 
_param: str) -> None:
             return
 
         if self._last_visible_child_name != 'default':
-            child = self.get_child_by_name(self._last_visible_child_name)
-            child.set_filter_text('')
-        self._last_visible_child_name = self.get_visible_child_name()
+            chat_list = cast(
+                ChatList,
+                self.get_child_by_name(self._last_visible_child_name))
+            chat_list.set_filter_text('')
+        last_child = self.get_visible_child_name() or 'default'
+        self._last_visible_child_name = last_child
 
     def get_chatlist(self, workspace_id: str) -> ChatList:
         return self._chat_lists[workspace_id]
@@ -116,7 +120,7 @@ def get_selected_chat(self) -> Optional[ChatRow]:
 
     def get_current_chat_list(self) -> Optional[ChatList]:
         workspace_id = self.get_visible_child_name()
-        if workspace_id == 'empty':
+        if workspace_id == 'empty' or workspace_id is None:
             return None
 
         return self._chat_lists[workspace_id]
@@ -130,11 +134,11 @@ def is_chat_active(self, account: str, jid: JID) -> bool:
         return chat.is_active
 
     def _on_filter_changed(self, _filter: ChatFilter, name: str) -> None:
-        chat_list = self.get_visible_child()
+        chat_list = cast(ChatList, self.get_visible_child())
         chat_list.set_filter(name)
 
     def _on_search_changed(self, search_entry: Gtk.SearchEntry) -> None:
-        chat_list = self.get_visible_child()
+        chat_list = cast(ChatList, self.get_visible_child())
         chat_list.set_filter_text(search_entry.get_text())
 
     def add_chat_list(self, workspace_id: str) -> ChatList:
@@ -165,12 +169,12 @@ def _on_row_selected(self,
         self.emit('chat-selected', row.workspace_id, row.account, row.jid)
 
     def show_chat_list(self, workspace_id: str) -> None:
-        current_workspace_id = self.get_visible_child_name()
-        if current_workspace_id == workspace_id:
+        cur_workspace_id = self.get_visible_child_name()
+        if cur_workspace_id == workspace_id:
             return
 
-        if current_workspace_id != 'default':
-            self._chat_lists[current_workspace_id].unselect_all()
+        if cur_workspace_id != 'default' and cur_workspace_id is not None:
+            self._chat_lists[cur_workspace_id].unselect_all()
 
         self.set_visible_child_name(workspace_id)
 
@@ -213,8 +217,10 @@ def _move_chat_to_workspace(self,
         new_workspace_id, account, jid = param.unpack()
         jid = JID.from_string(jid)
 
-        current_chatlist = self.get_visible_child()
+        current_chatlist = cast(ChatList, self.get_visible_child())
         type_ = current_chatlist.get_chat_type(account, jid)
+        if type_ is None:
+            return
         current_chatlist.remove_chat(account, jid)
 
         new_chatlist = self.get_chatlist(new_workspace_id)


=====================================
gajim/gtk/chat_stack.py
=====================================
@@ -12,8 +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 Dict
-from typing import Tuple
+from typing import Any
 from typing import Optional
 from typing import Generator
 
@@ -55,7 +54,7 @@ def __init__(self):
         ])
 
         self.show_all()
-        self._controls: Dict[Tuple[str, JID], ControlType] = {}
+        self._controls: dict[tuple[str, JID], ControlType] = {}
 
     def get_control(self, account: str, jid: JID) -> Optional[ControlType]:
         try:
@@ -138,7 +137,7 @@ def remove_chats_for_account(self, account: str) -> None:
                 continue
             self.remove_chat(account, jid)
 
-    def _on_account_changed(self, *args):
+    def _on_account_changed(self, *args: Any) -> None:
         for control in self._controls.values():
             control.update_account_badge()
 
@@ -153,7 +152,7 @@ def __init__(self):
             'org.gajim.Gajim-symbolic',
             100,
             self.get_scale_factor(),
-            0)
+            Gtk.IconLookupFlags.FORCE_SIZE)
         image = Gtk.Image.new_from_pixbuf(pixbuf)
         image.get_style_context().add_class('dim-label')
         self.add(image)
@@ -163,5 +162,5 @@ def __init__(self):
         button.connect('clicked', self._on_start_chatting)
         self.add(button)
 
-    def _on_start_chatting(self, _button):
+    def _on_start_chatting(self, _button: Gtk.Button) -> None:
         app.app.activate_action('start-chat', GLib.Variant('s', ''))


=====================================
gajim/gtk/controls/base.py
=====================================
@@ -147,7 +147,7 @@ def __init__(self, widget_name: str, account: str, jid: 
JID) -> None:
 
         self.xml = get_builder(f'{widget_name}.ui')
         self.xml.connect_signals(self)
-        self.widget = self.xml.get_object(f'{widget_name}_hbox')
+        self.widget: Gtk.Box = self.xml.get_object(f'{widget_name}_hbox')
 
         self._account_badge = AccountBadge(self.account)
         self.xml.account_badge_box.add(self._account_badge)



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/ce258cf33acd040148e8f7359b4c1076ab9c3bcb...60b577d6dbfaf42a9c042adbbf2ad6281aa9f69d

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/ce258cf33acd040148e8f7359b4c1076ab9c3bcb...60b577d6dbfaf42a9c042adbbf2ad6281aa9f69d
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to