@@ -307,20 +307,32 @@ def read_message(self, index: int = -1) -> None:
307
307
308
308
309
309
class DMPanel (urwid .Pile ):
310
- def __init__ (self , submenu_view : List [Any ], view : Any ) -> None :
310
+ def __init__ (
311
+ self ,
312
+ submenu_view : Optional [List [Any ]],
313
+ view : Any ,
314
+ show_function : Callable [[], Any ],
315
+ ) -> None :
311
316
self .view = view
312
317
count = self .view .model .unread_counts .get ("all_pms" , 0 )
313
318
self .view .pm_button = DMPanelButton (
314
- controller = self .view .controller , count = count
319
+ controller = self .view .controller , count = count , show_function = show_function
315
320
)
316
321
317
- self ._contents = [
318
- ("pack" , self .view .pm_button ),
319
- ("pack" , urwid .Divider (div_char = SECTION_DIVIDER_LINE )),
320
- submenu_view ,
321
- ]
322
+ if submenu_view :
323
+ self ._contents = [
324
+ ("pack" , self .view .pm_button ),
325
+ ("pack" , urwid .Divider (div_char = SECTION_DIVIDER_LINE )),
326
+ submenu_view ,
327
+ ]
328
+ focus_item = 2
329
+ else :
330
+ self ._contents = [
331
+ ("pack" , self .view .pm_button ),
332
+ ]
333
+ focus_item = 0
322
334
323
- super ().__init__ (self .contents )
335
+ super ().__init__ (self .contents , focus_item = focus_item )
324
336
325
337
326
338
class DMView (urwid .Frame ):
@@ -347,19 +359,35 @@ def __init__(self) -> None:
347
359
348
360
349
361
class StreamPanel (urwid .Pile ):
350
- def __init__ (self , submenu_view : List [Any ], view : Any ) -> None :
362
+ def __init__ (
363
+ self ,
364
+ submenu_view : Optional [List [Any ]],
365
+ view : Any ,
366
+ show_function : Callable [[], Any ],
367
+ ) -> None :
351
368
self .view = view
352
369
count = self .view .model .unread_counts .get ("all_stream_msg" , 0 )
353
370
self .view .stream_button = StreamPanelButton (
354
- controller = self .view .controller , count = count
371
+ controller = self .view .controller ,
372
+ count = count ,
373
+ show_function = show_function ,
355
374
)
356
- self ._contents = [
357
- ("pack" , self .view .stream_button ),
358
- ("pack" , urwid .Divider (div_char = SECTION_DIVIDER_LINE )),
359
- submenu_view ,
360
- ]
361
375
362
- super ().__init__ (self .contents , focus_item = 2 )
376
+ if submenu_view :
377
+ self ._contents = [
378
+ ("pack" , self .view .stream_button ),
379
+ ("pack" , urwid .Divider (div_char = SECTION_DIVIDER_LINE )),
380
+ submenu_view ,
381
+ ]
382
+ focus_item = 2
383
+ else :
384
+ self ._contents = [
385
+ ("pack" , self .view .stream_button ),
386
+ ("pack" , urwid .Divider (div_char = SECTION_DIVIDER_LINE )),
387
+ ]
388
+ focus_item = 0
389
+
390
+ super ().__init__ (self .contents , focus_item = focus_item )
363
391
364
392
365
393
class StreamsView (urwid .Frame ):
@@ -833,14 +861,15 @@ def __init__(self, view: Any) -> None:
833
861
self .controller = view .controller
834
862
self .menu_v = self .menu_view ()
835
863
self .dm_v = self .dms_view ()
836
- self .dm_panel = self .dms_panel (self . dm_v )
864
+ self .dm_panel = self .dms_panel (None )
837
865
self .stream_v = self .streams_view ()
838
866
self .stream_panel = self .streams_panel (self .stream_v )
839
867
self .is_in_topic_view = False
868
+ self .is_in_dm_panel_view = False
840
869
contents = [
841
870
(3 , self .menu_v ),
842
871
("pack" , urwid .Divider (COLUMN_TITLE_BAR_LINE )),
843
- self .dm_panel ,
872
+ ( "pack" , self .dm_panel ) ,
844
873
("pack" , urwid .Divider (COLUMN_TITLE_BAR_LINE )),
845
874
self .stream_panel ,
846
875
]
@@ -869,11 +898,15 @@ def menu_view(self) -> Any:
869
898
return w
870
899
871
900
def streams_panel (self , submenu_view : Any ) -> Any :
872
- self .view .stream_p = StreamPanel (submenu_view , self .view )
901
+ self .view .stream_p = StreamPanel (
902
+ submenu_view , self .view , show_function = self .show_stream_panel
903
+ )
873
904
return self .view .stream_p
874
905
875
906
def dms_panel (self , submenu_view : Any ) -> Any :
876
- self .view .dm_p = DMPanel (submenu_view , self .view )
907
+ self .view .dm_p = DMPanel (
908
+ submenu_view , self .view , show_function = self .show_dm_panel
909
+ )
877
910
return self .view .dm_p
878
911
879
912
def dms_view (self ) -> Any :
@@ -1012,10 +1045,26 @@ def show_topic_view(self, stream_button: Any) -> None:
1012
1045
self .options (height_type = "weight" ),
1013
1046
)
1014
1047
1048
+ def show_dm_panel (self ) -> None :
1049
+ self .dm_panel = self .dms_panel (self .dm_v )
1050
+ self .contents [2 ] = (self .dm_panel , self .options (height_type = "weight" ))
1051
+ self .stream_panel = self .streams_panel (None )
1052
+ self .contents [4 ] = (self .stream_panel , self .options (height_type = "pack" ))
1053
+ self .focus_position = 2
1054
+ self .is_in_dm_panel_view = True
1055
+
1056
+ def show_stream_panel (self ) -> None :
1057
+ self .stream_panel = self .streams_panel (self .stream_v )
1058
+ self .contents [4 ] = (self .stream_panel , self .options (height_type = "weight" ))
1059
+ self .dm_panel = self .dms_panel (None )
1060
+ self .contents [2 ] = (self .dm_panel , self .options (height_type = "pack" ))
1061
+ self .focus_position = 4
1062
+ self .is_in_dm_panel_view = False
1063
+
1015
1064
def keypress (self , size : urwid_Size , key : str ) -> Optional [str ]:
1016
- if is_command_key ("SEARCH_STREAMS" , key ) or is_command_key (
1065
+ if ( is_command_key ("SEARCH_STREAMS" , key ) or is_command_key (
1017
1066
"SEARCH_TOPICS" , key
1018
- ):
1067
+ )) and not self . is_in_dm_panel_view :
1019
1068
self .focus_position = 4
1020
1069
self .view .stream_p .focus_position = 2
1021
1070
if self .is_in_topic_view :
@@ -1025,6 +1074,10 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
1025
1074
return key
1026
1075
elif is_command_key ("GO_RIGHT" , key ):
1027
1076
self .view .show_left_panel (visible = False )
1077
+ elif is_command_key ("ALL_PM" , key ):
1078
+ self .show_dm_panel ()
1079
+ elif key == "S" :
1080
+ self .show_stream_panel ()
1028
1081
return super ().keypress (size , key )
1029
1082
1030
1083
0 commit comments