Problem 1498

Summary: Qt: request for QFileOpenEvent support
Product: Geant4 Reporter: Mojca Miklavec <mojca.miklavec.lists>
Component: visualizationAssignee: garnier
Status: RESOLVED FIXED    
Severity: enhancement CC: garnier, John.Allison, perl
Priority: P5    
Version: other   
Hardware: Apple   
OS: Mac OS X   

Description Mojca Miklavec 2013-07-17 06:54:15 CEST
For Gate and other applications it would sometimes be handy to be able to double-click on a file filename.mac and let Geant4 run "/control/excute filename.mac" (or maybe some other configurable command).

This requires catching the QFileOpenEvent events, see:
http://qt-project.org/doc/qt-4.8/qfileopenevent.html
http://doc.qt.digia.com/qq/qq18-macfeatures.html#newevents

I would like to use this in Gate.app that will be shipped via MacPorts (the app is already set up and working), but it is a low priority request.

Thank you,
   Mojca
Comment 1 garnier 2013-08-01 11:40:29 CEST
Hi, 

This event is only for MacOS : "This class is currently supported for Mac OS X and Symbian only."

What will happen if more than one geant4 application is open at the same time ?

Could another way to do this be to drag your .mac file on the Gate.app window ? In this case it will be more easy to do something generic for all plateforms.
Comment 2 Mojca Miklavec 2013-08-01 13:10:51 CEST
Yes, I'm aware that this is very platform-specific, but this shouldn't be a problem. All it means is that the event will never be triggered on other platforms. Then again, I don't know (yet) how the same can be achieved on other OSes.

About what happens if more windows are open, I'm just speculating at the moment, but here's how I think it would work.

1.) The application (Something.app) needs to be registered in the system somehow. Then the user can open files with "open -a Something filename.mac". If the applications isn't running yet, it will open it first and then load the file. I don't believe that this could start an application from /some/random/place without properly packing it in the app bundle first. Also, I don't think that it could open the macro in an already running application that has been started from command line. (But maybe I'm wrong.)

2.) Usually only a single instance of a bundled application can run at the same time. If one would want to run two simulations inside, say, Gate, at the same time, one would either need to start Gate from the command line (and that application cannot open files with that method), or Geant4 would need to be patched to allow more than one independent simulation at the same time (multiple independent Qt windows). Probably that (patching geant) would require too much work for hardly any benefit.

3.) Given that there can only be a single instance of the same application open at the same time, only that one can open the file. In office application opening a file would mean opening a new window with that document only. If Geant4 would support multiple windows at the same time, then Geant4 would probably need to create a new window with a new simulation and load that file. As it stands now, the most sensible thing to do would be to just append the macro file on top of the single simulation that's running. If the application was closed before, it would start it and /control/execute the macro file.

4.) If there are multiple bundled applications which all support opening *.mac files, user can either specify the application from command line to open that macro file with Gate "open -a Gate thismacro.mac" or another [Geant4] application with "open -a AnotherApplication thismacro.mac". When double-clicking the file, there are system defaults that specify what application to use by default (like: should png files open with Safari/Opera/Firefox/Preview/Gimp/...), but user can also specify which program should open the file on per-file basis. So the user could say that this.mac should be opened with B3.app and that.mac should be opened with B4.app.

5.) Dragging wouldn't work when application is still closed, but it would indeed be a nice feature that probably solves all other "problems" mentioned above.

But as I said ... this is a low priority request. I would much prefer to see the other issues implemented/solved: pasting multiple lines into the Qt window, finding the data files automatically, handling the crashes gracefully, being able to load icons.mac (I still need to answer that), being able to use File->Open to load the macro file, setting the icon, ...

