Recent

Author Topic: How do you change a package icon once set?  (Read 6312 times)

n7800

  • Hero Member
  • *****
  • Posts: 644
  • Lazarus IDE contributor
    • GitLab profile
Re: How do you change a package icon once set?
« Reply #15 on: July 20, 2025, 03:48:53 pm »
n7800, I have a question for you if I may please. In the packageeditor.pas how does one get a form to display when a menu item is clicked? I have managed to get the ShowMessage dialog working but I need to display a from that has our icon stuff in it like the option to select between the .lrs legacy format or the .res newer format. If anyone out there knows please show me how!

As usual, search for something similar in the IDE, look at the code and repeat ))

If I understood the question correctly, then as a quick answer, I can suggest looking at the "Add" drop down button, and its "New Component" command. It also shows a window for creating a component.

As you can see, the button click event mnuAddNewCompClick calls ShowNewCompDialog method, which calls the global function ShowAddToPackageDlg from another unit addtopackagedlg.pas, which contains the required form.
In it, this form is created and called as a modal. It can do something or return some data (like fParams here), after which the form is freed and control is returned to the button.



This is how almost all dialog windows (modal) in the IDE are designed. In fact, they work as a function that returns data from a window (which is created just like a regular class).

Of course, functions like ShowAddToPackageDlg are created simply to reduce code duplication. The form can be created and called directly in the button event.
As far as I can see, the "extra" ShowNewCompDialog method in this chain is created here because it is called from another unit too.

I recommend always studying the places where variables/methods are used by searching in files [Ctrl+Shift+F]. Such a simple text search gives a lot of unnecessary results (since it does not take into account the visibility of variables), but it usually helps a lot.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4689
  • I like bugs.
Re: How do you change a package icon once set?
« Reply #16 on: July 20, 2025, 08:07:57 pm »
Juha, so if I want to debug the actual IDE source let's say if I open up /home/aruna/lazarus/packager/pkgmanager.pas then set a breakpoint on line :158:   procedure MainIDEitmPkgNewPackageClick(Sender: TObject); this shoudl trigger and activate the debugger? (Yes / Nope / Definitely a maybe?) I have not done this before. I have debugged my own projects many times but never tried with the actual IDE.
n7800 already explained the usage of "lazarus.lpi" project. Remember to build Lazarus with debug info first. (Profile "Debug IDE").
Another way to debug is to add DebugLn() lines into the code and look at their output. At least on Linux the output goes to the same console where lazarus was started from which is nice. I guess on Windows you must define a log file.
DebugLn() is especially handy when debugging actions triggered by mouse. Mouse clicks in the 2. Lazarus instance can confuse and lock the first instance.
Often you just need to know when a certain function is called and what values its variables have. DebugLn() is perfect for that.
Yet when you must see deep into the call stack or do other advanced stuff, you need the real debugger.

The first screenshot shows an additional menu item under the Package Manager > Use menu — we now have an Icon Resource Manager. 🎉
The second screenshot speaks for itself. We’re making progress!
Good!  :)

Quote
That said, once again I find myself humbled by the Lazarus IDE, not just by its features, but by the work of a single individual.
There are many contributors, not just one. Using the PackageEditor as an example you can run eg.
 $ gitk packager/packageeditor.pas &
to see the whole commit history
How to reach Mattias Gaertner? AFAIK he does not follow this forum much but he reads Lazarus mailing list.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

wp

  • Hero Member
  • *****
  • Posts: 13401
Re: How do you change a package icon once set?
« Reply #17 on: July 20, 2025, 08:32:20 pm »
The first screenshot shows an additional menu item under the Package Manager > Use menu — we now have an Icon Resource Manager. 🎉
Sorry, I think this is a risky feature. How does the package editor know where the icon is? The manual package administration that I described above runs completely outside the IDE, the IDE has no chance to find the icon file to be replaced. When the package resources were created like this, but the user interferes with your Icon Resource Manager there is a risk of duplicate resources. Also, when you restrict the resources to the lrs format which are embedded in the source files, it could be that the icon is not in the file that you clicked.

I am convinced that it is a quite demanding job to write an Icon Resource Manager which covers all possible cases or at least gives warnings in risky cases.

Aruna

  • Hero Member
  • *****
  • Posts: 793
Re: How do you change a package icon once set?
« Reply #18 on: July 21, 2025, 03:23:54 am »
The reason I was hoping for a direct dialogue with Mattias is simply because he wrote the packageeditor.pas unit. Who better to understand the intent behind the design, and who else could explain the best way to hook into certain areas without breaking things? It was never meant to bypass or diminish the importance of the broader community, quite the opposite. I am very sorry if it came out that way and my sincere and humble apologies if I have offended anyone.

