plcopen/XSLTModelQuery.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 16 Feb 2018 18:38:30 +0100
changeset 1941 cde74a39df51
parent 1940 8dc4ebc97777
child 1943 9dc0e38552b2
permissions -rw-r--r--
Fixed Exception dialog disapearing after a view second when exception occurs during app startup.
Problem was caused by splashscreen timeout, wx closing averything else if there is no more main frame.
Changes:
- no more timeout for splashscreen
- use wx.App OnInit method to give first operation to mainloop, object are then now created in mainloop
- main loop is then created _before_ showing splash screen
- no more wxyield or wx processevent tricks needed to display splash screen
- exception handler not blocking anymore on dialog (callafter)
- because of mainloop being there before everything, exit must be called explicitely if exception caught during startup -> exit parameter in handle_exception + try/except around startup calls

UNTESTED ON WINDOWS
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of Beremiz.
# See COPYING file for copyrights details.

from __future__ import absolute_import
import os
from lxml import etree
import util.paths as paths
from plcopen.structures import StdBlckLibs

ScriptDirectory = paths.AbsDir(__file__)

class XSLTModelQuery(object):
    """ a class to handle XSLT queries on project and libs """
    def __init__(self, controller, xsltpath, ext = []):
        # arbitrary set debug to false, updated later
        self.debug = False

        # merge xslt extensions for library access to query specific ones
        xsltext = [
            ("GetProject", lambda *_ignored: 
                controller.GetProject(self.debug)),
            ("GetStdLibs", lambda *_ignored: 
                [lib for lib in StdBlckLibs.values()]),
            ("GetExtensions", lambda *_ignored: 
                [ctn["types"] for ctn in controller.ConfNodeTypes])
        ] + ext

        # parse and compile. "beremiz" arbitrary namespace for extensions 
        self.xslt = etree.XSLT(
            etree.parse(
                os.path.join(ScriptDirectory, xsltpath),
                etree.XMLParser()),
            extensions={ ("beremiz", name):call for name, call in xsltext})

    def _process_xslt(self, root, debug, **kwargs):
        self.debug = debug
        return self.xslt(root,**{k:etree.XSLT.strparam(v) for k,v in kwargs.iteritems()})