Skip to content

Commit 6f8c36a

Browse files
committed
add stop button and play/pause to toolbar
1 parent 23f5ebd commit 6f8c36a

4 files changed

Lines changed: 69 additions & 31 deletions

File tree

app/Resources/en.lproj/PlotDeviceDocument.xib

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
<outlet property="exportSheet" destination="2ZA-Wl-gCw" id="Z4Z-5p-VeV"/>
1414
<outlet property="graphicsView" destination="15o-mm-Ppr" id="oax-n6-MB2"/>
1515
<outlet property="outputView" destination="31" id="37"/>
16+
<outlet property="runButton" destination="OFm-Uo-o5t" id="run-button-outlet"/>
1617
<outlet property="statusView" destination="NAS-Uo-kIt" id="OWZ-kH-bik"/>
18+
<outlet property="stopButton" destination="wUL-BX-PpT" id="stop-button-outlet"/>
1719
<outlet property="window" destination="5" id="dxm-Qo-rrG"/>
1820
</connections>
1921
</customObject>
@@ -118,13 +120,13 @@
118120
</splitView>
119121
</subviews>
120122
</view>
121-
<toolbar key="toolbar" implicitIdentifier="46B074B4-EE8C-4F09-9547-E60CB5854BF6" autosavesConfiguration="NO" allowsUserCustomization="NO" displayMode="iconAndLabel" sizeMode="regular" id="1Ye-0t-gpR">
123+
<toolbar key="toolbar" implicitIdentifier="46B074B4-EE8C-4F09-9547-E60CB5854BF6" autosavesConfiguration="NO" allowsUserCustomization="NO" displayMode="iconOnly" sizeMode="regular" id="1Ye-0t-gpR">
122124
<allowedToolbarItems>
123125
<toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="ByI-gB-2LU"/>
124126
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="1vH-nG-f9L"/>
125127
<toolbarItem implicitItemIdentifier="5089AF19-F362-4D9B-8F29-55B0FAA5865D" label="Custom View" paletteLabel="Custom View" tag="-1" sizingBehavior="auto" id="t02-8K-CYR">
126128
<nil key="toolTip"/>
127-
<customView key="view" id="NAS-Uo-kIt" customClass="StatusView">
129+
<customView key="view" autoresizesSubviews="NO" id="NAS-Uo-kIt" customClass="StatusView">
128130
<rect key="frame" x="0.0" y="14" width="100" height="22"/>
129131
<autoresizingMask key="autoresizingMask"/>
130132
<subviews>
@@ -160,14 +162,20 @@
160162
</connections>
161163
</customView>
162164
</toolbarItem>
163-
<toolbarItem implicitItemIdentifier="1B170BFA-98A0-4CDA-BC30-1F929B40EC04" label="Run Script" paletteLabel="Run Script" toolTip="Run the script" tag="-1" image="NSTouchBarPlayTemplate" bordered="YES" sizingBehavior="auto" id="OFm-Uo-o5t">
165+
<toolbarItem implicitItemIdentifier="1B170BFA-98A0-4CDA-BC30-1F929B40EC04" explicitItemIdentifier="run-script" label="Run Script" paletteLabel="Run Script" toolTip="Run the script" tag="-1" image="play.fill" catalog="system" bordered="YES" sizingBehavior="auto" id="OFm-Uo-o5t">
164166
<connections>
165167
<action selector="runScript:" target="-1" id="fSU-Wg-1X7"/>
166168
</connections>
167169
</toolbarItem>
170+
<toolbarItem implicitItemIdentifier="C7B1FE38-0BD0-4352-9171-E6F8F88D2159" explicitItemIdentifier="stop-script" label="Stop Script" paletteLabel="Stop Script" toolTip="Stop the script" tag="-1" image="stop.fill" catalog="system" bordered="YES" sizingBehavior="auto" id="wUL-BX-PpT">
171+
<connections>
172+
<action selector="stopScript:" target="-1" id="7UT-vo-kcR"/>
173+
</connections>
174+
</toolbarItem>
168175
</allowedToolbarItems>
169176
<defaultToolbarItems>
170177
<toolbarItem reference="t02-8K-CYR"/>
178+
<toolbarItem reference="wUL-BX-PpT"/>
171179
<toolbarItem reference="OFm-Uo-o5t"/>
172180
</defaultToolbarItems>
173181
</toolbar>
@@ -572,6 +580,7 @@ DQ
572580
</objects>
573581
<resources>
574582
<image name="NSStopProgressFreestandingTemplate" width="15" height="15"/>
575-
<image name="NSTouchBarPlayTemplate" width="12" height="13"/>
583+
<image name="play.fill" catalog="system" width="12" height="13"/>
584+
<image name="stop.fill" catalog="system" width="14" height="13"/>
576585
</resources>
577586
</document>