No offense, your intentions to look at the author of the unit and contact him are completely logical. I just wanted to say that no matter who created the unit, in open source software it is often supplemented by many other developers (and contributors). So it is possible that other team members also know it, or knowledge about it is scattered among the participants ))
Agreed fully  :)

Aruna

  • Hero Member
  • *****
  • Posts: 793
Re: How do you change a package icon once set?
« Reply #19 on: July 21, 2025, 04:25:04 am »
n7800, I have a question for you if I may please. In the packageeditor.pas how does one get a form to display when a menu item is clicked? I have managed to get the ShowMessage dialog working but I need to display a from that has our icon stuff in it like the option to select between the .lrs legacy format or the .res newer format. If anyone out there knows please show me how!

As usual, search for something similar in the IDE, look at the code and repeat ))

If I understood the question correctly, then as a quick answer, I can suggest looking at the "Add" drop down button, and its "New Component" command. It also shows a window for creating a component.

As you can see, the button click event mnuAddNewCompClick calls ShowNewCompDialog method, which calls the global function ShowAddToPackageDlg from another unit addtopackagedlg.pas, which contains the required form.
In it, this form is created and called as a modal. It can do something or return some data (like fParams here), after which the form is freed and control is returned to the button.



This is how almost all dialog windows (modal) in the IDE are designed. In fact, they work as a function that returns data from a window (which is created just like a regular class).

Of course, functions like ShowAddToPackageDlg are created simply to reduce code duplication. The form can be created and called directly in the button event.
As far as I can see, the "extra" ShowNewCompDialog method in this chain is created here because it is called from another unit too.

I recommend always studying the places where variables/methods are used by searching in files [Ctrl+Shift+F]. Such a simple text search gives a lot of unnecessary results (since it does not take into account the visibility of variables), but it usually helps a lot.
Thank you again this helps a lot. This is actually what I tried to do but the code is way above my current level of comfort with pascal. So it will take time and hopefully each time I go back to the code things will start becoming clearer.

Aruna

  • Hero Member
  • *****
  • Posts: 793
Re: How do you change a package icon once set?
« Reply #20 on: July 21, 2025, 04:34:18 am »
Juha, so if I want to debug the actual IDE source let's say if I open up /home/aruna/lazarus/packager/pkgmanager.pas then set a breakpoint on line :158:   procedure MainIDEitmPkgNewPackageClick(Sender: TObject); this shoudl trigger and activate the debugger? (Yes / Nope / Definitely a maybe?) I have not done this before. I have debugged my own projects many times but never tried with the actual IDE.
n7800 already explained the usage of "lazarus.lpi" project. Remember to build Lazarus with debug info first. (Profile "Debug IDE").
Another way to debug is to add DebugLn() lines into the code and look at their output. At least on Linux the output goes to the same console where lazarus was started from which is nice. I guess on Windows you must define a log file.
DebugLn() is especially handy when debugging actions triggered by mouse. Mouse clicks in the 2. Lazarus instance can confuse and lock the first instance.
Often you just need to know when a certain function is called and what values its variables have. DebugLn() is perfect for that.
Yet when you must see deep into the call stack or do other advanced stuff, you need the real debugger.
This is neat, I did not know about lazarus.lpi. Many thanks for sharing. Oh, when I tried writeln() it compiled with no issues but upon running nothing is shown in the console? Like I said before I still have many things to learn  :)

The first screenshot shows an additional menu item under the Package Manager > Use menu — we now have an Icon Resource Manager. 🎉
The second screenshot speaks for itself. We’re making progress!
Good!  :)
It is simply a placeholder right now does nothing. Once I start to understand the code more I will try to add stuiff.

Quote
That said, once again I find myself humbled by the Lazarus IDE, not just by its features, but by the work of a single individual.
There are many contributors, not just one. Using the PackageEditor as an example you can run eg.
 $ gitk packager/packageeditor.pas &
to see the whole commit history
How to reach Mattias Gaertner? AFAIK he does not follow this forum much but he reads Lazarus mailing list.
I did not know about gitk either many thanks again. I have attached a screenshot it is impressive!
« Last Edit: July 21, 2025, 04:46:26 am by Aruna »

Aruna

  • Hero Member
  • *****
  • Posts: 793
Re: How do you change a package icon once set?
« Reply #21 on: July 21, 2025, 04:44:05 am »
The first screenshot shows an additional menu item under the Package Manager > Use menu — we now have an Icon Resource Manager. 🎉
Sorry, I think this is a risky feature. How does the package editor know where the icon is?
The package editor once you select a package automatically scans and loads the icons for each component into the lower panel. So if we use the same code it should work without giving us any headaches. The screenshot in the lower panel that says Registered Plugins you will see it shows the currently selected components icon. So once I  find the code that does this it should be possible use it to do what we want without any risks.

