Exemple #1
0
def base_widget(element):
    element_tag = element.tag.lower()
    
    base_object(element) # add basic node features
    
    # all text is handled within this try/except block  
    try:
        if element.text is not None:
            element_text = element.text.strip()
            
            if WidgetRegister.types[element_tag].get('single-line-text',False) is True:
                element_text = element.text.replace("\n","")
            indent() # indent if necessary
            Compiler.code += element.get("id") + "." + WidgetRegister.types[element_tag]['text'] + "('" + element_text + "')\n"
    except KeyError: pass # element must not support text
    
    # handle properties
    handleProps(WidgetRegister.types['qwidget'], element)
    if WidgetRegister.types[element_tag].get('isqt',False) is False: # if this is an oxide widget
        handleProps(WidgetRegister.types['basewidget'], element) # give it oxide properties
    
    # handle signal-slot mechanisms
    handleSlots(WidgetRegister.types['qwidget'], element)
    if WidgetRegister.types[element_tag].get('isqt',False) is False: # if this is an oxide widget
        handleSlots(WidgetRegister.types['basewidget'], element) # give it oxide slots
Exemple #2
0
def parse_menu(rootid, idstring, menu):
    if menu.get("name") is None:
        raise MissingAttributeError(menu.tag + " is missing 'name' attribute")

    if idstring == "":
        is_root_menu = True
        idstring = menu.get("name")
    else:
        is_root_menu = False

    Compiler.code += rootid + "['" + idstring + "'] = QMenu('" + menu.get("name") + "')\n"

    menu.set("id", rootid + "['" + idstring + "']")
    handleProps(WidgetRegister.types["action"], menu)

    if is_root_menu:
        Compiler.code += rootid + "['bar']"
    else:
        Compiler.code += rootid + "['" + " -> ".join(idstring.split(" -> ")[:-1]) + "']"
    Compiler.code += ".addMenu(" + rootid + "['" + idstring + "']" + ")\n"

    for item in menu:
        if item.tag.lower() == "action":
            if menu.get("name") is None:
                raise MissingAttributeError(item.tag + " is missing 'name' attribute")

            Compiler.code += (
                rootid + "['" + idstring + " -> " + item.get("name") + "'] = QAction('" + item.get("name") + "', "
            )
            Compiler.code += rootid + "['" + idstring + "'])\n"

            item.set("id", rootid + "['" + idstring + " -> " + item.get("name") + "']")
            handleProps(WidgetRegister.types["action"], item)

            Compiler.code += (
                rootid
                + "['"
                + idstring
                + "'].addAction("
                + rootid
                + "['"
                + idstring
                + " -> "
                + item.get("name")
                + "'])\n"
            )

        elif item.tag.lower() == "menu":
            if menu.get("name") is None:
                raise MissingAttributeError(item.tag + " is missing 'name' attribute")
            parse_menu(rootid, idstring + " -> " + item.get("name"), item)

        elif item.tag.lower() == "separator":
            Compiler.code += rootid + "['" + idstring + "'].addSeparator()\n"
Exemple #3
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)