<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.labrps.com/index.php?action=history&amp;feed=atom&amp;title=Viewprovider</id>
	<title>Viewprovider - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.labrps.com/index.php?action=history&amp;feed=atom&amp;title=Viewprovider"/>
	<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=Viewprovider&amp;action=history"/>
	<updated>2026-05-07T16:08:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.2</generator>
	<entry>
		<id>https://wiki.labrps.com/index.php?title=Viewprovider&amp;diff=2055&amp;oldid=prev</id>
		<title>LabRPS: /* Introduction */</title>
		<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=Viewprovider&amp;diff=2055&amp;oldid=prev"/>
		<updated>2024-10-28T16:07:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Introduction&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:07, 28 October 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Introduction ==  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Introduction ==  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Viewprovider|Viewproviders]] are classes that define the way objects will look like in the [[tree_view|tree view]], and how they will interact with certain graphical actions such as &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Selection_methods|&lt;/del&gt;selection&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]]&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Viewprovider|Viewproviders]] are classes that define the way objects will look like in the [[tree_view|tree view]], and how they will interact with certain graphical actions such as selection.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;They complement the [[scripted_objects|scripted objects]]. While the base class of the scripted object defines its {{Emphasis|data}} [[property|properties]], the viewprovider defines it {{Emphasis|view}} [[property|properties]]. These view properties are not essential information of the object, as they only indicate superficial information like line width, height, etc. In a terminal only session, the viewprovider is not loaded because there will be no interface to manipulate those visible properties.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;They complement the [[scripted_objects|scripted objects]]. While the base class of the scripted object defines its {{Emphasis|data}} [[property|properties]], the viewprovider defines it {{Emphasis|view}} [[property|properties]]. These view properties are not essential information of the object, as they only indicate superficial information like line width, height, etc. In a terminal only session, the viewprovider is not loaded because there will be no interface to manipulate those visible properties.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>LabRPS</name></author>
	</entry>
	<entry>
		<id>https://wiki.labrps.com/index.php?title=Viewprovider&amp;diff=2053&amp;oldid=prev</id>
		<title>LabRPS: Created page with &quot;== Introduction ==   Viewproviders are classes that define the way objects will look like in the tree view, and how they will interact with certain graphical actions such as selection.  They complement the scripted objects. While the base class of the scripted object defines its {{Emphasis|data}} properties, the viewprovider defines it {{Emphasis|view}} properties. These v...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=Viewprovider&amp;diff=2053&amp;oldid=prev"/>
		<updated>2024-10-28T15:55:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Introduction ==   &lt;a href=&quot;/Viewprovider&quot; title=&quot;Viewprovider&quot;&gt;Viewproviders&lt;/a&gt; are classes that define the way objects will look like in the &lt;a href=&quot;/Tree_view&quot; title=&quot;Tree view&quot;&gt;tree view&lt;/a&gt;, and how they will interact with certain graphical actions such as &lt;a href=&quot;/index.php?title=Selection_methods&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Selection methods (page does not exist)&quot;&gt;selection&lt;/a&gt;.  They complement the &lt;a href=&quot;/Scripted_objects&quot; title=&quot;Scripted objects&quot;&gt;scripted objects&lt;/a&gt;. While the base class of the scripted object defines its {{Emphasis|data}} &lt;a href=&quot;/Property&quot; title=&quot;Property&quot;&gt;properties&lt;/a&gt;, the viewprovider defines it {{Emphasis|view}} &lt;a href=&quot;/Property&quot; title=&quot;Property&quot;&gt;properties&lt;/a&gt;. These v...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Introduction == &lt;br /&gt;
