Write a Module

This tutorial shows how to write a Module.

Step 1: Create a class

A Module is simply a MATLAB class that subclasses from symphonyui.ui.Module.

Create a new class in your personal Symphony package by navigating to the package in MATLAB's Current Folder, right-clicking on the "+modules" directory, and selecting New File > Class.

new class

Name the class file "Demo.m" and open it in the MATLAB Editor.

classdef Demo
    %DEMO Summary of this class goes here
    %   Detailed explanation goes here

    properties
    end

    methods
    end

end

Remove the comments and edit the classdef line to subclass from the symphonyui.ui.Module class.

classdef Demo < symphonyui.ui.Module

    properties
    end

    methods
    end

end

You now have an empty Module.

Step 2: Override createUi

You add user interface controls to a module by overriding the createUi() method.

Override the createUi() method in the "Demo" module.

classdef Demo < symphonyui.ui.Module

    properties
    end

    methods

        function createUi(obj, figureHandle)

        end

    end

end

Set the figure title to "Demo" and the size to 200 by 100.

function createUi(obj, figureHandle)
    set(figureHandle, ...
        'Name', 'Demo', ...
        'Position', appbox.screenCenter(200, 100));
end

Add a "Run" button to the figure and implement its callback function.

function createUi(obj, figureHandle)
    set(figureHandle, ...
        'Name', 'Demo', ...
        'Position', appbox.screenCenter(200, 100));

    layout = uix.HBox( ...
        'Parent', figureHandle, ...
        'Padding', 11);

    uicontrol( ...
        'Parent', layout, ...
        'Style', 'pushbutton', ...
        'String', 'Run', ...
        'Callback', @obj.onSelectedRun);
end

function onSelectedRun(obj, ~, ~)

end
Note: Symphony includes the GUI Layout Toolbox, seen being used to create a layout above. While not required, it is highly recommended that you use the layout toolbox if you want to make anything more than the simplest module UI.

You now have a Module with a single button.

module

Step 3: Use services

The Symphony app is built on three services that all modules have access to:

  • symphonyui.app.AcquistionService - Contains methods related to selecting and controlling protocols.
  • symphonyui.app.ConfigurationService - Contains methods related to initializing and controlling rigs.
  • symphonyui.app.DocumentationService - Contains methods related to creating and controlling files.

You can utilize these services to access capabilities of the Symphony app from within a module, such as selecting a protocol, setting its property values, and running it or starting a new file, adding a source, and beginning an epoch group. The services are accessible through the acquisitionService, configurationService, and documentationService properties of a module.

Edit the onSelectedRun() method implemented above to run the current selected protocol when the "Run" button is pressed.

function onSelectedRun(obj, ~, ~)
    obj.acquisitionService.viewOnly();
end

You now have a simple, fully functioning, Module.

results matching ""

    No results matching ""