Week+of+2-25+to+3-3

Time for Chapter 12. This chapter focuses on expanding the abilities of GUI-making for the reader. He makes sure to note that it is not necessarily a tutorial, but rather a reference for future GUI-making endeavors. So, I will explain the content, but not get too engrossed in putting the ideas into practice just yet. The first group of ideas the author addresses is "GUI pop-ups". These are little tools that can be added to GUIs that enhance them outside the capabilities of the other GUI elements. The first one discussed is the 'waitbar'. Since MATLAB often deals with huge data sets and extremely complex calculations, this tool is designed to keep the user at peace when things take a while. During a long calculation when the GUI will just sit still for a bit, the user might become worried it has frozen, they need to do something, or they just want to know how long it will be before the program moves on. Waitbars are great for stopping the reader from having to worry about these things. They are bars that show how much of a calculation has been completed. For example, when there is a complex 'for' loop with many calculations inside it, the programmer might display a waitbar that shows how much percent of the iterations is finished. This is accomplished by initializing a waitbar before the loop begins, and having the waitbar re-evaluate its value during each iteration of the loop, displaying the percentage of iterations that are finished. A waitbar can then be gotten rid of when it is finished by using the 'close' command. The next one discussed is a 'file dialog'. First, the author explains the use of '.mat' files. These are binary files that cannot be read by anything/anyone except MATLAB and store the values of certain variables. The 'save' command with parameters of a filename and then whatever variables will be in the file is the way to create and update these files. If no variables are specified, the entire current workspace gets stored. Then the 'load' command allows users to recall certain variables from this file. A note is that the filename can include the folder index so that these files can be saved wherever. A note is that if a certain variable has been stored in the workspace, calling the 'load' command will overwrite it if that variable is recalled int the 'load'. In a GUI, the 'load' function is not the end of the road. The loaded variables would need to be stored in the proper GUI element variable. I imagine the waitbar will be something to put in the CMS GUI if it does not have one already. Next, one very cool thing GUIs can do is let the user interactively save and load things. The 'uiputfile' command causes the GUI to pull up the dialog box for saving a file that we are all very familiar with from using Word and other programs. 'uigetfile' pulls up this same dialog box for opening another file. Programmers should look out because merely using the dialog box doesn't actually save or load the file, but rather returns the data with which you can then run a 'save' or 'load' command to actually perform the action. The next capability of MATLAB discussed is the ability to use text files. The main purpose for this ability is ease of human reading and ease of interpretation by things outside of MATLAB. Otherwise, using a text file is rather inefficient. This is achieved using various commands beginning with the letter f. 'fopen' opens an already created file or creates a new one. The 'fprintf' function adds certain things to the file. The 'fclose' function must be used after the editing is finished in order to not leave the program thinking the function is still being edited. There is one parameter of the 'fopen' command that asks for a letter that designates an "access mode". 'a' is "append" mode and adds text onto the end of the file. 'w' is "write" mode and replaces the old text with new text. 'r' is "read" mode and would potentially show the GUI user the file's contents. There are various ways to format the strings that are added to the file, which I will not dive into now because that's not really necessary unless I actually use this feature of MATLAB. The 'textscan' command uses the same formatting as 'fprintf' but rather returns a cell array of the data which can be accessed from vectors of the columns called 'theData{1}', 'theData{2}' down the list. There are all kinds of ways for MATLAB to mess around with data storage, and a GUI component for importing and exporting files is 'uiimport'. The next thing shown is the 'input dialog'. This is another way for users to input data outside of the standard 'edit textbox'. The 'inputdlg' command calls one of these up and has various parameters for what to call the input boxes and what to title the dialog, etc. If the user hits cancel, a null string will be returned. Another dialog that can be used is the question dialog. 'questdlg' creates a dialog similar to the one in 'inputdlg', but rather than enter numbers, the user simply has the option to click "yes", "no", or "cancel". This is very limited, but when dealing with binary choices can be a very friendly tool for the user. The three choices can be customized, but the book does not specify how, and it says that this box must create exactly three choices. This is the last of the pop-up tools the author discusses. The next topic is the sharing of data between functions. The process used earlier of having one function set a value and another get the value is limited because it is always dealing with things displayed in the GUI objects. If, say, a series of calculations is performed, with multiple components calculated by multiple functions and one function needs to use these results and then it will communicate with the GUI to display the data, that intermediate transfer of data before the final result cannot be performed by the GUI elements. 'setappdata' and 'getappdata' and 'gcf' (get the handle of the current figure) can be used to perform data transfers anchored to a certain GUI element without actually using the element itself. They are essentially invisible versions of 'set' and 'get' that use an arbitrarily created storage point. The next topic is keyboard input. The 'KeyPressFcn' property of any figure can be set as the handle of a certain function, and thus that function would be called every time any key on the keyboard is pressed. The keyboard is separated by MATLAB into Characters, Keys, and Modifiers (shift, alt, etc.), and these can be used in the function to process key presses in various ways. The next set of topics addressed is making graphic objects interactive. The first component of this is clicking the mouse in order to get things to happen. The sample program used in the book lets the user click a triangle and the color changes from red to blue or vice versa. The way this is accomplished is by using the 'ButtonDownFcn' property in a function to check when the mouse is clicked down on the triangle. Next the author addresses mouse events and object dragging. 'ButtonDownFcn' is used again to figure out when the object in question was clicked. 'WindowButtonMotionFcn' determines what function is used when the mouse moves. 'WindowButtonUpFcn' is used to end the motion when the mouse is released. The author provides something of a template for making objects drag. It uses the mouse, but could be slightly altered to use the arrow keys. The reason this ability is so great is because it gives way for custom GUI elements to be created. For example, using the dragging, a programmer could potentially create a 2-Dimensional slider tool that was responsible for two values at once. The final GUI idea addressed is the creation of menus (such as "File", "Edit", etc. in Word) for GUIs. The "Menu Editor" is one of the options in the "Tools" menu in GUIDE. The book guides the user through the creation of a very basic menu. Essentially, the Menu Editor is very interactive and the setting of the options and handles is easy enough. Then, as with all GUIDE creations, callback functions are inserted into the .m file for the GUI for each menu option and the menu button itself. The function for the menu button itself is usually negligible and can be ignored or deleted. "Save" and "Load" buttons in menus would call up the dialogs defined earlier in this post. One final thing the author mentions is the 'Checked' property of the options. Rather than have choosing an option call up a dialog or something like that, it can get checked in order to change a property of the GUI. Maybe it would be useful to create a menu that lets the user control which elements of the GUI he sees by checking or un-checking them. I apologize for the last two posts being all text but I will make up for that next post by making it all programming.