dymokomi/luced-photo
Source of release 0.1.0
## Capture the window for tools/preview.py:
## preview OUTPUT.ppm LIBRARY [position [cell [settings]]]
## Opens the library, selects the photo at `position`, waits for thumbnails and
## the viewer's preview, then reads the frame back.
import probe
import presets
from app import LucedPhoto
import preset_marks
from luce_ui.ui import Event
from luce_window.input import EventKind, ScrollUnit
pub func main(arguments: list[str]) -> int!:
let photo = LucedPhoto(arguments[1])
let position = int(arguments[2]) if arguments.length > 2 else 0
let cell = float(arguments[3]) if arguments.length > 3 else 0.0
let develop = arguments[4] if arguments.length > 4 else ""
let guiding = arguments.length > 5 and arguments[5] == "guides"
let zoomed = arguments.length > 5 and arguments[5] == "zoom"
let exporting = arguments.length > 6 and arguments[5] == "export"
let undoing = arguments.length > 5 and arguments[5] == "undo"
let cropping = arguments.length > 5 and arguments[5] == "crop"
# Save the --develop edit as a preset, then click it on the next photo.
let presetting = arguments.length > 5 and arguments[5] == "presets"
# Open (making it) the library at the next argument.
let switching = arguments.length > 6 and arguments[5] == "switch"
# A mouse wheel over the viewer's middle, then a middle-button drag, through
# the window's own routing.
let wheeling = arguments.length > 5 and arguments[5] == "wheel"
# A left click at window point (x, y), given as "x,y" after "click".
let clicking = arguments.length > 6 and arguments[5] == "click"
# Film look N given to the photo, the frame read T ticks (50 ms) after:
# "N:T" after "look", to see what the window shows while it develops.
let looking = arguments.length > 6 and arguments[5] == "look"
let look_at = int(arguments[6].split(":")[0]) if looking else 0
let look_after = int(arguments[6].split(":")[1]) if looking else 0
# Film look 0 given to the photo, its film preset copied and pasted onto
# the first photo, then the photos' right-click menu opened over it.
let film_copying = arguments.length > 5 and arguments[5] == "film"
# Film look 0 given to the photo, then Before / After on.
let comparing = arguments.length > 5 and arguments[5] == "compare"
# Mode N (modes.luc) after the photo is shown: "mode" then N.
let moding = arguments.length > 6 and arguments[5] == "mode"
var ticks = 0
var capture = -1
let timer = photo.app.every(0.05, func () -> unit!:
ticks += 1
let grid = photo.panels.library_pane.grid
if ticks == 4:
if cell > 0.0:
grid.set_cell_size(cell)
if position < grid.item_count():
grid.select(position)
photo.panels.show_selection(position)
if develop != "":
photo.panels.session.apply_preset([position], "Preview", develop)
if ticks == 30 and cropping:
photo.panels.properties.develop.set_cropping(true)
if ticks == 30 and presetting:
let panels = photo.panels
let text = panels.session.preset_text() else return
_ = panels.library.save_preset("Preview Look", text, presets.default_exposed)
_ = panels.library.save_preset("Another Look", "saturation=-40", presets.default_exposed)
panels.presets.show()
grid.select(position + 1)
panels.show_selection(position + 1)
if ticks == 40 and presetting:
let presets = photo.panels.library.presets
photo.panels.presets.apply_mark(preset_marks.for_saved(presets.id(presets.position_of_name("Preview Look"))))
if ticks == 30 and wheeling:
let box = photo.panels.viewer.layout().bounds()
let x = box.x + box.width * 0.5
let y = box.y + box.height * 0.5
photo.app.dispatch(Event(kind = EventKind.pointer_moved, x = x, y = y))
photo.app.dispatch(Event(kind = EventKind.scroll, x = x, y = y, scroll_y = 12.0, scroll_unit = ScrollUnit.lines))
photo.app.dispatch(Event(kind = EventKind.pointer_down, button = 2, x = x, y = y))
photo.app.dispatch(Event(kind = EventKind.pointer_moved, button = 2, x = x + 200.0, y = y + 120.0))
photo.app.dispatch(Event(kind = EventKind.pointer_up, button = 2, x = x + 200.0, y = y + 120.0))
if ticks == 30 and clicking:
let point = arguments[6].split(",")
let x = float(point[0])
let y = float(point[1])
photo.app.dispatch(Event(kind = EventKind.pointer_moved, x = x, y = y))
photo.app.dispatch(Event(kind = EventKind.pointer_down, button = 0, x = x, y = y))
photo.app.dispatch(Event(kind = EventKind.pointer_up, button = 0, x = x, y = y))
if ticks == 30 and looking:
photo.panels.presets.apply_mark(preset_marks.for_look(look_at))
if looking and ticks == 30 + look_after and capture < 0:
capture = 0
if ticks == 30 and film_copying:
photo.panels.presets.apply_mark(preset_marks.for_look(0))
if ticks == 34 and film_copying:
photo.panels.actions.copy_film.trigger()
grid.select(0)
photo.panels.show_selection(0)
photo.panels.actions.paste_film.trigger()
let index = photo.panels.library.index
print(f"copied from: {index.settings(position)}")
print(f"pasted onto: {index.settings(0)}")
if ticks == 60 and film_copying:
let box = grid.layout().bounds()
let x = box.x + 40.0
let y = box.y + 40.0
photo.app.dispatch(Event(kind = EventKind.pointer_moved, x = x, y = y))
photo.app.dispatch(Event(kind = EventKind.pointer_down, button = 1, x = x, y = y))
photo.app.dispatch(Event(kind = EventKind.pointer_up, button = 1, x = x, y = y))
if film_copying and ticks == 64 and capture < 0:
capture = 0
if ticks == 30 and comparing:
photo.panels.presets.apply_mark(preset_marks.for_look(0))
photo.panels.actions.before_after.trigger()
if ticks == 30 and moding:
photo.panels.set_mode(int(arguments[6]))
if ticks == 30 and switching:
photo.panels.open_library(arguments[6])
if ticks == 40 and undoing:
photo.panels.session.undo()
if ticks == 10 and exporting:
photo.panels.library_pane.grid.mark(position + 1, true)
photo.panels.export(0, 90, 2048, arguments[6])
if ticks == 30 and zoomed:
photo.panels.viewer.toggle_zoom()
if ticks == 30 and guiding:
photo.panels.properties.develop.set_guiding(true)
if ticks == 90 and capture < 0:
capture = 0
if ticks > 200:
photo.app.stop()
photo.panels.body.layout().invalidate())
# The frame after `begin` is the one read back; the next ends the run.
let observed = photo.app.on_frame(func (elapsed: float) -> unit!:
_ = elapsed
if capture == 0:
capture = 1
probe.begin(photo.app.title())
photo.panels.body.layout().invalidate()
elif capture == 1:
capture = 2
photo.app.stop())
photo.app.run()
observed.disconnect()
photo.app.cancel(timer)
probe.save(arguments[0])
probe.end()
photo.close()
return 0