MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Uživatelský manuál Strana 210

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 330
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 209
8 Programming the GUI
8-38
When a user selects the to file option under the Edit menu’s Copy option, only
the
to file callback is required to perform the action.
Suppose, however, that only certain objects can be copied to a file. You can use
the
Copy item Callback callback to enable or disable the to file item,
depending on the type of object selected.
Opening a Dialog Box from a Menu Callback
The Callback callback for the to file menu item could contain code such as the
following to display the standard dialog box for saving files.
[file,path] = uiputfile('animinit.m','Save file name');
'Save file name'
is the dialog box title. In the dialog box, the filename field
is set to
animinit.m, and the filter set to M-files (*.m). For more information,
see the
uiputfile reference page.
Updating a Menu Item Check
A check is useful to indicate the current state of some menu items. If you
selected
Check mark this item in the Menu Editor, the item initially appears
checked. Each time the user selects the menu item, the callback for that item
must turn the check
on or off. The following example shows you how to do this
by changing the value of the menu item’s
Checked property.
if strcmp(get(gcbo, 'Checked'),'on')
set(gcbo,'Checked','off');
else
set(gcbo,'Checked','on');
end
The gcbo function returns the handle of the object whose callback is executing,
in this case the menu item. The
strcmp function compares two strings and
returns logical
1 (true) if the two are identical and logical 0 (false) otherwise.
If you set the axes to be visible when a user first opens the GUI, make sure to
select the
Check mark this item check box in the Menu Editor, so that a check
will appear next to the
Show axes menu item initially.
Zobrazit stránku 209
1 2 ... 205 206 207 208 209 210 211 212 213 214 215 ... 329 330

Komentáře k této Příručce

Žádné komentáře