def insertGoal(goalList:GoalList, goalNum:int, newGoalDesc:str): if goalList.includes(newGoalDesc): warn(The_GoalsApp_Entity(), f"Can't insert the goal \"{newGoalDesc}\", because it is already in your goals list.") return goalList.addGoal(newGoalDesc) if goalNum >= goalList.nGoals: # User wanted it at end. return # We're done. goals = goalList.goals # Pull goals forward. i = goalList.nGoals - 1 while(1): goals[i].text = goals[i-1].text i -= 1 if i < goalNum: goals[i].text = newGoalDesc # Plop new guy down here. break output(The_GoalsApp_Entity(), f"Inserted new goal at position #{goalNum}: {newGoalDesc}")
def deleteGoal(goalList:GoalList, goalNum:int): _logger.debug(f"goalList.deleteGoal(): Deleting goal #{goalNum}...") goals = goalList.goals nGoals = goalList.nGoals _logger.debug(f"goalList.deleteGoal(): There are {nGoals} before delete.") if goalNum < 1 or goalNum > nGoals: error(The_GoalsApp_Entity(), f"Can't delete goal #{goalNum} because it doesn't exist!") return oldText = goals[goalNum-1].text for i in range(goalNum, goalList.nGoals): goals[i-1].text = goals[i].text goals = goals[:-1] # Drops last element. goalList._goals = goals # Need a cleaner way to do this. _logger.debug(f"goalList.deleteGoal(): There are {goalList.nGoals} after delete.") Goal._nGoals -= 1 output(The_GoalsApp_Entity(), f"Deleted old goal #{goalNum}, which was \"{oldText}\".")
def changeGoal(goalList:GoalList, goalNum:int, newGoalDesc:str): if goalList.includes(newGoalDesc): warn(The_GoalsApp_Entity(), f"Can't change goal #{goalNum} to \"{newGoalDesc}\" because it is already in your goals list.") return goals = goalList.goals nGoals = goalList.nGoals if goalNum < 1 or goalNum > nGoals: error(The_GoalsApp_Entity(), f"Can't change goal #{goalNum} because it doesn't exist!") return goal = goals[goalNum - 1] goal.text = newGoalDesc #goalList._fixnums() # Temporary hack output(The_GoalsApp_Entity(), f"Changed goal #{goal.num} to \"{newGoalDesc}\".")
def handler(thisAppLaunchCmd: AppLaunchCommand, groups: list = None): """This is the handler method that is called when a generic app-launch command is invoked. The <groups> argument, if present, is a list of match groups; it should include the command word (or prefix), and the argument list (if any).""" cmd = thisAppLaunchCmd app = cmd._app # This gets the application that we're supposed to start. if groups is None: # Really should give some kind of error return if len(groups) >= 1: cmdWord = groups[0] else: cmdWord = None # Currently the app-launch commands don't even allow argument lists, # but this code will be needed in the future if that changes. if len(groups) >= 2: argList = groups[1] else: argList = None _logger.info("Handling app-launch command for app {app} with " f"cmdWord='{cmdWord}', argList='{argList}'.") app.launch() # Launch the app (if not already launched). # (This automatically also foregrounds the app, whether or # not it was launched.) output(The_AppSystem_Entity(), f"Launched/refreshed the {app.name} app.")
def moveGoal(goalList:GoalList, fromGoal:int, toGoal:int): movingGoalText = goalList.goals[fromGoal-1].text info(The_GoalsApp_Entity(), "Moving goal by first deleting, then inserting...") goalList.deleteGoal(fromGoal) goalList.insertGoal(toGoal, movingGoalText) output(The_GoalsApp_Entity(), f"Moved goal \"{movingGoalText}\" from #{fromGoal} to #{toGoal}.")
def addGoal(goalList:GoalList, newGoalDesc:str): if goalList.includes(newGoalDesc): warn(The_GoalsApp_Entity(), f"Can't add the goal \"{newGoalDesc}\", because it is already in your goals list.") return goals = goalList.goals goalRec = {'goal-text': newGoalDesc} newGoal = Goal(goalRec) goals.append(newGoal) output(The_GoalsApp_Entity(), f"Added new goal #{newGoal.num}: {newGoalDesc}")