summaryrefslogtreecommitdiff
path: root/poezio/tabs
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-03-14 22:31:22 +0100
committermathieui <mathieui@mathieui.net>2021-04-02 17:44:36 +0200
commit4b198be9771594a28824cc082e737fe15ab681ec (patch)
tree01de648647136734d176ba0fa33e96a61bbafc88 /poezio/tabs
parentbc4f4f1e0766aedb6b0e9f3df90fee9ea841786c (diff)
downloadpoezio-4b198be9771594a28824cc082e737fe15ab681ec.tar.gz
poezio-4b198be9771594a28824cc082e737fe15ab681ec.tar.bz2
poezio-4b198be9771594a28824cc082e737fe15ab681ec.tar.xz
poezio-4b198be9771594a28824cc082e737fe15ab681ec.zip
fix: tons of type errors
Diffstat (limited to 'poezio/tabs')
-rw-r--r--poezio/tabs/basetabs.py36
-rw-r--r--poezio/tabs/bookmarkstab.py4
-rw-r--r--poezio/tabs/muctab.py5
-rw-r--r--poezio/tabs/privatetab.py4
-rw-r--r--poezio/tabs/xmltab.py2
5 files changed, 36 insertions, 15 deletions
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index 7e584a92..0c59b89c 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -26,6 +26,7 @@ from xml.sax import SAXParseException
from typing import (
Any,
Callable,
+ cast,
Dict,
List,
Optional,
@@ -48,6 +49,7 @@ from poezio.text_buffer import TextBuffer
from poezio.theming import get_theme, dump_tuple
from poezio.ui.funcs import truncate_nick
from poezio.ui.types import BaseMessage, InfoMessage, Message
+from poezio.timed_events import DelayedEvent
from slixmpp import JID, InvalidJID, Message as SMessage
@@ -117,6 +119,10 @@ class Tab:
# Placeholder values, set on resize
height = 1
width = 1
+ core: Core
+ input: Optional[windows.Input]
+ key_func: Dict[str, Callable[[], Any]]
+ commands: Dict[str, Command]
def __init__(self, core: Core):
self.core = core
@@ -234,7 +240,7 @@ class Tab:
*,
desc='',
shortdesc='',
- completion: Optional[Callable] = None,
+ completion: Optional[Callable[[windows.Input], Completion]] = None,
usage=''):
"""
Add a command
@@ -286,7 +292,6 @@ class Tab:
comp = command.comp(the_input)
if comp:
return comp.run()
- return comp
return False
def execute_command(self, provided_text: str) -> bool:
@@ -294,8 +299,10 @@ class Tab:
Execute the command in the input and return False if
the input didn't contain a command
"""
+ if self.input is None:
+ raise NotImplementedError
txt = provided_text or self.input.key_enter()
- if txt.startswith('/') and not txt.startswith('//') and\
+ if txt and txt.startswith('/') and not txt.startswith('//') and\
not txt.startswith('/me '):
command = txt.strip().split()[0][1:]
arg = txt[2 + len(command):] # jump the '/' and the ' '
@@ -461,6 +468,9 @@ class Tab:
class GapTab(Tab):
+ def __init__(self, core: Optional[Core], *args, **kwargs):
+ super().__init__(core, **args, **kwargs)
+
def __bool__(self):
return False
@@ -485,7 +495,10 @@ class ChatTab(Tab):
"""
plugin_commands: Dict[str, Command] = {}
plugin_keys: Dict[str, Callable] = {}
+ last_sent_message: Optional[SMessage]
message_type = 'chat'
+ timed_event_paused: Optional[DelayedEvent]
+ timed_event_not_paused: Optional[DelayedEvent]
def __init__(self, core, jid: Union[JID, str]):
Tab.__init__(self, core)
@@ -507,7 +520,7 @@ class ChatTab(Tab):
self.timed_event_paused = None
self.timed_event_not_paused = None
# Keeps the last sent message to complete it easily in completion_correct, and to replace it.
- self.last_sent_message = {}
+ self.last_sent_message = None
self.key_func['M-v'] = self.move_separator
self.key_func['M-h'] = self.scroll_separator
self.key_func['M-/'] = self.last_words_completion
@@ -625,6 +638,8 @@ class ChatTab(Tab):
self.input.auto_completion(words, ' ', quotify=False)
def on_enter(self):
+ if self.input is None:
+ raise NotImplementedError
txt = self.input.key_enter()
if txt:
if not self.execute_command(txt):
@@ -740,16 +755,18 @@ class ChatTab(Tab):
if self.timed_event_paused is not None:
self.core.remove_timed_event(self.timed_event_paused)
self.timed_event_paused = None
- self.core.remove_timed_event(self.timed_event_not_paused)
- self.timed_event_not_paused = None
+ if self.timed_event_not_paused is not None:
+ self.core.remove_timed_event(self.timed_event_not_paused)
+ self.timed_event_not_paused = None
def set_last_sent_message(self, msg: SMessage, correct: bool = False) -> None:
"""Ensure last_sent_message is set with the correct attributes"""
if correct:
# XXX: Is the copy needed. Is the object passed here reused
# afterwards? Who knows.
- msg = copy(msg)
- msg['id'] = self.last_sent_message['id']
+ msg = cast(SMessage, copy(msg))
+ if self.last_sent_message is not None:
+ msg['id'] = self.last_sent_message['id']
self.last_sent_message = msg
@command_args_parser.raw
@@ -783,7 +800,8 @@ class ChatTab(Tab):
self.text_win.remove_line_separator()
self.text_win.add_line_separator(self._text_buffer)
self.text_win.refresh()
- self.input.refresh()
+ if self.input:
+ self.input.refresh()
def get_conversation_messages(self):
return self._text_buffer.messages
diff --git a/poezio/tabs/bookmarkstab.py b/poezio/tabs/bookmarkstab.py
index a953c750..986e0b9d 100644
--- a/poezio/tabs/bookmarkstab.py
+++ b/poezio/tabs/bookmarkstab.py
@@ -34,8 +34,8 @@ class BookmarksTab(Tab):
self.new_bookmarks: List[Bookmark] = []
self.removed_bookmarks: List[Bookmark] = []
self.header_win = windows.ColumnHeaderWin(
- ('name', 'room@server/nickname', 'password', 'autojoin',
- 'storage'))
+ ['name', 'room@server/nickname', 'password', 'autojoin',
+ 'storage'])
self.bookmarks_win = windows.BookmarksWin(
self.bookmarks, self.height - 4, self.width, 1, 0)
self.help_win = windows.HelpText('Ctrl+Y: save, Ctrl+G: cancel, '
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py
index 188ed156..b6360e92 100644
--- a/poezio/tabs/muctab.py
+++ b/poezio/tabs/muctab.py
@@ -166,6 +166,7 @@ class MucTab(ChatTab):
"""
Join the room
"""
+ seconds: Optional[int]
status = self.core.get_status()
if self.last_connection:
delta = to_utc(datetime.now()) - to_utc(self.last_connection)
@@ -725,7 +726,7 @@ class MucTab(ChatTab):
new_nick = presence.xml.find(
'{%s}x/{%s}item' % (NS_MUC_USER, NS_MUC_USER)
).attrib['nick']
- old_color = user.color
+ old_color_tuple = user.color
if user.nick == self.own_nick:
self.own_nick = new_nick
# also change our nick in all private discussions of this room
@@ -741,7 +742,7 @@ class MucTab(ChatTab):
if config.get_by_tabname('display_user_color_in_join_part',
self.general_jid):
color = dump_tuple(user.color)
- old_color = dump_tuple(old_color)
+ old_color = dump_tuple(old_color_tuple)
else:
old_color = color = "3"
info_col = dump_tuple(get_theme().COLOR_INFORMATION_TEXT)
diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py
index 9d782df8..a00f032d 100644
--- a/poezio/tabs/privatetab.py
+++ b/poezio/tabs/privatetab.py
@@ -109,7 +109,7 @@ class PrivateTab(OneToOneTab):
if not isinstance(msg, Message):
return
if not logger.log_message(
- self.jid.full, msg.nickname, msg.txt, date=msg.time, typ=typ):
+ self.jid.full, msg.nickname or '', msg.txt or '', date=msg.time, typ=typ):
self.core.information('Unable to write in the log file', 'Error')
def on_close(self):
@@ -160,7 +160,7 @@ class PrivateTab(OneToOneTab):
self.core.events.trigger('private_say', msg, self)
if not msg['body']:
return
- if correct or msg['replace']['id']:
+ if correct or msg['replace']['id'] and self.last_sent_message:
msg['replace']['id'] = self.last_sent_message['id']
else:
del msg['replace']
diff --git a/poezio/tabs/xmltab.py b/poezio/tabs/xmltab.py
index 0409b445..15fd2ed4 100644
--- a/poezio/tabs/xmltab.py
+++ b/poezio/tabs/xmltab.py
@@ -10,6 +10,7 @@ log = logging.getLogger(__name__)
import curses
import os
+from typing import Union, Optional
from slixmpp import JID, InvalidJID
from slixmpp.xmlstream import matcher, StanzaBase
from slixmpp.xmlstream.tostring import tostring
@@ -55,6 +56,7 @@ MATCHERS_MAPPINGS = {
class XMLTab(Tab):
+ input: Optional[Union[windows.HelpText, windows.CommandInput]]
def __init__(self, core):
Tab.__init__(self, core)
self.state = 'normal'