@@ -1256,9 +1256,16 @@ def __init__(self, controller: Any, title: str) -> None:
1256
1256
super ().__init__ (controller , body , "MARKDOWN_HELP" , popup_width , title , header )
1257
1257
1258
1258
1259
+ PopUpConfirmationViewLocation = Literal ["top-left" , "center" ]
1260
+
1261
+
1259
1262
class PopUpConfirmationView (urwid .Overlay ):
1260
1263
def __init__ (
1261
- self , controller : Any , question : Any , success_callback : Callable [[], None ]
1264
+ self ,
1265
+ controller : Any ,
1266
+ question : Any ,
1267
+ success_callback : Callable [[], None ],
1268
+ location : PopUpConfirmationViewLocation = "top-left" ,
1262
1269
):
1263
1270
self .controller = controller
1264
1271
self .success_callback = success_callback
@@ -1268,19 +1275,31 @@ def __init__(
1268
1275
no ._w = urwid .AttrMap (urwid .SelectableIcon ("No" , 4 ), None , "selected" )
1269
1276
display_widget = urwid .GridFlow ([yes , no ], 3 , 5 , 1 , "center" )
1270
1277
wrapped_widget = urwid .WidgetWrap (display_widget )
1271
- prompt = urwid .LineBox (
1272
- urwid .ListBox (
1273
- urwid .SimpleFocusListWalker ([question , urwid .Divider (), wrapped_widget ])
1274
- )
1275
- )
1278
+ widgets = [question , urwid .Divider (), wrapped_widget ]
1279
+ prompt = urwid .LineBox (urwid .ListBox (urwid .SimpleFocusListWalker (widgets )))
1280
+
1281
+ if location == "top-left" :
1282
+ align = "left"
1283
+ valign = "top"
1284
+ width = LEFT_WIDTH + 1
1285
+ height = 8
1286
+ else :
1287
+ align = "center"
1288
+ valign = "middle"
1289
+
1290
+ max_cols , max_rows = controller .maximum_popup_dimensions ()
1291
+ # +2 to compensate for the LineBox characters.
1292
+ width = min (max_cols , max (question .pack ()[0 ], len ("Yes" ), len ("No" ))) + 2
1293
+ height = min (max_rows , sum (widget .rows ((width ,)) for widget in widgets )) + 2
1294
+
1276
1295
urwid .Overlay .__init__ (
1277
1296
self ,
1278
1297
prompt ,
1279
1298
self .controller .view ,
1280
- align = "left" ,
1281
- valign = "top" ,
1282
- width = LEFT_WIDTH + 1 ,
1283
- height = 8 ,
1299
+ align = align ,
1300
+ valign = valign ,
1301
+ width = width ,
1302
+ height = height ,
1284
1303
)
1285
1304
1286
1305
def exit_popup_yes (self , args : Any ) -> None :
0 commit comments