Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-02

GUI frontend to a console application

19 messages · 11 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

This is probably more related to unix systems... Has anybody got a small sample application, some documentation or is a sample included in Lazarus that shows how to go about writing a GUI frontend to a console application?

For our company I want to implement a GUI app to help them setup a few basic things on a Linux system and interact with some console apps. Our users are NOT tech-savy, so I need a GUI to help them along. Any idea how I go about this?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Thierry Andriamirado
to Graeme Geldenhuys

Le Tue, 24 Feb 2009 10:46:43 +0200,
Graeme Geldenhuys a ?crit :

in Lazarus that shows how to go about writing a GUI frontend to a console application?

FreeVision? (fpcsrc/2.2.x/packages/fv)

I don't know if it's still working, I din't use it for years now and I can't compile the example project. If it works for you, any TurboVision doc & sample apps can help you.

Regards,
Thierry

Toraka Bilaogy : http://torakabilaogy.blogspot.com Le 'salon' Madagascar : http://friendfeed.com/rooms/madagascar (New!) Thierry sur Facebook : http://profile.to/thierryandriamirado/

Reply by email

Marco van de Voort
to Thierry Andriamirado
Thierry Andriamirado wrote 8 lines
> in Lazarus that shows how to go about writing a GUI frontend to a > console application? FreeVision? (fpcsrc/2.2.x/packages/fv) I don't know if it's still working, I din't use it for years now and I can't compile the example project. If it works for you, any TurboVision doc & sample apps can help you.

It is working largely. The example also compiles.What error do you get ?

Reply by email

Graeme Geldenhuys
to Thierry Andriamirado: Le Tue, 24 Feb 2009 10:46:43 +0200, Graeme Geldenhuys a ?crit : FreeVision?…
Thierry Andriamirado wrote
FreeVision? (fpcsrc/2.2.x/packages/fv)

I didn't mean writing a GUI in the console. I meant a true GUI app (LCL or fpGUI based), which uses a console application as the backend.

For example, Linux has many GUI frontends for programs like makeiso, burncd, cdrecord, cvs, mpg123 etc...

eg:
FLTK burncd GUI frontend for burncd
http://linux.softpedia.com/get/Programming/UI-User-Interfaces-/FLTK-burncd-GUI-frontend-3184.shtml

bburn GUI frontend for mkisofs/cdrecord
http://savannah.nongnu.org/projects/bburn/

Gnome-Toaster - gui frontend for cdrecord
http://gnometoaster.rulez.org/

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
For example, Linux has many GUI frontends for programs like makeiso, burncd, cdrecord, cvs, mpg123 etc...

The most obvious example would probably be all the GUI frontends available for GDB debugger. :-)

I have no clue how to write such a GUI application. Anybody know?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

ik
to Graeme Geldenhuys: This is probably more related to unix systems... Has anybody got a small sample…

It simple, you need to use TProcess (TProcessUTF8 if you must), and pipes. if you need input as well as output then you need to work with them both.

The svn integration in Lazarus contain good example on how to do it. And you can also use my code:
http://ik.homelinux.org/projects/files/mazrim-nx.tar.gz

Ido

Graeme Geldenhuys wrote 24 lines
Hi, This is probably more related to unix systems... Has anybody got a small sample application, some documentation or is a sample included in Lazarus that shows how to go about writing a GUI frontend to a console application? For our company I want to implement a GUI app to help them setup a few basic things on a Linux system and interact with some console apps. Our users are NOT tech-savy, so I need a GUI to help them along. ?Any idea how I go about this? Regards, ?- Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Henry Vermaak
to Graeme Geldenhuys: On Tue, Feb 24, 2009 at 2:41 PM, Graeme Geldenhuys The most obvious example would…

2009/2/24 Graeme Geldenhuys :

Show quoted text 10 lines
On Tue, Feb 24, 2009 at 2:41 PM, Graeme Geldenhuys wrote: > > For example, Linux has many GUI frontends for programs like makeiso, > burncd, cdrecord, cvs, mpg123 etc... The most obvious example would probably be all the GUI frontends available for GDB debugger. ?:-) I have no clue how to write such a GUI application. Anybody know?

it depends how the back-end works. your gui would set the options to the back-end, start it, then read and write from the back-end. you can do all of this with tprocess

henry

Reply by email

Sebastian Kraft
to Graeme Geldenhuys: On Tue, Feb 24, 2009 at 2:41 PM, Graeme Geldenhuys The most obvious example would…
Graeme Geldenhuys wrote 11 lines
On Tue, Feb 24, 2009 at 2:41 PM, Graeme Geldenhuys wrote: > For example, Linux has many GUI frontends for programs like > makeiso, burncd, cdrecord, cvs, mpg123 etc... The most obvious example would probably be all the GUI frontends available for GDB debugger. :-) I have no clue how to write such a GUI application. Anybody know?

