Hi,
The short question is: How do I add a button to the toolbar in Ptolemy.
I'm working on a add-on for ptolemy to do some specific actions. The goal is for users to click the to-be made button and then let the magic happen: validation of some values against a database. The huge amount of code dazzled me :) Where do I start with extending vergil/ptolemy to fit my needs?
The simplest way to do this is to define an attribute that you drop into your model where double clicking on your attribute invokes your magic. Below is an example of such an attribute that in this case opens its own, custom UI for a verification tool called Chic.
You can also add buttons to the toolbar, but doing so is more involved. You need to subclass the ActorGraphFrame to add to the toolbar, and ActorGraphTableau, which creates the ActorGraphFrame (both in $PTII/ptolemy/vergil/actor). Then you need to create a Configuration (like those in $PTII/ptolemy/configs) to create this tableau rather than the default one.
This latter mechanism is intended for much more drastic changes to the UI than just adding a button to the toolbar (you can create a completely custom UI for a model this way).
Hope this helps... Edward
----------- the attribute that you drop in your model:
public class ChicInvoker extends Attribute {
/** Construct an attribute with the specified container and name. * @param container The container. * @param name The name of the attribute. * @exception IllegalActionException If the factory is not of an * acceptable attribute for the container. * @exception NameDuplicationException If the name coincides with * an attribute already in the container. */ public ChicInvoker(NamedObj container, String name) throws IllegalActionException, NameDuplicationException { super(container, name);
// Create a custom icon. _attachText("_iconDescription", "<svg>\n" + "<rect x=\"-50\" y=\"-25\" " + "width=\"100\" height=\"50\" " + "style=\"fill:white\"/>\n" + "<image x=\"-50\" y=\"-25\" width=\"100\" height=\"50\" " + "xlink:href=\"ptolemy/chic/chic.gif\"/>\n" + "</svg>\n");
// Do not show the actor name. new SingletonAttribute(this, "_hideName");
// Create the attribute that overrides what you do when you // double click. new ChicControllerFactory(this, "_controllerFactory");
... }
-------------------------- The controller attribute:
/* An attribute that produces a custom node controller for ChicInvoker.
Copyright (c) 1998-2003 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software.
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY
@ProposedRating @AcceptedRating */
package ptolemy.chic;
// Diva imports import diva.graph.GraphController;
// Ptolemy imports import ptolemy.kernel.util.*; import ptolemy.vergil.basic.NamedObjController; import ptolemy.vergil.basic.NodeControllerFactory;
// Java imports
////////////////////////////////////////////////////////////////////////// //// ChicControllerFactory /** This is an attribute that produces a custom node controller for Chic visible attributes. This class creates an instance of ChicController, for controlling Chic visible attributes in a ptolemy model.
@author Eleftherios Matsikoudis @version $Id: ChicControllerFactory.java,v 1.2 2003/07/28 01:26:53 cxh Exp $ @since Ptolemy II 3.0 */ public class ChicControllerFactory extends NodeControllerFactory {
/** Construct a new attribute with the given container and name. * @param container The container. * @param name The name. * @exception IllegalActionException If the attribute cannot be contained * by the proposed container. * @exception NameDuplicationException If the container already has an * attribute with this name. */ public ChicControllerFactory(NamedObj container, String name) throws NameDuplicationException, IllegalActionException { super(container, name); }
/////////////////////////////////////////////////////////////////// //// public methods ////
/** Return a new node controller. This method returns an * instance of ChicController. * @param controller The associated graph controller. * @return A new node controller. */ public NamedObjController create(GraphController controller) { return new ChicController(controller); } }
------------ Edward A. Lee, Professor 518 Cory Hall, UC Berkeley, Berkeley, CA 94720 phone: 510-642-0455, fax: 510-642-2739 [EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal
---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]