dymokomi/luced-photo
Source of release 0.1.1
0.1.1 / tests / modes / main.luc
## The five modes on a fresh library in HOME: each shows its stages' sections
## in Properties (Capture the camera and the film, Develop the chemistry, Print
## the Output and its stages, View the display and the frame); the Output menu
## swaps Print's stages; a switched-off Lens still shows, to switch on; the
## Library mode shows the exposed parameters alone (Exposure and White Balance
## without a preset); the window draws in every mode. Prints PASS or traps.
from app import LucedPhoto
from luce_std import files, paths
import modes
func close(a: list[float], b: list[float]) -> bool:
for at in 0..<a.length:
if a[at] - b[at] > 1.0e-4 or b[at] - a[at] > 1.0e-4:
return false
return true
func expect(condition: bool, what: str) -> unit!:
if not condition:
print(f"FAIL modes: {what}")
trap(what)
pub func main(arguments: list[str]) -> int!:
let photo = LucedPhoto(paths.join(files.home_directory(), "Modes.library"))
let panels = photo.panels
let controls = panels.properties.develop
expect(panels.mode == modes.library, "the app opens in Library")
controls.exposed = ["exposure", "temperature", "tint"]
controls.show_mode(modes.library)
expect(controls.section_shown("Exposure") and controls.section_shown("White Balance"), "Library shows the exposure and white balance")
expect(not controls.section_shown("Film") and not controls.section_shown("Develop"), "Library shows nothing else")
controls.exposed = ["film_grain"]
controls.show_mode(modes.library)
expect(controls.section_shown("Film") and not controls.section_shown("Exposure"), "an exposed grain shows the Film section")
panels.set_mode(modes.capture)
expect(controls.section_shown("Film") and controls.section_shown("Exposure"), "Capture shows the film and the exposure")
expect(controls.section_shown("Lens") and not controls.look.has_stage(3), "Capture shows the Lens, switched off")
expect(not controls.section_shown("Develop") and not controls.section_shown("Output"), "Capture shows no chemistry and no output")
panels.set_mode(modes.develop)
expect(controls.section_shown("Develop") and not controls.section_shown("Film"), "Develop shows the chemistry alone")
panels.set_mode(modes.printing)
expect(controls.section_shown("Output") and controls.section_shown("Scan") and controls.section_shown("Tone"), "Print shows the telecine")
expect(not controls.section_shown("Print"), "a telecine has no release print")
controls.look.set_output(1)
controls.show_values()
expect(controls.section_shown("Print") and not controls.section_shown("Scan"), "a release print swaps the stages")
panels.set_mode(modes.viewing)
expect(controls.section_shown("Crop") and not controls.section_shown("View"), "View frames a print; no display rendering for it")
controls.look.set_stage_used(3, true)
expect(controls.look.has_stage(3) and controls.look.output() == 1, "switching the Lens on keeps the output")
# Rotate Right turns the photo a quarter and its crop with it; Left turns both back.
controls.set_crop([0.1, 0.2, 0.9, 0.7])
controls.turn(1)
expect(controls.look.get("geometry_turn") == 1.0, "Rotate Right turns a quarter")
let turned = [controls.look.get("crop_left"), controls.look.get("crop_top"), controls.look.get("crop_right"), controls.look.get("crop_bottom")]
expect(close(turned, [0.3, 0.1, 0.8, 0.9]), "the crop turns with the photo")
controls.turn(-1)
let back = [controls.look.get("crop_left"), controls.look.get("crop_top"), controls.look.get("crop_right"), controls.look.get("crop_bottom")]
expect(controls.look.get("geometry_turn") == 0.0 and close(back, [0.1, 0.2, 0.9, 0.7]), "Rotate Left turns both back")
controls.turn(-1)
expect(controls.look.get("geometry_turn") == 3.0, "Rotate Left from upright is three quarters")
for mode in 0..<modes.count:
panels.set_mode(mode)
photo.run(["luced-photo", "--smoke"])
# Each mode keeps its arrangement: a narrower Photos pane in Library, then
# Develop and back, comes back as it was; Reset Layout gives the usual one.
panels.set_mode(modes.library)
let usual = panels.dock.layout_text()
panels.dock.set_fraction(panels.library_pane.panel, 0.25)
let narrow = panels.dock.layout_text()
expect(narrow != usual, "the Photos pane narrowed")
panels.set_mode(modes.develop)
expect(panels.dock.layout_text() != narrow, "Develop has its own arrangement")
panels.set_mode(modes.library)
expect(panels.dock.layout_text() == narrow, "Library comes back as it was left")
panels.actions.reset_layout.trigger()
expect(panels.dock.layout_text() == usual, "Reset Layout gives the usual arrangement")
photo.close()
print("PASS modes: each mode shows its stages; outputs and switches change them; every mode draws; each keeps its arrangement")
return 0