def basicWidget(widgetName,element,root,interfacename,iswindow=True): code = "" if not root.tag == "buffer": code += formatCode(element.get("id")," = Q",widgetName,"()",iw=iswindow) # the check for an element having an id comes before basicWidget is called # here we have the init function, which is passed the widget if element.get("init") is not None: code += formatCode(element.get("init"), "(" + element.get("id"), ")\n") ######################### QWidget Events ######################### if element.get("mouse-pressed") is not None: code += formatCode(element.get("id"),".mousePressEvent = ",element.get("mouse-pressed"),iw=iswindow) code += captan.props.handleProps(types['basicwidget'], element, interfacename, iswindow) ######################## QWidget Metrics ######################### # if element.get("width") is not None: # code += formatCode(element.get("id"),".setFixedWidth(",element.get("width"),")",iw=iswindow) ################### QWidget Windows Properties #################### # if element.get("title") is not None: # code += formatCode(element.get("id"),".setWindowTitle('",prepStr(element.get("title")),"')",iw=iswindow) return code
def parseWidget(widgetType,element,root,mainWindowId,interfacename, iswindow): code = "" code += basicWidget(widgetType['widgetName'], element, root, interfacename,iswindow=iswindow) # initialize its QWidget features # now we add it to a layout, if its in one if root.tag.lower() in BoxLayouts: code += formatCode(root.get("id") + ".addWidget(" + element.get("id") + ", ", element.get("stretch","0") + ", " + element.get("alignment","0") + ")", iw=iswindow) # or if it is central, make it so elif element.get("central") is not None or \ (root.__len__() == 1 and root.get("id") == mainWindowId): code += formatCode(mainWindowId + ".setCentralWidget(" + element.get("id") + ")", iw=iswindow) # this is a way to make children of non-QMainWindow widgets central, however it is only enabled for # container type widgets (see captan.constants to find out more about what widgets are containers elif element.get("central") is not None or \ (root.__len__() == 1 and root.tag.lower() in Containers): if iswindow is False: code += formatCode("self.MAIN_LAYOUT = QVBoxLayout()", iw=iswindow) # it could really be any type of layout, but QVBoxLayout was the first that came to mind code += formatCode("self.MAIN_LAYOUT.addWidget(" + element.get("id") + ")", iw=iswindow) code += formatCode("self.setLayout(self.MAIN_LAYOUT)", iw=iswindow) return code
def parseLayout(widgetType,element,root,mainWindowId,interfacename, iswindow): code = "" code += formatCode(basicLayout(widgetType['widgetName'], root, element), iw=iswindow) # initialize its QLayout features, addWidget is implemented in parseWidget addorset = "add" # this will be used when the layout is inside another if root.tag.lower() not in Layouts: addorset = "set" # otherwise, we will be setting the layout # we don't need to worry about these in the next check because the mainWindow wont be a layout if root.get("id") == mainWindowId: # is this the main layout # if so, we have to get around the annoyance of main windows needing a main widget code += formatCode("MAIN_WIDGET = QWidget()\n", iw=iswindow) code += formatCode("MAIN_WIDGET.setLayout(" + element.get("id") + ")\n", iw=iswindow) code += formatCode(mainWindowId + ".setCentralWidget(MAIN_WIDGET)\n", iw=iswindow) elif root.get("type"): # is the direct child of a buffer object # buffer objects always have a type, isbufferobject would be passed through to parseLayout, # but the root needs to be checked, not the current layout code += "\t\tself." + addorset + "Layout(" + element.get("id") + ")\n" # there's no need for formatCode here else: # we're somewhere in the buffer tag code += formatCode(root.get("id") + "." + addorset + "Layout(" + element.get("id") + ")", iw=iswindow) return code
def handleSlots(widgetType, element, iswindow): code = "" try: for propname,slotname in widgetType['slots'].items(): if element.get(propname) is not None: code += formatCode(element.get("id") + "." + slotname + ".connect(" + element.get(propname) + ")\n", iw=iswindow) except KeyError: pass return code
def handleText(widgetType, element, iswindow): code = "" try: # handling the text (contents) of the widget textto = widgetType['text'] # what method do we use to set the text? if element.text is not None: # does the element have any contents code += formatCode(element.get("id") + "." + textto + "('" + element.text + "')\n", iw=iswindow) except KeyError: pass return code
def basicLayout(layoutName,root,element,iswindow=True): code = "" code += formatCode(element.get("id")," = Q",layoutName,"()",iw=iswindow) return code