User Guide

More advanced information

DecoderPro User Guide - Create a custom programmer

How do I create my own custom programmer?

The answer starts with the creation of an xml file in the "programmers" subdirectory of the JMRI distribution. The contents of the file are described below.

Specifying items to display

The basic element of a programmer pane is a "display". This tells the programmer to present a single variable. The attributes are:

  • name - (Required) This is the "standard name" of the variable to be presented.
  • label - If present, this will be used to label the variable on the pane instead of the name or standard name of the variable.
  • layout - Where to locate the label with respect to the edittable field, e.g. the text box. Possible values are "left", "above", "below", "right" with a default of "right".
  • format -

    How the variable should be presented. Numeric variables can be presented as

    • an editable text field, which is the default if nothing is specified
    • hslider - a horizontal slider
    • vslider - a vertical slider

    Enum variables can be presented as

    • a selection box, which is the default if nothing is specified
    • radiobuttons - Each possible value is presented as an individual button
    • checkbox - An enum with only two states can also be presented as a checkbox
    • offradiobutton - A single button that sets the 0 choice for the variable when selected
    • onradiobutton - A single button that sets the 1 choice for the variable when selected

    These last two can be useful for indicating which parts of a configuration are active; see the "Speed Table" pane of Comprehensive.xml for an example.

  • tooltip - Allows you to specify a tooltip to be presented when the cursor is left over the variable. If not present, the tooltip defined in the decoder file is used. (Note: This is not fully implemented yet, but you should include them in your programmer definitions as they will work soon)

Which name to display is controlled by the pane's 'nameFmt' attribute, and the 'label' attribute on each display element (variable).

The choices are:

  • If a label is specified, it will be used. Use a label if you want absolute control over what a variable should be called, regardless of what the decoder file calls it, and you don't like the standard name.
  • The pane's nameFmt attribute is "item", in which case the item name will be used regardless of what the decoder file calls the variable. Use this is you want a uniform appearance for the pane for all decoders. But be aware that some standard names are really so generic as to be useless.
  • If the pane's nameFmt attribute is allowed to default, or contains "mfg", the decoder definition file's name will be used. This is the normal form, as it allows a manufacturer to specify in some detail what a variable defines.

Formatting

Each pane of the programmer consists of (nested) rows and/or columns. Columns lay out variables from top to bottom. Rows lay out variables from left to right. You can nest these to achieve various effects; for an example of this, see the "Speed Table" pane of the Comprehensive.xml file. It has two columns, the left of each uses a row to put some sliders from left to right.

Special Elements
There are a number of elements you can use to get the programmer formatted exactly the way you want:
Installing your new programmer

All of the .xml files in the "programmers" subdirectory will appear in the selection box when you create a new programmer in Decoder Pro. To use your new file, just put it in the "programmers" subdirectory of the "prefs" directory and select it. You don't have to restart the program, as the list is remade each time you open a new programmer window.

There is an option to present/hide panes from the decoder file. If you're writing a very basic programmer, you might want to hide them.

How variables in a decoder file match up with the programmer file

Each decoder file defines
variables that describe specific controls within the decoder. The programmer file then describes how to place those on panes so that the user can find and manipulate them.

Each "display" element in the programmer file defines one thing to show. But which one? That's controlled by the "name" attribute of the "display" element. DecoderPro takes that "name" and looks through the decoder definition for a "variable" element that has either the same "item" or "label" attribute.

This has some nice effects:

  1. The "name" in the "display" element is effectively a "standard name", that can be used in decoder definition files from many different manufacturers. Since this is separate from the "label" on the decoder variable, it's possible to have a generic programmer file that works for many types of different decoders, while still displaying specific variable names. For more on this, please see above.
  2. It lets you use very generic names to control where somewhat different things go. For example, different sound decoders provide different controls. One might have "Airpump", while another doesn't have that at all, and instead has "Brake Squeal". We don't want to have the programmer files contain zillions of "display" elements to handle every possible option. Instead, we use elements with more generic names, like "Sound Option 1", for the display name.

    The decoder definition then has a "label" of "Airpump" or whatever, and an "item" of "Sound Option 1". Everything matches up properly, and "Airpump" appears on the computer's screen.