Skip to content

Commit

Permalink
fix: circular imports when importing widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ElpadoCan committed Jun 28, 2023
1 parent 34a6eb8 commit e49d978
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ notebooks/.ipynb_checkpoints
.idea/
test.txt
cellacdc/qrc_resources.py
cellacdc/_tests
cellacdc/scripts/test.py
cellacdc/scripts/test1.py
cellacdc/scripts/correct_shift_X_old.py
Expand Down
10 changes: 2 additions & 8 deletions cellacdc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@


# Create the application
app, splashScreen = _run._setup_app()
app, splashScreen = _run._setup_app(splashscreen=True)

import sys
import re
Expand Down Expand Up @@ -139,14 +139,8 @@
class mainWin(QMainWindow):
def __init__(self, app, parent=None):
self.checkConfigFiles()

scheme = self.getColorScheme()
from ._palettes import getPaletteColorScheme, setToolTipStyleSheet
self.app = app
palette = getPaletteColorScheme(app.palette(), scheme=scheme)
app.setPalette(palette)
load.rename_qrc_resources_file(scheme)
setToolTipStyleSheet(app, scheme=scheme)
scheme = self.getColorScheme()
self.welcomeGuide = None

super().__init__(parent)
Expand Down
53 changes: 34 additions & 19 deletions cellacdc/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ def _setup_gui():
[sys.executable, '-m', 'pip', 'install', '-U', 'seaborn']
)

def _setup_app():
from qtpy import QtCore, QtWidgets
def _setup_app(splashscreen=False):
from qtpy import QtCore:
if QtCore.QCoreApplication.instance() is not None:
return QtCore.QCoreApplication.instance(), None

from qtpy import QtWidgets
# Handle high resolution displays:
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
Expand Down Expand Up @@ -137,24 +141,35 @@ def _setup_app():

from qtpy import QtWidgets, QtGui

class AcdcSPlashScreen(QtWidgets.QSplashScreen):
def __init__(self):
super().__init__()
logo_path = os.path.join(resources_folderpath, 'logo.png')
self.setPixmap(QtGui.QPixmap(logo_path))
splashScreen = None
if splashscreen:
class AcdcSPlashScreen(QtWidgets.QSplashScreen):
def __init__(self):
super().__init__()
logo_path = os.path.join(resources_folderpath, 'logo.png')
self.setPixmap(QtGui.QPixmap(logo_path))

def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
pass

def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
pass
# Launch splashscreen
splashScreen = AcdcSPlashScreen()
splashScreen.setWindowIcon(QIcon(icon_path))
splashScreen.setWindowFlags(
QtCore.Qt.WindowStaysOnTopHint
| QtCore.Qt.SplashScreen
| QtCore.Qt.FramelessWindowHint
)
splashScreen.show()
splashScreen.raise_()

# Launch splashscreen
splashScreen = AcdcSPlashScreen()
splashScreen.setWindowIcon(QIcon(icon_path))
splashScreen.setWindowFlags(
QtCore.Qt.WindowStaysOnTopHint
| QtCore.Qt.SplashScreen
| QtCore.Qt.FramelessWindowHint
)
splashScreen.show()
splashScreen.raise_()
from ._palettes import getPaletteColorScheme, setToolTipStyleSheet
from ._palettes import get_color_scheme
from . import load
scheme = get_color_scheme()
palette = getPaletteColorScheme(app.palette(), scheme=scheme)
app.setPalette(palette)
load.rename_qrc_resources_file(scheme)
setToolTipStyleSheet(app, scheme=scheme)

return app, splashScreen
2 changes: 1 addition & 1 deletion cellacdc/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
)

from . import exception_handler
from . import widgets
from . import load, prompts, core, measurements, html_utils
from . import is_mac, is_win, is_linux, temp_path, config
from . import qrc_resources, printl
Expand All @@ -66,6 +65,7 @@
from . import qutils
from . import _palettes
from . import base_cca_df
from . import widgets

PRE_PROCESSING_STEPS = [
'Adjust Brightness/Contrast',
Expand Down
9 changes: 0 additions & 9 deletions cellacdc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
from . import load, myutils
from . import base_cca_df, printl

from . import GUI_INSTALLED
if GUI_INSTALLED:
from . import apps
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
from matplotlib.patches import Rectangle, Circle, PathPatch, Path


def get_indices_dash_pattern(arr, line_length, gap):
n = len(arr)
sampling_rate = (line_length+gap)
Expand Down
3 changes: 2 additions & 1 deletion cellacdc/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
)
import pyqtgraph as pg
from . import prompts
from . import apps
from . import widgets

import warnings
Expand Down Expand Up @@ -1751,6 +1750,7 @@ def askInputMetadata(
forceEnableAskSegm3D=False,
warnMultiPos=False
):
from . import apps
SizeZ_metadata = None
SizeT_metadata = None
if hasattr(self, 'metadataFound'):
Expand Down Expand Up @@ -1929,6 +1929,7 @@ def QtPrompt(
allow_abort=True, show=False, toggleMulti=False,
allowMultiSelection=True
):
from . import apps
font = QtGui.QFont()
font.setPixelSize(13)
win = apps.QtSelectItems(
Expand Down
5 changes: 3 additions & 2 deletions cellacdc/myutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
if GUI_INSTALLED:
from qtpy.QtWidgets import QMessageBox
from qtpy.QtCore import Signal, QObject, QCoreApplication

from . import apps

from . import widgets
from . import config

Expand Down Expand Up @@ -461,6 +460,7 @@ def install_java():
subprocess.check_call(['javac', '-version'])
return False
except Exception as e:
from . import apps
win = apps.installJavaDialog()
win.exec_()
return win.clickedButton == win.cancelButton
Expand Down Expand Up @@ -1804,6 +1804,7 @@ def _install_deepsea():
)

def import_tracker(posData, trackerName, realTime=False, qparent=None):
from . import apps
downloadWin = apps.downloadModel(trackerName, parent=qparent)
downloadWin.download()

Expand Down
3 changes: 2 additions & 1 deletion cellacdc/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from . import printl
from . import widgets, _core, error_below, error_close
from . import _run

def matplotlib_cmap_to_lut(
cmap: Union[Iterable, matplotlib.colors.Colormap, str],
Expand Down Expand Up @@ -75,7 +76,7 @@ def imshow(
image = image.astype(np.uint8)
casted_images.append(image)

app = widgets.setupApp()
app = _run._setup_app()
win = widgets.ImShow(parent=parent, link_scrollbars=link_scrollbars)
win.setWindowTitle(window_title)
if app is not None:
Expand Down
4 changes: 3 additions & 1 deletion cellacdc/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from qtpy.QtCore import Qt
from qtpy.QtGui import QFont

from . import apps, myutils, printl, html_utils, load
from . import myutils, printl, html_utils, load
from . import temp_path

class RichTextPushButton(QPushButton):
Expand Down Expand Up @@ -219,6 +219,7 @@ def _save_last_selection(self, selection):
txt.write(selection)

def askChannelName(self, filenames, images_path, ask, ch_names):
from . import apps
if not ask:
return ch_names
filename = self.basename
Expand Down Expand Up @@ -260,6 +261,7 @@ def askChannelName(self, filenames, images_path, ask, ch_names):

def QtPrompt(self, parent, channel_names, informativeText='',
CbLabel='Select channel name: '):
from . import apps
font = QFont()
font.setPixelSize(13)
win = apps.QDialogCombobox(
Expand Down

0 comments on commit e49d978

Please sign in to comment.