Skip to content

Commit 053838a

Browse files
committed
mypy: Unify type of size parameter to keypress/mouse_event calls.
NOTE: View keypress uses a non-standard type here that needs to be resolved.
1 parent 9a70827 commit 053838a

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

zulipterminal/ui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def show_right_panel(self, *, visible: bool) -> None:
145145
if visible:
146146
self.body.focus_position = 2
147147

148+
# FIXME: The type of size should be urwid_Size; this needs checking
148149
def keypress(self, size: Tuple[int, int], key: str) -> str:
149150
self.model.new_user_input = True
150151
if self.controller.editor_mode:

zulipterminal/ui_tools/boxes.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from zulipterminal.helper import (
1616
Message, match_groups, match_stream, match_user,
1717
)
18+
from zulipterminal.urwid_types import urwid_Size
1819

1920

2021
class WriteBox(urwid.Pile):
@@ -128,7 +129,7 @@ def autocomplete_streams(self, text: str, state: int) -> Optional[str]:
128129
except IndexError:
129130
return None
130131

131-
def keypress(self, size: Tuple[int, int], key: str) -> str:
132+
def keypress(self, size: urwid_Size, key: str) -> str:
132133
if is_command_key('SEND_MESSAGE', key):
133134
if self.msg_edit_id:
134135
if not self.to_write_box:
@@ -645,7 +646,7 @@ def selectable(self) -> bool:
645646
# is designed to take focus.
646647
return True
647648

