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

  • 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 236
List Box Directory Reader
10-13
guidata(handles.figure1,handles)
set(handles.listbox1,'String',handles.file_names,...
'Value',1)
set(handles.text1,'String',pwd)
The List Box Callback
The list box callback handles only one case: a double-click on 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 directory, the GUI changes
to that directory and lists its contents.
Defining How to Open File Types
The callback makes use of the fact that the open command can handle a
number of different file types. However, the callback treats FIG-files
differently. Instead of opening the FIG-file, it passes it to the
guide command
for editing.
Determining Which Item the User Selected
Since a single click on an item also invokes the list box callback, it is necessary
to query the figure
SelectionType property to determine when the user has
performed a double click. A double-click on an item sets the
SelectionType
property to
open.
All the items in the list box are referenced by an index from
1 to n, where 1
refers to the first item and
n is the index of the nth item. MATLAB 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.
Determining if the Selected Item is a File or Directory
The load_listbox function uses the dir command to obtain a list of values
that indicate whether an item is a file or directory. These values (1 for
directory, 0 for file) are saved in the
handles structure. The list box callback
queries these values to determine if current selection is a file or directory and
takes the following action:
If the selection is a directory — change to the directory (
cd) and call
load_listbox again to populate the list box with the contents of the new
directory.
Zobrazit stránku 236
1 2 ... 232 233 234 235 236 237 238 239 240 241 242 ... 329 330

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

Žádné komentáře