Beispiel #1
0
def apply(classes, tags, topClassName):
    print('APPLY: in Apply\n')
    global classesToProcess
    global classesEncoded
    classesEncoded = {}

    # Choose an appropriate app style
    appStyle = 'default'
    topWhichScreenFieldID = topClassName + '::whichScreen(int)'
    if (progSpec.doesClassDirectlyImlementThisField(
            classes[0], topClassName,
            topWhichScreenFieldID)):  # if all data fields are classes
        appStyle = 'Z_stack'
    else:
        appStyle = 'TabbedStack'
    guiStructName = topClassName + '_GUI'
    classesEncoded[guiStructName] = 1
    classesToProcess = [[topClassName, 'struct', appStyle, guiStructName]]

    # Amend items to each GUI data class
    for classToAmend in classesToProcess:
        [className, widgetType, dialogStyle, newStructName] = classToAmend
        cdlog(
            1, 'BUILDING ' + dialogStyle + ' GUI for ' + widgetType + ' ' +
            className + ' (' + newStructName + ')')
        if widgetType == 'struct':
            BuildGuiForStruct(classes, className, dialogStyle, newStructName)
        #elif widgetType == 'list':
        #buildListRowView(classes, className, dialogStyle, newStructName)

    # Fill createAppArea()
    primaryGUIName = 'primary_GUI_Mgr'

    CODE = '''
struct APP{
    our ''' + topClassName + ''': primary
    our ''' + guiStructName + ''': <PRIMARY_GUI>
    me void: createAppArea(me GUI_Frame: frame) <- {
        Allocate(primary)
        Allocate(<PRIMARY_GUI>)
        their GUI_storyBoard: appStoryBoard <- <PRIMARY_GUI>.initWidget(primary)
        initializeAppGui()
        addToContainerAndExpand (frame, appStoryBoard)
    }
}'''

    CODE = CODE.replace('<PRIMARY_GUI>', primaryGUIName)
    #print ('==========================================================\n'+CODE)
    codeDogParser.AddToObjectFromText(classes[0], classes[1], CODE, 'APP')

    return
Beispiel #2
0
def apply(classes, tags, topClassName):
    print "APPLY: in Apply\n"
    global classesToProcess
    global classesEncoded
    classesEncoded={}

    # Choose an appropriate app style
    appStyle='default'
    topWhichScreenFieldID = topClassName+'::whichScreen(int)'
    if (progSpec.doesClassDirectlyImlementThisField(classes[0], topClassName, topWhichScreenFieldID)): # if all data fields are classes
        appStyle='Z_stack'
    else: appStyle='TabbedStack'
    guiStructName = topClassName+'_GUI'
    classesEncoded[guiStructName]=1
    classesToProcess=[[topClassName, 'struct', appStyle, guiStructName]]

    # Amend items to each GUI data class
    for classToAmend in classesToProcess:
        [className, widgetType, dialogStyle, newStructName] = classToAmend
        cdlog(1, "BUILDING "+dialogStyle+" GUI for "+widgetType+" " + className + ' ('+newStructName+')')
        if widgetType == 'struct':
            BuildGuiForStruct(classes, className, dialogStyle, newStructName)
        elif widgetType == 'list':
            BuildGuiForList(classes, className, dialogStyle, newStructName)

    # Fill createAppArea()
    primaryGUIName = 'primary_GUI_Mgr'
    primaryMakerFuncName = 'make'+topClassName[0].upper() + topClassName[1:]+'Widget'

    CODE ='''
struct APP{
    our <TOPCLASSNAME>: primary
    our <GUI_STRUCTNAME>: <PRIMARY_GUI>
    me void: createAppArea(me GUI_Frame: frame) <- {
        Allocate(primary)
        Allocate(<PRIMARY_GUI>)
        their GUI_storyBoard: appStoryBoard <- <PRIMARY_GUI>.<PRIMARY_MAKERFUNCNAME>(primary)
        initializeAppGui()
        gui.addToContainerAndExpand (frame, appStoryBoard)
    }
}'''

    CODE = CODE.replace('<PRIMARY_GUI>', primaryGUIName)
    CODE = CODE.replace('<TOPCLASSNAME>', topClassName)
    CODE = CODE.replace('<GUI_STRUCTNAME>', guiStructName)
    CODE = CODE.replace('<PRIMARY_MAKERFUNCNAME>', primaryMakerFuncName)
    #print '==========================================================\n'+CODE
    codeDogParser.AddToObjectFromText(classes[0], classes[1], CODE, 'APP')

    return
Beispiel #3
0
def BuildGuiForStruct(classes, className, dialogStyle, newStructName):
    # This makes 4 types of changes to the class:
    #   It adds a widget variable for items in model // newWidgetFields: '    their '+typeName+': '+widgetName
    #   It adds a set Widget from Vars function      // widgetFromVarsCode: Func UpdateWidgetFromVars()
    #   It adds a set Vars from Widget function      // varsFromWidgetCode: Func UpdateVarsFromWidget()
    #   It add an initialize Widgets function.       // widgetInitFuncCode: widgetName+' <- '+makeTypeNameCall+'\n    addToContainer(box, '+widgetName+')\n'

    # dialogStyles: 'Z_stack', 'X_stack', 'Y_stack', 'TabbedStack', 'FlowStack', 'WizardStack', 'Dialog', 'SectionedDialogStack', 'V_viewable'
    # also, handle non-modal dialogs

    global classesEncoded
    global currentClassName
    global currentModelSpec
    classesEncoded[className]=1
    currentClassName = className

    # reset the string vars that accumulate the code
    global newWidgetFields
    global widgetInitFuncCode
    global widgetFromVarsCode
    global varsFromWidgetCode

    newWidgetFields=''
    widgetInitFuncCode=''
    widgetFromVarsCode=''
    varsFromWidgetCode=''

    # Find the model
    modelRef         = progSpec.findSpecOf(classes[0], className, 'model')
    currentModelSpec = modelRef
    if modelRef==None: cdErr('To build a GUI for class "'+className+'" a model is needed but is not found.')
    #TODO: write func body for: widgetFromVarsCode(selected item & click edit) & varsFromWidgetCode(ckick OK from editMode)
    ### Write code for each field
    for field in modelRef['fields']:
        typeSpec     = field['typeSpec']
        fldCat       = progSpec.fieldsTypeCategory(typeSpec)
        fieldName    = field['fieldName']
        labelText    = deCamelCase(fieldName)
        if fieldName=='settings':
            # add settings
            continue

        structTypeName=''
        if fldCat=='struct': # Add a new class to be processed
            structTypeName =typeSpec['fieldType'][0]
            if (progSpec.doesClassDirectlyImlementThisField(classes, structTypeName, structTypeName+':managedWidget')
                    or structTypeName.endswith('Widget')):
                fldCat = 'widget'
            else:
                newGUIStyle    = 'Dialog'
                guiStructName  = structTypeName+'_'+newGUIStyle+'_GUI'
                addNewStructToProcess(guiStructName, structTypeName, 'struct', 'Dialog')

        if fldCat != 'widget' and progSpec.isAContainer(typeSpec):# Add a new list to be processed
            structTypeName = typeSpec['fieldType'][0]
            guiStructName  = structTypeName+'_LIST_View'
            addNewStructToProcess(guiStructName, structTypeName, 'list', 'Dialog')

        #TODO: make actions for each function
        if fldCat=='func':
            if fieldName[-4:]== '_btn':
                buttonLabel = deCamelCase(fieldName[:-4])
                # Add a button whose click calls this.
                print "ADDING BUTTON FOR:", fieldName
                getButtonHandlingCode(classes, buttonLabel, fieldName)

        else: # Here is the main case where code to edit this field is written
            getWidgetHandlingCode(classes, fldCat, fieldName, field, structTypeName, dialogStyle, '')

    # Parse everything
    initFuncName = 'make'+className[0].upper() + className[1:]+'Widget'
    if dialogStyle == 'Z_stack': containerWidget='makeStoryBoardWidget("makeStoryBoardWidget")'
    elif dialogStyle == 'TabbedStack': containerWidget='makeTabbedWidget("makeTabbedWidget")'
    else: containerWidget='makeFrameWidget()'


    CODE =  '''
struct <CLASSNAME> {}
struct <NEWSTRUCTNAME> {
    <NEWWIDGETFIELDS>
    our <CLASSNAME>: <CLASSNAME>_data
    their GUI_Frame: <INITFUNCNAME>(our <CLASSNAME>: Data) <- {
        <CLASSNAME>_data<-Data
        their GUI_Frame:box <- <CONTAINERWIDGET>
        <WIDGETINITFUNCCODE>
        return(box)
    }
    void: setValue(our <CLASSNAME>: var) <- {
        <WIDGETFROMVARSCODE>
    }
    void: getValue() <- {
        <VARSFROMWIDGETCODE>
    }
}\n'''  # TODO: add <VARSFROMWIDGETCODE>

    CODE = CODE.replace('<NEWSTRUCTNAME>', newStructName)
    CODE = CODE.replace('<NEWWIDGETFIELDS>', newWidgetFields)
    CODE = CODE.replace('<CLASSNAME>', className)
    CODE = CODE.replace('<WIDGETINITFUNCCODE>', widgetInitFuncCode)
    CODE = CODE.replace('<INITFUNCNAME>', initFuncName)
    CODE = CODE.replace('<WIDGETFROMVARSCODE>', widgetFromVarsCode)
    CODE = CODE.replace('<VARSFROMWIDGETCODE>', varsFromWidgetCode)
    CODE = CODE.replace('<CONTAINERWIDGET>', containerWidget)
    if newStructName == "EntryPad_Dialog_GUI":print '==========================================================\n'+CODE
    codeDogParser.AddToObjectFromText(classes[0], classes[1], CODE, newStructName)
