Example #1
0
def parse_menubar(element):
    Compiler.to_be_own_class = False

    if element.get("id") is None:
        addDefaultId(element)

    Compiler.code += element.get("id") + " = {}\n"
    Compiler.code += element.get("id") + "['bar'] = QMenuBar()\n"

    for menu in element:
        parse_menu(element.get("id"), "", menu)

    Compiler.to_be_own_class = True
Example #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)