Beispiel #1
0
def component(cls):
    js_annots = _get_js_annots(cls)
    jscls = JSDict(js_annots)
    attr_dict = {}
    if hasattr(cls, 'ComponentData'):
        data = cls.ComponentData
        for a in Component.METADATA:
            if hasattr(data, a):
                attr_dict[a] = getattr(data, a)
        if hasattr(data, 'directives'):
            attr_dict['directives'] = []
            for d in data.directives:
                if hasattr(d, '_component') and d._component is not None:
                    attr_dict['directives'].append(
                        javascript.pyobj2jsobj(d._component))
                elif type(d) == type(""):
                    attr_dict['directives'].append(jsimport(d))
                elif issubclass(d, directives.Self):
                    attr_dict['directives'].append(js_annots['constructor'])
                else:
                    attr_dict['directives'].append(d)

        if hasattr(data, 'ViewElements'):
            attr_dict['queries'] = {}
            for k in dir(data.ViewElements):
                if not k[0] == '_':
                    val = getattr(data.ViewElements, k)
                    attr_dict['queries'][k] = val.to_js()
            attr_dict['queries'] = JSDict(attr_dict['queries'])

        if hasattr(data, 'Inputs'):
            attr_dict['inputs'] = []
            for k in dir(data.Inputs):
                if not k[0] == '_':
                    attr_dict['inputs'].append(k)

        if hasattr(data, 'Outputs'):
            attr_dict['outputs'] = []
            for k in dir(data.Outputs):
                if not k[0] == '_':
                    attr_dict['outputs'].append(k)

    meta = JSDict(attr_dict)
    logger.debug("Meta:", meta)
    logger.debug("CLS:", jscls)

    cls._component = jsng.core.Component(meta).Class(jscls)
    return cls
Beispiel #2
0
import javascript
from browser import document
from .jsdict import JSDict
from .services import ServiceFactory
from jsmodules import jsimport
from jsconverters import pyobj2js
from lib.logger import Logger

jsng = jsimport('ng')
logger = Logger(__name__, level=Logger.SEVERITY_ERROR)


class _ng:
    class core:
        ViewChild = javascript.JSConstructor(jsng.core.ViewChild)


class Query:
    def to_js(self):
        return javascript.pyobj2jsobj(self._ng_obj)


class ViewChild(Query):
    def __init__(self, reference):
        if hasattr(reference, '_component'):
            self._ref = reference
        else:
            self._ref = reference
        self._ng_obj = _ng.core.ViewChild(self._ref)

import javascript
from browser import console

import lib.angular.core as ngcore
from jsconverters import pyobj2js
from jsmodules import jsimport
from lib.RPCClient import RPCClient

from components.test import ClickComponent, RPCServiceComponent
from components import CodeMirrorComponent, Doc




primeng = jsimport("primeng")

@ngcore.component
class TestComponent(ngcore.Component):

    class ComponentData:
        selector = 'test-app'
        templateUrl = "app/templates/test/test.component.html"
        directives = [ClickComponent,CodeMirrorComponent,RPCServiceComponent]

        class ViewElements:
            header = ngcore.ViewChild('header')


    def __init__(self):
        super(TestComponent,self).__init__()
        console.log("Initializing App")
Beispiel #4
0
import javascript
from browser import timer
from jsmodules import jsimport
from lib.angular import core as ngcore
from lib.logger import Logger

logger = Logger(__name__)

CodeMirror = jsimport('CodeMirror')
CodeMirror.js_func = CodeMirror
CM = javascript.JSConstructor(CodeMirror)


class Doc:
    @ngcore.export2js
    def __init__(self, val=''):
        self._val = val
        self.change = ngcore.Output()

    def on_change(self, change):
        self._val = change.value

    @property
    def value(self):
        return self._val

    @value.setter
    def value(self, val):
        self._val = val
        self.change.emit(val)
Beispiel #5
0
import sys

from app_component import AppComponent
from lib.angular.core import bootstrap,JSDict,_js_constructor
from jsconverters import pyobj2js

from jsmodules import jsimport
jsng = jsimport('ng')

from lib.logger import Logger
logger = Logger(__name__)


class MyExceptionHandler:
    def __init__(self):
        logger.debug("Initializing exception handler")
        pass

    def call(self, *args):
        logger.debug("Calling my exception Handler")
        logger.debug("ARGLEN:",len(args))
        logger.debug("Arguments:", *args)
        logger.debug("DIR 0", dir(args[0]))
        try:
            pass
            #logger.exception(ex)
        except:
            logger.error(*args)

    def exceptionToString(self, *args):
        logger.debug("Calling my exception to string")
import javascript
from browser import timer
from jsmodules import jsimport
from lib.angular import core as ngcore
from lib.logger import Logger

logger = Logger(__name__)


CodeMirror = jsimport('CodeMirror')
CodeMirror.js_func = CodeMirror
CM = javascript.JSConstructor(CodeMirror)


class Doc:
    @ngcore.export2js
    def __init__(self,val=''):
        self._val=val
        self.change = ngcore.Output()

    def on_change(self,change):
        self._val = change.value

    @property
    def value(self):
        return self._val

    @value.setter
    def value(self,val):
        self._val = val
        self.change.emit(val)