Matlab - Send Variable From GUI to Function - user-interface

I am trying to call a GUI from a function, select an item from a pop-up menu in the GUI, and pass a variable associated with the pop-up selection back to the function. The only tutorials I find on GUIs have to do with just changing things within the GUI, but not sending anything out back to a main function.
So say I have 3 options in the pop-up: Image 1, Image 2, Image 3. When for instance Image 2 is selected and the OK button is pressed, I'd like the string 'Image 2' be passed back to the main function that called the GUI.
Thanks for the help!

You can try something like: [selection, ok] = listdlg('PromptString','Select a value:', 'SelectionMode','single', 'ListString',['Value 1';'Value 2';'Value 3']). The variable selection will give you the index of the selected value.

Related

MATLAB GUI: How do I turn off a push button when a text box is empty?..... Also, how can I produce error message when wrong file type is opened?

I am making a GUI in Matlab (I am a newbie to this) and I am stuck on two things:
1) I would like to prevent the user from selecting a file type other than .wav. I have managed to get the open dialog box to display only .wav files but that doesn't stop them selecting all files and opening another file type. This breaks the rest of my GUI. How can I defend against this?
2) I would like to prevent my 'Compute' push button being selectable when a certain text box is empty. How can I do this? I have tried the following but it doesn't seem to work:
p = get(handles.textbox,'String');
if isempty(p)
set(handles.compute, 'enable', 'off');
else
set(handles.compute, 'enable', 'on');
end
I would really appreciate some help.
Thank you very much
Best regards
1) you can throw an error and reset the selection if the file type doesn't have the extension '.wav'. Check the file name extension using the fileparts command.
2) Ensure that (a) if the textbox starts out empty, the button starts out with 'enable' set to 'off' and (b) your logic of testing the text box is inside the text box's callback. If you're setting the contents of the textbox from some other function, then the textbox's callback is not normally called. In that case, you should manually call the textbox's callback within that other function after setting the textbox's string, like:
set(handles.textbox, 'string', 'some_file.wav');
textbox_Callback(handles.textbox, eventdata, handles);

How to click a particular object using TestComplete without using co-ordinates

I am using VB scripting language to automate using TestComplete. The script records using co-ordinates of an object, so the script fails if it is run on some other machine. If I don't specify any co-ordinate then it randomly clicks any of the buttons on that page. Please let me know how to click a button without using the co-ordinates?
When you remove coordinates from the Click action in your test, TestComplete will click the center point of the corresponding control. If TestComplete clicks a random object in your case then you call the Click method of a wrong object. Find the correct button object using the Object Spy and call the Click or ClickButton method of this object.
If you want to click a button without coordinates, the best way is to send keystrokes,
So: either send the "spacebar" keystroke, or send the shortcut keystroke "Alt-X" (or similar)
get the name of the object using the object spy and use the .CLICK method and the object will be clicked in the center.
if you do not want to have click item then you can try and create a custom function to select a item in case of combo boxes .clickCell in case of grid etc.

Simple Oracle Forms Menu

I wan't to have a simple menu (main menu not menu bar) whith buttons to link to another form(s)/window(s)/caveses(s). Or atleast the code to switch bettween the screen.
What code (SQL/PL) would I put in the buttons or is there a better way to do this?
That's a very broad question. If you want to show a specific window on WHEN-BUTTON-PRESSED then you can use built in like below-
SET_WINDOW_PROPERTY('WINDOW_NAME', VISIBLE, PROPERTY_TRUE); --This would display the window
SET_WINDOW_PROPERTY('WINDOW_NAME', VISIBLE, PROPERTY_FALSE); --This will hide the window
The above would work if you use the SET_WINDOW_PROPERTY within the same form.
In case you want to call another form from the parent form (which is the case as per your comment screenshot) you need to to use CALL_FORM built-in like
CALL_FORM('MEMBERS');
Why dont you just make 1 form only?1 form, many datablock,canvas, window
anyway, for your question, just call the block
go_block('your_block');
if you want to call another block
go_block('another_block');
hide_window('1st_open_window');
you should make 1 canvas in 1 window for better arrangement
You can also use Stack canvas within the same form which gets visible as you click on the button.
SHOW_VIEW('CANVAS_NAME');
And in that stack you can do whatever you want.

How do you add UI inside cells in a google spreadsheet using app script?

