<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.vistrails.org//index.php?action=history&amp;feed=atom&amp;title=VistrailsPackagePythonCalcExample</id>
	<title>VistrailsPackagePythonCalcExample - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.vistrails.org//index.php?action=history&amp;feed=atom&amp;title=VistrailsPackagePythonCalcExample"/>
	<link rel="alternate" type="text/html" href="https://www.vistrails.org//index.php?title=VistrailsPackagePythonCalcExample&amp;action=history"/>
	<updated>2026-05-05T11:29:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.2</generator>
	<entry>
		<id>https://www.vistrails.org//index.php?title=VistrailsPackagePythonCalcExample&amp;diff=195&amp;oldid=prev</id>
		<title>Cscheid at 16:45, 31 January 2007</title>
		<link rel="alternate" type="text/html" href="https://www.vistrails.org//index.php?title=VistrailsPackagePythonCalcExample&amp;diff=195&amp;oldid=prev"/>
		<updated>2007-01-31T16:45:08Z</updated>

		<summary type="html">&lt;p&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 16:45, 31 January 2007&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-l90&quot;&gt;Line 90:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 90:&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;          # to capture the error and report it to the caller of the evaluation&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;          # to capture the error and report it to the caller of the evaluation&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;div&gt;          # function.&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;          # function.&lt;/div&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;          raise ModuleError(&amp;quot;unrecognized operation: '%s'&amp;quot; % op)&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;          raise ModuleError(&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;self, &lt;/ins&gt;&amp;quot;unrecognized operation: '%s'&amp;quot; % op)&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;div&gt;   &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;   &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;div&gt;  ###############################################################################&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;  ###############################################################################&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wikidb-vistrails_:diff::1.12:old-194:rev-195 --&gt;
