|
| 1 | +# coding=utf-8 |
| 2 | +""" TaskApplication object for the Pycasa app. |
| 3 | +""" |
| 4 | +import logging |
| 5 | + |
| 6 | +from pyface.tasks.api import TasksApplication, TaskFactory |
| 7 | +from pyface.api import SplashScreen |
| 8 | +from pyface.action.api import Action |
| 9 | +from pyface.action.schema.api import SchemaAddition, SGroup |
| 10 | + |
| 11 | +from ..ui.tasks.pycasa_task import PycasaTask |
| 12 | +from ..ui.image_resources import app_icon, new_icon |
| 13 | + |
| 14 | +logger = logging.getLogger(__name__) |
| 15 | + |
| 16 | + |
| 17 | +class PycasaApplication(TasksApplication): |
| 18 | + """ An application to explore image files and detect faces. |
| 19 | + """ |
| 20 | + id = "pycasa_application" |
| 21 | + |
| 22 | + name = "Pycasa" |
| 23 | + |
| 24 | + description = "An example Tasks application that explores image files." |
| 25 | + |
| 26 | + def _task_factories_default(self): |
| 27 | + return [ |
| 28 | + TaskFactory( |
| 29 | + id='pycasa.pycasa_task_factory', |
| 30 | + name="Main Pycasa Task Factory", |
| 31 | + factory=PycasaTask |
| 32 | + ) |
| 33 | + ] |
| 34 | + |
| 35 | + def _icon_default(self): |
| 36 | + return app_icon |
| 37 | + |
| 38 | + def _splash_screen_default(self): |
| 39 | + splash_screen = SplashScreen(image=app_icon) |
| 40 | + return splash_screen |
| 41 | + |
| 42 | + def create_new_task_window(self): |
| 43 | + from pyface.tasks.task_window_layout import TaskWindowLayout |
| 44 | + |
| 45 | + layout = TaskWindowLayout() |
| 46 | + layout.items = [self.task_factories[0].id] |
| 47 | + window = self.create_window(layout=layout) |
| 48 | + self.add_window(window) |
| 49 | + window.title += " {}".format(len(self.windows)) |
| 50 | + return window |
| 51 | + |
| 52 | + def create_new_task_menu(self): |
| 53 | + return SGroup( |
| 54 | + Action(name="New", |
| 55 | + accelerator='Ctrl+N', |
| 56 | + on_perform=self.create_new_task_window, |
| 57 | + image=new_icon), |
| 58 | + id='NewGroup', name='NewGroup', |
| 59 | + ) |
| 60 | + |
| 61 | + def _extra_actions_default(self): |
| 62 | + extra_actions = [ |
| 63 | + SchemaAddition(id='pycasa.custom_new', |
| 64 | + factory=self.create_new_task_menu, |
| 65 | + path="MenuBar/File/OpenGroup", |
| 66 | + absolute_position="first") |
| 67 | + ] |
| 68 | + return extra_actions |
0 commit comments