From 3740cc2c35901bfc1483b142b15a27dc3104f975 Mon Sep 17 00:00:00 2001 From: Taylor Denouden Date: Tue, 15 Dec 2020 10:33:35 -0800 Subject: [PATCH 1/4] Fix windows build --- .github/workflows/gui_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gui_release.yml b/.github/workflows/gui_release.yml index db859bc..057c77e 100644 --- a/.github/workflows/gui_release.yml +++ b/.github/workflows/gui_release.yml @@ -69,7 +69,7 @@ jobs: pip install -r requirements.txt - name: Building GUI run: | - pyinstaller --name=GlintMaskGenerator-${{ steps.tag.outputs.tag }} --onefile --windowed --icon="gui/resources/gmt.ico" --hidden-import="gui.widgets.buffer_ctrl" --hidden-import="gui.widgets.threshold_ctrl" --hidden-import="gui.widgets.directory_path" --add-data="gui/resources/*.ui;." gui/main.py + pyinstaller --name=GlintMaskGenerator-${{ steps.tag.outputs.tag }} --onefile --windowed --icon="gui\resources\gmt.ico" --hidden-import="gui.widgets.buffer_ctrl" --hidden-import="gui.widgets.threshold_ctrl" --hidden-import="gui.widgets.directory_path" --add-data="gui\resources\*.ui;." "gui\main.py" - name: Building CLI run: | pyinstaller --name=glint-mask-${{ steps.tag.outputs.tag }} -F cli.py From cba6f6c316ff7e670a51c7932c7aded5c5a41d13 Mon Sep 17 00:00:00 2001 From: Taylor Denouden Date: Tue, 15 Dec 2020 11:19:44 -0800 Subject: [PATCH 2/4] Fix windows build --- .github/workflows/gui_release.yml | 12 +++---- gui/main.py => gui.py | 34 ++++++++++++++---- gui/__init__.py | 6 ---- gui/constants.py | 30 ---------------- gui/utils.py | 23 ------------ {gui/resources => resources}/buffer_ctrl.ui | 0 .../resources => resources}/directory_path.ui | 0 {gui/resources => resources}/gmt.ico | Bin {gui/resources => resources}/gui.ui | 6 ++-- .../resources => resources}/threshold_ctrl.ui | 0 {gui/widgets => widgets}/__init__.py | 0 {gui/widgets => widgets}/buffer_ctrl.py | 6 ++-- {gui/widgets => widgets}/directory_path.py | 6 ++-- {gui/widgets => widgets}/threshold_ctrl.py | 6 ++-- 14 files changed, 49 insertions(+), 80 deletions(-) rename gui/main.py => gui.py (90%) delete mode 100644 gui/__init__.py delete mode 100644 gui/constants.py delete mode 100644 gui/utils.py rename {gui/resources => resources}/buffer_ctrl.ui (100%) rename {gui/resources => resources}/directory_path.ui (100%) rename {gui/resources => resources}/gmt.ico (100%) rename {gui/resources => resources}/gui.ui (99%) rename {gui/resources => resources}/threshold_ctrl.ui (100%) rename {gui/widgets => widgets}/__init__.py (100%) rename {gui/widgets => widgets}/buffer_ctrl.py (81%) rename {gui/widgets => widgets}/directory_path.py (81%) rename {gui/widgets => widgets}/threshold_ctrl.py (81%) diff --git a/.github/workflows/gui_release.yml b/.github/workflows/gui_release.yml index 057c77e..ae84c92 100644 --- a/.github/workflows/gui_release.yml +++ b/.github/workflows/gui_release.yml @@ -31,11 +31,11 @@ jobs: run: | pyinstaller --name=GlintMaskGenerator-${{ steps.tag.outputs.tag }} \ --onefile \ - --hidden-import="gui.widgets.buffer_ctrl" \ - --hidden-import="gui.widgets.threshold_ctrl" \ - --hidden-import="gui.widgets.directory_path" \ - --add-data="gui/resources/*.ui:." \ - gui/main.py + --hidden-import="widgets.buffer_ctrl" \ + --hidden-import="widgets.threshold_ctrl" \ + --hidden-import="widgets.directory_path" \ + --add-data="resources/*.ui:resources" \ + gui.py - name: Building CLI run: | pyinstaller --name=glint-mask-${{ steps.tag.outputs.tag }} -F cli.py @@ -69,7 +69,7 @@ jobs: pip install -r requirements.txt - name: Building GUI run: | - pyinstaller --name=GlintMaskGenerator-${{ steps.tag.outputs.tag }} --onefile --windowed --icon="gui\resources\gmt.ico" --hidden-import="gui.widgets.buffer_ctrl" --hidden-import="gui.widgets.threshold_ctrl" --hidden-import="gui.widgets.directory_path" --add-data="gui\resources\*.ui;." "gui\main.py" + pyinstaller --name=GlintMaskGenerator-${{ steps.tag.outputs.tag }} --onefile --windowed --icon="resources\gmt.ico" --hidden-import="widgets.buffer_ctrl" --hidden-import="widgets.threshold_ctrl" --hidden-import="widgets.directory_path" --add-data="resources\*.ui;resources" gui.py - name: Building CLI run: | pyinstaller --name=glint-mask-${{ steps.tag.outputs.tag }} -F cli.py diff --git a/gui/main.py b/gui.py similarity index 90% rename from gui/main.py rename to gui.py index 8ce671c..69d3dce 100644 --- a/gui/main.py +++ b/gui.py @@ -5,6 +5,7 @@ Description: """ +import os import sys from typing import List, Sequence @@ -12,8 +13,32 @@ from loguru import logger from core.maskers import Masker, MicasenseRedEdgeThresholdMasker, P4MSThresholdMasker, RGBThresholdMasker -from gui.constants import * -from gui.utils import resource_path + +# String constants reduce occurrence of silent errors due to typos when doing comparisons +BLUE = "BLUE" +GREEN = "GREEN" +RED = "RED" +REDEDGE = "REDEDGE" +NIR = "NIR" + +METHOD_THRESHOLD = "METHOD_THRESHOLD" +METHOD_RATIO = "METHOD_RATIO" + +IMG_TYPE_RGB = "IMG_TYPE_RGB" +IMG_TYPE_ACO = "IMG_TYPE_ACO" +IMG_TYPE_P4MS = "IMG_TYPE_P4MS" +IMG_TYPE_MICASENSE_REDEDGE = "IMG_TYPE_MICASENSE_REDEDGE" + +# Default slider values in GUI +DEFAULT_BLUE_THRESH = 0.875 +DEFAULT_GREEN_THRESH = 1.000 +DEFAULT_RED_THRESH = 1.000 +DEFAULT_REDEDGE_THRESH = 1.000 +DEFAULT_NIR_THRESH = 1.000 +DEFAULT_PIXEL_BUFFER = 0 +DEFAULT_MAX_WORKERS = 0 + +UI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'resources/gui.ui')) class MessageBox(QtWidgets.QMessageBox): @@ -40,8 +65,7 @@ def __init__(self, parent): class GlintMaskGenerator(QtWidgets.QMainWindow): def __init__(self): super().__init__() - - uic.loadUi(resource_path('gui.ui'), self) + uic.loadUi(UI_PATH, self) self.show() # Set default values @@ -202,5 +226,3 @@ def run_btn_clicked(self) -> None: app = QtWidgets.QApplication(sys.argv) main_window = GlintMaskGenerator() app.exec_() - -# /media/taylor/Samsung_T5/Datasets/ExampleImages/P4MS \ No newline at end of file diff --git a/gui/__init__.py b/gui/__init__.py deleted file mode 100644 index 078f13c..0000000 --- a/gui/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -Created by: Taylor Denouden -Organization: Hakai Institute -Date: 2020-09-18 -Description: -""" diff --git a/gui/constants.py b/gui/constants.py deleted file mode 100644 index 00235a0..0000000 --- a/gui/constants.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -Created by: Taylor Denouden -Organization: Hakai Institute -Date: 2020-09-17 -Description: -""" - -# String constants reduce occurrence of silent errors due to typos when doing comparisons -BLUE = "BLUE" -GREEN = "GREEN" -RED = "RED" -REDEDGE = "REDEDGE" -NIR = "NIR" - -METHOD_THRESHOLD = "METHOD_THRESHOLD" -METHOD_RATIO = "METHOD_RATIO" - -IMG_TYPE_RGB = "IMG_TYPE_RGB" -IMG_TYPE_ACO = "IMG_TYPE_ACO" -IMG_TYPE_P4MS = "IMG_TYPE_P4MS" -IMG_TYPE_MICASENSE_REDEDGE = "IMG_TYPE_MICASENSE_REDEDGE" - -# Default slider values in GUI -DEFAULT_BLUE_THRESH = 0.875 -DEFAULT_GREEN_THRESH = 1.000 -DEFAULT_RED_THRESH = 1.000 -DEFAULT_REDEDGE_THRESH = 1.000 -DEFAULT_NIR_THRESH = 1.000 -DEFAULT_PIXEL_BUFFER = 0 -DEFAULT_MAX_WORKERS = 0 diff --git a/gui/utils.py b/gui/utils.py deleted file mode 100644 index 27c8ca4..0000000 --- a/gui/utils.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -Created by: Taylor Denouden -Organization: Hakai Institute -Date: 2020-09-16 -Description: -""" - -import os -import sys - - -def resource_path(relative_path): - """ - Define function to import external files when using PyInstaller. - Get absolute path to resource, works for dev and for PyInstaller - """ - if hasattr(sys, "_MEIPASS"): - # PyInstaller creates a temp folder and stores path in _MEIPASS - base_path = sys._MEIPASS - else: - base_path = os.path.abspath("resources") - - return os.path.join(base_path, relative_path) diff --git a/gui/resources/buffer_ctrl.ui b/resources/buffer_ctrl.ui similarity index 100% rename from gui/resources/buffer_ctrl.ui rename to resources/buffer_ctrl.ui diff --git a/gui/resources/directory_path.ui b/resources/directory_path.ui similarity index 100% rename from gui/resources/directory_path.ui rename to resources/directory_path.ui diff --git a/gui/resources/gmt.ico b/resources/gmt.ico similarity index 100% rename from gui/resources/gmt.ico rename to resources/gmt.ico diff --git a/gui/resources/gui.ui b/resources/gui.ui similarity index 99% rename from gui/resources/gui.ui rename to resources/gui.ui index 15ad004..10df369 100644 --- a/gui/resources/gui.ui +++ b/resources/gui.ui @@ -450,19 +450,19 @@ ThresholdCtrl QWidget -
gui/widgets/threshold_ctrl.h
+
widgets/threshold_ctrl.h
1
DirectoryPath QWidget -
gui/widgets/directory_path.h
+
widgets/directory_path.h
1
BufferCtrl QWidget -
gui/widgets/buffer_ctrl.h
+
widgets/buffer_ctrl.h
1
diff --git a/gui/resources/threshold_ctrl.ui b/resources/threshold_ctrl.ui similarity index 100% rename from gui/resources/threshold_ctrl.ui rename to resources/threshold_ctrl.ui diff --git a/gui/widgets/__init__.py b/widgets/__init__.py similarity index 100% rename from gui/widgets/__init__.py rename to widgets/__init__.py diff --git a/gui/widgets/buffer_ctrl.py b/widgets/buffer_ctrl.py similarity index 81% rename from gui/widgets/buffer_ctrl.py rename to widgets/buffer_ctrl.py index b3dd2d8..76dd805 100644 --- a/gui/widgets/buffer_ctrl.py +++ b/widgets/buffer_ctrl.py @@ -5,16 +5,18 @@ Description: """ +import os + from PyQt5 import QtWidgets, uic -from gui.utils import resource_path +UI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../resources/buffer_ctrl.ui')) class BufferCtrl(QtWidgets.QWidget): def __init__(self, parent): super().__init__(parent) - uic.loadUi(resource_path('buffer_ctrl.ui'), self) + uic.loadUi(UI_PATH, self) self.show() self.slider.valueChanged.connect(lambda value: self.spinbox.setValue(int(value))) diff --git a/gui/widgets/directory_path.py b/widgets/directory_path.py similarity index 81% rename from gui/widgets/directory_path.py rename to widgets/directory_path.py index 0f82700..b9d51a8 100644 --- a/gui/widgets/directory_path.py +++ b/widgets/directory_path.py @@ -5,17 +5,19 @@ Description: """ +import os + from PyQt5 import QtWidgets, uic from PyQt5.QtWidgets import QFileDialog -from gui.utils import resource_path +UI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../resources/directory_path.ui')) class DirectoryPath(QtWidgets.QWidget): def __init__(self, parent): super().__init__(parent) - uic.loadUi(resource_path('directory_path.ui'), self) + uic.loadUi(UI_PATH, self) self.show() @property diff --git a/gui/widgets/threshold_ctrl.py b/widgets/threshold_ctrl.py similarity index 81% rename from gui/widgets/threshold_ctrl.py rename to widgets/threshold_ctrl.py index 2a8f66f..c049d94 100644 --- a/gui/widgets/threshold_ctrl.py +++ b/widgets/threshold_ctrl.py @@ -5,16 +5,18 @@ Description: """ +import os + from PyQt5 import QtWidgets, uic -from gui.utils import resource_path +UI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../resources/threshold_ctrl.ui')) class ThresholdCtrl(QtWidgets.QWidget): def __init__(self, parent): super().__init__(parent) - uic.loadUi(resource_path('threshold_ctrl.ui'), self) + uic.loadUi(UI_PATH, self) self.show() self.slider.valueChanged.connect(lambda value: self.spinbox.setValue(value / 1000.)) From a521d1f98fb261eb671a4b421d8fa4e0fbdfd405 Mon Sep 17 00:00:00 2001 From: Taylor Denouden Date: Tue, 15 Dec 2020 12:09:24 -0800 Subject: [PATCH 3/4] Move ui files and update pyinstaller paths --- .github/workflows/gui_release.yml | 5 +++-- gui.py | 6 +++--- resources/gui.ui => gui.ui | 0 widgets/buffer_ctrl.py | 6 ++++-- {resources => widgets}/buffer_ctrl.ui | 0 widgets/directory_path.py | 6 ++++-- {resources => widgets}/directory_path.ui | 0 widgets/threshold_ctrl.py | 6 ++++-- {resources => widgets}/threshold_ctrl.ui | 0 9 files changed, 18 insertions(+), 11 deletions(-) rename resources/gui.ui => gui.ui (100%) rename {resources => widgets}/buffer_ctrl.ui (100%) rename {resources => widgets}/directory_path.ui (100%) rename {resources => widgets}/threshold_ctrl.ui (100%) diff --git a/.github/workflows/gui_release.yml b/.github/workflows/gui_release.yml index ae84c92..6d283e2 100644 --- a/.github/workflows/gui_release.yml +++ b/.github/workflows/gui_release.yml @@ -34,7 +34,8 @@ jobs: --hidden-import="widgets.buffer_ctrl" \ --hidden-import="widgets.threshold_ctrl" \ --hidden-import="widgets.directory_path" \ - --add-data="resources/*.ui:resources" \ + --add-data="widgets/*.ui:." \ + --add-data="*.ui:." \ gui.py - name: Building CLI run: | @@ -69,7 +70,7 @@ jobs: pip install -r requirements.txt - name: Building GUI run: | - pyinstaller --name=GlintMaskGenerator-${{ steps.tag.outputs.tag }} --onefile --windowed --icon="resources\gmt.ico" --hidden-import="widgets.buffer_ctrl" --hidden-import="widgets.threshold_ctrl" --hidden-import="widgets.directory_path" --add-data="resources\*.ui;resources" gui.py + pyinstaller --name=GlintMaskGenerator-${{ steps.tag.outputs.tag }} --onefile --windowed --icon="resources\gmt.ico" --hidden-import="widgets.buffer_ctrl" --hidden-import="widgets.threshold_ctrl" --hidden-import="widgets.directory_path" --add-data="widgets\*.ui;." --add-data="*.ui;." gui.py - name: Building CLI run: | pyinstaller --name=glint-mask-${{ steps.tag.outputs.tag }} -F cli.py diff --git a/gui.py b/gui.py index 69d3dce..fd57fb0 100644 --- a/gui.py +++ b/gui.py @@ -4,9 +4,8 @@ Date: 2020-09-16 Description: """ - -import os import sys +from os import path from typing import List, Sequence from PyQt5 import QtWidgets, uic @@ -38,7 +37,8 @@ DEFAULT_PIXEL_BUFFER = 0 DEFAULT_MAX_WORKERS = 0 -UI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'resources/gui.ui')) +bundle_dir = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__))) +UI_PATH = path.abspath(path.join(bundle_dir, 'gui.ui')) class MessageBox(QtWidgets.QMessageBox): diff --git a/resources/gui.ui b/gui.ui similarity index 100% rename from resources/gui.ui rename to gui.ui diff --git a/widgets/buffer_ctrl.py b/widgets/buffer_ctrl.py index 76dd805..7c5f4d7 100644 --- a/widgets/buffer_ctrl.py +++ b/widgets/buffer_ctrl.py @@ -5,11 +5,13 @@ Description: """ -import os +import sys +from os import path from PyQt5 import QtWidgets, uic -UI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../resources/buffer_ctrl.ui')) +bundle_dir = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__))) +UI_PATH = path.abspath(path.join(bundle_dir, 'buffer_ctrl.ui')) class BufferCtrl(QtWidgets.QWidget): diff --git a/resources/buffer_ctrl.ui b/widgets/buffer_ctrl.ui similarity index 100% rename from resources/buffer_ctrl.ui rename to widgets/buffer_ctrl.ui diff --git a/widgets/directory_path.py b/widgets/directory_path.py index b9d51a8..73c3724 100644 --- a/widgets/directory_path.py +++ b/widgets/directory_path.py @@ -4,13 +4,15 @@ Date: 2020-09-17 Description: """ - import os +import sys +from os import path from PyQt5 import QtWidgets, uic from PyQt5.QtWidgets import QFileDialog -UI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../resources/directory_path.ui')) +bundle_dir = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__))) +UI_PATH = path.abspath(path.join(bundle_dir, 'directory_path.ui')) class DirectoryPath(QtWidgets.QWidget): diff --git a/resources/directory_path.ui b/widgets/directory_path.ui similarity index 100% rename from resources/directory_path.ui rename to widgets/directory_path.ui diff --git a/widgets/threshold_ctrl.py b/widgets/threshold_ctrl.py index c049d94..fd85278 100644 --- a/widgets/threshold_ctrl.py +++ b/widgets/threshold_ctrl.py @@ -5,11 +5,13 @@ Description: """ -import os +import sys +from os import path from PyQt5 import QtWidgets, uic -UI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../resources/threshold_ctrl.ui')) +bundle_dir = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__))) +UI_PATH = path.abspath(path.join(bundle_dir, 'threshold_ctrl.ui')) class ThresholdCtrl(QtWidgets.QWidget): diff --git a/resources/threshold_ctrl.ui b/widgets/threshold_ctrl.ui similarity index 100% rename from resources/threshold_ctrl.ui rename to widgets/threshold_ctrl.ui From 1fe5984801d59353c4cc78079fbe711d98d44312 Mon Sep 17 00:00:00 2001 From: Taylor Denouden Date: Tue, 15 Dec 2020 12:30:02 -0800 Subject: [PATCH 4/4] Fix broken numpy version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index faf94f2..44ff0cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ fire~=0.3.1 -numpy~=1.19.1 +numpy==1.19.3 pillow~=7.2.0 scipy~=1.5.2 tqdm~=4.49.0