Debian Codegraph @

envisage/examples/demo/plugins/tasks/attractors/attractors_preferences.py

raw
1 # (C) Copyright 2007-2025 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10
11 from apptools.preferences.api import PreferencesHelper
12 from traits.api import Bool, Dict, Str
13 from traitsui.api import EnumEditor, HGroup, Item, Label, VGroup, View
14
15 # Enthought library imports.
16 from envisage.ui.tasks.api import PreferencesPane
17
18
19 class AttractorsPreferences(PreferencesHelper):
20 """The preferences helper for the Attractors application."""
21
22 #### 'PreferencesHelper' interface ########################################
23
24 # The path to the preference node that contains the preferences.
25 preferences_path = "example.attractors"
26
27 #### Preferences ##########################################################
28
29 # The task to activate on app startup if not restoring an old layout.
30 default_task = Str
31
32 # Whether to always apply the default application-level layout.
33 # See TasksApplication for more information.
34 always_use_default_layout = Bool
35
36
37 class AttractorsPreferencesPane(PreferencesPane):
38 """The preferences pane for the Attractors application."""
39
40 #### 'PreferencesPane' interface ##########################################
41
42 # The factory to use for creating the preferences model object.
43 model_factory = AttractorsPreferences
44
45 #### 'AttractorsPreferencesPane' interface ################################
46
47 task_map = Dict(Str, Str)
48
49 view = View(
50 VGroup(
51 HGroup(
52 Item("always_use_default_layout"),
53 Label("Always use the default active task on startup"),
54 show_labels=False,
55 ),
56 HGroup(
57 Label("Default active task:"),
58 Item(
59 "default_task", editor=EnumEditor(name="handler.task_map")
60 ),
61 enabled_when="always_use_default_layout",
62 show_labels=False,
63 ),
64 label="Application startup",
65 ),
66 resizable=True,
67 )
68
69 ###########################################################################
70 # Private interface.
71 ###########################################################################
72
73 def _task_map_default(self):
74 return dict(
75 (factory.id, factory.name)
76 for factory in self.dialog.application.task_factories
77 )