From 38e28ec74acdaeff6541800c03144f4dc7b49790 Mon Sep 17 00:00:00 2001 From: Brady Jacobs Date: Tue, 21 Aug 2012 16:52:13 -0400 Subject: [PATCH] Dialogs List comprehensions and useful dialogs for unlocking. --- RankPanda/Commands.py | 44 +++++---- RankPanda/CoreWrapper.py | 86 ++++++++++-------- RankPanda/CubicHermiteSpline.py | 10 +-- RankPanda/GUIDialogs.py | 9 +- RankPanda/GUIMain.py | 153 +++++++++++++++++++------------- RankPanda/Move.py | 12 +-- RankPanda/Move_test.py | 9 ++ RankPanda/Song.py | 11 +-- 8 files changed, 200 insertions(+), 134 deletions(-) diff --git a/RankPanda/Commands.py b/RankPanda/Commands.py index eb914e3..f8f971d 100755 --- a/RankPanda/Commands.py +++ b/RankPanda/Commands.py @@ -12,56 +12,64 @@ def __init__(self, length, beginLocation): self._name = 'Command' - # Given the beginning location, calculates the location that the - # rank should be in after count counts. Uses information such as - # self._delta and the command type, but does NOT use - # self.endLocation. + # Be sure to overwrite this in each Command! def CalcLocation(self, count, beginLocation): + ''' Given the beginning location, calculates the location that the + rank should be in after count counts. Uses information such as + self._delta and the command type, but does NOT use + self.endLocation. ''' return beginLocation - # Splits the command in two, at the specified count. Changes this command - # to be the appropriate length, and returns this command as well as the - # new one. + # Be sure to overwrite this in each Command! def Split(self, count, beginLocation): + ''' Splits the command in two, at the specified count. Changes this command + to be the appropriate length, and returns this command as well as the + new one.''' pass - # Returns the current value of the self._name field. + def GetName(self): + ''' Returns the current value of the self._name field.''' return self._name - # Sets the value of the self._name field. + def SetName(self, name): + ''' Sets the value of the self._name field.''' self._name = name - # Returns the number of counts this command spans. If you want to change - # this value, make a new command instead. + def GetLength(self): + ''' Returns the number of counts this command spans. If you want to change + this value, make a new command instead.''' return round(self._length) - # Simple getter, in case the beginning location isn't readily available. + def GetEndLocation(self): + ''' Simple getter, in case the beginning location isn't readily available.''' return self._endLocation def SnapEndLocation(self, newBeginLocation): self._endLocation = self.CalcLocation(self.GetLength(), newBeginLocation) - # From the ending location, calculate the beginning location. Will require - # basically the same implementation as CalcLocation(), but in reverse. - # count should be the location in the whole command you want it to be - # returned. So, pass in 0 to run the whole command. + # Be sure to overwrite this in each Command! def CalcBeginLocation(self, count, endLocation): + ''' From the ending location, calculate the beginning location. Will require + basically the same implementation as CalcLocation(), but in reverse. + count should be the location in the whole command you want it to be + returned. So, pass in 0 to run the whole command.''' return None - # Checks following to see if it's a command of the same name. If so, - # return the merged commands. + def MergeWithFollowing(self, following): + ''' Checks following to see if it's a command of the same name. If so, + return the merged commands.''' if ((following._name == self._name) and (isinstance(following, self))): self._length = self._length + following._length self._endLocation = following._endLocation diff --git a/RankPanda/CoreWrapper.py b/RankPanda/CoreWrapper.py index 2a0ef18..f3ff675 100755 --- a/RankPanda/CoreWrapper.py +++ b/RankPanda/CoreWrapper.py @@ -20,9 +20,7 @@ class CoreWrapper(object): def __init__(self, title, numberMeasures, CountsPerMeasureList, StepsPerCountList): if (numberMeasures < 1): raise NameError("Number of measures can't be less than 1!") - if (len(CountsPerMeasureList) == 0): - raise NameError("You must input the initial number of counts per measure!") - if (CountsPerMeasureList[0][0] != 1): + if (len(CountsPerMeasureList) == 0 or CountsPerMeasureList[0][0] != 1): raise NameError("You must input the initial number of counts per measure!") self._song = Song.Song(title, numberMeasures, CountsPerMeasureList[0][1]) i = 1 @@ -54,16 +52,21 @@ def GetSong(self): # [(0, 'Move 0'), (1, 'Move 1'), ...] def GetMoves(self): listOfMoves = self._song.GetMoveList() - i = 0 - moveInfo = [] - while (i < len(listOfMoves)): - curmove = listOfMoves[i] - moveInfo.append((curmove.GetNumber(), curmove.GetName())) - i = i + 1 - return moveInfo + #(Brady) Trying list comprehension + return [(curmove.GetNumber(), curmove.GetName()) for curmove in listOfMoves] + #Original Code + #i = 0 + #moveInfo = [] + #while (i < len(listOfMoves)): + # curmove = listOfMoves[i] + # moveInfo.append((curmove.GetNumber(), curmove.GetName())) + # i = i + 1 + #return moveInfo + + # Returns (current move number, current move name, current length of move in counts) - # Returns None is there is no current move + # Returns None if there is no current move def GetCurrentMove(self): if (self._song.currentMove is None): return None @@ -76,29 +79,37 @@ def GetCurrentMove(self): # ? # List of all ranks in current move # [(id0, name0, location0), (id1, name1, location1)] - def GetRanks(self): + #(Brady) Merged next method with this + def GetRanks(self, moveNumber = None): if (self._song.currentMove is None): return None - allRanks = self._song.currentMove.GetAllRanks() - i = 0 - allRankInfo = [] - while (i < len(allRanks)): - allRankInfo.append((allRanks[i].GetID(), allRanks[i].GetName(), allRanks[i].GetEndLocation(), allRanks[i].GetLabelLocation())) - i = i + 1 - return allRankInfo - - + if (moveNumber is None): + allRanks = self._song.currentMove.GetAllRanks() + else: + allRanks = self._song.GetMoveList()[moveNumber].GetAllRanks() + #(Brady) List comprehensions + return [(r.GetID(), r.GetName(), r.GetEndLocation(), r.GetLabelLocation()) for r in allRanks] + #Orig. code + #i = 0 + #allRankInfo = [] + #while (i < len(allRanks)): + # allRankInfo.append((allRanks[i].GetID(), allRanks[i].GetName(), allRanks[i].GetEndLocation(), allRanks[i].GetLabelLocation())) + # i = i + 1 + #return allRankInfo + + #(Brady) merged with prev with optional args. Keeping this so I dont have to change all the method calls. # Same as above but now you input the move number. def GetRanksGivenMove(self, moveNumber): - if (self._song.currentMove is None): - return None - allRanks = self._song.GetMoveList()[moveNumber].GetAllRanks() - i = 0 - allRankInfo = [] - while (i < len(allRanks)): - allRankInfo.append((allRanks[i].GetID(), allRanks[i].GetName(), allRanks[i].GetEndLocation(), allRanks[i].GetLabelLocation())) - i = i + 1 - return allRankInfo + return self.GetRanks(moveNumber) + # if (self._song.currentMove is None): + # return None + # allRanks = self._song.GetMoveList()[moveNumber].GetAllRanks() + # i = 0 + # allRankInfo = [] + # while (i < len(allRanks)): + # allRankInfo.append((allRanks[i].GetID(), allRanks[i].GetName(), allRanks[i].GetEndLocation(), allRanks[i].GetLabelLocation())) + # i = i + 1 + # return allRankInfo def IsRankHeld(self, ID): @@ -113,12 +124,15 @@ def GetSelectedRanks(self): if (self._song.currentMove is None): return None allSelectedRanks = self._song.currentMove.GetSelectedRanks() - i = 0 - allSelectedRankInfo = [] - while (i < len(allSelectedRanks)): - allSelectedRankInfo.append((allSelectedRanks[i].GetID(), allSelectedRanks[i].GetName(), allSelectedRanks[i].GetEndLocation(), allSelectedRanks[i].GetLabelLocation())) - i = i + 1 - return allSelectedRankInfo + #(Brady) List comp. + return [(r.GetID(), r.GetName(), r.GetEndLocation(), r.GetLabelLocation()) for r in allSelectedRanks] + #Orig. code + #i = 0 + #allSelectedRankInfo = [] + #while (i < len(allSelectedRanks)): + # allSelectedRankInfo.append((allSelectedRanks[i].GetID(), allSelectedRanks[i].GetName(), allSelectedRanks[i].GetEndLocation(), allSelectedRanks[i].GetLabelLocation())) + # i = i + 1 + #return allSelectedRankInfo def GetAdditionalRanks(self): curList = [] diff --git a/RankPanda/CubicHermiteSpline.py b/RankPanda/CubicHermiteSpline.py index 8b6ed17..6c96b91 100755 --- a/RankPanda/CubicHermiteSpline.py +++ b/RankPanda/CubicHermiteSpline.py @@ -145,11 +145,11 @@ def GetPoints(cls, splineList): NUMBERPERSTEP = 8 lengths = SplineGenerator.GetLengths(splineList) i = 0 -# Ignore and feel free to remove the next lines, I think they're repetitiions of the GetLengths() function. -# while (i < len(splineList)): -# lengths.append(SplineGenerator.GetLength(splineList[i], 0.001)) -# i = i + 1 -# i = 0 + # Ignore and feel free to remove the next lines, I think they're repetitiions of the GetLengths() function. + # while (i < len(splineList)): + # lengths.append(SplineGenerator.GetLength(splineList[i], 0.001)) + # i = i + 1 + # i = 0 listOfPointLists = [] while (i < len(splineList)): total = NUMBERPERSTEP*lengths[i] diff --git a/RankPanda/GUIDialogs.py b/RankPanda/GUIDialogs.py index 2ccffbf..4913fe9 100755 --- a/RankPanda/GUIDialogs.py +++ b/RankPanda/GUIDialogs.py @@ -536,7 +536,7 @@ def __init__(self, parent, main, endpoint, rankName, length, FTAranks): # endpoi self.okButton.SetDefault() self.okButton.Bind(wx.EVT_BUTTON, self.OnOK) - self.straightButton = wx.BitmapButton(self, wx.ID_ANY, wx.Bitmap('icons/zigzagicon.png')) + self.straightButton = wx.BitmapButton(self, wx.ID_ANY, wx.Bitmap('icons/zigzagicon.png')) self.straightButton.SetDefault() self.straightButton.Bind(wx.EVT_BUTTON, self.OnStraight) @@ -833,14 +833,14 @@ def __init__(self, parent): # begin layout code self.directionPanel = wx.BoxSizer(wx.HORIZONTAL) self.directionChoices = ['Clockwise', 'Counter-clockwise'] - self.directionChoicesValues = [0, 1] + #self.directionChoicesValues = [0, 1] #These aren't really needed I dont think self.directionRadioBox = wx.RadioBox(self, wx.ID_ANY, "Direction", choices = self.directionChoices, majorDimension = 2, style = wx.RA_SPECIFY_COLS) self.directionRadioBox.SetSelection(0) # clockwise selected by default self.directionPanel.Add(self.directionRadioBox, 1) self.pivotPanel = wx.BoxSizer(wx.HORIZONTAL) self.pivotChoices = ['At arrow ', 'At point'] - self.pivotChoicesValues = [0, 1] + #self.pivotChoicesValues = [0, 1] self.pivotRadioBox = wx.RadioBox(self, wx.ID_ANY, "Non-Pivot Point", choices = self.pivotChoices, majorDimension = 2, style = wx.RA_SPECIFY_COLS) self.pivotRadioBox.SetSelection(0) # arrow selected by default self.pivotPanel.Add(self.pivotRadioBox, 1) @@ -896,7 +896,8 @@ def OnOK(self, event): d.ShowModal() d.Destroy() return - self.output = (self.directionChoicesValues[self.directionRadioBox.GetSelection()], self.pivotChoicesValues[self.pivotRadioBox.GetSelection()] , length) + #self.output = (self.directionChoicesValues[self.directionRadioBox.GetSelection()], self.pivotChoicesValues[self.pivotRadioBox.GetSelection()] , length) + self.output = (self.directionRadioBox.GetSelection(), self.pivotRadioBox.GetSelection(), length) self.EndModal(0) def OnCancel(self, event): diff --git a/RankPanda/GUIMain.py b/RankPanda/GUIMain.py index 05b0f7d..ac48b90 100755 --- a/RankPanda/GUIMain.py +++ b/RankPanda/GUIMain.py @@ -93,8 +93,8 @@ def __init__(self, parent): self.core = CoreWrapper.CoreWrapper("Dummy", 10, [(1, 4)], [(1, 1)]) while loop: - self.dirname = '' - e = wx.FileDialog(self, "Open File", self.dirname, "", "*.panda", wx.OPEN) + dirname = '' + e = wx.FileDialog(self, "Open File", dirname, "", "*.panda", wx.OPEN) if e.ShowModal() == wx.ID_OK: self.filename = os.path.join(e.GetDirectory(), e.GetFilename()) if self.core.Load(self.filename) == -1: # load failed @@ -123,6 +123,7 @@ def __init__(self, parent): #self.CreateStatusBar(2) #self.SetStatusText("Try these: Exit, Open, Help, About", 1) + # begin menubar code filemenu = wx.Menu() filemenu.Append(ID_OPEN, "&Open...", "Open something") @@ -236,10 +237,12 @@ def __init__(self, parent): self.fieldpanel = wx.BoxSizer(wx.VERTICAL) self.fieldpanel.Add(self.statusBar, 0, wx.ALIGN_CENTER) self.fieldpanel.Add(self.field, 1, wx.EXPAND) - + + + self.rankNameUnicode = wx.Button(self.panel, wx.ID_ANY, "Unicode") self.rankNameUnicode.Bind(wx.EVT_BUTTON, self.OnRankNameUnicode) - self.holdRankButton = wx.BitmapButton(self.panel, wx.ID_ANY, wx.Bitmap('icons/holdicon.png')) + self.holdRankButton = wx.BitmapButton(self.panel, wx.ID_ANY, wx.Bitmap('icons/holdicon.png')) self.holdRankButton.Bind(wx.EVT_BUTTON, self.OnHoldRank) self.curveRankButton = wx.BitmapButton(self.panel, wx.ID_ANY, wx.Bitmap('icons/curveicon.png')) self.curveRankButton.Bind(wx.EVT_BUTTON, self.OnCurveRank) @@ -276,7 +279,7 @@ def __init__(self, parent): self.fieldbar.Bind(wx.EVT_PAINT, self.fieldbar.OnPaint) self.fieldbar.Bind(wx.EVT_SIZE, self.fieldbar.OnResize) self.fieldbar.Bind(wx.EVT_LEFT_DOWN, self.fieldbar.OnLeftClick) - self.fieldbar.Bind(wx.EVT_RIGHT_DOWN, self.fieldbar.OnRightClick) + self.fieldbar.Bind(wx.EVT_RIGHT_DOWN, self.fieldbar.OnRightClick) #right clicks dont actually do anything, ATM. self.fieldbar.Bind(wx.EVT_LEFT_UP, self.fieldbar.OnLeftUnclick) self.fieldbar.Bind(wx.EVT_RIGHT_UP, self.fieldbar.OnRightUnclick) self.fieldbar.Bind(wx.EVT_MOTION, self.fieldbar.OnMouseMove) @@ -357,6 +360,7 @@ def __init__(self, parent): self.rankNamePanel = wx.BoxSizer(wx.HORIZONTAL) self.rankNamePanel.Add(self.rankNameListPanel, 1, wx.EXPAND) + #TODO Make this a static Module level or Class level variable. self.commandAddChoices = ['MT', 'Hlt', 'FM', 'BM', 'RS', 'LS', 'Flat'] self.commandAddButtons = [] @@ -419,7 +423,7 @@ def __init__(self, parent): self.animationCaption = wx.StaticText(self.panel, wx.ID_ANY, "Animation Controls") - self.playButton = wx.BitmapButton(self.panel, wx.ID_ANY, wx.Bitmap('icons/playicon.png')) + self.playButton = wx.BitmapButton(self.panel, wx.ID_ANY, wx.Bitmap('icons/playicon.png')) self.playButton.Bind(wx.EVT_BUTTON, self.OnAnimationBegin) self.stopButton = wx.BitmapButton(self.panel, wx.ID_ANY, wx.Bitmap('icons/stopicon.png')) self.stopButton.Bind(wx.EVT_BUTTON, self.OnAnimationEnd) @@ -485,6 +489,7 @@ def __init__(self, parent): self.animranks = None # list of animated rank locations when animating; None when not self.animtimer = wx.Timer(self, ID_ANIM_TIMER) wx.EVT_TIMER(self, ID_ANIM_TIMER, self.OnAnimationTimer) + def RefreshTitleBar(self): if self.filename is None: @@ -506,7 +511,7 @@ def RefreshMoveList(self): item.SetText(m[1]) item.SetImage(i) - self.moveSetList.Add(self.field.RenderSet(self.core.GetRanksGivenMove(i))) + self.moveSetList.Add(self.field.RenderSet(self.core.GetRanks(moveNumber = i))) #(Brady) changed from GetRanksGivenMove(i) to GetRanks(moveNumber=i) self.moveList.InsertItem(item) @@ -518,7 +523,7 @@ def RefreshMoveList(self): def RefreshCurrentMove(self): curr = self.core.GetCurrentMove()[0] - self.moveSetList.Replace(curr, self.field.RenderSet(self.core.GetRanksGivenMove(curr))) + self.moveSetList.Replace(curr, self.field.RenderSet(self.core.GetRanks(moveNumber = curr))) self.moveList.RefreshItem(curr) def RefreshRankList(self): @@ -531,10 +536,10 @@ def RefreshRankList(self): i = 0 for r in ranks: - if r[1] is not None: + if r[1] is not None: #checks the name isSelected = False - for s in selected: + for s in selected: #(Brady) This seems inefficient, try to fix if r[0] == s[0]: isSelected = True @@ -620,7 +625,7 @@ def CreateSong(self, event): self.RefreshCommandList() self.RefreshStatusBar() - def EditSong(self, event): + def EditSong(self, event): #try not having event. d = GUIDialogs.SongCreationDialog(self) if d.ShowModal() == 0: try: @@ -811,11 +816,20 @@ def OnCommandAddSpecialButtons(self, event, i): #d.ShowModal() #d.Destroy() #return - n=0 - while(n startCount): + if (self._moveList[i].GetStartCount() > startCount): #find move that starts after startCount stop = True else: i = i + 1 - if (i > 0): - if ((self._moveList[i - 1].GetStartCount() + self._moveList[i - 1].GetLength()) > startCount): + if (i > 0): #if move before i, would overlap with the startCount, return none + if ((self._moveList[i - 1].GetStartCount() + self._moveList[i - 1].GetLength()) > startCount): return None if (i < len(self._moveList)): - if (self._moveList[i].GetStartCount() < endCount): + if (self._moveList[i].GetStartCount() < endCount): #if move i starts before endCount return None prior = None following = None @@ -369,7 +369,8 @@ def AnimationBegin(self, count): def AnimationStep(self): if (not self.animating): - return (None, 0) + print("not self.animating") #(Brady) debug + return (None, 0, 0) #(Brady) added the last 0 to fix error unpacking tuple (try other values to see if it has any effect) if (self.songLoaded): time = self.timeOffset + pygame.mixer.music.get_pos() count = self.ConvertTimeToCount(time)