Is there a way to intercept the 'User Interrupt' window that pops up when the user types the interrupt key and replace it with a customized dialog window? I've used on: do: to intercept Error messages but can't seem to do the same with EventSensor messages. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi, there. 1) Subclass StandardToolSet. 2) There, implement #interrupt:label: as you want it. 3) Set your new tool set via "ToolSet register: MyToolSet" and "ToolSet default: MyToolSet". Note that ToolSet is an AppRegistry and hence a wrapper whereas StandardToolSet is an actual tool set. :-) Other app registries include WebBrowser and SoundService. The user interrupt is not implemented with exceptions but a watchdog process and a special semaphore. See EventSensor >> #userInterruptWatcher for more information. Best, Marcel
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Jim O'Brien
Hi OBrien J
One way to do this is to install a new interruptWatcher on Sensor. On the class you want to handle the message do something like Sensor installInterruptWatcher:[self userInterruptWatcher]. Yourclass >> userInterruptWatcher "Wait for user interrupts and open a notifier on the active process when one occurs." | interruptSemaphore | interruptSemaphore := InputSensor interruptSemaphore. [true] whileTrue: [ interruptSemaphore wait. self signal: #userInterrupt. ]. Then implement your handler with something like onUserInterrupt to respond to the signal. Or you could just call a method in your class to handle the interrupt. Hope that helps! All the best, Ron Teitelbaum On Sat, Dec 9, 2017 at 12:09 PM, obrienj <[hidden email]> wrote:
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Squeak complains that it doesn't know InputSensor.
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
You can use Sensor instead.
All the best, Ron Teitelbaum On Sat, Dec 9, 2017 at 2:56 PM, obrienj <[hidden email]> wrote:
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Tried that but Sensor doesn't know interruptSemaphore
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
I see. You are right. It's an instance var but there is no accessor for it. You will need to add an accessor for it to override the emergency evaluator. EventSensor >> interruptSemaphore "return the interruptSemaphore. Used for overriding the emergency evaluator on MyClass" ^interruptSemaphore Then it should work. All the best, Ron Teitelbaum On Sat, Dec 9, 2017 at 3:38 PM, obrienj <[hidden email]> wrote:
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Now Squeak complains that installInterruptWatcher is an unknown selector.
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Notice the colon on the selector. Check instance side of EventSensor for method. Ron On Sat, Dec 9, 2017, 11:46 PM obrienj <[hidden email]> wrote:
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by marcel.taeumel
Hi Marcel, I made MyToolSet, a subclass of StandardToolSet, and added a copy of #interrupt:label to it. I next created HaltExperiment as an Object subclass and added this simple, infinite loop method: infiniteLoop
| x |
ToolSet register: MyToolSet. ToolSet default: MyToolSet.
Transcript clear.
x := 0. [x >= 0] whileTrue: [x := x + 1. Transcript show: 'x = ', x; cr.]. As a test, I commented out the code in StandardToolSet’s #interrupt:label:, which stops the User Interrupt window from appearing but also causes Squeak to freeze after typing the interrupt key. Unfortunately, running HaltExperiment new infiniteLoop didn't restore the appearance of the User Interrupt window or stop Squeak from freezing even though MyToolSet has a complete copy of #interrupt:label:. What am I doing wrong? How do I implement MyToolSet's #interrupt:label so that a dialog window appears with its own message to the user when infiniteLoop is interrupted? Thanks, Jim
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Jim, well, the Debugger takes care of re-spawning a new UI process in case the interrupted one was the UI process. :-) You should do that, too: interrupt: process label: string "ToolSet register: self; default: self" Project current spawnNewProcessIfThisIsUI: process. self inform: string. Best, Marcel
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
...hmmm... this test seems to lock the Transcript's input semaphore. So, after CMD+Dot via MyToolSet, any calls to "Transcript show:" will freeze. Interesting. Any ideas? Best, Marcel
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Tried it but nothing changed. Looking at Debugger's methods, it appears that typing the interrupt key opens a notifier (the User Interrupt window), which gives the user the option to abandon the interrupted process. Is there a way to add a method to a program so that typing the interrupt key simply abandons the running process without the notifier opening?
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Thu, Dec 21, 2017 at 09:00:49PM -0500, obrienj wrote:
> Tried it but nothing changed. > > Looking at Debugger's methods, it appears that typing the interrupt key opens a notifier (the User Interrupt window), which gives the user the option to abandon the interrupted process. Is there a way to add a method to a program so that typing the interrupt key simply abandons the running process without the notifier opening? > Sure, there is probably a way to do that. But the most likely use case for interrupting the system with the interrupt key is that something is going wrong. You are trying to interrupt the process in which something bad is happening, and you want to stop the bad thing from happening in such a way that you can correct the problem, then proceed from that point. For this kind of situation, the ideal solution is to open a debugger on the failing process so that you can interact with it directly, correct the problem, and then resume the interrupted process after you have addressed the problem. That is the reason for providing the notifier that allows you to enter a debugger, or to do whatever else you may think may be necessary. Dave _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Dave, Thank you for your reply. I understand the purpose and use of the debugger. I am working on a program that compiles user input that could result in an infinite loop if the user isn't careful. I'd like to avoid the debugger's notifier and simply halt the compiler and let the user edit the input and try again but haven't found a way to do that. Jim
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |