Check-in [fa872bf983]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:
  • Forgotten to register exception translators for protocol errors.
  • Add exception handler for generic protocol errors in minx.core.wm event loop.
Timelines: family | ancestors | descendants | both | dev1.x
Files: files | file ages | folders
SHA1:fa872bf983fc73243447729df5c066e9d35ce951
User & Date: manuv 2013-07-28 13:06:07
Context
2013-07-28
14:56
  • Added support for end-user hook to create layouts before managing existing windows and entering event loop.
  • Made the display and root_windows members of the minx.core.wm class public (i.e., removed leading underscore) so that they can be accessed by the init_hook.
  • Removed unnecessary layout creation in wm.start() because the default layout logic in the layman.receptive_layout() method takes care of this already.
check-in: ac0236beec user: manuv tags: dev1.x
13:06
  • Forgotten to register exception translators for protocol errors.
  • Add exception handler for generic protocol errors in minx.core.wm event loop.
check-in: fa872bf983 user: manuv tags: dev1.x
12:49
Centralized Boost.Python converter registration in python.cc because, for example, both minxlib::display and minxlib::window return STL vectors of window objects and we would like to avoid registering duplicate converters for the same types, a situation more likely to arise when the converters are registered from the pythonize() functions of the different classes. check-in: 471330b4ef user: manuv tags: dev1.x
Changes

Changes to core/wm.py.

446
447
448
449
450
451
452




453
454
455
456
457
458
459
            # remove it later on during development when the design has
            # stabilized enough for us to be absolutely sure this bit of
            # code is no longer required.
            except minxlib.change_window_attributes as e:
                logger.warning(e)
                if e.error_code == minxlib.bad_window:
                   pass # ignore protocol error (should be okay)





            # Some other exception: log it and keep going
            except:
                logger.warning('received {} exception'.
                               format(sys.exc_info()[0]))
                logger.debug(traceback.format_exc())








>
>
>
>







446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
            # remove it later on during development when the design has
            # stabilized enough for us to be absolutely sure this bit of
            # code is no longer required.
            except minxlib.change_window_attributes as e:
                logger.warning(e)
                if e.error_code == minxlib.bad_window:
                   pass # ignore protocol error (should be okay)

            # Generic protocol error
            except minxlib.protocol_error as e:
                logger.warning(e)

            # Some other exception: log it and keep going
            except:
                logger.warning('received {} exception'.
                               format(sys.exc_info()[0]))
                logger.debug(traceback.format_exc())

Changes to minxlib/exception.cc.

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
311
312
313
314
315
316
317

318
319
320
321
322
323
324
...
392
393
394
395
396
397
398

399
400
401
402
403
404
405
}

// For all subclasses: retrieve the Python exception class corresponding
// to your type.
PyObject* exception::get_py_exception(type_info t)
{
    py_exception_map::const_iterator it = m_py_exception_map.find(t) ;
    if (it == m_py_exception_map.end()) // unregistered subclass! BUG!
        return m_py_exception_map[typeid(exception)] ;
    return it->second ;
}

// Expose C++ exception class to Python
void exception::pythonize()
{
................................................................................

// Expose protocol_error and its subclasses to Python
void protocol_error::pythonize()
{
    const char* py_name = "protocol_error" ;

    // Create Boost.Python wrapper for protocol_error class

    py::class_<protocol_error, py::bases<exception>,
               boost::shared_ptr<protocol_error> >(py_name, py::no_init).
        def_readonly("serial",       &protocol_error::serial      ).
        def_readonly("error_code",   &protocol_error::error_code  ).
        def_readonly("request_code", &protocol_error::request_code).
        def_readonly("minor_code",   &protocol_error::minor_code  ).
        def_readonly("resource_id",  &protocol_error::resource_id ).
................................................................................
    subclass::subclass(const XErrorEvent* e): protocol_error(e) {}          \
                                                                            \
    void subclass::pythonize()                                              \
    {                                                                       \
        const char* py_name = #subclass ;                                   \
        PyObject*   py_base = get_py_exception(typeid(protocol_error)) ;    \
                                                                            \

        py::class_<subclass, py::bases<protocol_error> >(py_name,           \
                                                         py::no_init).      \
            def(py::self_ns::str(py::self_ns::self)) ;                      \
        set_py_exception(typeid(subclass),                                  \
                         create_py_exception(py_name, py_base)) ;           \
    }                                                                       \
                                                                            \







|







 







>







 







>







100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
}

// For all subclasses: retrieve the Python exception class corresponding
// to your type.
PyObject* exception::get_py_exception(type_info t)
{
    py_exception_map::const_iterator it = m_py_exception_map.find(t) ;
    if ( it == m_py_exception_map.end()) // unregistered subclass! BUG!
        return m_py_exception_map[typeid(exception)] ;
    return it->second ;
}

// Expose C++ exception class to Python
void exception::pythonize()
{
................................................................................

// Expose protocol_error and its subclasses to Python
void protocol_error::pythonize()
{
    const char* py_name = "protocol_error" ;

    // Create Boost.Python wrapper for protocol_error class
    register_translator<protocol_error>() ;
    py::class_<protocol_error, py::bases<exception>,
               boost::shared_ptr<protocol_error> >(py_name, py::no_init).
        def_readonly("serial",       &protocol_error::serial      ).
        def_readonly("error_code",   &protocol_error::error_code  ).
        def_readonly("request_code", &protocol_error::request_code).
        def_readonly("minor_code",   &protocol_error::minor_code  ).
        def_readonly("resource_id",  &protocol_error::resource_id ).
................................................................................
    subclass::subclass(const XErrorEvent* e): protocol_error(e) {}          \
                                                                            \
    void subclass::pythonize()                                              \
    {                                                                       \
        const char* py_name = #subclass ;                                   \
        PyObject*   py_base = get_py_exception(typeid(protocol_error)) ;    \
                                                                            \
        register_translator<subclass>() ;                                   \
        py::class_<subclass, py::bases<protocol_error> >(py_name,           \
                                                         py::no_init).      \
            def(py::self_ns::str(py::self_ns::self)) ;                      \
        set_py_exception(typeid(subclass),                                  \
                         create_py_exception(py_name, py_base)) ;           \
    }                                                                       \
                                                                            \

Changes to minxlib/exception.hh.

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
        translator for their type. It simply generates a translator for
        type T (which is the exception::translate<T>() function) and calls
        the appropriate @boostpylink API to register
        exception::translate<T>() as the exception translator for type T.
    */
    template<typename T>
    static void register_translator() {
        boost::python::register_exception_translator<T>(translate<T>) ;
    }

public:
    /**
        @brief  Expose exception interface to Python.
        @return Nothing.








|







252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
        translator for their type. It simply generates a translator for
        type T (which is the exception::translate<T>() function) and calls
        the appropriate @boostpylink API to register
        exception::translate<T>() as the exception translator for type T.
    */
    template<typename T>
    static void register_translator() {
        py::register_exception_translator<T>(translate<T>) ;
    }

public:
    /**
        @brief  Expose exception interface to Python.
        @return Nothing.