Closing SWT application when focus goes to another application - swt

I want that when the focus of the application moves to another application the application will be closed, for example, if the user clicks somewhere on the desktop the application should be closed.
I tried to use focus listener but it does not work. What's the solution to this?

In addition to the focus listener, you need to add an SWT.Deactivate listener to the shell and exit the application if this event occurs.
For example:
Shell shell = ...
shell.addListener( SWT.Deactivate, event -> shell.close() );
...
while( !shell.isDisposed() ) {
if( !display.readAndDispatch() )
display.sleep();
}
The example assumes that shell is the only shell, thus causing the program to end.

Related

How to know if Ionic split pane is opened or closed?

I'm trying to adjust some CSS properties depending on the state of the split pane, I mean, if it is opened or closed. I can detect when its state changes using ionChange event on the view, but I can't know if it was opened or closed. Is there a way to do this?
Split Pane documentation: https://ionicframework.com/docs/api/components/split-pane/SplitPane/
I was looking for the same behavior and found this. Here's an example:
<ion-split-pane (ionChange)="onSplitPaneChange($event)">
...
</ion-split-pane>
And in your component:
onSplitPaneChange(e) {
if (e._visible) {
// desktop
} else {
// mobile
}
}
This was tested for Ionic 3.
According to Redwolf, on Ionic 4 you'll have to read e.detail.visible instead of e._visible (I didn't try it myself yet - comment if you did). The rest may remain and works the same way though.

How to start launch configuration after finishing another launch programmatically? (Eclipse)

So I need to start an launch config. depending on output from another launch configuration.
Launch launch = (Launch) configurations[0].launch(ILaunchManager.RUN_MODE,
console);
do {
if(launch.isTerminated()){
configurations[1].launch(ILaunchManager.RUN_MODE,
new NullProgressMonitor());
break;
}
} while (!launch.isTerminated());
Something like this, but even this is not working. It executes only first launch. And how can I acces the output(from console) of first launch?
You get notified about the process associated with a launch terminating by using an IDebugEventSetListener listener.
Add the listener with:
DebugPlugin.getDefault().addDebugEventListener(listener);
When the process associated with the launch (if there is one) terminate a DebugEvent will be passed to the listener's handleDebugEvents method.
The event getKind() method will return DebugEvent.TERMINATE for a terminated process. The event getSource() returns the IProcess which terminated.

How do I navigate from panel to panel in console mode of install4J installer?

well, all is in the title.
In InstallAnywhere when in console mode you type back or next or quit. I haven't seen something like this in install4j.
Thanks,
X.
In install4j, console mode shows the user interface as a continuous stream of questions and so it's not organized into separate screens.
However, the installer has a "Console screen change handler" property where you can implement something like that. For example with code like
if (context.getBooleanVariable("showConsoleNavigation")) {
if (console.askYesNo("Do you want to repeat the last step?")) {
context.goBackInHistory(1);
} else {
console.println("* " + title);
}
}
You would set the installer variable "showConsoleNavigation" to Boolean.TRUE once you want to start the navigation.

Why the OnBeforeUnload doesn't intercept the back button in my GWT app?

I have a hook on the beforeUnload event. If i try to click on a link, reload or close the tab or the navigator, the app ask for confirmation before leaving. That's the desired behavior.
But if click on the back button or the backspace outside an input, no confirmation.
At the beginning of the html :
window.onbeforeunload = function() {
if (confirmEnabled)
return "";
}
And i use the Gwt PlaceHistoryMapper.
What did i miss ? Where did i forgot to look ?
Thanks !
As long as you stay within your app, because it's a single-page app, it doesn't by definition unload, so there's no beforeunload event.
When using Places, the equivalent is the PlaceChangeRequestEvent dispatched by the PlaceController on the EventBus. This event is also dispatched in beforeunload BTW, and is the basis for the mayStop() handling in Activities.
Outside GWT, in the JS world, an equivalent would be hashchange and/or popstate, depending on your PlaceHistoryHandler.Historian implementation (the default one uses History.newItem(), so that would be hashchange).

GTK: Destroy window and run an external script on button clicked

That's pretty much the question's title. I must be missing some signals interpretation here...
On PyGTK, I'm doing:
class Foo:
def __init__(self):
self.gladefile = gladefile
self.wTree = gtk.glade.XML(self.gladefile, 'some_window')
self.window = self.wTree.get_widget('some_window')
events = { 'on_code_submit_clicked' : self.submit }
self.wTree.signal_autoconnect(events)
def submit(self):
self.window.destroy()
os.system('external_script')
code = Foo()
What's happening, is that when the button is clicked, it stay pressed, then the script runs, and after the external program is closed, the window "blinks", getting destroyed and recreated again.
I also tried the "pressed" and "released" signals.
The behavior I need:
Click on the button
Destroy the current window
Run external script (that will open another program's window)
Recreate the Foo() window after closing the external app.
What I can imagine is that the event is being run during the clicked event, not after. That's why the window remain opened. The PyGTK docs don't say anything about something like gtk_signal_connect_after on the glade page, that leaves me totally lost about it.
Why not hide the window and show it after the external script?
self.window.hide()
os.system('external_script')
self.window.show()
It looks like you'll have to call the external script from a thread.
I haven't worked with threads with python, but it looks like the threading module would do the job (at least that's what I would try). Glib also has thread support, but I can't find the pygtk docs for it.
When the external script has finished, don't recreate Foo from the thread but schedule a callback function to do so using gobject.idle_add. This is because all GUI work should be done on the gtk event thread, otherwise your program may crash.
Posting my solution... it's easy as.
self.window.hide()
glib.idle_add(subprocess.call, ['external_script', 'param'])
glib.idle_add(self.window.show)