From: <mie...@us...> - 2011-01-24 18:36:37
|
Revision: 6641 http://oorexx.svn.sourceforge.net/oorexx/?rev=6641&view=rev Author: miesfeld Date: 2011-01-24 18:36:30 +0000 (Mon, 24 Jan 2011) Log Message: ----------- Add a progress indicator to the ooDialog samples in the incubator Added Paths: ----------- incubator/samples/ooDialog/progress.indicator/ incubator/samples/ooDialog/progress.indicator/ProgressDialog.cls incubator/samples/ooDialog/progress.indicator/progressProgram.rex Added: incubator/samples/ooDialog/progress.indicator/ProgressDialog.cls =================================================================== --- incubator/samples/ooDialog/progress.indicator/ProgressDialog.cls (rev 0) +++ incubator/samples/ooDialog/progress.indicator/ProgressDialog.cls 2011-01-24 18:36:30 UTC (rev 6641) @@ -0,0 +1,188 @@ +/*----------------------------------------------------------------------------*/ +/* */ +/* Copyright (c) 2011-2011 Rexx Language Association. All rights reserved. */ +/* */ +/* This program and the accompanying materials are made available under */ +/* the terms of the Common Public License v1.0 which accompanies this */ +/* distribution. A copy is also available at the following address: */ +/* http://www.oorexx.org/license.html */ +/* */ +/* Redistribution and use in source and binary forms, with or */ +/* without modification, are permitted provided that the following */ +/* conditions are met: */ +/* */ +/* Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in */ +/* the documentation and/or other materials provided with the distribution. */ +/* */ +/* Neither the name of Rexx Language Association nor the names */ +/* of its contributors may be used to endorse or promote products */ +/* derived from this software without specific prior written permission. */ +/* */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ +/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ +/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */ +/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ +/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ +/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */ +/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ +/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */ +/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ +/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ +/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* */ +/*----------------------------------------------------------------------------*/ + +::requires 'ooDialog.cls' + +::class 'ProgressDialog' public subclass UserDialog + +::attribute captionText +::attribute msgText +::attribute rangeMax +::attribute rangeMin +::attribute incrStep +::attribute worker unguarded private + +::method init + + self~init:super + + self~setDefaults + + +::method setDefaults private + expose interruptible width height + + self~captionText = "Processing ..." + self~msgText = "Background processing is taking place. Please be patient." + + self~rangeMax = 100 + self~rangeMin = 0 + self~incrStep = 1 + + self~worker = .nil + + width = 350 + height = 150 + +::method begin unguarded + expose width height + + reply 0 + + if self~createCenter(width, height, self~captionText) then do + self~popup('ShowTop') + end + else do + self~initCode = 1 + j = infoDialog("Failed to create underyling dialog.") + end + +::method setInterruptible unguarded + use strict arg w + + signal on syntax + + if \ w~isA(.Interruptible) then do + raise syntax 93.948 array ("1", "Interruptible") + end + + self~worker = w + return + +syntax: + c = condition('O') + if c~traceBack \== .nil then c~traceBack~remove(c~traceback~first) + raise propagate + +::method updateStatus unguarded + expose statusBar + use strict arg text + + statusBar~setText("Status:" text) + + +::method increase unguarded + expose pb + use strict arg incr = (self~incrStep) + pb~step(incr) + +::method complete unguarded + expose pb + use strict arg + pb~setPos(self~rangeMax) + +::method endNow unguarded + return self~ok:super + + +::method defineDialog + + self~createStaticText(101, 5, 5, self~sizeX - 10, 50, , self~msgText) + self~createStaticText(102, 5, self~sizeY - 40, self~sizeX - 10, 15, , "" ) + self~createProgressBar(100, 5, self~sizeY - 20, self~sizeX - 10, 10, 'Smooth') + + +::method initDialog + expose pb statusBar + + pb = self~newProgressBar(100) + pb~setRange(self~rangeMin, self~rangeMax) + pb~setStep(1) + + self~newStatic(101)~setText(self~msgText) + + statusBar = self~newStatic(102) + statusBar~setText("Status: ") + +-- Don't let the user close the dialog, unless the work can be stopped. + +::method cancel unguarded + expose worker + say 'worker:' worker + if worker <> .nil then do + if worker~interruptible then do + worker~interrupt + return + end + end + + self~giveStatus + + +::method ok unguarded + expose worker + say 'worker:' worker + if worker <> .nil then do + if worker~interruptible then do + worker~interrupt + return + end + end + + self~giveStatus + + +::method giveStatus unguarded + expose pb + + reply 0 + + r = pb~getFullRange + percentDone = trunc((pb~getPos / (r~max - r~min)) * 100) + + msg = "Processing is only" percentDone"% done " || .endOfLine || - + "and can not be canceled at this time. " || .endOfLine || - + "(Try canceling later.)" || .endOfLine~copies(2) || - + "Please be patient." + + j = infoDialog(msg) + + +::class 'Interruptible' public mixinclass Object +::method interrupt unguarded abstract +::method interruptible unguarded abstract + Added: incubator/samples/ooDialog/progress.indicator/progressProgram.rex =================================================================== --- incubator/samples/ooDialog/progress.indicator/progressProgram.rex (rev 0) +++ incubator/samples/ooDialog/progress.indicator/progressProgram.rex 2011-01-24 18:36:30 UTC (rev 6641) @@ -0,0 +1,152 @@ +/*----------------------------------------------------------------------------*/ +/* */ +/* Copyright (c) 2011-2011 Rexx Language Association. All rights reserved. */ +/* */ +/* This program and the accompanying materials are made available under */ +/* the terms of the Common Public License v1.0 which accompanies this */ +/* distribution. A copy is also available at the following address: */ +/* http://www.oorexx.org/license.html */ +/* */ +/* Redistribution and use in source and binary forms, with or */ +/* without modification, are permitted provided that the following */ +/* conditions are met: */ +/* */ +/* Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in */ +/* the documentation and/or other materials provided with the distribution. */ +/* */ +/* Neither the name of Rexx Language Association nor the names */ +/* of its contributors may be used to endorse or promote products */ +/* derived from this software without specific prior written permission. */ +/* */ +/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ +/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ +/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */ +/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ +/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ +/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */ +/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ +/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */ +/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ +/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ +/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* */ +/*----------------------------------------------------------------------------*/ + +/* + progressProgram.rex + + Originally from code written by Kees Wiegal. Heavily rewritten. + + Demonstrates using a progress bar while work is done. Needs ooDialog 4.2.0 + at least. + + The class ProgressDialog is intended to be the start of the fix for the + undocumented ProgressIndicator in UtilityClasses.cls +*/ + + -- Create the progress indicator dialog. + progressDlg = .ProgressDialog~new + + -- Create the worker and start working. + worker = .Worker~new(progressDlg) + worker~startWorking + + say "The work" worker~getStatus + +return 0 + + +::requires 'ProgressDialog.cls' + +::class 'Worker' inherit Interruptible + +::method init + expose progressDlg interruptible canceled status + use strict arg progressDlg + + interruptible = .true + canceled = .false + status = 'was not started' + + progressDlg~setInterruptible(self) + + +::method startWorking + expose progressDlg interruptible canceled status + + --reset timer + call time('R') + + interruptible = .false + status = "was started" + + progressDlg~setDlgFont('Comic Sans MS', 10) + progressDlg~msgText = "Some other text".endOfLine"besides".endOfLine"the default" + progressDlg~rangeMax = 200 + progressDlg~begin + + if progressDlg~initCode <> 0 then do + status = "failed to start" + return + end + + -- Start of work, just a simulation + + do i = 1 to progressDlg~rangeMax - progressDlg~rangeMin + call SysSleep 0.1 + + -- Update the progress indicator's status with the processing time + eMin = time('E') % 60; eMin = eMin~right(2,'0') + eSec = (time('E')//60)~format(,0); eSec = eSec~right(2,'0') + progressDlg~updateStatus('processing time:' eMin':'eSec) + + -- Have the progress bar step. + progressDlg~increase + + -- Simulate periods when we can be halted, and when we can not + select + when i == 1 then interruptible = .true + when i // 10 == 0 then interruptible = .false + when i // 4 == 0 & \interruptible then interruptible = .true + otherwise nop + end + + if interruptible & canceled then do + progressDlg~updateStatus('Canceled at:' eMin':'eSec) + progressDlg~complete + + -- Give the user a little time to see results + call SysSleep 1.5 + status = "was interrupted" + leave + end + end + + -- End of simulated work + + if status \== "was interrupted" then status = "was finished successfully" + + -- End the progress indicator. + progressDlg~endNow + + +::method interrupt unguarded + expose interruptible canceled status + + if \ interruptible then return .false + + canceled = .true + status = 'was canceled' + return .true + +::method interruptible unguarded + expose interruptible + return interruptible + +::method getStatus + expose status + return status + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |