diff --git a/beeref/widgets/welcome_overlay.py b/beeref/widgets/welcome_overlay.py index 510ee0c..ec5fc4b 100644 --- a/beeref/widgets/welcome_overlay.py +++ b/beeref/widgets/welcome_overlay.py @@ -47,15 +47,16 @@ def data(self, index, role): class RecentFilesView(QtWidgets.QListView): - def __init__(self, parent, files=None): + def __init__(self, parent, view, files=None): super().__init__(parent) + self.view = view self.files = files or [] self.clicked.connect(self.on_clicked) self.setModel(RecentFilesModel(self.files)) self.setMouseTracking(True) def on_clicked(self, index): - self.parent().parent().open_from_file(self.files[index.row()]) + self.view.open_from_file(self.files[index.row()]) def update_files(self, files): self.files = files @@ -96,13 +97,16 @@ def __init__(self, parent): self.init_main_controls(main_window=parent.parent) # Recent files - self.files_layout = QtWidgets.QVBoxLayout() - self.files_layout.addStretch(50) - self.files_layout.addWidget( + self.files_widget = QtWidgets.QWidget(self) + files_layout = QtWidgets.QVBoxLayout() + files_layout.addStretch(50) + files_layout.addWidget( QtWidgets.QLabel('

Recent Files

', self)) - self.files_view = RecentFilesView(self) - self.files_layout.addWidget(self.files_view) - self.files_layout.addStretch(50) + self.files_view = RecentFilesView(self, parent) + files_layout.addWidget(self.files_view) + files_layout.addStretch(50) + self.files_widget.setLayout(files_layout) + self.files_widget.hide() # Help text self.label = QtWidgets.QLabel(self.txt, self) @@ -117,8 +121,9 @@ def __init__(self, parent): def show(self): files = BeeSettings().get_recent_files(existing_only=True) self.files_view.update_files(files) - if files and self.layout.indexOf(self.files_layout) < 0: - self.layout.insertLayout(0, self.files_layout) + if files and self.layout.indexOf(self.files_widget) < 0: + self.layout.insertWidget(0, self.files_widget) + self.files_widget.show() super().show() def disable_mouse_events(self): diff --git a/tests/widgets/test_welcome_overlay.py b/tests/widgets/test_welcome_overlay.py index 7e75562..397cc3b 100644 --- a/tests/widgets/test_welcome_overlay.py +++ b/tests/widgets/test_welcome_overlay.py @@ -37,12 +37,12 @@ def test_welcome_overlay_when_no_recent_files(qapp): view = BeeGraphicsView(qapp, parent) overlay = WelcomeOverlay(view) overlay.show() - assert overlay.layout.indexOf(overlay.files_layout) < 0 + assert overlay.layout.indexOf(overlay.files_widget) < 0 def test_recent_files_view_size_hint(qapp): parent = QtWidgets.QMainWindow() - files_view = RecentFilesView(parent) + files_view = RecentFilesView(parent, None) files_view.sizeHintForRow = lambda i: 10 + i files_view.sizeHintForColumn = lambda i: 50 + i @@ -50,6 +50,18 @@ def test_recent_files_view_size_hint(qapp): assert files_view.sizeHint() == QtCore.QSize(53, 25) +def test_recent_files_view_on_click(qapp): + parent = QtWidgets.QMainWindow() + view = BeeGraphicsView(qapp, parent) + view.open_from_file = MagicMock() + overlay = WelcomeOverlay(view) + overlay.files_view.update_files(['foo.bee', 'bar.bee']) + overlay.files_view.on_clicked( + RecentFilesModel( + ['foo.bee', 'bar.bee']).createIndex(1, 0)) + view.open_from_file.assert_called_once_with('bar.bee') + + @patch('beeref.widgets.welcome_overlay.BeeSettings.get_recent_files', return_value=['foo.bee', 'bar.bee']) def test_welcome_overlay_when_recent_files(qapp): @@ -57,7 +69,7 @@ def test_welcome_overlay_when_recent_files(qapp): view = BeeGraphicsView(qapp, parent) overlay = WelcomeOverlay(view) overlay.show() - assert overlay.layout.indexOf(overlay.files_layout) == 0 + assert overlay.layout.indexOf(overlay.files_widget) == 0 @patch('PyQt6.QtWidgets.QGraphicsView.mousePressEvent')