def test(): """Run object editor test""" import datetime, numpy as np from SMlib.pil_patch import Image image = Image.fromarray(np.random.random_integers(255, size=(100, 100))) example = { 'str': 'kjkj kj k j j kj k jkj', 'list': [1, 3, 4, 'kjkj', None], 'dict': { 'd': 1, 'a': np.random.rand(10, 10), 'b': [1, 2] }, 'float': 1.2233, 'array': np.random.rand(10, 10), 'image': image, 'date': datetime.date(1945, 5, 8), 'datetime': datetime.datetime(1945, 5, 8), } image = oedit(image) class Foobar(object): def __init__(self): self.text = "toto" foobar = Foobar() print oedit(foobar) print oedit(example) print oedit(np.random.rand(10, 10)) print oedit(oedit.__doc__) print example
def create_dialog(obj, obj_name): """Creates the editor dialog and returns a tuple (dialog, func) where func is the function to be called with the dialog instance as argument, after quitting the dialog box The role of this intermediate function is to allow easy monkey-patching. (uschmitt suggested this indirection here so that he can monkey patch oedit to show eMZed related data) """ # Local import from SMlib.widgets.texteditor import TextEditor from SMlib.widgets.dicteditorutils import (ndarray, FakeObject, Image, is_known_type) from SMlib.widgets.dicteditor import DictEditor from SMlib.widgets.arrayeditor import ArrayEditor conv_func = lambda data: data readonly = not is_known_type(obj) if isinstance(obj, ndarray) and ndarray is not FakeObject: dialog = ArrayEditor() if not dialog.setup_and_check(obj, title=obj_name, readonly=readonly): return elif isinstance(obj, Image) and Image is not FakeObject \ and ndarray is not FakeObject: dialog = ArrayEditor() import numpy as np data = np.array(obj) if not dialog.setup_and_check(data, title=obj_name, readonly=readonly): return from SMlib.pil_patch import Image conv_func = lambda data: Image.fromarray(data, mode=obj.mode) elif isinstance(obj, (str, unicode)): dialog = TextEditor(obj, title=obj_name, readonly=readonly) else: dialog = DictEditor() dialog.setup(obj, title=obj_name, readonly=readonly) def end_func(dialog): return conv_func(dialog.get_value()) return dialog, end_func
def test(): """Run object editor test""" import datetime, numpy as np from SMlib.pil_patch import Image image = Image.fromarray(np.random.random_integers(255, size=(100, 100))) example = {'str': 'kjkj kj k j j kj k jkj', 'list': [1, 3, 4, 'kjkj', None], 'dict': {'d': 1, 'a': np.random.rand(10, 10), 'b': [1, 2]}, 'float': 1.2233, 'array': np.random.rand(10, 10), 'image': image, 'date': datetime.date(1945, 5, 8), 'datetime': datetime.datetime(1945, 5, 8), } image = oedit(image) class Foobar(object): def __init__(self): self.text = "toto" foobar = Foobar() print oedit(foobar) print oedit(example) print oedit(np.random.rand(10, 10)) print oedit(oedit.__doc__) print example