Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
tpeulen committed Feb 10, 2025
2 parents c5b5836 + 740481e commit ee4b41f
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 61 deletions.
112 changes: 63 additions & 49 deletions chisurf/gui/tools/code_editor/qsci_editor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import pathlib
import sys

from PyQt5.Qsci import QsciScintilla
Expand Down Expand Up @@ -70,7 +71,6 @@ def __init__(
# Set the default font
font = QtGui.QFont()
font.setFamily(font_family)
font.setFixedPitch(True)
font.setPointSize(int(font_point_size))

self.setFont(font)
Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(
# Set Python lexer
# Set style for Python comments (style number 1) to a fixed-width
# courier.
if lexers_available:
if lexers_available and isinstance(language, str):
if language.lower() == "python":
lexer = QsciLexerPython()
elif language.lower() == "json":
Expand Down Expand Up @@ -142,43 +142,53 @@ def on_margin_clicked(self, nmargin, nline, modifiers):

class CodeEditor(QtWidgets.QWidget):

def load_file_event(self, event, filename: str = None, **kwargs):
self.load_file(filename)

def load_file(self, filename: str = None, **kwargs):
if filename is None:
filename = chisurf.gui.widgets.get_filename()
self.filename = filename
"""Load a file into the editor."""
filename = filename or chisurf.gui.widgets.get_filename()
if not filename:
return
try:
logging.log(0, f"Loading file: {filename}")
text = ""
with open(filename) as fp:
text = fp.read()
self.editor.setText(text)
self.line_edit.setText(
str(filename)
)
except IOError:
logging.log(1, f"CodeEditor, not a valid filename: {filename}")

def run_macro(self):
with open(filename, encoding="utf-8") as file:
self.editor.setText(file.read())
self.line_edit.setText(str(filename))
self.filename = filename
except IOError as e:
logging.log(1, f"Error loading file {filename}: {e}")

def run_macro(self, event):
"""Execute the currently loaded Python script."""
if not self.filename:
logging.log(1, "No file to run.")
return
self.save_text()
chisurf.console.run_macro(filename=self.filename)

def save_text(self):
if self.filename is None or self.filename == '':
self.filename = chisurf.gui.widgets.save_file(file_type='Python script (*.py)')
with io.zipped.open_maybe_zipped(self.filename, 'w') as fp:
text = str(self.editor.text())
fp.write(text)
self.line_edit.setText(str(self.filename.as_posix))
def save_text(self, event = None):
"""Save the current text to a file."""
if not self.filename:
self.filename = chisurf.gui.widgets.save_file(file_type="Python script (*.py)")
if not self.filename:
return
try:
with io.zipped.open_maybe_zipped(self.filename, "w") as file:
file.write(self.editor.text())
self.line_edit.setText(str(pathlib.Path(self.filename).as_posix()))
except IOError as e:
logging.log(1, f"Error saving file {self.filename}: {e}")

def __init__(
self,
*args,
filename: str = None,
language: str = 'Python',
can_load: bool = True,
**kwargs
self,
*args,
filename: str = None,
language: str = "Python",
can_load: bool = True,
**kwargs
):
super(CodeEditor, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

layout = QtWidgets.QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
Expand All @@ -192,29 +202,33 @@ def __init__(
language=language
)
layout.addWidget(self.editor)
h_layout = QtWidgets.QHBoxLayout()

load_button = QtWidgets.QPushButton('load')
save_button = QtWidgets.QPushButton('save')
run_button = QtWidgets.QPushButton('run')

h_layout.addWidget(self.line_edit)
h_layout.addWidget(load_button)
h_layout.addWidget(save_button)
h_layout.addWidget(run_button)
layout.addLayout(h_layout)
# Button layout
button_layout = QtWidgets.QHBoxLayout()
self.load_button = QtWidgets.QPushButton("Load")
self.save_button = QtWidgets.QPushButton("Save")
self.run_button = QtWidgets.QPushButton("Run")

button_layout.addWidget(self.line_edit)
button_layout.addWidget(self.load_button)
button_layout.addWidget(self.save_button)
button_layout.addWidget(self.run_button)
layout.addLayout(button_layout)

# Connect buttons to actions
self.save_button.clicked.connect(self.save_text)
self.load_button.clicked.connect(self.load_file_event)
self.run_button.clicked.connect(self.run_macro)

# Handle initial file loading
if isinstance(filename, str) and pathlib.Path(filename).is_file():
self.load_file(filename=filename)

save_button.clicked.connect(self.save_text)
load_button.clicked.connect(self.load_file)
run_button.clicked.connect(self.run_macro)
if isinstance(language, str) and language.lower() != "python":
self.run_button.hide()

# Load the file
if filename is not None and filename != '':
self.load_file(filename=filename)
if language != 'Python':
run_button.hide()
if not can_load:
load_button.hide()
self.load_button.hide()


if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions chisurf/gui/widgets/experiments/tcspc/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def __init__(self, *args, **kwargs):
self.actionParametersChanged.triggered.connect(self.onParametersChanged)
self.onParametersChanged()

def show(self):
super().show()
# Call onParametersChanged on show to make sure that the
# settings match the UI
self.onParametersChanged()

def onParametersChanged(self):
micro_time_coarsening = self.comboBox_2.currentText()
channel_numbers = self.lineEdit.text()
Expand Down
7 changes: 6 additions & 1 deletion chisurf/plugins/anisotropy/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,24 @@ def create_fits(self):

# Link VH parameters to VV
#######################################

# number of photons
self.fit_vh.model.parameters_all_dict['n0'].link = self.fit_vv.model.parameters_all_dict['n0']
self.fit_vv.model.parameters_all_dict['n0'].fixed = False
self.fit_vh.model.parameters_all_dict['n0'].fixed = False

self.fit_vv.model.parameters_all_dict['l1'].fixed = False
self.fit_vv.model.parameters_all_dict['l1'].value = self.conf_edit.dict['l1']
self.fit_vv.model.parameters_all_dict['l1'].fixed = True
self.fit_vv.model.parameters_all_dict['l1'].controller.finalize()

self.fit_vv.model.parameters_all_dict['l2'].fixed = False
self.fit_vv.model.parameters_all_dict['l2'].value = self.conf_edit.dict['l2']
self.fit_vv.model.parameters_all_dict['l2'].fixed = True
self.fit_vv.model.parameters_all_dict['l2'].controller.finalize()

self.fit_vv.model.parameters_all_dict['g'].fixed = False
self.fit_vv.model.parameters_all_dict['g'].value = self.conf_edit.dict['g_factor']
self.fit_vv.model.parameters_all_dict['g'].fixed = True
self.fit_vv.model.parameters_all_dict['g'].controller.finalize()

# rotation
Expand Down
12 changes: 6 additions & 6 deletions chisurf/settings/settings_chisurf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ parameter:
hide_label: false
gui:
editor:
margins_background_color: "#a1a1a1"
marker_background_color: "#d6d6d6"
caret_line_background_color: "#747677"
paper_color: "#747677"
default_color: "#e1e1e1"
margins_background_color: "#808080"
marker_background_color: "#f0f0f0"
caret_line_background_color: "#afafaf"
paper_color: "#cfcfcf"
default_color: "#000006"
font_size: 9
font_family: Sans-Serif
font_family: Courier New
language: Python
style_sheet: dark.css
RubberBandResize: true
Expand Down
18 changes: 13 additions & 5 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if exist build rmdir /s /q build
mkdir build
cd build
:: Configure the build using CMake
cmake .. -G "Visual Studio 15 2017" -A x64 ^
cmake .. -G "Visual Studio 17 2022" -A x64 ^
-DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" ^
-DCMAKE_PREFIX_PATH="%PREFIX%" ^
-DBUILD_PYTHON_INTERFACE=ON ^
Expand All @@ -60,7 +60,7 @@ cmake .. -G "Visual Studio 15 2017" -A x64 ^
cmake --build . --config Release --target install
cd ..\..\..

:: Build fit2x module (same as build.sh)
:: Build fit2x module
cd modules\fit2x
git switch master
if exist build rmdir /s /q build
Expand All @@ -72,14 +72,22 @@ for /f "tokens=2 delims= " %%v in ('%PYTHON% --version 2^>^&1') do set PYTHON_VE
:: Extract only the numeric part of the version
for /f "tokens=1-3 delims=." %%a in ("%PYTHON_VERSION%") do set PYTHON_VERSION_NUMERIC=%%a.%%b.%%c

cmake .. -G "Visual Studio 15 2017" -A x64 ^
REM Configure the build using CMake
cmake .. -G "Visual Studio 17 2022" ^
-DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" ^
-DCMAKE_PREFIX_PATH="%PREFIX%" ^
-DBUILD_PYTHON_INTERFACE=ON ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY="%SP_DIR%" ^
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE="%SP_DIR%" ^
-DPYTHON_VERSION="%PYTHON_VERSION_NUMERIC%" ^
-DCMAKE_SWIG_OUTDIR="%SP_DIR%"
-DCMAKE_SWIG_OUTDIR="%SP_DIR%" ^
-DPython_ROOT_DIR="%PREFIX%\bin" ^
-DBUILD_LIBRARY=OFF ^
-DBUILD_PYTHON_DOCS=ON ^
-DWITH_AVX=OFF ^
-Wno-dev ^
-DBoost_USE_STATIC_LIBS=OFF

:: Build and install the project
cmake --build . --config Release --target install
cd ..\..\..
Expand Down

0 comments on commit ee4b41f

Please sign in to comment.