Skip to content

Commit

Permalink
gui: Show a message when no tabs are loaded
Browse files Browse the repository at this point in the history
Instead of just showing a blank screen (which can be interpreted as the GUI
hanging), when there are no data files loaded show buttons to load a data file
or run a new test.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
  • Loading branch information
tohojo committed Jan 17, 2024
1 parent e4c5f65 commit 1f6452a
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
15 changes: 15 additions & 0 deletions flent/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ def __init__(self, settings):
self.viewArea.tabCloseRequested.connect(self.close_tab)
self.viewArea.currentChanged.connect(self.activate_tab)

self.openFileButton.clicked.connect(self.on_open)
self.runTestButton.clicked.connect(self.run_test)
self.update_empty_view()

self.plotDock.visibilityChanged.connect(self.plot_visibility)
self.metadataDock.visibilityChanged.connect(self.metadata_visibility)
self.plotSettingsDock.visibilityChanged.connect(self.plot_settings_visibility)
Expand Down Expand Up @@ -409,6 +413,14 @@ def read_settings(self):
self.openFilesView.horizontalHeader().restoreState(value)
self.openFilesView.setSortingEnabled(True)

def update_empty_view(self):
if self.viewArea.count():
self.viewArea.show()
self.emptyWidget.hide()
else:
self.viewArea.hide()
self.emptyWidget.show()

def closeEvent(self, event):
# Cleaning up matplotlib figures can take a long time; disable it when
# the application is exiting.
Expand Down Expand Up @@ -654,6 +666,7 @@ def close_tab(self, idx=None):
widget.setParent(None)
widget.deleteLater()
self.shorten_tabs()
self.update_empty_view()
self.busy_end()

def close_all(self):
Expand All @@ -662,6 +675,7 @@ def close_all(self):
for i in range(self.viewArea.count()):
widgets.append(self.viewArea.widget(i))
self.viewArea.clear()
self.update_empty_view()
for w in widgets:
w.setUpdatesEnabled(False)
w.disconnect_all()
Expand Down Expand Up @@ -775,6 +789,7 @@ def add_tab(self, results=None, title=None, plot=None, focus=True):
if title is None:
title = widget.title
idx = self.viewArea.addTab(widget, title)
self.update_empty_view()
if hasattr(widget, "long_title"):
self.viewArea.setTabToolTip(idx, widget.long_title)
if focus or self.focus_new:
Expand Down
94 changes: 94 additions & 0 deletions flent/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,100 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="emptyWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="emptyLabel">
<property name="text">
<string>No data files loaded. To show data, open a data file or run a new test.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="openFileButton">
<property name="text">
<string>Open data file</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="runTestButton">
<property name="text">
<string>Run new test</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTabWidget" name="viewArea">
<property name="sizePolicy">
Expand Down

0 comments on commit 1f6452a

Please sign in to comment.