Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: LETARTARE on May 25, 2022, 01:53:05 pm

Title: External application end event
Post by: LETARTARE on May 25, 2022, 01:53:05 pm
Is there an event that signals to 'CB' the end of an external application launched from the 'Tools' menu?
explanation : I launch 'Poedit' from the 'Tools' menu and I would like to be warned in 'CB' of its closing.
Title: Re: External application end event
Post by: BlueHazzard on May 25, 2022, 02:29:01 pm
Do you want to be warned in codeblocks that po edit is closed, or that po edit is still open when you close codeblocks

Anyway at the moment there is not such functionality. Also i think this would be quite complicated...
Title: Re: External application end event
Post by: LETARTARE on May 25, 2022, 02:30:52 pm
I want be warned when 'Poedit' is closed.
Title: Re: External application end event
Post by: BlueHazzard on May 25, 2022, 02:36:54 pm
And also probably prevent the closing?
Title: Re: External application end event
Post by: LETARTARE on May 25, 2022, 02:46:00 pm
No.
When I close 'Poedit', it has already saved two files '*.po' and '*.mo' and these are the two files I want to recover next automatically.
Title: Re: External application end event
Post by: LETARTARE on May 25, 2022, 05:48:41 pm
1- The only event that handles the termination of an executable in 'CB' is
Quote
'cbEVT_PIPEDPROCESS_TERMINATED'.
2- in 'ToolsManager::Execute(...)' then you have to use the option
Quote
'LAUNCH_VISIBLE' to use a 'PipedProcess'
3- then the event ending is reserved for the parent in
Code
'PipedProcess::OnTerminate(...)' 
by
Code
'wxPostEvent(m_Parent, event)'
4- I then added 
Code
'Manager::Get()->ProcessEvent(event)'
and I can get this event from a 'CB' plugin.

But I don't know if there are side effects, and if this modification is possible in 'CB' !

What do you think?
Title: Re: External application end event
Post by: Pecan on May 25, 2022, 06:23:45 pm
Is there an event that signals to 'CB' the end of an external application launched from the 'Tools' menu?
explanation : I launch 'Poedit' from the 'Tools' menu and I would like to be warned in 'CB' of its closing.

You could run your own wrapper program from the tools menu that wxExecutes then waits for the poedit process. Just the fact that it returned means that poedit ended.

It also gives you control over return codes from poedit and the ability to start/stop subsequent programs.
Title: Re: External application end event
Post by: LETARTARE on May 25, 2022, 07:22:20 pm
@Pecan :Thanks

I will try this track.
Title: Re: External application end event
Post by: BlueHazzard on May 25, 2022, 09:34:35 pm
Also, do the files exists, or are they generated by po edit?

I would need some event handling about changes in files. And i am willing to work on this...
Title: Re: External application end event
Post by: LETARTARE on May 25, 2022, 10:53:56 pm
In the 1st solution I had added
Quote
'Manager::Get()->ProcessEvent(event)'
to
Quote
'PipedProcess::OnTerminate(...)'
In a 2nd solution I added 
Quote
'Manager::Get()->ProcessEvent(event)'
at the end of
Quote
'ToolsManager::OnToolTerminated(CodeBlocksEvent& event)'
Both work well for me.

In the plugin 'CB' I proposed in 'https://github.com/LETARTARE/CB_Collector' :
1- I generated the file 'project_name.po' in the 'CB' editor,
2- I call by program the menu 'Tools->Poedit'  with parameter 'project_name.po'
3- from 'Poedit, I translate strings then i create 'project_name.mo' and quit
4- on return,
     - if I have translated strings, I get a warning from 'CB' to reload 'project_name.po' which has been
        modified : I reload
     - otherwise nothing to do
5- I want to be notified when 'Poedit' is closed to copy the file ''project_name.po'' to another directory

Actually, I use 'cbEVT_EDITOR_MODIFIED' but it is not satisfactory.
Title: Re: External application end event
Post by: LETARTARE on May 26, 2022, 08:33:04 am
You could run your own wrapper program from the tools menu that wxExecutes then waits for the poedit process. Just the fact that it returned means that poedit ended.
Thanks very much.

I already had a synchronous wrapper to run 'xgettext' and 'wxrc', so this simplified the code, avoiding event monitoring.
Title: Re: External application end event
Post by: Miguel Gimenez on May 26, 2022, 09:07:18 am
You can replace the call to poedit with a batch file calling poedit followed by the copy command.