How can I reset a value of a Simulink mask parameter each time the 'MaskVisibilities' is set to 'off'? I tried to set the value in a callback which set the visibility at on or off.
I solved my problem with:
param = get_param(gcb, 'MaskValues');
param{length(param)} = '20';
set_param(gcb, 'MaskValues', param);
Now, my last parameter is set to 20 each time the callback is executed (to set the 'Visibilities' to 'off').
Related
I'm trying to figure out how to make a GUI with radio buttons that will enable/disable options based on radio button selections. Here's an example of one way I have tried:
fig = uifigure('NumberTitle','off','Name','Option Selection','Position',[750,300,460,520]);
panel1 = uipanel(fig,'Title','Options','Position',[140,80,200,280]);
bg = uibuttongroup(fig,'Position',[140 290 200 51],'SelectionChangedFcn',#bselection);
rb1 = uiradiobutton(bg,'Position',[5 30 100 20],'FontWeight','bold');rb1.Text = 'Option 1';
rb2 = uiradiobutton(bg,'Position',[5 10 100 20],'FontWeight','bold');rb2.Text = 'Option 2';
Opt1_label = uilabel(panel1,'text','Option 1','Position',[5 180 100 20],'FontWeight','bold');
Opt1_field = uieditfield(panel1,'text','Position',[5 160 100 20]);
Opt2_label = uilabel(panel1,'text','Option 2','Position',[5 60 250 20],'FontWeight','bold');
Opt2_field = uitextarea(panel1,'Position',[5 15 190 45]);
function bselection(bg,Opt1_label,Opt1_field,Opt2_label,Opt2_field)
if bg.Buttons(1).Value == 1
Opt1_label.Enable=1;
Opt1_field.Enable=1;
Opt2_label.Enable=0;
Opt2_field.Enable=0;
elseif bg.Buttons(2).Value == 1
Opt1_label.Enable=0;
Opt1_field.Enable=0;
Opt2_label.Enable=1;
Opt2_field.Enable=1;
end
end
The enable/disable if statement works standalone, but I cannot figure out how to get it to work as a callback. Option 2 is not disabled even though option 1 is selected first by default, and if I select another radio button, either nothing changes or I will get an error saying the Enable handle isn't found.
Any ideas are much appreciated
Thanks in advance!
You have configured your function bgselection() to be a callback function for a UI element. Callback functions have two specific rules for the input arguments:
The first argument must be the handle of the object that called the function, and the second must be "eventData" for the callback event. So in your function, the argument Opt1_label is being treated as a eventData variable. Since it does not have the information expected in that variable, there is an error. So to follow this rule, change your function definition to:
function bselection(bg,eventData,Opt1_label,Opt1_field,Opt2_label,Opt2_field)
The second rule is that if you want to have more than the required two input arguments, you need to list them in a cell array when the function is assigned to the object. So in your case, define the uibuttongroup like this:
bg = uibuttongroup(fig,'Position',[140 290 200 51],'SelectionChangedFcn',{#bselection,Opt1_label,Opt1_field,Opt2_label,Opt2_field});
You will have to move the definitions of Opt1_, Opt2_ etc before the bg statement, so that they exist and can be included in the cell array.
You can see the documentation for this here. There are a couple other options for passing arguments, but these are the most common methods.
Also, the eventData has some useful information, such as the label of the button that is selected. Try adding disp(eventData) to the function to see what is included there.
I am trying to change the color value of a textlabel. I am doing so using:
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.R = 0
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.G = 255
script.Parent.Parent.toggled2.SurfaceGui.SIGN.TextColor3.B = 0
basically it navigates to a button (a part, parent of the script) then to the group its in, then to a part with the text (in this case toggled2) then to the surfacegui inside then the textlabel (which is named SIGN) it then modifies the TextColor3 attribute 3 times at once, adjusting all the R,G,B values.
Why wont it let me alter the value? do i have to do something like :new() or .new()?
In order to assign a value to the TextColor3 property, you have to pass a Color3 object :
local sign = script.Parent.Parent.toggled2.SurfaceGui.SIGN
sign.TextColor3 = Color3.new(0, 255, 0)
I am trying to create a receipt form where people will confirm if they've received the full quantity of an order. As part of this, I want the following to happen:
If they received the full quantity, a green check mark appears
If they received a partial quantity, an orange triangle appears
If they received no items, a red x appears
To accomplish this, I'm using a continuous form with 3 image files for each situation. I'm using the code below to change the image when the quantity is changed. The problem is, when the quantity is change on 1 line, the symbol changes for all lines. I'll post pictures as well.
Any thoughts on how I can fix this?
I'm open to other methods of accomplishing this idea too.
Private Sub FinalQTY_AfterUpdate()
If IsNull(Me.FinalQty) Then
MsgBox "You must enter a quantity for this item"
Me.FinalQty.SetFocus
Exit Sub
Else
LValue = Me.[FinalQty]
If IsNumeric(LValue) = 0 Then
Me.FinalQty = ""
MsgBox "Qty must be a numeric value"
Me.QTY.SetFocus
Exit Sub
End If
End If
Me.FinalTotalPrice = Me.FinalPrice * Me.FinalQty
If Me.FinalQty = 0 Then
Me.Yes.Visible = False
Me.Change.Visible = False
Me.No.Visible = True
End If
If Me.FinalQty < Me.QTY Then
Me.Yes.Visible = False
Me.Change.Visible = True
Me.No.Visible = False
End If
If Me.FinalQty = Me.QTY Then
Me.Yes.Visible = True
Me.Change.Visible = False
Me.No.Visible = False
End If
End Sub
This is before I adjust the quantity:
This is after I adjust the qty of only the second line:
Since the formatting of each record displayed by a continuous form is inherited from the form design template, any changes to the template will be automatically applied to all records displayed by the form, aside from Conditional Formatting rules in effect or the handful of properties which may changed via the OnPaint event of the Detail section.
One possible alternative might be to add a new field to your table with a data type of OLE Object and populate the value on the AfterUpdate event using the AppendChunk method, sourcing image data from a separate table containing three records corresponding to your green tick, orange triangle, and red cross images.
The table cell is edit with a simple click, I want it to be edit only on double click. Simple click will select the cell.
I'm use this property of uitable:
set(hTable, 'Data',data,...
'ColumnEditable', edit,...
First you need to set the cell editabiliy to false by default:
set(hTable,'ColumnEditable', [false false ...]); %accordingly your number of columns
and introduce a CellSelectionCallback:
set(hTable,'CellSelectionCallback',#cellSelect);
which calls the following function within the same script
function cellSelect(src,evt)
getstate = get(src,'ColumnEditable'); %gets status of editability
index = evt.Indices; %index of clicked cell
state = [false false ...]; %set all cells to default: not editable
state(index) = ~getstate(index); %except the clicked one, was it
%already false before set it true
set(src,'ColumnEditable', state) %pass property to table
end
and also a CellEditCallback:
set(hTable,'CellEditCallback',#cellEdit);
calling
function cellEdit(src,~)
state = [false false ...];
set(src,'ColumnEditable', state)
end
minimal example
function minimalTable
h = figure('Position',[600 400 402 100],'numbertitle','off','MenuBar','none');
defaultData = {'insert number...' , 'insert number...'};
uitable(h,'Units','normalized','Position',[0 0 1 1],...
'Data', defaultData,...
'ColumnName', [],'RowName',[],...
'ColumnWidth', {200 200},...
'ColumnEditable', [false false],...
'ColumnFormat', {'numeric' , 'numeric'},...
'CellSelectionCallback',#cellSelect);
end
function cellSelect(src,evt)
getstate = get(src,'ColumnEditable');
index = evt.Indices;
state = [false false];
state(index) = ~getstate(index);
set(src,'ColumnEditable', state)
end
function cellEdit(src,~)
state = [false false];
set(src,'ColumnEditable', state)
end
As you figured out this is not always working. Because you have the same issues like I had before with popup menus. It's exactly the same problem: ColumnEditable is just a row vector and not a matrix. I had to deal with the ColumnFormat property, which is also just a row vector. If the double click feature is really important to you, you can consult the following two answers:
Is it possible to prevent an uitable popup menu from popping up? Or: How to get a callback by clicking a cell, returning the row & column index?
How to deselect cells in uitable / how to disable cell selection highlighting?
The threads basically suggest to create a unique uitable for every single row, so that every single row has a unique ColumnEditable property. That's the only solution so far.
I'm afraid there is no simple solution. I can't offer you further help, except the complicated workarounds of the other answers. Or just use the simple one above and live with the little drawbacks.
Although this thread is old but in my opinion still valuable to some users.
I have tested the following with R2010b 32bit.
I have achieved editing only on double click simply by setting
set(hTable,'CellSelectionCallback',#tableCellSelectCB,'ColumnEditable',true)
and defining its function the following
function tableCellSelectCB(~,~)
try
h.jtable.getCellEditor().stopCellEditing();
catch
end
end
where h.jtable refers to the underlying java object of your uitable.
This way, I can select even single and multiple cells, without going into edit mode. On a double click on a single cells lets me edit its contents.
Extension to have individual editable rows
I wanted to have checkboxes in the top row and non-editable (not directly at least) data in the rest of the table. You can easily modify the above:
function tableCellSelectCB(~,evd)
if evd.Indices(1) > 1
try
h.jtable.getCellEditor().stopCellEditing();
catch
end
end
end
Setting a radio button in the current form is simple:
$clone->set_visible([radio => '1']);
With an unknown number of radio buttons (probably 10 to 20) a loop should work:
while(1) {last if (!$clone->set_visible([radio => '1']));};
However, though setvisible always returns 1. My guess is it only returns 0 when nothing is set at all. But if even one field is set, it can get "re-set".
How do i stop after all radios are set? Or do i need to determine how many there are first?
You can find all inputs you need first:
my #radio_inputs = $mech->find_all_inputs(
type => 'radio',
);