File: ui_service.py

package info (click to toggle)
python-envisageplugins 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,616 kB
  • ctags: 1,970
  • sloc: python: 7,047; makefile: 11; sh: 11; lisp: 1
file content (135 lines) | stat: -rw-r--r-- 3,981 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#-----------------------------------------------------------------------------
#
#  Copyright (c) 2007 by Enthought, Inc.
#  All rights reserved.
#
#-----------------------------------------------------------------------------

"""
The UI service for the Data plugin.

"""

# Standard library imports.
import logging

# Enthought library imports.
from enthought.envisage.api import ApplicationObject, UOL
from enthought.pyface.api import confirm, error, FileDialog, information, YES

# Data library imports.

# Local imports.
from services import IDATA_MODEL


# Setup a logger for this module
logger = logging.getLogger(__name__)

    
class UiService(ApplicationObject):
    """
    The UI service for the Data plugin.

    """

    ##########################################################################
    # Attributes
    ##########################################################################

    #### public 'UiService' interface ########################################

    # A reference to the Data plugin's model service.
    model_service = UOL


    ##########################################################################
    # 'Object' interface
    ##########################################################################

    #### operator methods ####################################################

    def __init__(self, **kws):
        """
        Constructor.

        Extended to ensure our UOL properties are set.

        """

        super(UiService, self).__init__(**kws)

        # Ensure we have a default model-service if one wasn't specified.
        if self.model_service is None:
            self.model_service = 'service://%s' % IDATA_MODEL

        return


    ##########################################################################
    # 'UIService' interface
    ##########################################################################

    #### public methods ######################################################



    #TODO cgalvan: to be implemented
#    def delete_data(self, context, data_name, parent_window):
#        """
#        Delete a Data.
#
#        """
#
#        # Open confirmation-dialog to confirm deletion
#        message = 'Are you sure you want to delete %s?' % data_name
#        if confirm(parent_window, message) == YES:
#            self.model_service.delete_context_item(context, data_name)
#
#        return

    def edit_data(self, window, data):
        """
        Edit the data parameters of the specified data.

        """

        data_parameters = data.data_parameters

        edit_ui = data_parameters.edit_traits(view='data_view',
                                              kind = 'livemodal',
                                              # handler=handler,
                                              parent=window)

        return edit_ui.result

    def display_message(self, msg, title=None, is_error=False):
        """
        Display the specified message to the user.

        """

        # Ensure we record any reasons this method doesn't work.  Especially
        # since it's critical in displaying errors to users!
        try:

            # Attempt to identify the current application window.
            parent_window = None
            workbench = self.application.get_service('enthought.envisage.'
                'workbench.IWorkbench')
            if workbench is not None:
                parent_window = workbench.active_window.control

            # Display the requested message
            if is_error:
                error(parent_window, msg, title=title)
            else:
                information(parent_window, msg, title=title)

        except:
            logger.exception('Unable to display pop-up message')

        return

#### EOF #####################################################################