Master parameter persistence, configuration files, and value priority in EZInput
EZInput automatically remembers widget values between sessions. This is perfect for iterative workflows where you're tuning parameters.
from ezinput import EZInput
# First run - user enters values
gui = EZInput("my_analysis")
threshold = gui.add_float_range("thresh", "Threshold:", 0.0, 1.0)
iterations = gui.add_int_range("iter", "Iterations:", 10, 1000)
gui.show()
# User enters: threshold=0.75, iterations=500
# --------------------------------------------------
# Second run (next day) - values are remembered!
gui = EZInput("my_analysis") # Same title = same config
threshold = gui.add_float_range("thresh", "Threshold:", 0.0, 1.0)
iterations = gui.add_int_range("iter", "Iterations:", 10, 1000)
gui.show()
# Defaults are now: threshold=0.75, iterations=500 ✨
EZInput())~/.ezinput/{title}.yml
Use the remember_value parameter (defaults to True) to control which values persist:
gui = EZInput("preprocessing")
# These values change frequently (don't remember)
input_file = gui.add_text("input", "Input file:", remember_value=False)
output_dir = gui.add_text("output", "Output directory:", remember_value=False)
# These are stable parameters (remember them - this is the default)
method = gui.add_dropdown("method", ["watershed", "otsu"], "Method:",
remember_value=True)
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1,
remember_value=True)
gui.show()
# Next time: method and threshold are remembered,
# but input/output need to be re-entered
When to use remember_value=True (default):
When to use remember_value=False:
gui = EZInput("cell_segmentation")
# Add widgets
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1)
min_size = gui.add_int_range("min_size", "Min size:", 10, 1000)
method = gui.add_dropdown("method", ["otsu", "adaptive"], "Method:")
gui.show()
# User enters optimal values...
# Save current configuration
gui.save_parameters("optimal_settings.yml")
# Or specify full path
gui.save_parameters("/path/to/configs/experiment1.yml")
gui = EZInput("cell_segmentation")
# Load saved configuration
gui.load_parameters("optimal_settings.yml")
# Add widgets (values from file will be used)
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1)
min_size = gui.add_int_range("min_size", "Min size:", 10, 1000)
method = gui.add_dropdown("method", ["otsu", "adaptive"], "Method:")
gui.show()
# Widgets now have values from optimal_settings.yml!
Configuration files are stored in:
~/.ezinput/{title}.yml
Where {title} is the name you passed to EZInput().
Example:
gui = EZInput("image_analysis_v2")
# Config saved to: ~/.ezinput/image_analysis_v2.yml
EZInput uses YAML format for configuration files. Here's what a config file looks like:
# ~/.ezinput/my_analysis.yml
thresh:
value: 0.75
type: float
method:
value: watershed
type: str
min_size:
value: 250
type: int
use_gpu:
value: true
type: bool
You can manually edit these files or share them with colleagues!
When multiple sources provide values for a widget, EZInput follows this priority:
load_parameters()
remember_value=True parameter
default=0.5)
# Example 1: Loaded parameters override everything
gui = EZInput("test")
gui.load_parameters("config.yml") # Contains thresh=0.9
# This default is ignored because config.yml has thresh=0.9
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1, default=0.5)
gui.show()
# Result: threshold defaults to 0.9 (from config.yml)
# Example 2: Remembered values override explicit defaults
# Previous run: user entered thresh=0.75
gui = EZInput("test")
gui.remember_value("thresh")
# This default is ignored because remembered value exists
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1, default=0.5)
gui.show()
# Result: threshold defaults to 0.75 (remembered from before)
# Example 3: Explicit defaults override widget defaults
gui = EZInput("test")
# Uses your explicit default (no config file, not remembered)
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1, default=0.8)
gui.show()
# Result: threshold defaults to 0.8 (explicit default)
# Example 4: Widget defaults (last resort)
gui = EZInput("test")
# No config, not remembered, no explicit default
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1)
gui.show()
# Result: threshold defaults to 0 (min_val is the widget default)
Configuration files are perfect for sharing parameter sets with collaborators or across projects.
# Researcher 1: Find optimal parameters
gui = EZInput("cell_analysis")
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1)
min_size = gui.add_int_range("min_size", "Min size:", 10, 1000)
gui.show()
# After experimentation, save optimal settings
gui.save_parameters("optimal_cell_params.yml")
# Share optimal_cell_params.yml with team
# --------------------------------------------------
# Researcher 2: Use the optimal parameters
gui = EZInput("cell_analysis")
gui.load_parameters("optimal_cell_params.yml")
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1)
min_size = gui.add_int_range("min_size", "Min size:", 10, 1000)
gui.show()
# Automatically starts with optimal values! 🎉
optimal_params_v2.yml, production_config.yml~/.ezinput/ to .gitignore (personal settings)from ezinput import EZInput
# Different configs for different scenarios
configs = {
"fast": "fast_preview.yml",
"balanced": "balanced_quality.yml",
"high_quality": "high_quality.yml"
}
# Let user select config
gui = EZInput("config_selector")
config_choice = gui.add_dropdown("config", list(configs.keys()),
"Quality preset:")
gui.show()
# Load selected config
analysis_gui = EZInput("image_analysis")
analysis_gui.load_parameters(configs[config_choice.value])
# Add widgets (values from selected config)
threshold = analysis_gui.add_float_range("thresh", "Threshold:", 0, 1)
iterations = analysis_gui.add_int_range("iter", "Iterations:", 10, 1000)
analysis_gui.show()
The restore_defaults() method clears all remembered values, returning widgets to their original defaults.
In Jupyter: You must re-run the cell containing your widgets after calling restore_defaults().
In Terminal: You must re-run your script after calling restore_defaults().
The method removes the memory file (~/.ezinput/{title}.yml), but the widgets won't visually change until you re-execute the code that creates them.
from ezinput import EZInput
gui = EZInput("my_analysis")
# Add widgets with remember_value=True parameter
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1,
default=0.5, remember_value=True)
method = gui.add_dropdown("method", ["A", "B", "C"], "Method:",
default="A", remember_value=True)
gui.show()
# After user runs multiple times with different values...
# Clear all remembered values
gui.restore_defaults()
print("✓ Remembered values cleared!")
print("🔄 Re-run this cell/script to see default values restored.")
# Cell 1: Initial setup with remembered values
from ezinput import EZInput
gui = EZInput("experiment")
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1,
default=0.5, remember_value=True)
gui.show()
# User sets threshold=0.8, runs analysis multiple times...
# threshold.value is now remembered as 0.8
# Cell 2: Reset to defaults
gui.restore_defaults() # Deletes ~/.ezinput/experiment.yml
# Cell 3: Re-run Cell 1 to see defaults
# NOW when you re-run Cell 1, threshold will default to 0.5 again!
# analyze.py
from ezinput import EZInput
import sys
if len(sys.argv) > 1 and sys.argv[1] == "--reset":
# User ran: python analyze.py --reset
gui = EZInput("analysis")
gui.restore_defaults()
print("✓ Defaults restored!")
print("🔄 Run 'python analyze.py' again to use default values.")
sys.exit(0)
# Normal execution
gui = EZInput("analysis")
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1,
default=0.5, remember_value=True)
gui.show()
# Run analysis with threshold.value...
# Usage:
# python analyze.py # Normal run (uses remembered values)
# python analyze.py --reset # Clear remembered values
# python analyze.py # Next run uses defaults again
remember_value=True parameter for stable paramsfrom ezinput import EZInput
gui = EZInput("advanced")
# Add widgets
threshold = gui.add_float_range("thresh", "Threshold:", 0, 1)
method = gui.add_dropdown("method", ["A", "B"], "Method:")
gui.show()
# Get all current values as dict
values = gui.get_values()
print(f"Threshold: {values['thresh'].value}")
print(f"Method: {values['method'].value}")
# Access individual widgets
threshold_widget = gui["thresh"]
print(f"Current threshold: {threshold_widget.value}")
# Update values programmatically
gui["thresh"].value = 0.8
# Save current state
gui.save_parameters("current_state.yml")