Just take TProcess class and run your console app. Then you can pass input and read output from there.
I think there is some example in the wiki.

For a more detailed example you can also look at my mplayer class. http://svn.berlios.de/svnroot/repos/cactusjukebox/source/mplayer.pas It's an interface to mplayer console app.

Sebastian

Reply by email

Martin Friebe
to Graeme Geldenhuys: This is probably more related to unix systems... Has anybody got a small sample…
Graeme Geldenhuys wrote 7 lines
Hi, This is probably more related to unix systems... Has anybody got a small sample application, some documentation or is a sample included in Lazarus that shows how to go about writing a GUI frontend to a console application?

While it isn't a "small" example. The IDE itself contains such code wrapping gdb.

debugger\cmdlinedebugger.pp

It will be similar (probably easier) if the command line app is *not* interactive.

Best Regards
Martin

Reply by email

Graeme Geldenhuys
to ik: It simple, you need to use TProcess (TProcessUTF8 if you must), and pipes. if you need…
ik wrote
The svn integration in Lazarus contain good example on how to do it. And you can also use my code: http://ik.homelinux.org/projects/files/mazrim-nx.tar.gz

Thanks Ido, that's exactly what I wanted to know. Never thought to look at the svn integration code. :)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Sebastian Kraft: Just take TProcess class and run your console app. Then you can pass input and read…
Sebastian Kraft wrote
For a more detailed example you can also look at my mplayer class. http://svn.berlios.de/svnroot/repos/cactusjukebox/source/mplayer.pas It's an interface to mplayer console app.

This will come in very handy. Thanks Sebastian!

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Martin Friebe: While it isn't a "small" example. The IDE itself contains such code wrapping gdb.…
Martin Friebe wrote
It will be similar (probably easier) if the command line app is *not* interactive.

The console apps we want to wrap works similar to the SubVersion (svn) command line client. Execute with certain parameters and read back the results, which must be displayed in a GUI form via various components.

Some console apps which we will be writing ourselves will output % progress, which we would like to represent with a TProgressBar. The reason we want both console and a GUI wrapper is so that we can script/automate the console app, but also allow the user to run it manually via a easier to use GUI frontend.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Vincent Snijders
to Graeme Geldenhuys: On Tue, Feb 24, 2009 at 2:41 PM, Graeme Geldenhuys The most obvious example would…
Graeme Geldenhuys wrote 9 lines
On Tue, Feb 24, 2009 at 2:41 PM, Graeme Geldenhuys wrote: > For example, Linux has many GUI frontends for programs like makeiso, > burncd, cdrecord, cvs, mpg123 etc... The most obvious example would probably be all the GUI frontends available for GDB debugger. :-) I have no clue how to write such a GUI application. Anybody know?

Browsing the projects using Lazarus on the wiki, I got to http://www.ullihome.de/index.php/QFront I bet there are more on that page.

And the most (all?) of the examples on
http://wiki.lazarus.freepascal.org/Executing_External_Programs are GUIs calling console apps.

Vincent

Reply by email

Hans-Peter Diettrich
to Graeme Geldenhuys: On Tue, Feb 24, 2009 at 11:43 AM, Thierry Andriamirado I didn't mean writing a GUI in the…
I didn't mean writing a GUI in the console. I meant a true GUI app (LCL or fpGUI based), which uses a console application as the backend.

What then is your technical problem?

For example, Linux has many GUI frontends for programs like makeiso, burncd, cdrecord, cvs, mpg123 etc...

These frontends most probably collect the options and then call the backends with the appropriate command line.

Or they use the application libraries directly, without starting the console programs. In this case the command line argument evaluation has to be moved to the GUI frontend, which finally calls the same procedures as the main procedure of the console application does. For easy maintenance the console programs can be changed to use a shared library, which then can be used by every frontend. The shared libraries then should not do any console output, eventually output to stdout or stderr must be caught by the frontend, or the handles must be redirected/piped to the frontend. I never separated existing applications into shared libraries, so I don't know about the best solution for console output. When every output ends up in a few unique procedures, these procedures can be replaced by callback functions, provided by the frontend and installed during initialization of the shared library.

DoDi

Reply by email

Luiz Americo Pereira Camara
to Graeme Geldenhuys: The console apps we want to wrap works similar to the SubVersion (svn) command line…
Graeme Geldenhuys wrote 17 lines
On Tue, Feb 24, 2009 at 3:08 PM, Martin Friebe wrote: > It will be similar (probably easier) if the command line app is *not* > interactive. > The console apps we want to wrap works similar to the SubVersion (svn) command line client. Execute with certain parameters and read back the results, which must be displayed in a GUI form via various components. Some console apps which we will be writing ourselves will output % progress, which we would like to represent with a TProgressBar. The reason we want both console and a GUI wrapper is so that we can script/automate the console app, but also allow the user to run it manually via a easier to use GUI frontend.

