Skip to content

Commit

Permalink
build: fix splash and pyinstaller for GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Dec 22, 2023
1 parent 18f4651 commit c31ec6b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0.1.0
- initial working release
- initial prototype release
0.0.3
- fix readme
0.0.1
Expand Down
13 changes: 13 additions & 0 deletions build-recipes/hook-chipstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
# Hook for MPL-Data-Cast
from PyInstaller.utils.hooks import collect_data_files

hiddenimports = [
"chipstream",
"chipstream.cli",
"chipstream.gui",
"dcnum",
"dcnum.feat",
"dcnum.logic",
"dcnum.meta",
"dcnum.read",
"dcnum.segm",
"dcnum.write",
]

# Data files
datas = collect_data_files("chipstream", include_py_files=True)
datas += collect_data_files("chipstream", subdir="gui/img")
Expand Down
19 changes: 19 additions & 0 deletions chipstream/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,34 @@
PyQt6 = None


class DevNull:
"""Effectively a file-like object for piping everything to nothing."""
def write(self, *args, **kwargs):
pass


if PyQt6 is None:
def main(*args, **kwargs):
print("Please install 'chipstream[gui]' to access the GUI!")
else:
def main():
from importlib import resources
import multiprocessing as mp
import sys
from PyQt6 import QtWidgets, QtCore, QtGui

mp.freeze_support()

# In case we have a frozen application, and we encounter errors
# in subprocesses, then these will try to print everything to stdout
# and stderr. However, if we compiled the app with PyInstaller with
# the --noconsole option, sys.stderr and sys.stdout are None and
# an exception is raised, breaking the program.
if sys.stdout is None:
sys.stdout = DevNull()
if sys.stderr is None:
sys.stderr = DevNull()

from .main_window import ChipStream

app = QtWidgets.QApplication(sys.argv)
Expand Down
4 changes: 4 additions & 0 deletions chipstream/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from .._version import version

from . import splash


class ChipStream(QtWidgets.QMainWindow):
run_completed = QtCore.pyqtSignal()
Expand Down Expand Up @@ -87,6 +89,8 @@ def __init__(self, *arguments):
self.timer.timeout.connect(self.tableView_input.on_selection_changed)
self.timer.start(1000)

splash.splash_close()

# finalize
self.show()
self.activateWindow()
Expand Down
11 changes: 11 additions & 0 deletions chipstream/gui/splash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
try:
import pyi_splash
except (ImportError, ModuleNotFoundError):
pyi_splash = None


def splash_close():
"""Close the splash screen"""
if pyi_splash is not None:
if pyi_splash.is_alive():
pyi_splash.close()
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ tracker = "https://github.com/DC-Analysis/ChipStream/issues"
documentation = "https://chipstream.readthedocs.io/en/stable/"
changelog = "https://chipstream.readthedocs.io/en/stable/sec_changelog.html"

# We need the following, because automatic package discovery does not work
# when running cibuildwheel on GitHub Actions (there will be a "wheelhouse"
# directory).
[tool.setuptools]
packages = ["chipstream"]

[tool.setuptools_scm]
write_to = "chipstream/_version.py"
version_scheme = "post-release"

0 comments on commit c31ec6b

Please sign in to comment.