The manual package administration that I described above runs completely outside the IDE, the IDE has no chance to find the icon file to be replaced. When the package resources were created like this, but the user interferes with your Icon Resource Manager there is a risk of duplicate resources. Also, when you restrict the resources to the lrs format which are embedded in the source files, it could be that the icon is not in the file that you clicked.

I am convinced that it is a quite demanding job to write an Icon Resource Manager which covers all possible cases or at least gives warnings in risky cases.
I am also thinking of working on two tools. One in the IDE package editor the other a separate external application that does what you showed me entirely outside the IDE.

wp

  • Hero Member
  • *****
  • Posts: 13401
Re: How do you change a package icon once set?
« Reply #22 on: July 21, 2025, 11:45:32 am »
The package editor once you select a package automatically scans and loads the icons for each component into the lower panel. So if we use the same code it should work without giving us any headaches.
Now I understand. Nice idea.

n7800

  • Hero Member
  • *****
  • Posts: 644
  • Lazarus IDE contributor
    • GitLab profile
Re: How do you change a package icon once set?
« Reply #23 on: July 22, 2025, 02:23:33 am »
Oh, when I tried writeln() it compiled with no issues but upon running nothing is shown in the console?

There are big problems with the console on Windows:
1. When run the IDE from the terminal, it runs "separately" from it. Nothing is output to the console, and it considers the command executed.
2. Calling "WriteLn" will result in an error "File not open". This applies to any non-console application on Windows written in Lazarus*.

In the IDE, use "DebugLn" instead of "WriteLn". It has the advantage of formatting the input and the ability to output to a file via "lazarus.exe --debug-log=file.log".

* But in fact, there is a trick - specify "-WG-" (the minus at the beginning and end) in the build mode options. Then the console window will always open with the IDE. But this is not very convenient.

440bx

  • Hero Member
  • *****
  • Posts: 6130
Re: How do you change a package icon once set?
« Reply #24 on: July 22, 2025, 02:37:55 am »
There are a couple of "bugs" in the thank you list ... they are:

47. af0815                 
48. af0815

looks like a duplicate identifier ;)

56. [bannon   

that's an "unknown identifier" due to a misspelling ;)

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Aruna

  • Hero Member
  • *****
  • Posts: 793
Re: How do you change a package icon once set?
« Reply #25 on: July 22, 2025, 04:12:58 am »
Oh, when I tried writeln() it compiled with no issues but upon running nothing is shown in the console?

There are big problems with the console on Windows:
1. When run the IDE from the terminal, it runs "separately" from it. Nothing is output to the console, and it considers the command executed.
2. Calling "WriteLn" will result in an error "File not open". This applies to any non-console application on Windows written in Lazarus*.

In the IDE, use "DebugLn" instead of "WriteLn". It has the advantage of formatting the input and the ability to output to a file via "lazarus.exe --debug-log=file.log".

* But in fact, there is a trick - specify "-WG-" (the minus at the beginning and end) in the build mode options. Then the console window will always open with the IDE. But this is not very convenient.
I'm running Linux Debian and this happened while using Linux. I will test debugln() and see. Thank you n7800.
« Last Edit: July 22, 2025, 04:20:09 am by Aruna »

Aruna

  • Hero Member
  • *****
  • Posts: 793
Re: How do you change a package icon once set?
« Reply #26 on: July 22, 2025, 04:14:50 am »
There are a couple of "bugs" in the thank you list ... they are:

47. af0815                 
48. af0815

looks like a duplicate identifier ;)

56. [bannon   

that's an "unknown identifier" due to a misspelling ;)
Oh dear, that is a duplicate I will correct soon and the other is my buddy from down under dbannon again will correct soon. Thank's 440bx.

Aruna

  • Hero Member
  • *****
  • Posts: 793
Re: How do you change a package icon once set?
« Reply #27 on: July 22, 2025, 04:46:14 am »
The package editor once you select a package automatically scans and loads the icons for each component into the lower panel. So if we use the same code it should work without giving us any headaches.
Now I understand. Nice idea.
Thank you. But I just went and broke my IDE for the umpteenth time :o ( trying to test your work-flow) but it is all good I just learnt a few things. The  attached screenshots need no explanations  ;)

440bx

  • Hero Member
  • *****
  • Posts: 6130
Re: How do you change a package icon once set?
« Reply #28 on: July 22, 2025, 05:01:14 am »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18765
  • To Europe: simply sell USA bonds: dollar collapses
Re: How do you change a package icon once set?
« Reply #29 on: July 22, 2025, 06:58:10 am »
1. When run the IDE from the terminal, it runs "separately" from it. Nothing is output to the console, and it considers the command executed.
2. Calling "WriteLn" will result in an error "File not open". This applies to any non-console application on Windows written in Lazarus*.
[edit] I'll be back in a minute, copy paste error.
« Last Edit: July 22, 2025, 10:20:00 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

 

TinyPortal © 2005-2018