Ejemplo n.º 1
0
def parse_toplevel(element):
    parse_abstract_element(element)  # use basic_widget to give the window basic widget features

    #     if element.__len__() == 1 and element[0].tag.lower() not in Compiler.constants.Layouts: # dialog/window has a central widget
    #         parse_abstract_element(element[0]) # parse that widget     and set it as central
    #         Compiler.code += element.get("id") + ".setCentralWidget(" + element[0].get("id") + ")\n"
    # layouts are implemented in oxide.parsing.widgets.core.base_widget()

    if element.tag.lower() == "window":
        Compiler.code += element.get("id") + ".show()#topleve;\n"  # then show the window
Ejemplo n.º 2
0
def parse_interface(interfacename):
    tree = xmlparse("views" + QDir.separator() + interfacename + ".xml").getroot() # get the tree
    Compiler.current_interfacename = interfacename # set the current interfacename
    imported = [] # this is the list of interfaces to parse after this one
    
    Compiler.code += "from PySide.QtGui import *\nfrom PySide.QtCore import *\n" # import PySide
    Compiler.code += "from oxide.widgets.all import *\n" # import Oxide
    if interfacename == Compiler.start: # if this is the start interface, create a QApplication
        Compiler.code += "import sys\n"         # using sys.argv,
        Compiler.code += "app = OxideApplication(sys.argv)\n" # create a QApplication
        
    add_util_funcs() # add the utility functions
    
    add_model(interfacename,"__main__") # now add the model code to the output file
    
    for element in tree: # iterate through the elements in the tree
        if element.tag.lower() == "animations": # here we handle the special 'animations' tag
            Compiler.to_be_own_class = False # there is no way that we're in the resources tag here
            for animation in element: # go through each animation
                parse_animation(animation) # and parse it
        
        elif element.tag.lower() == "window": # here we handle the window
            Compiler.to_be_own_class = False # there is no way that we're in the resources tag here
            parse_toplevel(element)       # using parse_window
            
        elif element.tag.lower() == "resources":
            Compiler.to_be_own_class = True
            
            for child in element:
                Compiler.direct_resources_child = True
                parse_abstract_element(child)
                Compiler.direct_resources_child = False
                    
            Compiler.direct_resources_child = False
            
        elif element.tag.lower() == "import":
            Compiler.code += "import " + element.get('interface') + "\n"
            imported.append(element.get('interface'))
                    
    if interfacename == Compiler.start: # to finish up, if this is the start file
        Compiler.code += "sys.exit(app.exec_())\n" # run the application
    
    # now it has come time to put the code on the filesystem        
    if not QDir("bin").exists(): # if the 'bin' folder doesn't exist
        QDir().mkdir("bin")     # create it
    interfacefile = open(Compiler.gendir + QDir.separator() + interfacename + ".py", 'w')
    interfacefile.write(Compiler.code) # write Compiler.code to the file
    
    Compiler.code = "" # reset Compiler.code
    
    for interface in imported:
        parse_interface(interface)