Beispiel #1
0
 def testAddAction(self):
     action1 = Action('action1')
     action2 = Action('action2')
     overview = Overview('test')
     overview.addAction(action1)
     overview.addAction(action2)
     self.assertEqual(overview.actions, [action1, action2])
Beispiel #2
0
class ActionFormatterTestCase(OfficeTestCase):
    def setUp(self):
        super().setUp()
        self.overview = Overview('test sheet')
        self.overview.modifiers = [
            Modifier('aa'), Modifier('bb'),
            Modifier('cc')
        ]
        self.action = Action('attack 1', phases=2, hitPhase=1, default=True)
        self.action.addModifier(0, Modifier('aa'))
        self.action.addModifier(1, Modifier('bb'))
        self.action.addNote(0, "note 1")
        self.action.addNote(0, "note 2")
        self.action.addNote(0, "note 3")
        self.action.setNotes(1, ["note 1", "note 2", "note 3"])
        self.action.setPhaseFrames(0, 1)
        self.action.setPhaseFrames(1, 2)
        self.overview.addAction(self.action)

    def testFormattingAction(self):
        formatter = ActionFormatter(self.overview, self.action)
        data = formatter.format()
        # name, hit, frames, phase, def, aa, bb, cc, notes 1, notes 2, notes 3
        result = [[
            'attack 1', '', '1', '0', 'x', 'x', '', '', 'note 1', 'note 2',
            'note 3'
        ],
                  [
                      'attack 1', 'x', '2', '1', 'x', '', 'x', '', 'note 1',
                      'note 2', 'note 3'
                  ]]
        self.assertEqual(data, result)
Beispiel #3
0
 def testAddModifier(self):
     modifier1 = Modifier('mods1')
     modifier2 = Modifier('mods2')
     overview = Overview('test')
     overview.addModifier(modifier1)
     overview.addModifier(modifier2)
     self.assertEqual(overview.modifiers, [modifier1, modifier2])
Beispiel #4
0
 def createOverview(masterSheet, viewName):
     """
     Factory to build Overview class instance from Master sheet instance and
     from given view name. Modifiers from Modifier sheet will also be used.
     """
     modifiers = Modifiers(MODIFIER_LIST_SHEET_NAME)
     actions = masterSheet.getActions(viewName)
     overview = Overview(viewName)
     overview.modifiers = modifiers.getModifiers()
     for action in actions:
         overview.addAction(
             Action(action.name, color=action.color, phases=action.phases))
     return overview
Beispiel #5
0
    def setOverviewModifierColors(self, sheetName):
        """
        This function sets colors to all the columns in the modifier block of an Overview.
        The code has to access the sheet itself to change the colors.
        """
        overview = Overview.fromSheet(sheetName)
        modifiers = Modifiers('Modifiers')
        columnLength = len(overview.data)
        startCol = overview.modifierStartColumn
        headerRow = overview.headerRowIndex

        offset = 0
        for a in range(len(overview.modifiers)):
            currentColor = color.Color(modifiers.modifierColors[a].value)
            nextColor = color.Color(0)

            # Ensures that no runtime error is created from reading from a too high index.
            if a != len(overview.modifiers) - 1:
                nextColor = color.Color(modifiers.modifierColors[a + 1].value)

            # Compares the color value of the current and next column. If they're the same
            # then they can be colored in the same CellRange to save time.
            if currentColor.value == nextColor.value:
                offset = offset + 1
            else:
                overview.sheet.getCellRangeByPosition(
                    startCol + a - offset, headerRow, startCol + a, columnLength - headerRow
                    ).CellBackColor = currentColor.value
                offset = 0
Beispiel #6
0
 def setUp(self):
     super().setUp()
     self.overview = Overview('test sheet')
     self.overview.modifiers = [
         Modifier('aa'), Modifier('bb'),
         Modifier('cc')
     ]
     self.action = Action('attack 1', phases=2, hitPhase=1, default=True)
     self.action.addModifier(0, Modifier('aa'))
     self.action.addModifier(1, Modifier('bb'))
     self.action.addNote(0, "note 1")
     self.action.addNote(0, "note 2")
     self.action.addNote(0, "note 3")
     self.action.setNotes(1, ["note 1", "note 2", "note 3"])
     self.action.setPhaseFrames(0, 1)
     self.action.setPhaseFrames(1, 2)
     self.overview.addAction(self.action)
Beispiel #7
0
 def testFindAction(self):
     action1 = Action('action1')
     action2 = Action('action2')
     action3 = Action('action3')
     overview = Overview('test')
     overview.addAction(action1)
     overview.addAction(action2)
     overview.addAction(action3)
     self.assertTrue(action2.name == overview.findAction(action2).name)
     self.assertIsNone(overview.findAction(Action('cannot find')))
Beispiel #8
0
def updateDetails(*args, **kwargs):
    """
    A macro function that will update one Details-sheet while preserving
    previous user data. Movelister can have multiple Details-views. To determine
    which one is updated, the code checks which Overview button was pressed to
    trigger the macro.
    """
    try:
        if not Sheet.checkTemplatesExists():
            message_box.showWarningWithOk(
                'This file doesn\'t seem to have all necessary templates. Can\'t generate.'
            )
            return

        # Get Overview sheet name from active sheet or from provided kwargs.
        activeOverviewName = kwargs.get('activeSheet',
                                        helper.getActiveSheetName())
        # Get view name for the Details. This is presented in Overview sheet name inside parentheses.
        viewName = names.getViewName(activeOverviewName)
        detailsSheetName = names.getDetailsName(viewName)
        previousDetails = Details(viewName)
        if Sheet.hasByName(detailsSheetName):
            # Check if user wants to update existing Details-sheet.
            if not message_box.showSheetUpdateWarning():
                return
            previousDetails = Details.fromSheet(detailsSheetName)
        modifiersSheet = Modifiers(MODIFIER_LIST_SHEET_NAME)
        parentOverview = Overview.fromSheet(activeOverviewName)
        # Create new Details sheet by combining new and existing data.
        newDetails = UpdateDetails.update(modifiersSheet, parentOverview,
                                          previousDetails, viewName)
        # Delete previous Details-sheet and generate a new one.
        Sheet.deleteSheetByName(detailsSheetName)
        formatter = DetailsFormatter(newDetails, parentOverview)
        unoDetailsSheet = formatter.generate()
        # Make columns width optimal.
        length = cursor.getWidth(unoDetailsSheet)
        format.setOptimalWidthToRange(unoDetailsSheet, 0, length)
        # Generate data validation.
        validation.setDataValidationToDetailsSheet(unoDetailsSheet, viewName)
        # Generate named ranges.
        about = About(ABOUT_SHEET_NAME)
        if about.isGenerateNamedRangesOn():
            NamedRanges(unoDetailsSheet, 0, viewName).generate()
        # Generate cell styles used for details sheet.
        UpdateStyles.update()
        # Create conditional format ranges to the new details sheet which uses
        # styles created above.
        masterSheet = Master(MASTER_LIST_SHEET_NAME)
        resultsSheet = Results(RESULT_LIST_SHEET_NAME)
        inputSheet = Inputs(INPUT_LIST_SHEET_NAME)
        conditionalFormat.createDetailsConditionalFormats(
            unoDetailsSheet, masterSheet, resultsSheet, inputSheet, viewName)
        # Set new sheet as currently active sheet.
        helper.setActiveSheet(unoDetailsSheet)
    except errors.MovelisterError as e:
        helper.setActiveSheet(e.activeSheet)
        message_box.showWarningWithOk(str(e))
Beispiel #9
0
 def update(cls, previousOverview, name):
     """
     Create new Overview class instance with given name. Created Overview
     will use latest modifier and action data filled to by the user. New
     data is combined with existing data user filled data.
     """
     cls.newOverview = Overview(name)
     cls._updateLatestModifiers()
     cls._updateLatestActions(name)
     cls._updateActions(previousOverview)
     return cls.newOverview
Beispiel #10
0
 def testGroupRows(self):
     """
     TODO: finish writing comment
     """
     overview = Overview.fromSheet('Overview (default)')
     actionNames = overview.actionNames
     column = overview.nameColumnIndex
     groups = filter.groupRows(overview.dataRows, column)
     self.assertEqual(len(actionNames), len(groups))
     for group in groups:
         name = actionNames.pop(0)
         for row in group:
             self.assertEqual(name, row[column])
Beispiel #11
0
 def setUpClass(cls):
     super().setUpClass()
     cls.overviewName = 'Overview (default)'
     cls.overview = Overview.fromSheet(cls.overviewName)
Beispiel #12
0
def updateOverview(*args, **kwargs):
    """
    A macro function to update or create a new Overview sheet. Updated sheet
    will include earlier user data in the old Overview if any.
    """
    try:
        if not Sheet.checkTemplatesExists():
            message_box.showWarningWithOk(
                'This file doesn\'t seem to have all necessary templates. Can\'t generate.'
            )
            return

        # Get name of the Overview which user wants to generate.
        masterSheet = Master(MASTER_LIST_SHEET_NAME)
        activeSheetName = kwargs.get('activeSheet', '')
        if activeSheetName == '':
            viewName = masterSheet.getOverviewName()
            overviewSheetName = names.getOverviewName(viewName)
        else:
            viewName = names.getViewName(activeSheetName)
            overviewSheetName = activeSheetName

        # Some error checking.
        if not viewName:
            message_box.showWarningWithOk(
                'You can\'t generate an Overview if no View-name is set in cell C1.'
            )
            return

        if viewName not in masterSheet.getViewNames():
            message_box.showWarningWithOk(
                'You can\'t generate a View that has no Actions. Make sure at least one '
                +
                'Action uses the View-name written in cell C1 before continuing.'
            )
            return

        oldOverview = Overview(viewName)
        # If document has existing Overview, then that is set as previous instead.
        if Sheet.hasByName(overviewSheetName):
            # Check if user wants to update existing Overview.
            if not message_box.showSheetUpdateWarning():
                return
            oldOverview = Overview.fromSheet(overviewSheetName)

        newOverview = UpdateOverview.update(oldOverview, viewName)

        # Place new Overview sheet on the same position as the previous one. If previous one
        # does not exist, then place right of the Master sheet instead.
        position = Sheet.getPosition(overviewSheetName)
        if not position:
            position = Sheet.getPosition(MASTER_LIST_SHEET_NAME) + 1
        # Delete old sheet if exists.
        Sheet.deleteSheetByName(overviewSheetName)
        # Generate a new one.
        formatter = OverviewFormatter(newOverview)
        unoOverviewSheet = formatter.generate(position)
        # Make columns width optimal.
        length = cursor.getWidth(unoOverviewSheet)
        format.setOptimalWidthToRange(unoOverviewSheet, 0, length)
        # Fix sheet colors.
        formatter.setOverviewModifierColors(overviewSheetName)
        # Set new sheet as currently active sheet.
        helper.setActiveSheet(unoOverviewSheet)
    except errors.MovelisterError as e:
        helper.setActiveSheet(e.activeSheet)
        message_box.showWarningWithOk(str(e))
