| 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 |
""" An action that displays the preferences dialog. """ |
| 11 |
|
| 12 |
|
| 13 |
from pyface.action.api import Action |
| 14 |
|
| 15 |
# Enthought library imports. |
| 16 |
from pyface.api import ImageResource |
| 17 |
|
| 18 |
|
| 19 |
class EditPreferencesAction(Action): |
| 20 |
"""An action that displays the preferences dialog.""" |
| 21 |
|
| 22 |
#### 'Action' interface ################################################### |
| 23 |
|
| 24 |
# A longer description of the action. |
| 25 |
description = "Manage Preferences" |
| 26 |
|
| 27 |
# The action's image (displayed on tool bar tools etc). |
| 28 |
image = ImageResource("preferences") |
| 29 |
|
| 30 |
# The action's name (displayed on menus/tool bar tools etc). |
| 31 |
name = "Preferences" |
| 32 |
|
| 33 |
# A short description of the action used for tooltip text etc. |
| 34 |
tooltip = "Manage Preferences" |
| 35 |
|
| 36 |
########################################################################### |
| 37 |
# 'Action' interface. |
| 38 |
########################################################################### |
| 39 |
|
| 40 |
def perform(self, event): |
| 41 |
"""Performs the action.""" |
| 42 |
|
| 43 |
from apptools.preferences.ui.api import PreferencesManager |
| 44 |
|
| 45 |
# Lookup the preferences manager service. |
| 46 |
manager = event.window.application.get_service(PreferencesManager) |
| 47 |
ui = manager.edit_traits(parent=event.window.control, kind="modal") |
| 48 |
|
| 49 |
# If the user hit the "Ok" button, then save the preferences in case |
| 50 |
# application crashes before it exits! |
| 51 |
if ui.result: |
| 52 |
self.window.application.preferences.save() |