Skip to content

Commit 35cc808

Browse files
author
Krypton Cougars
committed
Allows CancelCommand with Sequential
1 parent 47ebb7a commit 35cc808

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

commandbased/cancelcommand.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
from wpilib.command import InstantCommand
1+
from wpilib.command import Command
22

3-
class CancelCommand(InstantCommand):
3+
4+
def checkIfCanceled(self):
5+
if self.forceCancel:
6+
self.forceCancel = False
7+
return True
8+
9+
return self._isFinished()
10+
11+
12+
class CancelCommand(Command):
413
'''
514
When this command is run, it cancels the command it was passed, even if that
615
command is part of a :class:`wpilib.CommandGroup`.
@@ -14,7 +23,18 @@ def __init__(self, command):
1423
super().__init__('Cancel %s' % command)
1524

1625
self.command = command
26+
if hasattr(self.command, '_isFinished'):
27+
return
28+
29+
self.command._isFinished = self.command.isFinished
30+
self.command.isFinished = checkIfCanceled.__get__(self.command)
31+
self.command.forceCancel = False
1732

1833

1934
def initialize(self):
20-
self.command._cancel()
35+
if self.command.isRunning():
36+
self.command.forceCancel = True
37+
38+
39+
def isFinished(self):
40+
return not self.command.isRunning()

0 commit comments

Comments
 (0)