Mojca
Comment 3 garnier 2013-08-01 13:50:26 CEST
(In reply to comment #2)
> Yes, I'm aware that this is very platform-specific, but this shouldn't be a
> problem. All it means is that the event will never be triggered on other
> platforms. Then again, I don't know (yet) how the same can be achieved on other
> OSes.

Of course,
> 
> About what happens if more windows are open, I'm just speculating at the
> moment, but here's how I think it would work.
> 
> 1.) The application (Something.app) needs to be registered in the system
> somehow. Then the user can open files with "open -a Something filename.mac". If
> the applications isn't running yet, it will open it first and then load the
> file. I don't believe that this could start an application from
> /some/random/place without properly packing it in the app bundle first.
> Also, I
> don't think that it could open the macro in an already running application that
> has been started from command line. (But maybe I'm wrong.)

I'm not a expert in this field, but I think you are right.


> 
> 2.) Usually only a single instance of a bundled application can run at the same
> time. If one would want to run two simulations inside, say, Gate, at the same
> time, one would either need to start Gate from the command line (and that
> application cannot open files with that method), or Geant4 would need to be
> patched to allow more than one independent simulation at the same time
> (multiple independent Qt windows). Probably that (patching geant) would require
> too much work for hardly any benefit.
> 
> 3.) Given that there can only be a single instance of the same application open
> at the same time, only that one can open the file. In office application
> opening a file would mean opening a new window with that document only. If
> Geant4 would support multiple windows at the same time, then Geant4 would
> probably need to create a new window with a new simulation and load that file.
> As it stands now, the most sensible thing to do would be to just append the
> macro file on top of the single simulation that's running. If the application
> was closed before, it would start it and /control/execute the macro file.
> 
There is another case, geant4 is used in a lot of scientific fields and some times you have to run on two or more applications (for two or more detectors for example). In this case, you could have a lot of geant4 applications running at the same time.


> 4.) If there are multiple bundled applications which all support opening *.mac
> files, user can either specify the application from command line to open that
> macro file with Gate "open -a Gate thismacro.mac" or another [Geant4]
> application with "open -a AnotherApplication thismacro.mac". When
> double-clicking the file, there are system defaults that specify what
> application to use by default (like: should png files open with
> Safari/Opera/Firefox/Preview/Gimp/...), but user can also specify which program
> should open the file on per-file basis. So the user could say that this.mac
> should be opened with B3.app and that.mac should be opened with B4.app.

Yes

> 
> 5.) Dragging wouldn't work when application is still closed, but it would
> indeed be a nice feature that probably solves all other "problems" mentioned
> above.

Right, when a bundle application is closed, the only we have is when clicking on .mac file, open the bundle geant4 application (but which one if we have several examples ?)

> 
> But as I said ... this is a low priority request. I would much prefer to see
> the other issues implemented/solved: pasting multiple lines into the Qt window,
> finding the data files automatically, handling the crashes gracefully, being
> able to load icons.mac (I still need to answer that), being able to use
> File->Open to load the macro file, setting the icon, ...

Yes, I will reply to theses request ;-)

Laurent

> 
> Mojca
Comment 4 Mojca Miklavec 2013-08-01 15:53:16 CEST
(In reply to comment #3)
> (In reply to comment #2)
>
> There is another case, geant4 is used in a lot of scientific fields and some
> times you have to run on two or more applications (for two or more detectors
> for example). In this case, you could have a lot of geant4 applications running
> at the same time.

I can easily imagine the user like me who wants to run 10 totally different simulations in Gate. All I'm saying is that this is probably not yet supported on Mac unless the user calls the application from command-line. I had the same problem with Blender. If I wanted to work on two scenes, I had to call /Applications/blender.app/Contents/MacOS/blender from command line. On linux or windows this problem doesn't exist.


> > 5.) Dragging wouldn't work when application is still closed, but it would
> > indeed be a nice feature that probably solves all other "problems" mentioned
> > above.
> 
> Right, when a bundle application is closed, the only we have is when clicking
> on .mac file, open the bundle geant4 application (but which one if we have
> several examples ?)

If user has B3.app and B4.app, he can right-click and select "Open with ... -> B3".

On mac he cannot run B3.app twice.

It's exactly the same question as "what program to use to open this png file". The OS takes care of that (in the sense that it will always use the default application/example unless the user chooses a different default for a particular file). I don't think that Geant4 needs to address that question in any way. All that needs to be implemented is "run '/control/execute filename' if *this* application receives the event". If Geant actually supports multiple simulations by running the executable once (Does it? I believe it doesn't), then actually all you can do is start a new simulation and open that file on a fresh simulation. (Or if a single simulation is open, attach the macros to that one. Or attach it to the application that was last active. But that would be confusing.)
Comment 5 garnier 2013-11-24 23:55:08 CET
Hi, 

Pasting multiple lines into the Qt window is now allowed, it would be available in the next version. All others requirements are marked as enhancements.
Cheers, 
Laurent