Beispiel #4
0
def BuildGuiForStruct(classes, className, dialogStyle, newStructName):
    # This makes 4 types of changes to the class:
    #   It adds a widget variable for items in model // newWidgetFields: '    their '+typeName+': '+widgetName
    #   It adds a set Widget from Vars function      // widgetFromVarsCode: Func setValue()
    #   It adds a set Vars from Widget function      // varsFromWidgetCode: Func getValue()
    #   It add an initialize Widgets function.       // widgetInitFuncCode: widgetName+' <- '+makeTypeNameCall+'\n    addToContainer(box, '+widgetName+')\n'

    # dialogStyles: 'Z_stack', 'X_stack', 'Y_stack', 'TabbedStack', 'FlowStack', 'WizardStack', 'Dialog', 'SectionedDialogStack', 'V_viewable'
    # also, handle non-modal dialogs
    global classesEncoded
    global currentClassName
    global currentModelSpec
    classesEncoded[className] = 1
    currentClassName = className

    # reset the string vars that accumulate the code
    global newWidgetFields
    global widgetInitFuncCode
    global widgetFromVarsCode
    global varsFromWidgetCode
    global clearWidgetCode

    newWidgetFields = ''
    widgetInitFuncCode = ''
    widgetFromVarsCode = ''
    varsFromWidgetCode = ''
    clearWidgetCode = ''
    containerWidget = ''
    boxFooterCode = ''
    scrollerCode = ''
    onLoadedCode = ''
    tagCode = ''
    makeBoxFooter = False
    makeBackBtn = False
    makeNextBtn = False
    makeVScroller = False

    # Find the model
    modelRef = findModelRef(classes[0], className)
    currentModelSpec = modelRef
    classPrimaryGuiItem = progSpec.searchATagStore(modelRef['tags'],
                                                   'primaryGuiItem')
    if classPrimaryGuiItem != None:  # This GUI Item is important visually
        classPrimaryGuiItem = classPrimaryGuiItem[0]
    classOptionsTags = progSpec.searchATagStore(modelRef['tags'],
                                                'classOptions')
    guiStyleTag = progSpec.searchATagStore(modelRef['tags'], 'dialogStyle')
    if guiStyleTag != None:  # This GUI Item is important visually
        guiStyleTag = guiStyleTag[0]
        if guiStyleTag == 'WizardStack': dialogStyle = 'WizardStack'
        if guiStyleTag == 'Z_stack': dialogStyle = 'Z_stack'
        if guiStyleTag == 'WizardChild':
            dialogStyle = 'WizardChild'
            makeBoxFooter = True
            makeBackBtn = True
            makeNextBtn = True
            clickNextLabel = "Next"
        if guiStyleTag == 'WizardChildLast':
            dialogStyle = 'WizardChild'
            makeBoxFooter = True
            makeBackBtn = True
            makeNextBtn = True
            clickNextLabel = "Done"
        if guiStyleTag == 'WizardChildFirst':
            dialogStyle = 'WizardChild'
            makeBoxFooter = True
            makeNextBtn = True
            clickNextLabel = "Next"
    classProperties = progSpec.searchATagStore(modelRef['tags'], 'properties')
    if classProperties != None:
        for classProperty in classProperties:
            if classProperty[0] == 'vScroller': makeVScroller = True
    ### Write code for each field
    for field in modelRef['fields']:
        typeSpec = field['typeSpec']
        fldCat = progSpec.fieldsTypeCategory(typeSpec)
        fieldName = field['fieldName']
        labelText = deCamelCase(fieldName)
        fieldType = typeSpec['fieldType']
        if fieldName == 'settings':
            # add settings
            continue

        structTypeName = ''
        if fldCat == 'struct':  # Add a new class to be processed
            structTypeName = typeSpec['fieldType'][0]
            if (progSpec.doesClassDirectlyImlementThisField(
                    classes, structTypeName, structTypeName + ':managedWidget')
                    or structTypeName.endswith('Widget')):
                fldCat = 'widget'
            else:
                newGUIStyle = 'Dialog'
                guiStructName = structTypeName + '_' + newGUIStyle + '_GUI'
                addNewStructToProcess(guiStructName, structTypeName, 'struct',
                                      'Dialog')

        if fldCat != 'widget' and progSpec.isAContainer(
                typeSpec):  # Add a new list to be processed
            if not isinstance(fieldType, str): fieldType = fieldType[0]
            structTypeName = fieldType
            guiStructName = structTypeName + '_ROW_View'
            addNewStructToProcess(guiStructName, structTypeName, 'list',
                                  'Dialog')

        #TODO: make actions for each function
        if fldCat == 'func':
            if fieldName[-4:] == '_btn':
                buttonLabel = deCamelCase(fieldName[:-4])
                # Add a button whose click calls this.
                print('ADDING BUTTON FOR:', fieldName)
                getButtonHandlingCode(classes, buttonLabel, fieldName)

        else:  # Here is the main case where code to edit this field is written
            getWidgetHandlingCode(classes, fldCat, fieldName, field,
                                  structTypeName, dialogStyle,
                                  classPrimaryGuiItem, classOptionsTags, '')

    onLoadedCode = 'onLoaded()\n'
    returnCode = '        return(box)'
    if dialogStyle == 'Z_stack':
        newWidgetFields += '    their GUI_ZStack: Zbox\n'
        newWidgetFields += '    me List<me string>: children\n'
        newWidgetFields += '    me int: activeScreenIdx <-1\n'
        newWidgetFields += '    void: setActiveChild(me int: N) <- {\n'
        newWidgetFields += '        if (N >= 0 and N < children.size()){'
        newWidgetFields += '            me string: childName <- children[N]\n'
        #newWidgetFields   += '            print("^^^setZStackActive: ",N)\n'
        newWidgetFields += '            setZStackActive(Zbox, childName)\n'
        newWidgetFields += '            activeScreenIdx <- N\n'
        newWidgetFields += '        }\n'
        newWidgetFields += '    }\n'
        containerWidget = 'Zbox <- makeZStack("' + className + '")\n'
        onLoadedCode = 'setActiveChild(0)\n'
        onLoadedCode += '        onLoaded()\n'
        returnCode = '        return(Zbox)\n'
    elif dialogStyle == 'TabbedStack':
        containerWidget = 'their GUI_Frame:box <- makeTabbedWidget("makeTabbedWidget")'
    elif dialogStyle == 'WizardStack':
        newWidgetFields += '    our wizardWidget: wiz\n'
        newWidgetFields += '    their GUI_Frame: box\n'
        newWidgetFields += '''    void: clickNext() <-{
            me int: size <- wiz.children.size()
            if (wiz.activeScreenIdx == size-1){
                _data.wizardFinished(wiz.widgetID)
            }
            else if (wiz.activeScreenIdx < size-1){
                wiz.activeScreenIdx <- wiz.activeScreenIdx+1
                wiz.setActiveChild(wiz.activeScreenIdx)
            }
        }\n'''
        newWidgetFields += '''    void: clickBack() <-{
            me int: size <- wiz.children.size()
            if (wiz.activeScreenIdx > 0){wiz.activeScreenIdx <- wiz.activeScreenIdx-1}
            wiz.setActiveChild(wiz.activeScreenIdx)
        }\n'''
        containerWidget = 'Allocate(wiz)\n'
        containerWidget += '        box <- wiz.initWidget("' + currentClassName + '")\n'
        containerWidget += '        wiz._data <- _data\n'
        containerWidget += '        wiz.parentGuiMgr <- self\n'
        widgetInitFuncCode += '        wiz.activeScreenIdx <- 0\n'
        widgetInitFuncCode += '        wiz.setActiveChild(wiz.activeScreenIdx)\n'
    elif dialogStyle == 'X_stack':
        newWidgetFields += '    their GUI_XStack:box\n'
        containerWidget = 'box <- makeXStack("")'
    elif dialogStyle == 'rowWidget':
        newWidgetFields += '    their GUI_XStack: box\n'
        containerWidget = 'box <- makeXStack("")'
    else:
        newWidgetFields += '    their GUI_Frame:box\n'
        containerWidget = 'box <- makeYStack("")'
    if makeBoxFooter:
        newWidgetFields += '    their GUI_Frame:  boxFooter\n'
        boxFooterCode += 'boxFooter       <- makeXStack("")\n'
        if makeBackBtn:
            newWidgetFields += '    their GUI_button: backBtn\n'
            newWidgetFields += '    void: clickBack() <-{parentGuiMgr.clickBack()}\n'
            boxFooterCode += '        backBtn         <- makeButtonWidget("Back")\n'
            boxFooterCode += '        GUI.setBtnCallback(backBtn, "clicked", clickBack, this)\n'
            boxFooterCode += '        addToContainer(boxFooter, backBtn)\n'
            tagCode += ''
        if makeNextBtn:
            newWidgetFields += '    their GUI_button: nextBtn\n'
            newWidgetFields += '''    void: clickNext() <-{
                if(isComplete()){
                    save()
                    parentGuiMgr.clickNext()
                }
            }\n'''
            newWidgetFields += '''    void: setNextBtnActive(me bool: checkState) <-{
                nextBtn.setWidgetActive(checkState)
            }\n'''
            newWidgetFields += '''    void: onChanged() <- {
                getValue()
                setNextBtnActive(isComplete())
            }\n'''
            boxFooterCode += '        nextBtn         <- makeButtonWidget("' + clickNextLabel + '")\n'
            boxFooterCode += '        nextBtn.setWidgetActive(false)\n'
            boxFooterCode += '        GUI.setBtnCallback(nextBtn, "clicked", clickNext, this)\n'
            boxFooterCode += '        addToContainer(boxFooter, nextBtn)\n'
            tagCode += ''
        boxFooterCode += '        addToContainer(box, boxFooter)\n'
    if makeVScroller:
        scrollerCode = 'their GUI_VerticalScroller: scroller <- makeVerticalScroller()\n'
        scrollerCode += 'addToContainerAndExpand(scroller, box)\n'
        returnCode = 'return (scroller)'

    CODE =  '''
struct <CLASSNAME>:inherits=appComponentData{}
struct <NEWSTRUCTNAME>:inherits=appComponentGUI '''+tagCode+'''{
    '''+newWidgetFields+'''
    our <CLASSNAME>: _data
    their GUI_Frame: initWidget(our <CLASSNAME>: Data) <- {
        _data <- Data
        _data.guiMgr <- self
        '''+containerWidget+'''
        '''+widgetInitFuncCode+'''
        '''+boxFooterCode+'''
        '''+scrollerCode+'''
        '''+onLoadedCode+'''
        '''+returnCode+'''
    }
    void: setValue(our <CLASSNAME>: var) <- {
        '''+widgetFromVarsCode+'''
    }
    void: getValue() <- {
        '''+varsFromWidgetCode+'''
    }
    void: clear() <- {
        '''+clearWidgetCode+'''
    }
}\n'''  # TODO: add <VARSFROMWIDGETCODE>

    CODE = CODE.replace('<NEWSTRUCTNAME>', newStructName)
    CODE = CODE.replace('<CLASSNAME>', className)
    #print ('==========================================================\n'+CODE)
    codeDogParser.AddToObjectFromText(classes[0], classes[1], CODE,
                                      newStructName)