I use either Ubuntu or Linux Mint on my desktop, whichever is currently working better. I prefer Linux Mint and then I use the Mate desktop. Mate (Pronounced like an Aussie pronouncing Matey.) Mate is based on the old Gnome 2.x desktop from years ago and has a sort of Windows XP look and feel. Well, whatever, I like it and it just feels comfortable. No Windows Ribbons crap, the desktop is not a moving target where you have to continually relearn how to do things that you already knew how to do.
Well on the task bar I had placed a weather app. It shows the current temperature right on the task bar and if I click on it, it will display all of the current conditions or the forecast in a pop up box. Well, about two weeks ago a Server IP address or something changed and it quit downloading the current conditions. Sometimes the forcast works and sometimes it doesn't.
I ran updates on my system to see if that would fix it. Nope, no change. So yesterday I got a little pissy about it and started looking around google for an easy fix. I didn't find one, similar problems have occurred in the past.
Well, there is a command line or terminal program called "Weather-Util", but to use it, I would have to start a terminal session and type in "weather-util "Des Moines, IA"" to get the temperature and such. Not the best solution, the beauty of what I had was the current temperature was always right on the task bar and at most the info I wanted was always not much more then a click away.
My favorite programming language is Pascal and have been using the Free Pascal compiler for many years. Free Pascal has the Lazarus front end that can make GUI Apps. Basically, it is very similar to the old Borland Delphi which is a form based programming environment.
So I started Lazarus and dropped a Memo right on the main form. I then had to add a library called process to the project. This allows one to start background proccesses to your app, I have found this very useful.
You than have to declare some variables:
Var
WProc: TProcess;
WSL: TStringList;
These are object oriented variables, the TProcess is the datastucture we use to run background processes and the tstringlist is sort of an array of strings. It is possible to dump the output of the background process right into the TStringList. These few instructions is all it takes:
WMemo.Clear;
WProc := TProcess.Create(nil);
WProc.Executable := 'weather-util';
WProc.Parameters.Add('fips1921000');
WProc.Options := WProc.Options + [poWaitOnExit, poUsePipes];
WProc.Execute;
WSL := TStringList.Create;
WSL.LoadFromStream(WProc.Output);
WMemo.Lines := WSL;
WMemo.Clear;
just clears any data out of the memo field.
WProc := TProcess.Create(nil);
Initializes the data structure for TProcess.
WProc.Executable := 'weather-util';
Tells TProcess what background process to run
WProc.Parameters.Add('fips1921000');
Adds a parameter to the process
WProc.Options := WProc.Options + [poWaitOnExit, poUsePipes];
The POWaitOnExit tells my app to stop and wait for the background process to finish
PoUsePipes copies any output from background process into a pipe, a sort of electronic pipe between two processes.
WProc.Execute;
Run the background process.
WSL.LoadFromStream(WProc.Output);
Copy the data from the pipe into the TSStringList.
WMemo.Lines := WSL;
Move the TStringList into the memo internal TStringList field.
I ran this routine right after the app starts and wallah, it displays the current conditions as soon as the app starts. I also added a button that added a additional parm that gives the forecast. All I did then was put an icon on my taskbar that will start this app. Now with just a single click I can have a working weather app.
What's left to do. Well it's not very pretty, but it displays all of the data I need. I maybe could bold the words temperature and the days being forecasted to make them stand out a little better.