#!/usr/bin/python # -*- coding: utf-8 -*- # """ Nome: actions.py Autor: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com ) Descricão: TODO """ import sys import traceback from interface import * from segmentation import * from util import * DEBUG = True IException = Interface.InterfaceException f = File.File segmenter = Slic.Slic() image = None const_image = None segments = None def open_image(tk): global image, const_image def onclick(event): if event.xdata != None and event.ydata != None and int(event.ydata) != 0: x = int(event.xdata) y = int(event.ydata) tk.write_logger("Coordinates: x = %d y = %d ", x, y) if segments is not None: tk.append_logger("Segment = %d", segments[y, x]) imagename = tk.utils.ask_image_name() if imagename: image = f.open_image(imagename) name = f.get_filename(imagename) tk.write_logger("Opening %s...", name) tk.add_image(image, name, onclick) const_image = image def rotate_image(tk): global image, const_image if const_image is None: raise IException("Image not found") image = f.rotate_image(const_image) tk.write_logger("Rotating image 90 degrees") tk.refresh_image(image) const_image = image def close_image(tk): global const_image if const_image is None: raise IException("Image not found") if tk.close_image(): tk.write_logger("Closing image...") const_image = None segments = None def run_segmentation(tk): global image, const_image, segments if const_image is None: raise IException("Image not found") tk.write_logger("Running %s,,,", segmenter.get_name()) tk.append_logger("\nConfig: %s", str(segmenter.get_summary_config())) segments, image, run_time = segmenter.run(const_image) tk.append_logger("\nTime elapsed: %0.3f seconds", run_time) tk.refresh_image(image) def config_segmentation(tk): global segmenter title = "Configuring %s" % segmenter.get_name() tk.write_logger(title) current_config = segmenter.get_config() def process_config(): new_config = tk.get_config_and_destroy() segmenter.set_config(new_config) tk.append_logger("\nConfig updated: %s", str(segmenter.get_summary_config())) tk.dialogue_config(title, current_config, process_config) def func_not_available(tk): tk.write_logger("This functionality is not available right now.")