Creating XPM icons for toolbar is no longer available?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Creating XPM icons for toolbar is no longer available?

Post by Evgeniy »

I make example based on this wiki page https://wiki.freecadweb.org/Module_Creation
I tried to create an icon from XMP by different ways, but nothing works, but the workbench icon is displayed normally.

Log results when icon is loading to toolbar:
Cannot find icon:
/* XPM */
static const char * ViewProviderBox_xpm[] = {
"16 16 6 1",
Although wiki example tell's that is possible... May be something broken in the source code?

Code: Select all

import FreeCAD, FreeCADGui

IconGlobal = """
      /* XPM */
      static const char * ViewProviderBox_xpm[] = {
      "16 16 6 1",
      "    c None",
      ".   c #141010",
      "+   c #615BD2",
      "@   c #C39D55",
      "#   c #000000",
      "$   c #57C355",
      "        ........",
      "   ......++..+..",
      "   .@@@@.++..++.",
      "   .@@@@.++..++.",
      "   .@@  .++++++.",
      "  ..@@  .++..++.",
      "###@@@@ .++..++.",
      "##$.@@$#.++++++.",
      "#$#$.$$$........",
      "#$$#######      ",
      "#$$#$$$$$#      ",
      "#$$#$$$$$#      ",
      "#$$#$$$$$#      ",
      " #$#$$$$$#      ",
      "  ##$$$$$#      ",
      "   #######      "};
      """

class MyTool:
	"""Explanation of the command."""

	def __init__(self):
		"""Initialize variables for the command that must exist at all times."""
		pass
	
	def GetResources(self):
		return {"MenuText": "My Command",
			"Accel": "Ctrl+M",
			"ToolTip": "ToolTip command",
			"Pixmap"  : IconGlobal}

	def Activated(self):
		# do something here...
		print("Activated")

	def IsActive(self):
		if FreeCAD.ActiveDocument == None:
			return False
		else:
			return True

# The commands must be "registered" with a unique name by calling its class.
FreeCADGui.addCommand('My_Command1', MyTool())
FreeCADGui.addCommand('My_Command2', MyTool())
FreeCADGui.addCommand('My_Command3', MyTool())

class MyWorkbench ( Workbench ):
	"My workbench object"
	Icon = IconGlobal
	MenuText = "My Workbench"
	ToolTip = "This is workbench"

	def GetClassName(self):
		return "Gui::PythonWorkbench"
	
	def Initialize(self):
		self.appendToolbar("My Tools", ["My_Command1","My_Command2","My_Command3"])
		self.appendMenu("My Tools", ["My_Command1","My_Command2","My_Command3"])
		Log ("Loading MyModule... done\n")

	def Activated(self):
		# do something here if needed...
		Msg ("MyWorkbench.Activated()\n")

	def Deactivated(self):
		# do something here if needed...
		Msg ("MyWorkbench.Deactivated()\n")

FreeCADGui.addWorkbench(MyWorkbench)
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Creating XPM icons for toolbar is no longer available?

Post by mario52 »

Hi

here other example Custom_icon_in_tree_view but the icon is not permanent after Save/Open the file

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: Creating XPM icons for toolbar is no longer available?

Post by Evgeniy »

mario52 wrote: Sat Jul 31, 2021 10:28 am here other example Custom_icon_in_tree_view but the icon is not permanent after Save/Open the file
Hi

Thanks for link. But it tells about how to add XPM icon to ViewProvider but i tell about how add XPM icon to ToolBar via Command.
In ViewProvider all works fine... but not in toolbar.


ToolBar.png
ToolBar.png (17.44 KiB) Viewed 1410 times


I'm look the forum, and find very old post (2014 year) from jmwright Trouble With XPM and SVG Icons With a Command. He was talking about the same problem as me. But yorik says:
yorik wrote: Fri Nov 14, 2014 12:28 pm We don't use that mechanism anymore, and I wonder if it was not disabled at some point.
This is very strange. Apparently, one of the developers accidentally or for some purpose broke this mechanism. But at the same time, this mechanism works successfully in the ViewProvider and as a Workbench icon. Perhaps it has something to do with the scaling of toolbar icons...

But the wiki page https://wiki.freecadweb.org/Module_Creation continues to show disinformation for users since 2014...
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Creating XPM icons for toolbar is no longer available?

Post by mario52 »

hi

sorry maybe see one little workBench addon for study

similar problem Work Feature workbench with parametric objects

(i make this little ToolBar (not workBench) with icon in macro, maybe ... )

Image

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: Creating XPM icons for toolbar is no longer available?

Post by Evgeniy »

Intresting example. I look code it real use load XPM from string...
I try launch it in FreeCAD 0.20 under Linux. Only the color of the toolbar changes, but not the icons.
In the subject of the example, users write that in one version of FreeCAD the icons are visible and in the other version they are no longer there.
This means that this method is not reliable for use yet...

I don't understand how it works yet, maybe it's pure Qt.
Is possible to use this mechanism to load SVG from python code?
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Creating XPM icons for toolbar is no longer available?

Post by openBrain »

Evgeniy wrote: Sat Jul 31, 2021 11:44 am But the wiki page https://wiki.freecadweb.org/Module_Creation continues to show disinformation for users since 2014...
Yep, probably everybody did same as you since there : comment rather than changing the content...
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Creating XPM icons for toolbar is no longer available?

Post by onekk »

At the top of the page:
https://wiki.freecadweb.org/Module_Creation

There is a "deprecation warning" that says that this page has to be deleted after the relevant (and I suppose working) informations are moved to:


https://wiki.freecadweb.org/Workbench_creation


I doubt that is since 2014 that the information are outdated, maybe after the passage to PySide2 something is chanced or maybe you have to install some libraries to read some image formats (maybe this is something OS related).

As this page:

https://doc.qt.io/qt-5/qpixmap.html

XPM format is supported by QT5, that is used by PySide2.

Hope it helps.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Creating XPM icons for toolbar is no longer available?

Post by mario52 »

Evgeniy wrote: Sat Jul 31, 2021 1:08 pm Only the color of the toolbar changes, but not the icons.

In the subject of the example, users write that in one version of FreeCAD the icons are visible and in the other version they are no longer there.
This means that this method is not reliable for use yet...

I don't understand how it works yet, maybe it's pure Qt.
the macro work fine just see

Code: Select all

Tools > Edit parameter > User parameter:BaseApp/Preferences/Macros/FCMmacros/ToolViewReverse_ToolBar
for change parameters : color or not, loco or conventional view ...
Evgeniy wrote: Sat Jul 31, 2021 1:08 pm Is possible to use this mechanism to load SVG from python code?
normally yes

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: Creating XPM icons for toolbar is no longer available?

Post by Evgeniy »

openBrain wrote: Sat Jul 31, 2021 2:00 pm Yep, probably everybody did same as you since there : comment rather than changing the content...
You don't have to be particularly smart to judge someone.
The administration has not yet granted me the rights for confirm edits of source wiki pages.
Therefore, I have no special motivation to fix something, because my corrections may be lost or ignored.
Wiki have too many errors to create a topics for discussion every time.

Page fixed.

onekk wrote: Sat Jul 31, 2021 2:36 pm There is a "deprecation warning" that says that this page has to be deleted after the relevant (and I suppose working) informations are moved to:
For some reason I did not notice it.
"The information on this page that is still valid". Maybe valid.
I was found this incongruity about XPM by accident.
In fact, I am more interested in loading SVG format from string.

mario52 wrote: Sat Jul 31, 2021 4:33 pm Tools > Edit parameter > User parameter:BaseApp/Preferences/Macros/FCMmacros/ToolViewReverse_ToolBar
for change parameters : color or not, loco or conventional view ...
Confirm. It works.

Regards for comments to all.
Post Reply