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

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 500
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 294
Interactive List Box in a GUIDE UI
9-49
Displays the current folder in the text box by setting its String property to the
output of the pwd command.
The load_listbox function is called by the opening function, as well as by the list box
callback.
function load_listbox(dir_path, handles)
cd (dir_path)
dir_struct = dir(dir_path);
[sorted_names,sorted_index] = sortrows({dir_struct.name}');
handles.file_names = sorted_names;
handles.is_dir = [dir_struct.isdir];
handles.sorted_index = sorted_index;
guidata(handles.figure1,handles)
set(handles.listbox1,'String',handles.file_names,...
'Value',1)
set(handles.text1,'String',pwd)
Code List Box Behavior
The listbox1_Callback code handles only one case: a double-click of an item. Double
clicking is the standard way to open a file from a list box. If the selected item is a file, it
is passed to the open command; if it is a folder, the program navigates to that folder and
lists the contents.
Define how to open file types
The open command can handle a number of different file types, however, the callback
treats FIG-files differently. Instead of opening the FIG-file as a standalone figure, it
opens it with guide for editing.
Determine which item was selected
Since a single click of an item also invokes the list box callback, you must query the
figure SelectionType property to determine when you have performed a double
click. A double-click of an item sets the SelectionType property to open.
All the items in the list box are referenced by an index from 1 to n. A value of 1 refers
to the first item, and a value of n is the index of the nth item. The software saves this
index in the list box Value property.
The callback uses this index to get the name of the selected item from the list of items
contained in the String property.
Zobrazit stránku 294
1 2 ... 290 291 292 293 294 295 296 297 298 299 300 ... 499 500

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

Žádné komentáře