&lt;br /&gt;
[[Viewprovider|Viewproviders]] are classes that define the way objects will look like in the [[tree_view|tree view]], and how they will interact with certain graphical actions such as [[Selection_methods|selection]].&lt;br /&gt;
&lt;br /&gt;
They complement the [[scripted_objects|scripted objects]]. While the base class of the scripted object defines its {{Emphasis|data}} [[property|properties]], the viewprovider defines it {{Emphasis|view}} [[property|properties]]. These view properties are not essential information of the object, as they only indicate superficial information like line width, height, etc. In a terminal only session, the viewprovider is not loaded because there will be no interface to manipulate those visible properties.&lt;br /&gt;
&lt;br /&gt;
Like with data properties, view properties are accessible from the [[property_editor|property editor]].&lt;br /&gt;
&lt;br /&gt;
== Python view providers == &lt;br /&gt;
&lt;br /&gt;
The viewproviders classes usually include {{incode|ViewProvider}} in their name. They are assigned on the {{incode|ViewObject}} attribute of the base object.&lt;br /&gt;
&lt;br /&gt;
In this example, we define two properties for the viewprovider, only if the properties don&amp;#039;t already exist, and assign their default values. We also define the {{incode|onChanged}} method that runs every time a property changes. We need to test the property by name, and then we will call one of two methods that will do the actual work of updating the pattern or setting its size.&lt;br /&gt;
{{Code|code=&lt;br /&gt;
# views/view_custom.py&lt;br /&gt;
class ViewProviderCustom:&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Viewprovider of the custom object.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self, vobj):&lt;br /&gt;
        self.Object = vobj.Object&lt;br /&gt;
&lt;br /&gt;
        self._set_properties(vobj)&lt;br /&gt;
        vobj.Proxy = self&lt;br /&gt;
&lt;br /&gt;
    def _set_properties(self, vobj):&lt;br /&gt;
        if not hasattr(vobj, &amp;quot;Pattern&amp;quot;):&lt;br /&gt;
            vobj.addProperty(&amp;quot;App::PropertyEnumeration&amp;quot;,&lt;br /&gt;
                             &amp;quot;Pattern&amp;quot;,&lt;br /&gt;
                             &amp;quot;Custom&amp;quot;,&lt;br /&gt;
                             &amp;quot;Defines a hatch pattern for this object.&amp;quot;)&lt;br /&gt;
            vobj.Pattern = [&amp;quot;None&amp;quot;, &amp;quot;diagonals&amp;quot;, &amp;quot;cross&amp;quot;, &amp;quot;brick&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
        if not hasattr(vobj, &amp;quot;PatternSize&amp;quot;):&lt;br /&gt;
            vobj.addProperty(&amp;quot;App::PropertyFloat&amp;quot;,&lt;br /&gt;
                             &amp;quot;PatternSize&amp;quot;,&lt;br /&gt;
                             &amp;quot;Custom&amp;quot;,&lt;br /&gt;
                             &amp;quot;Defines the size of the hatch pattern.&amp;quot;)&lt;br /&gt;
            vobj.PatternSize = 1&lt;br /&gt;
&lt;br /&gt;
    def onChanged(self, vobj, prop):&lt;br /&gt;
        if prop in &amp;quot;Pattern&amp;quot;:&lt;br /&gt;
            self._set_pattern(vobj.Pattern)&lt;br /&gt;
        if prop in &amp;quot;PatternSize&amp;quot;:&lt;br /&gt;
            self._set_size(vobj.PatternSize)&lt;br /&gt;
&lt;br /&gt;
    def _set_pattern(self, pattern):&lt;br /&gt;
        ...&lt;br /&gt;
&lt;br /&gt;
    def _set_size(self, size):&lt;br /&gt;
        ...&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The normal workflow is to first add the object proxy class, for example, {{incode|CustomObject}}, and then the viewprovider, for example, {{incode|ViewProviderCustom}}. The viewprovider can only be assigned when we have verified that the graphical interface is available, as otherwise the {{incode|ViewObject}} attribute doesn&amp;#039;t exist, and it will be an error to use this element as input for our class.&lt;br /&gt;
{{Code|code=&lt;br /&gt;
import LabRPS as App&lt;br /&gt;
import objects.custom as custom&lt;br /&gt;
import views.view_custom as view_custom&lt;br /&gt;
&lt;br /&gt;
doc = App.newDocument()&lt;br /&gt;
obj = doc.addObject(&amp;quot;Part::FeaturePython&amp;quot;, &amp;quot;Custom&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
custom.CustomObject(obj)&lt;br /&gt;
&lt;br /&gt;
if App.GuiUp:&lt;br /&gt;
    view_custom.ViewProviderCustom(obj.ViewObject)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Custom icons == &lt;br /&gt;
&lt;br /&gt;
By implementing the {{incode|getIcon}} method, you can specify the icon that will be shown in the [[tree_view|tree view]] in the upper part of the [[combo_view|combo view]].&lt;br /&gt;
&lt;br /&gt;
The return value can be the full path to an icon.&lt;br /&gt;
{{Code|code=&lt;br /&gt;
import os&lt;br /&gt;
some_path = &amp;quot;/home/user/.LabRPS/custom_icons&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class ViewProviderCustom:&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
    def getIcon(self):&lt;br /&gt;
        return os.path.join(some_path, &amp;quot;my_icon.svg&amp;quot;)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The relative path to an icon inside a compiled resource file.&lt;br /&gt;
{{Code|code=&lt;br /&gt;
import MyModule_rc.py&lt;br /&gt;
&lt;br /&gt;
class ViewProviderCustom:&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
    def getIcon(self):&lt;br /&gt;
        return &amp;quot;:/icons/my_icon.svg&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A raw [https://en.wikipedia.org/wiki/X_PixMap XPM icon], which is essentially ASCII art.&lt;br /&gt;
{{Code|code=&lt;br /&gt;
import MyModule_rc.py&lt;br /&gt;
&lt;br /&gt;
class ViewProviderCustom:&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
    def getIcon(self):&lt;br /&gt;
        return &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
               /* XPM */&lt;br /&gt;
               static char *Some_icon_xpm[] = {&lt;br /&gt;
               /* columns rows colors chars-per-pixel */&lt;br /&gt;
               &amp;quot;16 16 3 1 &amp;quot;,&lt;br /&gt;
               &amp;quot;  c None&amp;quot;,&lt;br /&gt;
               &amp;quot;. c #D71414&amp;quot;,&lt;br /&gt;
               &amp;quot;+ c #AA1919&amp;quot;,&lt;br /&gt;
               /* pixels */&lt;br /&gt;
               &amp;quot;                &amp;quot;,&lt;br /&gt;
               &amp;quot;  +          +  &amp;quot;,&lt;br /&gt;
               &amp;quot; +.+        +.+ &amp;quot;,&lt;br /&gt;
               &amp;quot;  +.+      +.+  &amp;quot;,&lt;br /&gt;
               &amp;quot;   +        +   &amp;quot;,&lt;br /&gt;
               &amp;quot;      ++++      &amp;quot;,&lt;br /&gt;
               &amp;quot;     +....+     &amp;quot;,&lt;br /&gt;
               &amp;quot;     +...++     &amp;quot;,&lt;br /&gt;
               &amp;quot;     +..+++     &amp;quot;,&lt;br /&gt;
               &amp;quot;     +.++.+     &amp;quot;,&lt;br /&gt;
               &amp;quot;      ++++      &amp;quot;,&lt;br /&gt;
               &amp;quot;   +        +   &amp;quot;,&lt;br /&gt;
               &amp;quot;  +.+      +.+  &amp;quot;,&lt;br /&gt;
               &amp;quot; +.+        +.+ &amp;quot;,&lt;br /&gt;
               &amp;quot;  +          +  &amp;quot;,&lt;br /&gt;
               &amp;quot;                &amp;quot;&lt;br /&gt;
               };&lt;br /&gt;
               &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
See various examples in [[Custom_icon_in_tree_view|Custom icon in tree view]].&lt;br /&gt;
&lt;br /&gt;
{{Powerdocnavi}}&lt;br /&gt;
[[Category:Developer Documentation]]&lt;br /&gt;
[[Category:Python Code]]&lt;br /&gt;
{{clear}}&lt;/div&gt;</summary>
		<author><name>LabRPS</name></author>
	</entry>
</feed>