648-
def mouse_event(self, size: Tuple[int, int], event: Any, button: Any,
649+
def mouse_event(self, size: urwid_Size, event: Any, button: Any,
649650
col: int, row: int, focus: int) -> Union[bool, Any]:
650651
if event == 'mouse press':
651652
if button == 1:
@@ -665,7 +666,7 @@ def mouse_event(self, size: Tuple[int, int], event: Any, button: Any,
665666

666667
return super().mouse_event(size, event, button, col, row, focus)
667668

668-
def keypress(self, size: Tuple[int, int], key: str) -> str:
669+
def keypress(self, size: urwid_Size, key: str) -> str:
669670
if is_command_key('ENTER', key):
670671
if self.message['type'] == 'private':
671672
self.model.controller.view.write_box.private_box_view(
@@ -789,7 +790,7 @@ def main_view(self) -> Any:
789790
blcorner=u'─', rline=u'', bline=u'─', brcorner=u'─')
790791
return [self.search_bar, self.recipient_bar]
791792

792-
def keypress(self, size: Tuple[int, int], key: str) -> str:
793+
def keypress(self, size: urwid_Size, key: str) -> str:
793794
if is_command_key('GO_BACK', key):
794795
self.text_box.set_edit_text("")
795796
self.controller.editor_mode = False
@@ -820,7 +821,7 @@ def __init__(self, panel_view: Any, search_command: str,
820821
urwid.connect_signal(self, 'change', update_function)
821822
super().__init__(edit_text=self.search_text)
822823

823-
def keypress(self, size: Tuple[int, int], key: str) -> str:
824+
def keypress(self, size: urwid_Size, key: str) -> str:
824825
if is_command_key('ENTER', key):
825826
self.panel_view.view.controller.editor_mode = False
826827
self.panel_view.set_focus("body")

zulipterminal/ui_tools/buttons.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import urwid
44

55
from zulipterminal.config.keys import is_command_key, keys_for_command
6+
from zulipterminal.urwid_types import urwid_Size
67

78

89
class MenuButton(urwid.Button):
@@ -77,7 +78,7 @@ def activate(self, key: Any) -> None:
7778
self.controller.view.body.focus_col = 1
7879
self.show_function(self)
7980

80-
def keypress(self, size: Tuple[int, int], key: str) -> str:
81+
def keypress(self, size: urwid_Size, key: str) -> str:
8182
if is_command_key('ENTER', key):
8283
self.activate(key)
8384
return super().keypress(size, key)
@@ -168,7 +169,7 @@ def mark_unmuted(self) -> None:
168169
# All messages in this stream are read.
169170
self.update_count(0)
170171

171-
def keypress(self, size: Tuple[int, int], key: str) -> str:
172+
def keypress(self, size: urwid_Size, key: str) -> str:
172173
if is_command_key('TOGGLE_TOPIC', key):
173174
topic_view = self.view.left_panel.topics_view(self)
174175
self.view.left_panel.is_in_topic_view = True

zulipterminal/ui_tools/views.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
UnreadPMButton, UserButton,
1616
)
1717
from zulipterminal.ui_tools.utils import create_msg_box_list
18+
from zulipterminal.urwid_types import urwid_Size
1819

1920

2021
class ModListWalker(urwid.SimpleFocusListWalker):
@@ -130,7 +131,7 @@ def load_new_messages(self, anchor: int) -> None:
130131
self.model.controller.update_screen()
131132
self.new_loading = False
132133

133-
def mouse_event(self, size: Any, event: str, button: int, col: int,
134+
def mouse_event(self, size: urwid_Size, event: str, button: int, col: int,
134135
row: int, focus: Any) -> Any:
135136
if event == 'mouse press':
136137
if button == 4:
@@ -141,7 +142,7 @@ def mouse_event(self, size: Any, event: str, button: int, col: int,
141142
return True
142143
return super().mouse_event(size, event, button, col, row, focus)
143144

144-
def keypress(self, size: Tuple[int, int], key: str) -> str:
145+
def keypress(self, size: urwid_Size, key: str) -> str:
145146
if is_command_key('NEXT_MESSAGE', key) and not self.new_loading:
146147
try:
147148
position = self.log.next_position(self.focus_position)
@@ -278,7 +279,7 @@ def update_streams(self, search_box: Any, new_text: str) -> None:
278279
self.log.extend(streams_display)
279280
self.view.controller.update_screen()
280281

281-
def mouse_event(self, size: Any, event: str, button: int, col: int,
282+
def mouse_event(self, size: urwid_Size, event: str, button: int, col: int,
282283
row: int, focus: Any) -> Any:
283284
if event == 'mouse press':
284285
if button == 4:
@@ -289,7 +290,7 @@ def mouse_event(self, size: Any, event: str, button: int, col: int,
289290
return True
290291
return super().mouse_event(size, event, button, col, row, focus)
291292

292-
def keypress(self, size: Tuple[int, int], key: str) -> str:
293+
def keypress(self, size: urwid_Size, key: str) -> str:
293294
if is_command_key('SEARCH_STREAMS', key):
294295
self.set_focus('header')
295296
return key
@@ -365,7 +366,7 @@ def update_topics_list(self, stream_id: int, topic_name: str,
365366
if sender_id == self.view.model.user_id:
366367
self.list_box.set_focus(0)
367368

368-
def mouse_event(self, size: Any, event: str, button: int, col: int,
369+
def mouse_event(self, size: urwid_Size, event: str, button: int, col: int,
369370
row: int, focus: Any) -> Any:
370371
if event == 'mouse press':
371372
if button == 4:
@@ -376,7 +377,7 @@ def mouse_event(self, size: Any, event: str, button: int, col: int,
376377
return True
377378
return super().mouse_event(size, event, button, col, row, focus)
378379

379-
def keypress(self, size: Tuple[int, int], key: str) -> str:
380+
def keypress(self, size: urwid_Size, key: str) -> str:
380381
if is_command_key('TOGGLE_TOPIC', key):
381382
# Exit topic view
382383
self.view.left_panel.contents[1] = (
@@ -404,7 +405,7 @@ def __init__(self, users_btn_list: List[Any]) -> None:
404405
self.log = urwid.SimpleFocusListWalker(users_btn_list)
405406
super().__init__(self.log)
406407

407-
def mouse_event(self, size: Any, event: str, button: int, col: int,
408+
def mouse_event(self, size: urwid_Size, event: str, button: int, col: int,
408409
row: int, focus: Any) -> Any:
409410
if event == 'mouse press':
410411
if button == 4:
@@ -460,7 +461,7 @@ def get_next_unread_pm(self) -> Optional[int]:
460461
return pm
461462
return None
462463

463-
def keypress(self, size: Tuple[int, int], key: str) -> str:
464+
def keypress(self, size: urwid_Size, key: str) -> str:
464465
if is_command_key('GO_BACK', key):
465466
self.header.keypress(size, 'esc')
466467
self.footer.keypress(size, 'esc')
@@ -610,7 +611,7 @@ def users_view(self, users: Any=None) -> Any:
610611
self.view.user_w = user_w
611612
return user_w
612613

613-
def keypress(self, size: Tuple[int, int], key: str) -> str:
614+
def keypress(self, size: urwid_Size, key: str) -> str:
614615
if is_command_key('SEARCH_PEOPLE', key):
615616
self.allow_update_user_list = False
616617
self.set_focus('header')
@@ -734,7 +735,7 @@ def topics_view(self, stream_button: Any) -> Any:
734735
)
735736
return w
736737

737-
def keypress(self, size: Tuple[int, int], key: str) -> str:
738+
def keypress(self, size: urwid_Size, key: str) -> str:
738739
if (is_command_key('SEARCH_STREAMS', key) or
739740
is_command_key('SEARCH_TOPICS', key)):
740741
self.focus_position = 1
@@ -786,7 +787,7 @@ def __init__(self, controller: Any) -> None:
786787

787788
super().__init__(self.log)
788789

789-
def keypress(self, size: Tuple[int, int], key: str) -> str:
790+
def keypress(self, size: urwid_Size, key: str) -> str:
790791
if is_command_key('GO_BACK', key) or is_command_key('HELP', key):
791792
self.controller.exit_popup()
792793
return super().keypress(size, key)
@@ -822,7 +823,7 @@ def exit_popup_yes(self, args: Any) -> None:
822823
def exit_popup_no(self, args: Any) -> None:
823824
self.controller.exit_popup()
824825

825-
def keypress(self, size: Tuple[int, int], key: str) -> str:
826+
def keypress(self, size: urwid_Size, key: str) -> str:
826827
if is_command_key('GO_BACK', key):
827828
self.controller.exit_popup()
828829
return super().keypress(size, key)
@@ -886,7 +887,7 @@ def __init__(self, controller: Any, msg: Message) -> None:
886887

887888
super().__init__(self.log)
888889

889-
def keypress(self, size: Tuple[int, int], key: str) -> str:
890+
def keypress(self, size: urwid_Size, key: str) -> str:
890891
if is_command_key('GO_BACK', key) or is_command_key('MSG_INFO', key):
891892
self.controller.exit_popup()
892893
return super().keypress(size, key)

zulipterminal/urwid_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from typing import Tuple, Union
2+
3+
4+
urwid_Size = Union[Tuple[()], Tuple[int], Tuple[int, int]]

0 commit comments

Comments
 (0)