I'd like to add buttons to specific cells in Google docs spreadsheet. The apps script UI documentation talks about how to add a new panel, but it's not clear how UI in that panel could be attached to specific rows or cells.
Is it possible to add UI to particular cells, or are we limited to adding new panels?
The apps UI only works for panels.
The best you can do is to draw a button yourself and put that into your spreadsheet. Than you can add a macro to it.
Go into "Insert > Drawing...", Draw a button and add it to the spreadsheet.
Than click it and click "assign Macro...", then insert the name of the function you wish to execute there. The function must be defined in a script in the spreadsheet.
Alternatively you can also draw the button somewhere else and insert it as an image.
More info: https://developers.google.com/apps-script/guides/menus
Status 2018:
There seems to be no way to place buttons (drawings, images) within cells in a way that would allow them to be linked to Apps Script functions.
This being said, there are some things that you can indeed do:
You can...
You can place images within cells using IMAGE(URL), but they cannot be linked to Apps Script functions.
You can place images within cells and link them to URLs using:
=HYPERLINK("http://example.com"; IMAGE("http://example.com/myimage.png"; 1))
You can create drawings as described in the answer of #Eduardo and they can be linked to Apps Script functions, but they will be stand-alone items that float freely "above" the spreadsheet and cannot be positioned in cells. They cannot be copied from cell to cell and they do not have a row or col position that the script function could read.
Use checkboxes(say, in F1) instead of buttons/Images. This is a intermediate to a full ui inside cells. Then hook your function, that is supposed to run on button click to onEdit() trigger function.
Sample script:
function onEdit(e){
const rg = e.range;
if(rg.getA1Notation() === "F1" && rg.isChecked() && rg.getSheet().getName() === "Sheet1"){
callFunctionAttachedToImage();
rg.uncheck();
}
}
References:
Class Range
Event Objects
Buttons can be added to frozen rows as images. Assigning a function within the attached script to the button makes it possible to run the function. The comment which says you can not is of course a very old comment, possibly things have changed now.
There is a silly trick to do something that might help you :
You can make the drawing object as tall as your sheet (To appear to every row in the sheet).
You can make the script affects the current cell value by the following code:
SpreadsheetApp.getActiveSpreadsheet().getActiveCell().setValue(cellValue);

In matlab, how do you save a figure as an image in the same way as using "Save As..." in the figure window?

When saving a figure, what function does Matlab use? For example, when a user selects File > Save As... and then selects .png or another image format, what is going on behind the scenes?
I am asking because I am trying to automate saving, but when I use saveas or print, the resulting image is really pixelated. However, the image looks really good when I save the figure using the method described above.
What method should I use to save my figure from the command line? The actual method that the figure window uses would work, but if you guys have better solutions, I'd appricate it!
The callback for the "Save As..." menu item invokes the function FILEMENUFCN with the first input argument being the handle of the figure the menu is in and the second input argument being the string 'FileSaveAs'. If you have the figure handle stored in the variable hFigure, then the following command should be equivalent to clicking the "Save As..." menu item in that figure window:
>> filemenufcn(hFigure,'FileSaveAs');
A few notes...
The function FILEMENUFCN is only partially documented. You can do help filemenufcn in the command window, but there is no entry for it in the online documentation. In MATLAB 2009a, the function can be found in the following folder:
C:\Program Files\MATLAB\R2009a\toolbox\matlab\uitools\filemenufcn.m
Looking through the function code, it appears that it ultimately calls either the function SAVEAS for .fig files or the function HGEXPORT (with additional input arguments) for other file types.
I was able to hunt down the callback for the "Save As..." menu item by searching through the children of the figure window and its menus. You can do this yourself by setting the root property 'ShowHiddenHandles' to 'on' and then traversing through the 'Children' properties of the figure window and its menus using the GET command. An alternative is to use the FINDALL command, assuming you know some properties of the objects you are looking for. For example, this will find the handle to the "File" menu for the current figure window:
>> hFileMenu = findall(gcf,'Label','&File');
And this will find the handle to the "Save As..." menu item and display its callback:
>> hSaveAs = findall(hFileMenu,'Label','Save &As...');
>> get(hSaveAs,'Callback')
ans =
filemenufcn(gcbf,'FileSaveAs')
I don't know about you, but for me the saved image looks nice.
Code example:
... create some figure ...
saveas(gcf, 'some_figure.png');
To set a user specified resolution use:
print(gcf,'some_figure','-dpng','-rSOMENUMBER')
where SOMENUMBERis a parameter used for the resolution.
The final resolution is (SOMENUMBER*8) x (SOMENUMBER*6)

Resources