Beispiel #1
0
def help(topic):  #@ReservedAssignment
    '''Creates a window that displays help information'''
    from pyfbsdk import FBAddRegionParam, FBAttachType, FBMemo, ShowTool  #@UnresolvedImport @Reimport
    from pyfbsdk_additions import CreateUniqueTool  #@UnresolvedImport

    win = CreateUniqueTool('Help')
    win.StartSizeX = 400
    win.StartSizeY = 500

    helpText = FBMemo()

    x = FBAddRegionParam(0, FBAttachType.kFBAttachLeft, "")
    y = FBAddRegionParam(0, FBAttachType.kFBAttachTop, "")
    w = FBAddRegionParam(0, FBAttachType.kFBAttachRight, "")
    h = FBAddRegionParam(0, FBAttachType.kFBAttachBottom, "")

    win.AddRegion("helpText", "helpText", x, y, w, h)

    win.SetControl("helpText", helpText)

    ShowTool(win)

    try:
        sys.stdout = StringIO()
        GenDoc(topic)
        helpText.Text = sys.stdout.getvalue()
    finally:
        sys.stdout = _stdout
    def createTool(self):
        moBuLogger.info('----------------------------------------')
        moBuLogger.info('|     Running Art Monkey v:%s     |' % _VERSION)
        moBuLogger.info('|     Build #:%s     |' % self.buildNumber)
        moBuLogger.info('----------------------------------------')

        pcsGlobalToolName = "Art Monkey"
        tool = FBCreateUniqueTool(pcsGlobalToolName)
        tool.StartSizeX = 610
        tool.StartSizeY = 185

        # Layout for the controls
        x = FBAddRegionParam(5, FBAttachType.kFBAttachLeft, "")
        y = FBAddRegionParam(0, FBAttachType.kFBAttachNone, "")
        w = FBAddRegionParam(50, FBAttachType.kFBAttachRight, "")
        h = FBAddRegionParam(85, FBAttachType.kFBAttachNone, "")
        tool.AddRegion("main", "main", x, y, w, h)

        # Add grid layout
        grid = FBGridLayout()
        tool.SetControl("main", grid)

        col = 0

        logo = FBButton()
        logo.SetImageFileNames('%s/logo_small.jpg' % self.pcsImagePath)
        logo.Caption = "yeah"
        logo.OnClick.Add(self.openToolDocs)
        grid.AddRange(logo, 0, 1, col, col)
        grid.SetColWidth(col, 70)

        v = FBLabel()
        v.Caption = 'v:%s' % _VERSION
        v.Style = FBTextStyle.kFBTextStyleItalic
        v.Justify = FBTextJustify.kFBTextJustifyCenter
        grid.Add(v, 2, col)
        col += 1

        # create load button
        loadB = FBButton()
        loadB.Caption = "Load"
        loadB.Look = FBButtonLook.kFBLookColorChange
        loadB.OnClick.Add(self.KToolsCallback)

        # create save button
        saveB = FBButton()
        saveB.Caption = "Save"
        saveB.Look = FBButtonLook.kFBLookColorChange
        saveB.OnClick.Add(self.KToolsCallback)

        # create saveAs button
        saveAsB = FBButton()
        saveAsB.Caption = "SaveAs"
        saveAsB.Look = FBButtonLook.kFBLookColorChange
        saveAsB.OnClick.Add(self.KToolsCallback)

        # add buttons to row 1,2,3 column 1
        grid.Add(loadB, 0, col)
        grid.Add(saveB, 1, col)
        grid.Add(saveAsB, 2, col)

        # want to fix the width of column 1 and 2 so the buttons are of a normal size
        grid.SetColWidth(col, 40)

        col += 1

        # create tab
        tab = FBTabControl()
        # we want the tab to span from row 0 to row 3 and from column 2 to column 2
        grid.AddRange(tab, 0, 3, col, col)

        # set the spacing between col0 and col1
        grid.SetColSpacing(col, 20)

        # now assign the rows and columns attributes
        # Fixed the height of row 0 and row 2 so the label and the buttons have a normal height
        grid.SetRowHeight(0, 20)
        grid.SetRowHeight(1, 20)
        grid.SetRowHeight(2, 20)
        grid.SetRowHeight(3, 70)

        # 1. Build a construction dictionary with {folder=[files]}
        self.menuDict, ext = self.getMenuDic()

        # 1.5 add top menu path for Load, Save, SaveAs
        #		menuTop = self.menuDict.keys()[0]
        if not Path.modulePath(self.mobuMenuPath):
            sys.path.append(self.mobuMenuPath)

        # 2. Sorted Keys list
        sKeys = []
        for dr in self.menuDict.iterkeys():
            sKeys.append(dr)
        sKeys.sort()

        for menu in sKeys:

            menuName = str(Path(menu).basename())
            # skip root and 'old'
            if not menuName == 'old' and not menuName == 'menu':
                tabLayout = FBGridLayout()
                #				lyt.default_space = 5
                tabLayout.SetRegionTitle("My Title", "Title")

                x = FBAddRegionParam(10, FBAttachType.kFBAttachLeft, "")
                y = FBAddRegionParam(20, FBAttachType.kFBAttachTop, "")
                w = FBAddRegionParam(140, FBAttachType.kFBAttachRight, "")
                h = FBAddRegionParam(75, FBAttachType.kFBAttachBottom, "")
                tabLayout.AddRegion(menuName, menuName, x, y, w, h)

                # must add dir to sys.path so imp can find it
                if not Path.modulePath(menu):
                    sys.path.append(menu)

                row = 0
                column = 0
                colWidth = 0
                colMax = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0}
                for script in self.menuDict[menu]:
                    if not script == '__init__%s' % ext:
                        toolName = str(Path(script).namebase)
                        lTool = FBButton()
                        lTool.Caption = toolName
                        lTool.Justify = FBTextJustify.kFBTextJustifyCenter

                        # Make "Fix this!" red
                        if toolName == 'Fix this!':
                            lTool.Look = FBButtonLook.kFBLookColorChange
                            lTool.SetStateColor(FBButtonState.kFBButtonState0,
                                                mbCore.Red)
                            lTool.SetStateColor(FBButtonState.kFBButtonState1,
                                                mbCore.Red)

                        # this callBack is active and all buttons will run this "last" menuModule.run()
                        lTool.OnClick.Add(self.KToolsCallback)
                        tabLayout.Add(lTool, row, column)

                        # make column maximum of all rows
                        colWidth = len(toolName) * 7 + 2
                        if colWidth > colMax[column]:
                            colMax[column] = colWidth

                        tabLayout.SetColWidth(column, colMax[column])
                        tabLayout.SetRowHeight(row, 30)
                        # add button to tabbed sub-layout
                        tabLayout.Add(lTool, row, column)

                        # increment columns, rows
                        column += 1
                        if column > 3:
                            row += 1
                            column = 0

                # add layouts to tabControl with name of dir
                tab.Add(menuName, tabLayout)

        # finish up tab
        tab.SetContent(0)
        tab.TabPanel.TabStyle = 0  # normal tabs