app/Resources/en.lproj/PlotDeviceScript.xib

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
</scrollView>
5959
</subviews>
6060
</view>
61-
<toolbar key="toolbar" implicitIdentifier="2E4A019F-C22A-413D-A96D-595F5B88CEC1" autosavesConfiguration="NO" allowsUserCustomization="NO" displayMode="iconAndLabel" sizeMode="regular" id="5QJ-Nr-i0E">
61+
<toolbar key="toolbar" implicitIdentifier="2E4A019F-C22A-413D-A96D-595F5B88CEC1" autosavesConfiguration="NO" allowsUserCustomization="NO" displayMode="iconOnly" sizeMode="regular" id="5QJ-Nr-i0E">
6262
<allowedToolbarItems>
6363
<toolbarItem implicitItemIdentifier="0F56688C-1EB0-4A6D-B08D-25B0037B2BB1" label="Custom View" paletteLabel="Custom View" tag="-1" sizingBehavior="auto" id="p4b-Gm-7hn">
6464
<nil key="toolTip"/>
65-
<customView key="view" id="RbF-zl-VKw" customClass="StatusView">
65+
<customView key="view" autoresizesSubviews="NO" id="RbF-zl-VKw" customClass="StatusView">
6666
<rect key="frame" x="0.0" y="14" width="100" height="22"/>
67-
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
67+
<autoresizingMask key="autoresizingMask"/>
6868
<subviews>
6969
<progressIndicator fixedFrame="YES" maxValue="100" displayedWhenStopped="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="P5L-MA-afK">
7070
<rect key="frame" x="83" y="3" width="17" height="17"/>
@@ -98,14 +98,22 @@
9898
</connections>
9999
</customView>
100100
</toolbarItem>
101-
<toolbarItem implicitItemIdentifier="18F11564-9324-411B-A6EE-B0286335D7DA" label="Run Script" paletteLabel="Run Script" tag="-1" image="NSTouchBarPlayTemplate" bordered="YES" sizingBehavior="auto" id="dMm-KR-TTT">
101+
<toolbarItem implicitItemIdentifier="18F11564-9324-411B-A6EE-B0286335D7DA" explicitItemIdentifier="run-script" label="Run Script" paletteLabel="Run Script" tag="-1" image="pause.fill" catalog="system" bordered="YES" id="dMm-KR-TTT">
102+
<size key="minSize" width="36" height="25"/>
103+
<size key="maxSize" width="36" height="25"/>
102104
<connections>
103105
<action selector="runScript:" target="-1" id="L79-Ub-51b"/>
104106
</connections>
105107
</toolbarItem>
108+
<toolbarItem implicitItemIdentifier="133F0992-F662-447D-BB3F-CE39BA0639A3" explicitItemIdentifier="stop-script" label="Stop Script" paletteLabel="Stop Script" tag="-1" image="stop.fill" catalog="system" bordered="YES" sizingBehavior="auto" id="Mor-T9-0sZ">
109+
<connections>
110+
<action selector="stopScript:" target="-1" id="TNR-tg-B3R"/>
111+
</connections>
112+
</toolbarItem>
106113
</allowedToolbarItems>
107114
<defaultToolbarItems>
108115
<toolbarItem reference="p4b-Gm-7hn"/>
116+
<toolbarItem reference="Mor-T9-0sZ"/>
109117
<toolbarItem reference="dMm-KR-TTT"/>
110118
</defaultToolbarItems>
111119
</toolbar>
@@ -138,7 +146,9 @@
138146
<outlet property="dashboardController" destination="170" id="EUP-eP-mMm"/>
139147
<outlet property="exportSheet" destination="NPn-1j-FnS" id="yP3-Mz-FOg"/>
140148
<outlet property="graphicsView" destination="vrd-6s-Y5i" id="TrA-Sg-ITa"/>
149+
<outlet property="runButton" destination="dMm-KR-TTT" id="run-button-outlet"/>
141150
<outlet property="statusView" destination="RbF-zl-VKw" id="XFX-qV-8NQ"/>
151+
<outlet property="stopButton" destination="Mor-T9-0sZ" id="stop-button-outlet"/>
142152
<outlet property="window" destination="5" id="ZRW-jd-ILx"/>
143153
</connections>
144154
</customObject>
@@ -644,6 +654,7 @@
644654
</objects>
645655
<resources>
646656
<image name="NSStopProgressFreestandingTemplate" width="15" height="15"/>
647-
<image name="NSTouchBarPlayTemplate" width="12" height="13"/>
657+
<image name="pause.fill" catalog="system" width="11" height="13"/>
658+
<image name="stop.fill" catalog="system" width="14" height="13"/>
648659
</resources>
649660
</document>

plotdevice/gui/document.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class ScriptController(NSWindowController):
121121
outputView = IBOutlet()
122122
editorView = IBOutlet()
123123
statusView = IBOutlet()
124+
runButton = IBOutlet()
125+
stopButton = IBOutlet()
124126

125127
# auxiliary windows
126128
dashboardController = IBOutlet()
@@ -198,6 +200,7 @@ def awakeFromNib(self):
198200
# wire up the statusView in the title bar
199201
statusItem = win.toolbar().items()[0]
200202
statusItem.setView_(self.statusView)
203+
self.setToolbarMode_('stop')
201204

