File: toolkit.py

package info (click to toggle)
matplotlib 0.98.1-1%2Blenny4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,624 kB
  • ctags: 22,599
  • sloc: python: 76,915; cpp: 63,459; ansic: 5,353; makefile: 111; sh: 12
file content (353 lines) | stat: -rw-r--r-- 13,033 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#------------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license.  The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#
# Author: David C. Morrill
# Date: 10/07/2004
#
#  Symbols defined: toolkit
#
#------------------------------------------------------------------------------
""" Defines the stub functions used for creating concrete implementations of
the standard EditorFactory subclasses supplied with the Traits package.

"""
#-------------------------------------------------------------------------------
#  Imports:
#-------------------------------------------------------------------------------

from enthought.traits.api \
    import HasTraits, HasPrivateTraits, TraitError

from ui_traits \
    import SequenceTypes

#-------------------------------------------------------------------------------
#  Constants:
#-------------------------------------------------------------------------------

# List of implemented UI toolkits
TraitUIToolkits = [ 'wx', 'null' ]

#-------------------------------------------------------------------------------
#  Data:
#-------------------------------------------------------------------------------

# The current GUI toolkit object being used
_toolkit = None

#-------------------------------------------------------------------------------
#  Low-level GUI toolkit selection function:
#-------------------------------------------------------------------------------

def toolkit ( *toolkits ):
    """ Selects and returns a low-level GUI toolkit.

    Use this function to get a reference to the current toolkit.
    """
    global _toolkit

    if len( toolkits ) == 0:
        if _toolkit is not None:
            return _toolkit
        toolkits = TraitUIToolkits
    for toolkit_name in toolkits:
        try:
            package  = 'enthought.traits.ui.' + toolkit_name
            module   = __import__( package )
            _toolkit = getattr( module.traits.ui, toolkit_name ).toolkit
            return _toolkit
        except ImportError:
            pass
    else:
        raise TraitError, ("Could not find any UI toolkit called: %s" %
                           ', '.join( toolkits ))

#-------------------------------------------------------------------------------
#  'Toolkit' class (abstract base class):
#-------------------------------------------------------------------------------

class Toolkit ( HasPrivateTraits ):
    """ Abstract base class for GUI toolkits.
    """
    #---------------------------------------------------------------------------
    #  Create GUI toolkit specific user interfaces using information from the
    #  specified UI object:
    #---------------------------------------------------------------------------

    def ui_panel ( self, ui, parent ):
        """ Creates a GUI-toolkit-specific panel-based user interface using
            information from the specified UI object.
        """
        raise NotImplementedError

    def ui_subpanel ( self, ui, parent ):
        """ Creates a GUI-toolkit-specific subpanel-based user interface using
            information from the specified UI object.
        """
        raise NotImplementedError

    def ui_livemodal ( self, ui, parent ):
        """ Creates a GUI-toolkit-specific modal "live update" dialog user
            interface using information from the specified UI object.
        """
        raise NotImplementedError

    def ui_live ( self, ui, parent ):
        """ Creates a GUI-toolkit-specific non-modal "live update" window user
            interface using information from the specified UI object.
        """
        raise NotImplementedError

    def ui_modal ( self, ui, parent ):
        """ Creates a GUI-toolkit-specific modal dialog user interface using
            information from the specified UI object.
        """
        raise NotImplementedError

    def ui_nonmodal ( self, ui, parent ):
        """ Creates a GUI-toolkit-specific non-modal dialog user interface using
            information from the specified UI object.
        """
        raise NotImplementedError

    def ui_wizard ( self, ui, parent ):
        """ Creates a GUI-toolkit-specific wizard dialog user interface using
            information from the specified UI object.
        """
        raise NotImplementedError

    def view_application ( self, context, view, kind = None, handler = None,
                                      id = '', scrollable = None, args = None ):
        """ Creates a GUI-toolkit-specific modal dialog user interface that
            runs as a complete application using information from the
            specified View object.

        Parameters
        ----------
        context : object or dictionary
            A single object or a dictionary of string/object pairs, whose trait
            attributes are to be edited. If not specified, the current object is
            used.
        view : view or string
            A View object that defines a user interface for editing trait
            attribute values.
        kind : string
            The type of user interface window to create. See the
            **enthought.traits.ui.view.kind_trait** trait for values and
            their meanings. If *kind* is unspecified or None, the **kind**
            attribute of the View object is used.
        handler : Handler object
            A handler object used for event handling in the dialog box. If
            None, the default handler for Traits UI is used.
        id : string
            A unique ID for persisting preferences about this user interface,
            such as size and position. If not specified, no user preferences
            are saved.
        scrollable : Boolean
            Indicates whether the dialog box should be scrollable. When set to
            True, scroll bars appear on the dialog box if it is not large enough
            to display all of the items in the view at one time.

        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Positions the associated dialog window on the display:
    #---------------------------------------------------------------------------

    def position ( self, ui ):
        """ Positions the associated dialog window on the display.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Shows a 'Help' window for a specified UI and control:
    #---------------------------------------------------------------------------

    def show_help ( self, ui, control ):
        """ Shows a Help window for a specified UI and control.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Sets the title for the UI window:
    #---------------------------------------------------------------------------

    def set_title ( self, ui ):
        """ Sets the title for the UI window.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Sets the icon for the UI window:
    #---------------------------------------------------------------------------

    def set_icon ( self, ui ):
        """ Sets the icon for the UI window.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Saves user preference information associated with a UI window:
    #---------------------------------------------------------------------------

    def save_window ( self, ui ):
        """ Saves user preference information associated with a UI window.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Rebuilds a UI after a change to the content of the UI:
    #---------------------------------------------------------------------------

    def rebuild_ui ( self, ui ):
        """ Rebuilds a UI after a change to the content of the UI.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Converts a keystroke event into a corresponding key name:
    #---------------------------------------------------------------------------

    def key_event_to_name ( self, event ):
        """ Converts a keystroke event into a corresponding key name.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Hooks all interesting events for all controls in a ui so that they can
    #  be routed to the corrent event handler:
    #---------------------------------------------------------------------------

    def hook_events ( self, ui, control ):
        """ Hooks all interesting events for all controls in a UI so that they
            can be routed to the correct event handler.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  Routes a 'hooked' event to the corrent handler method:
    #---------------------------------------------------------------------------

    def route_event ( self, ui, event ):
        """ Routes a "hooked" event to the corrent handler method.
        """
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  GUI toolkit dependent trait definitions:
    #---------------------------------------------------------------------------

    def color_trait ( self, *args, **traits ):
        raise NotImplementedError

    def rgb_color_trait ( self, *args, **traits ):
        raise NotImplementedError

    def font_trait ( self, *args, **traits ):
        raise NotImplementedError

    #---------------------------------------------------------------------------
    #  'EditorFactory' factory methods:
    #---------------------------------------------------------------------------

    def array_editor ( self, *args, **traits ):
        raise NotImplementedError

    def boolean_editor ( self, *args, **traits ):
        raise NotImplementedError

    def button_editor ( self, *args, **traits ):
        raise NotImplementedError

    def check_list_editor ( self, *args, **traits ):
        raise NotImplementedError

    def code_editor ( self, *args, **traits ):
        raise NotImplementedError

    def color_editor ( self, *args, **traits ):
        raise NotImplementedError

    def compound_editor ( self, *args, **traits ):
        raise NotImplementedError

    def custom_editor ( self, *args, **traits ):
        raise NotImplementedError

    def directory_editor ( self, *args, **traits ):
        raise NotImplementedError

    def drop_editor ( self, *args, **traits ):
        raise NotImplementedError

    def dnd_editor ( self, *args, **traits ):
        raise NotImplementedError

    def enum_editor ( self, *args, **traits ):
        raise NotImplementedError

    def file_editor ( self, *args, **traits ):
        raise NotImplementedError

    def font_editor ( self, *args, **traits ):
        raise NotImplementedError

    def key_binding_editor ( self, *args, **traits ):
        raise NotImplementedError

    def html_editor ( self, *args, **traits ):
        raise NotImplementedError

    def image_enum_editor ( self, *args, **traits ):
        raise NotImplementedError

    def instance_editor ( self, *args, **traits ):
        raise NotImplementedError

    def list_editor ( self, *args, **traits ):
        raise NotImplementedError

    def null_editor ( self, *args, **traits ):
        raise NotImplementedError

    def ordered_set_editor ( self, *args, **traits ):
        raise NotImplementedError

    def plot_editor ( self, *args, **traits ):
        raise NotImplementedError

    def range_editor ( self, *args, **traits ):
        raise NotImplementedError

    def rgb_color_editor ( self, *args, **traits ):
        raise NotImplementedError

    def shell_editor ( self, *args, **traits ):
        raise NotImplementedError

    def table_editor ( self, *args, **traits ):
        raise NotImplementedError

    def text_editor ( self, *args, **traits ):
        raise NotImplementedError

    def title_editor ( self, *args, **traits ):
        raise NotImplementedError

    def tree_editor ( self, *args, **traits ):
        raise NotImplementedError

    def tuple_editor ( self, *args, **traits ):
        raise NotImplementedError

    def value_editor ( self, *args, **traits ):
        raise NotImplementedError