Exemplo n.º 1
0
 def Compiler_FormLayout(element):  # @NoSelf
     for child in element:
         oxide.parsing.widgets.core.parse_abstract_element(child)
         if child.get('field-name') is not None: # this widget should be added as a form field
             Compiler.code += element.get("id") + ".addRow('" + prepStr(child.get('field-name')) + "', " + child.get('id') + ")\n"
         elif child.tag.lower() in WidgetRegister.layoutCompilers.keys(): # this is a layout
             Compiler.code += element.get('id') + ".addRow(" + child.get('id') + ")\n"
Exemplo n.º 2
0
def base_object(element):
    element_tag = element.tag.lower()
    
    # check that the element represents a known widget type
    try: WidgetRegister.types[element_tag]
    except KeyError: raise UnkownWidgetError("'" + element.tag + "' is not a known widget type")
    
    # here we put in the constructor and check that this is a known widget type
    if Compiler.direct_resources_child is False: # the code should not be wrapped in a class
        Compiler.code += "\n"
        if element.get("id") is None: # if the id has been omitted
            addDefaultId(element)  # generate a default one and add it to the element
        if Compiler.to_be_own_class is True: element.set("id","self." + element.get('id'))
            
        indent()
        Compiler.code += element.get("id") + " = " + WidgetRegister.types[element_tag]['widgetName'] + "("
        if WidgetRegister.types[element_tag].get('isqt',False) is False: # if this is an oxide widget
            Compiler.code += "'" + prepStr(element.get("styletype","default")) + "'"
        Compiler.code += ")\n"
        
    else: # the code should be wrapped in a class
        if element.get('name') is None: raise MissingAttributeError(element.tag + " has no name.")
        if element.get('name').startswith("__"): raise ForbiddenNameError("'name' attribute may not begin with '__'")
        Compiler.code += "class " + element.get("name") + "(" + WidgetRegister.types[element_tag]['widgetName'] + "):\n"
        element.set("id","self")
        
        add_class_funcs(WidgetRegister.types[element_tag]['widgetName']) # add any utility functions for the class
        
        # add the model code
        add_model(Compiler.current_interfacename,element.get('name'))
        
        # __init__ function definition
        Compiler.code += Compiler.model_indent + "def __init__(self, " + ", ".join(WidgetRegister.types[element_tag].get('init_args',[])) + "):\n" 

        Compiler.code += Compiler.model_indent*2 + WidgetRegister.types[element_tag]['widgetName'] + ".__init__(self, " # basic constructor 
        if WidgetRegister.types[element_tag].get('isqt',False) is False: # if this is an oxide widget
            Compiler.code += "'" + prepStr(element.get("styletype","default")) + "'" # the add the style type
        Compiler.code +=  ", ".join(WidgetRegister.types[element_tag].get('init_args',[])) + ")\n" # give it the necessary __init__ arguments
        
        
    handleProps(WidgetRegister.types[element_tag],element) # handle properites
    handleSlots(WidgetRegister.types[element_tag], element) # handle events/signals/slots
    
    if WidgetRegister.types[element_tag].get('isqt',False) is False: # if this is an oxide widget
        handleStyleProps(WidgetRegister.types[element_tag],element)