|
| 1 | +from traits.api import cached_property, Instance, Property |
| 2 | +from traitsui.api import Item, ModelView, View |
| 3 | +from traitsui.ui_editors.data_frame_editor import DataFrameEditor |
| 4 | + |
| 5 | +from pycasa.model.image_folder import ImageFolder |
| 6 | + |
| 7 | +DISPLAYED_COLUMNS = [ |
| 8 | + 'ApertureValue', 'ExifVersion', 'Model', 'Make', 'LensModel', 'DateTime', |
| 9 | + 'ShutterSpeedValue', 'XResolution', 'YResolution' |
| 10 | +] |
| 11 | + |
| 12 | + |
| 13 | +class ImageFolderView(ModelView): |
| 14 | + """ ModelView for a folder of images. |
| 15 | + """ |
| 16 | + model = Instance(ImageFolder) |
| 17 | + |
| 18 | + metadata_df = Property(depends_on="model.images.items") |
| 19 | + |
| 20 | + view = View( |
| 21 | + Item('model.directory', style="readonly", show_label=False), |
| 22 | + Item( |
| 23 | + 'metadata_df', |
| 24 | + editor=DataFrameEditor(columns=DISPLAYED_COLUMNS), |
| 25 | + show_label=False, |
| 26 | + width=1200, |
| 27 | + ), |
| 28 | + resizable=True |
| 29 | + ) |
| 30 | + |
| 31 | + @cached_property |
| 32 | + def _get_metadata_df(self): |
| 33 | + return self.model.create_metadata_df() |
| 34 | + |
| 35 | + |
| 36 | +if __name__ == '__main__': |
| 37 | + from os.path import dirname, join |
| 38 | + import ets_tutorial |
| 39 | + |
| 40 | + TUTORIAL_DIR = dirname(ets_tutorial.__file__) |
| 41 | + SAMPLE_IMG_DIR = join(TUTORIAL_DIR, "..", "sample_images") |
| 42 | + |
| 43 | + image_file = ImageFolder(directory=SAMPLE_IMG_DIR) |
| 44 | + view = ImageFolderView(model=image_file) |
| 45 | + view.configure_traits() |
0 commit comments