&lt;/table&gt;</summary>
		<author><name>Cscheid</name></author>
	</entry>
	<entry>
		<id>https://www.vistrails.org//index.php?title=VistrailsPackagePythonCalcExample&amp;diff=194&amp;oldid=prev</id>
		<title>Cscheid: New page: Here's a full example of a VisTrails package that implements a simple calculator module.    ############################################################################  ##  ## Copyright (...</title>
		<link rel="alternate" type="text/html" href="https://www.vistrails.org//index.php?title=VistrailsPackagePythonCalcExample&amp;diff=194&amp;oldid=prev"/>
		<updated>2007-01-31T16:44:32Z</updated>

		<summary type="html">&lt;p&gt;New page: Here&amp;#039;s a full example of a VisTrails package that implements a simple calculator module.    ############################################################################  ##  ## Copyright (...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Here's a full example of a VisTrails package that implements a simple calculator module.&lt;br /&gt;
 &lt;br /&gt;
 ############################################################################&lt;br /&gt;
 ##&lt;br /&gt;
 ## Copyright (C) 2006-2007 University of Utah. All rights reserved.&lt;br /&gt;
 ##&lt;br /&gt;
 ## This file is part of VisTrails.&lt;br /&gt;
 ##&lt;br /&gt;
 ## This file may be used under the terms of the GNU General Public&lt;br /&gt;
 ## License version 2.0 as published by the Free Software Foundation&lt;br /&gt;
 ## and appearing in the file LICENSE.GPL included in the packaging of&lt;br /&gt;
 ## this file.  Please review the following to ensure GNU General Public&lt;br /&gt;
 ## Licensing requirements will be met:&lt;br /&gt;
 ## http://www.opensource.org/licenses/gpl-license.php&lt;br /&gt;
 ##&lt;br /&gt;
 ## If you are unsure which license is appropriate for your use (for&lt;br /&gt;
 ## instance, you are interested in developing a commercial derivative&lt;br /&gt;
 ## of VisTrails), please contact us at vistrails@sci.utah.edu.&lt;br /&gt;
 ##&lt;br /&gt;
 ## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE&lt;br /&gt;
 ## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.&lt;br /&gt;
 ##&lt;br /&gt;
 ############################################################################&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot;This package implements a very simple VisTrails module called&lt;br /&gt;
 PythonCalc. This is intended as a simple example that can be referred&lt;br /&gt;
 to by users to create their own packages and modules later.&lt;br /&gt;
 &lt;br /&gt;
 If you're interested in developing new modules for VisTrails, you&lt;br /&gt;
 should also consult the documentation in&lt;br /&gt;
 core/modules/vistrails_module.py.&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 import core.modules&lt;br /&gt;
 import core.modules.module_registry&lt;br /&gt;
 from core.modules.vistrails_module import Module, ModuleError&lt;br /&gt;
 &lt;br /&gt;
 ###############################################################################&lt;br /&gt;
 # PythonCalc&lt;br /&gt;
 #&lt;br /&gt;
 # A VisTrails package is simply a Python class that subclasses from&lt;br /&gt;
 # Module.  For this class to be executable, it must define a method&lt;br /&gt;
 # compute(self) that will perform the appropriate computations and set&lt;br /&gt;
 # the results.&lt;br /&gt;
 #&lt;br /&gt;
 # Extra helper methods can be defined, as usual. In this case, we're&lt;br /&gt;
 # using a helper method op(self, v1, v2) that performs the right&lt;br /&gt;
 # operations.&lt;br /&gt;
 &lt;br /&gt;
 class PythonCalc(Module):&lt;br /&gt;
     &amp;quot;&amp;quot;&amp;quot;PythonCalc is a module that performs simple arithmetic operations&lt;br /&gt;
 on its inputs.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
     # This constructor is strictly unnecessary. However, some modules&lt;br /&gt;
     # might want to initialize per-object data. When implementing your&lt;br /&gt;
     # own constructor, remember that it must not take any extra&lt;br /&gt;
     # parameters.&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         Module.__init__(self)&lt;br /&gt;
 &lt;br /&gt;
     # This is the method you should implement in every module that&lt;br /&gt;
     # will be executed directly. VisTrails does not use the return&lt;br /&gt;
     # value of this method.&lt;br /&gt;
     def compute(self):&lt;br /&gt;
         # getInputFromPort is a method defined in Module that returns&lt;br /&gt;
         # the value stored at an input port. If there's no value&lt;br /&gt;
         # stored on the port, the method will return None.&lt;br /&gt;
         v1 = self.getInputFromPort(&amp;quot;value1&amp;quot;)&lt;br /&gt;
         v2 = self.getInputFromPort(&amp;quot;value2&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
         # You should call setResult to store the appropriate results&lt;br /&gt;
         # on the ports.  In this case, we are only storing a&lt;br /&gt;
         # floating-point result, so we can use the number types&lt;br /&gt;
         # directly. For more complicated data, you should&lt;br /&gt;
         # return an instance of a VisTrails Module. This will be made&lt;br /&gt;
         # clear in further examples that use these more complicated data.&lt;br /&gt;
         self.setResult(&amp;quot;value&amp;quot;, self.op(v1, v2))&lt;br /&gt;
 &lt;br /&gt;
     def op(self, v1, v2):&lt;br /&gt;
         op = self.getInputFromPort(&amp;quot;op&amp;quot;)&lt;br /&gt;
         if op == '+':&lt;br /&gt;
             return v1 + v2&lt;br /&gt;
         elif op == '-':&lt;br /&gt;
             return v1 - v2&lt;br /&gt;
         elif op == '*':&lt;br /&gt;
             return v1 * v2&lt;br /&gt;
         elif op == '/':&lt;br /&gt;
             return v1 / v2&lt;br /&gt;
         # If a module wants to report an error to VisTrails, it should raise&lt;br /&gt;
         # ModuleError with a descriptive error. This allows the interpreter&lt;br /&gt;
         # to capture the error and report it to the caller of the evaluation&lt;br /&gt;
         # function.&lt;br /&gt;
         raise ModuleError(&amp;quot;unrecognized operation: '%s'&amp;quot; % op)&lt;br /&gt;
 &lt;br /&gt;
 ###############################################################################&lt;br /&gt;
 # the function initialize is called for each package, after all&lt;br /&gt;
 # packages have been loaded. It it used to register the module with&lt;br /&gt;
 # the VisTrails runtime.&lt;br /&gt;
 &lt;br /&gt;
 def initialize(*args, **keywords):&lt;br /&gt;
 &lt;br /&gt;
     # We'll first create a local alias for the module_registry so that&lt;br /&gt;
     # we can refer to it in a shorter way.&lt;br /&gt;
     reg = core.modules.module_registry&lt;br /&gt;
 &lt;br /&gt;
     # VisTrails cannot currently automatically detect your derived&lt;br /&gt;
     # classes, and the ports that they support as input and&lt;br /&gt;
     # output. Because of this, you as a module developer need to let&lt;br /&gt;
     # VisTrails know that you created a new module. This is done by calling&lt;br /&gt;
     # function addModule:&lt;br /&gt;
     reg.addModule(PythonCalc)&lt;br /&gt;
 &lt;br /&gt;
     # In a similar way, you need to report the ports the module wants&lt;br /&gt;
     # to make available. This is done by calling addInputPort and&lt;br /&gt;
     # addOutputPort appropriately. These calls only show how to set up&lt;br /&gt;
     # one-parameter ports. We'll see in later tutorials how to set up&lt;br /&gt;
     # multiple-parameter plots.&lt;br /&gt;
     reg.addInputPort(PythonCalc, &amp;quot;value1&amp;quot;,&lt;br /&gt;
                      (core.modules.basic_modules.Float, 'the first argument'))&lt;br /&gt;
     reg.addInputPort(PythonCalc, &amp;quot;value2&amp;quot;,&lt;br /&gt;
                      (core.modules.basic_modules.Float, 'the second argument'))&lt;br /&gt;
     reg.addInputPort(PythonCalc, &amp;quot;op&amp;quot;,&lt;br /&gt;
                      (core.modules.basic_modules.String, 'the operation'))&lt;br /&gt;
     reg.addOutputPort(PythonCalc, &amp;quot;value&amp;quot;,&lt;br /&gt;
                       (core.modules.basic_modules.Float, 'the result'))&lt;/div&gt;</summary>
		<author><name>Cscheid</name></author>
	</entry>
</feed>