Beispiel #13
0
class OverviewFormatterTestCase(OfficeTestCase):
    def setUp(self):
        super().setUp()
        self.sheetName = 'test'
        self.overview = Overview(self.sheetName)

    def testFormatHeader(self):
        self.overview.modifiers = [Modifier('aa'), Modifier('bb')]
        formatter = OverviewFormatter(self.overview)
        data = formatter.formatHeader()
        self.assertEqual(data, [
            'Action Name', 'Hit', 'Frames', 'Phase', 'DEF', 'aa', 'bb',
            'Notes 1', 'Notes 2', 'Notes 3'
        ])

    def testFormatModifiers(self):
        modifier1 = Modifier('aa')
        modifier2 = Modifier('bb')
        self.overview.modifiers = [modifier1, modifier2]

        modAct1 = Action('attack 1', phases=2, hitPhase=1, default=True)
        modAct1.addModifier(0, Modifier('aa'))
        modAct1.addModifier(1, Modifier('bb'))
        self.overview.addAction(modAct1)

        formatter = OverviewFormatter(self.overview)
        data = formatter.formatActions()
        self.assertEqual(
            data, [['attack 1', '', '', '0', 'x', 'x', '', '', '', ''],
                   ['attack 1', 'x', '', '1', 'x', '', 'x', '', '', '']])

    def testFormat(self):
        modifier1 = Modifier('aa')
        modifier2 = Modifier('bb')
        modifier3 = Modifier('cc')
        self.overview.modifiers = [modifier1, modifier2, modifier3]

        modAct1 = Action('attack 1', phases=2, hitPhase=1, default=True)
        modAct1.addModifier(0, Modifier('aa'))
        modAct1.addModifier(1, Modifier('bb'))
        self.overview.addAction(modAct1)

        formatter = OverviewFormatter(self.overview)
        data = formatter.format()
        self.assertEqual(
            data, [['', '', '', '', '', '', '', '', '', '', ''],
                   [
                       'Action Name', 'Hit', 'Frames', 'Phase', 'DEF', 'aa',
                       'bb', 'cc', 'Notes 1', 'Notes 2', 'Notes 3'
                   ], ['attack 1', '', '', '0', 'x', 'x', '', '', '', '', ''],
                   ['attack 1', 'x', '', '1', 'x', '', 'x', '', '', '', '']])

    def testGenerate(self):
        """
        Test generating new Overview-sheet from template, then assert that the
        sheet really exists and has generated content in it.
        """
        modifier1 = Modifier('aa')
        modifier2 = Modifier('bb')
        modifier3 = Modifier('cc')
        self.overview.modifiers = [modifier1, modifier2, modifier3]

        modAct1 = Action('attack 1', phases=2, hitPhase=1, default=True)
        modAct1.addModifier(0, Modifier('aa'))
        modAct1.addModifier(1, Modifier('bb'))
        self.overview.addAction(modAct1)

        formatter = OverviewFormatter(self.overview)
        formatter.generate(1)

        sheet = Sheet.getByName(names.getOverviewName(self.sheetName))
        data = cursor.getSheetContent(sheet)
        self.assertEqual(
            data, [['', '', '', '', '', '', '', '', '', '', ''],
                   [
                       'Action Name', 'Hit', 'Frames', 'Phase', 'DEF', 'aa',
                       'bb', 'cc', 'Notes 1', 'Notes 2', 'Notes 3'
                   ], ['attack 1', '', '', '0', 'x', 'x', '', '', '', '', ''],
                   ['attack 1', 'x', '', '1', 'x', '', 'x', '', '', '', '']])
Beispiel #14
0
 def setUp(self):
     super().setUp()
     self.sheetName = 'test'
     self.overview = Overview(self.sheetName)