202205
# sign up for autoresume on quit-and-relaunch (but only if this isn't console.py)
203206
if self.editorView:
@@ -236,7 +239,6 @@ def windowDidLoad(self):
236239
if self.vm.source:
237240
self.editorView.source = self.vm.source
238241

239-
240242
def encodeRestorableStateWithCoder_(self, coder):
241243
# walk through editor's superviews to autosave the splitview positions
242244
if self.editorView:
@@ -357,6 +359,27 @@ def runFullscreen_(self, sender):
357359
NSCursor.hide()
358360
self.runScript()
359361

362+
def validateToolbarItem_(self, item):
363+
return item.isEnabled()
364+
365+
def setToolbarMode_(self, mode):
366+
# mode is export/play/pause/stop
367+
toolbar = self.window().toolbar()
368+
if mode=='export':
369+
while len(toolbar.items()) > 1:
370+
toolbar.removeItemAtIndex_(1)
371+
else:
372+
if len(toolbar.items()) == 1:
373+
toolbar.insertItemWithItemIdentifier_atIndex_(self.stopButton.itemIdentifier(), 1)
374+
toolbar.insertItemWithItemIdentifier_atIndex_(self.runButton.itemIdentifier(), 2)
375+
376+
if mode == 'stop':
377+
run_style = ('play.fill', 'Run Script')
378+
else:
379+
run_style = ('play.fill', 'Resume') if mode == 'pause' else ('pause.fill', 'Pause')
380+
self.runButton.setImage_(NSImage.imageWithSystemSymbolName_accessibilityDescription_(*run_style))
381+
self.stopButton.setEnabled_(mode != 'stop')
382+
360383
def runScript(self):
361384
"""Compile the script and run its global scope.
362385
@@ -368,13 +391,16 @@ def runScript(self):
368391
call self.invoke('draw') until cancelled by the user.
369392
"""
370393

371-
# halt any animation that was already running
394+
# if an animation is already running, either pause or resume it
372395
if self.animationTimer:
373-
self.animationTimer.invalidate()
374-
self.animationTimer = None
396+
if self.animationTimer.isValid():
397+
self.animationTimer.invalidate()
398+
else:
399+
self.animationTimer = set_timeout(self, 'step', 1.0/self.vm.speed, repeat=True)
400+
self.setToolbarMode_("play" if self.animationTimer.isValid() else "pause")
401+
return
375402

376-
# get all the output progress indicators going
377-
self.statusView.beginRun()
403+
# clear the previous run's output
378404
if (self.outputView):
379405
self.editorView.clearErrors()
380406
self.outputView.clear(timestamp=True)
@@ -392,9 +418,6 @@ def runScript(self):
392418
success = self.invoke("setup")
393419

394420
if not success or not self.vm.animated:
395-
# halt the progress indicator if we crashed (or if we succeeded in a non-anim)
396-
self.statusView.endRun()
397-
398421
# don't mess with the gui window-state if running in fullscreen until the
399422
# user explicitly cancels with esc or cmd-period
400423
if success and not self.fullScreen:
@@ -416,6 +439,9 @@ def runScript(self):
416439
# Start the timer
417440
self.animationTimer = set_timeout(self, 'step', 1.0/self.vm.speed, repeat=True)
418441

442+
# enable the stop button in the toolbar
443+
self.setToolbarMode_("play")
444+
419445
def step(self):
420446
"""Keep calling the script's draw method until an error occurs or the animation complete."""
421447
ok = self.invoke("draw")
@@ -518,6 +544,9 @@ def exportInit(self, kind, fname, opts):
518544
# if we're exporting multiple frames, give some ui feedback
519545
if self.outputView:
520546
self.outputView.clear(timestamp=True)
547+
548+
# replace the toolbar buttons with a progress indicator
549+
self.setToolbarMode_("export")
521550
if self.statusView:
522551
self.statusView.beginExport()
523552

@@ -580,9 +609,8 @@ def stopScript(self):
580609
result = self.vm.stop()
581610
self.echo(result.output)
582611

583-
# disable progress spinner
584-
if self.statusView and not self.vm.session:
585-
self.statusView.endRun()
612+
# re-enable the play button
613+
self.setToolbarMode_("stop")
586614

587615
# relay any errors to the text panes (if we're in the app)
588616
if self.editorView:

plotdevice/gui/widgets.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ def awakeFromNib(self):
2525
self.cancel.cell().setShowsStateBy_(NSContentsCellMask)
2626
self.counter.setHidden_(True)
2727

28-
def beginRun(self):
29-
self._state = 'run'
30-
self.spinner.setIndeterminate_(True)
31-
self.spinner.startAnimation_(None)
32-
33-
def endRun(self):
34-
self._state = 'idle'
35-
self.spinner.stopAnimation_(None)
36-
self.cancel.setHidden_(True)
37-
3828
def beginExport(self):
3929
self._state = 'run'
4030

0 commit comments

Comments
 (0)