4747 import typing
4848 from faslr .model import FIBNRModel
4949 from pandas import DataFrame
50+ from PyQt6 .QtCore import QAbstractItemModel
5051 from typing import Any
5152
5253class FSelectionModel (FAbstractTableModel ):
@@ -270,8 +271,6 @@ def select_average_row(self, index: QModelIndex) -> None:
270271 """
271272 Makes the ratio selection, i.e., selects the LDFs or loss ratios.
272273 """
273- for row in self .included_averages_rows :
274- print (row )
275274 # If double-clicked row is not in the included averages, do nothing.
276275 if index .row () not in self .included_averages_rows :
277276 return None
@@ -399,62 +398,77 @@ def __init__(
399398 self .setWindowTitle (window_title )
400399
401400 self .layout = QVBoxLayout ()
402- self .add_average_button = QPushButton ("Available Averages" )
403- self .add_average_button .setFixedWidth (self .add_average_button .sizeHint ().width ())
404-
405- self .add_average_button .setContentsMargins (
406- 2 ,
407- 2 ,
408- 2 ,
409- 2
410- )
411401
412402 # Container widget for upper-right hand tools (add average button, etc.).
413- self .tool_container = QWidget ()
414- self .tool_layout = QHBoxLayout ()
415- self .tool_container .setLayout (self .tool_layout )
416-
417- self .tool_layout .setContentsMargins (
418- 0 ,
419- 0 ,
420- 0 ,
421- 0
422- )
423-
424- self .tool_layout .addWidget (
425- self .add_average_button
403+ self .toolbox = FSelectionModelToolbox (
404+ parent = self ,
405+ averages = averages
426406 )
427407
428408 self .layout .addWidget (
429- self .tool_container ,
409+ self .toolbox ,
430410 alignment = Qt .AlignmentFlag .AlignRight
431411 )
432412
413+ # If selection model and view has already been subclass, skip, otherwise use base classes.
433414 if not (hasattr (self , 'selection_model' ) and hasattr (self , 'selection_model_view' )):
434415 self .selection_model = FSelectionModel (data = data , averages = averages , parent = self )
435416 self .selection_model_view = FModelView (parent = self )
436417
437- self .average_box = FAverageBox (data = averages , parent = self )
438-
439418 self .selection_model_view .setModel (self .selection_model )
440419
441420 self .layout .addWidget (self .selection_model_view )
442421
443422 self .setLayout (self .layout )
444423
445- self .add_average_button .clicked .connect (self .open_average_box ) # noqa
446424
447- def open_average_box (self ):
425+ class FSelectionModelToolbox (QWidget ):
426+ """
427+ Toolbox that appears above the model view in a FSelectionModelWidget. Contains utilities such
428+ as a button for adding averages, and a heatmap button.
429+ """
430+ def __init__ (
431+ self ,
432+ parent : FSelectionModelWidget ,
433+ averages : DataFrame
434+ ):
435+ super ().__init__ ()
436+ self .parent : FSelectionModelWidget = parent
437+ self .add_average_button = QPushButton ("Available Averages" )
438+ self .add_average_button .setFixedWidth (self .add_average_button .sizeHint ().width ())
439+
440+ self .add_average_button .setContentsMargins (
441+ 2 ,
442+ 2 ,
443+ 2 ,
444+ 2
445+ )
446+
447+ self .layout = QHBoxLayout ()
448+ self .setLayout (self .layout )
448449
449- self .average_box .show ()
450+ self .setContentsMargins (
451+ 0 ,
452+ 0 ,
453+ 0 ,
454+ 0
455+ )
450456
457+ self .average_box = FAverageBox (
458+ parent = self ,
459+ data = averages ,
460+ selection_model = self .parent .selection_model
461+ )
451462
452- class FSelectionModelToolBox (QWidget ):
453- def __init__ (self ):
454- super ().__init__ ()
463+ self .layout .addWidget (self .add_average_button )
455464
456- self .layout = QHBoxLayout ()
465+ self .add_average_button . clicked . connect ( self . open_average_box ) # noqa
457466
467+ def open_average_box (self ) -> None :
468+ """
469+ Opens the dialog box for adding averages to a selection model.
470+ """
471+ self .average_box .show ()
458472
459473class FModelView (FTableView ):
460474 def __init__ (
@@ -470,9 +484,8 @@ def __init__(
470484 def keyPressEvent (self , e : QKeyEvent ) -> None :
471485 clipboard = QApplication .clipboard ()
472486 if e .matches (QKeySequence .StandardKey .Paste ):
473- print ('asdfasdf' )
474487 value = clipboard .text ()
475- model : FSelectionModel = self .model ()
488+ model : QAbstractItemModel = self .model ()
476489 for index in self .selectedIndexes ():
477490 model .setData (index = index , value = value , role = Qt .ItemDataRole .EditRole )
478491
0 commit comments