I tweaked a class found in PasDoc project (made it standalone) that provides methods to "talk" with a process.
http://code.google.com/p/luipack/source/browse/trunk/miscutils/processlinetalk.pas It's used by sevenzipwrapper found in the same dir

Luiz

Reply by email

Graeme Geldenhuys
to Hans-Peter Diettrich: What then is your technical problem? These frontends most probably collect the options…
Hans-Peter Diettrich wrote 5 lines
> I didn't mean writing a GUI in the console. I meant a true GUI app > (LCL or fpGUI based), which uses a console application as the backend. What then is your technical problem?

I simply didn't know how to do it. But thanks to all the other posts I now know to use TProcess and how to read the output generated by the console application (the latter was the major obstacle for me)...

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Thierry Andriamirado
to Marco van de Voort: It is working largely. The example also compiles.What error do you get ?

Le Tue, 24 Feb 2009 11:37:51 +0100,
Marco van de Voort a ?crit :

> FreeVision? (fpcsrc/2.2.x/packages/fv) It is working largely. The example also compiles.What error do you get ? _______________________________________________

Nothing serious: "can't find unit Drivers used by testapp". I think this is because I use a 'dpkg-dist' version of /etc/fpc.cfg since 2 weeks. Obviously I just have to add the right unit path.

Glad to know that FreeVision is still working, as one of my projects 'll need it soon ;-)

Thanks a lot,
Thierry

Toraka Bilaogy : http://torakabilaogy.blogspot.com Le 'salon' Madagascar : http://friendfeed.com/rooms/madagascar (New!) Thierry sur Facebook : http://profile.to/thierryandriamirado/

Reply by email

Funky Beast
to Graeme Geldenhuys: The console apps we want to wrap works similar to the SubVersion (svn) command line…
Graeme Geldenhuys wrote 27 lines
On Tue, Feb 24, 2009 at 3:08 PM, Martin Friebe wrote: > It will be similar (probably easier) if the command line app is *not* > interactive. The console apps we want to wrap works similar to the SubVersion (svn) command line client. Execute with certain parameters and read back the results, which must be displayed in a GUI form via various components. Some console apps which we will be writing ourselves will output % progress, which we would like to represent with a TProgressBar. The reason we want both console and a GUI wrapper is so that we can script/automate the console app, but also allow the user to run it manually via a easier to use GUI frontend. Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

If the console app is self-written, you can use a mix of TProcess and TSimpleIPCServer and TSimpleIPCClient.

Add a TSimpleIPCClient to your console app, so that it can send message to its paired up TSimpleIPCServer which is hosted on the GUI frontend. This way, your console app can "speak" to your GUI frontend app. Be sure to read an argument as your IPCServerName, so it knows which IPCServer to talk to. On your GUI frontend, use a thread to read messages from the IPCServer continuously.

If you want to execute multiple console apps simultaneously, use TProcess to execute your console apps with poWaiting and poUsePipes turned off (so that it returns control to your app immediately) and use a TSimpleIPCServer to listen to the TSimpleIPCClient from your console app.

In the long run you should have a multi-threaded process-manager that handles a collection of TProcess and TSimpleIPCServer.

I have chopped up all my big apps into small console apps and frontends. So, my apps can all run with or without a GUI. So my big app is now a package of console apps and a frontend, sort of like how Linux works.

A rough model of my process-manager:
**********************************************************************************************
 TIPCServerThread = class (TThread)
 public
  IPCServer: TSimpleIPCServer;//For listening to the IPCClient of the console app
 end;
 TIPCProcess = class (TCollectionItem)
 public
  Process: TProcess;//For executing the console app (Execute without waiting)
  IPCServerThread: TIPCServerThread;//Listens and update status of this process
  property Status;
  property Progress;
  property MaxProgress;
  property Errors;
  //Note: the console app will receive an IPCServerName as a argument so it knows
  //      which IPCServer to talk to.
 end;

TIPCProcessList = class (TCollection)//For handling a collection of TIPCProcess.

 TIPCProcessManager = class(TComponent)
  //For complex mangement of processes like executing events when a particular process completes.
  //or a timer for polling the processlist for status to be displayed or actions to be taken.
**********************************************************************************************

This allows me to add features to my app easier as debugging my new console app is easier than debugging the monolithic app (most of my console apps handles long-loopy functions).

Also you take advantage of multi-core processors instantly as the OS will do it for you like as though you open multiple programs, you don't need to spend time tweaking your threads to consume or force-feed them to a paticular core. The front end serves only to display or execute console apps and load results.

my $0.002
Funky Beast

Reply by email

Graeme Geldenhuys
to Funky Beast
Funky Beast wrote
If the console app is self-written, you can use a mix of TProcess and TSimpleIPCServer and TSimpleIPCClient.

This is a very interesting approach. Thanks for mentioning it. I will definitely give this a try. And I love the benefit of the multi-core system. :-)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email