On pressing a button in panel, why is the data being sent twice, Is there a solution to only send it once? - capl

If I press a radio button (send data) on Panel, the data is being sent twice or thrice, sometimes once, for the following code:
on sysvar RC::send_data
{
systemData.byte(0) = 0x01;
systemData.byte(1) = 0x01;
systemData.byte(2) = 0x01;
systemData.byte(3) = 0x01;
systemData.byte(4) = 0x01;
systemData.byte(5) = 0x01;
systemData.byte(6) = 0x01;
systemData.byte(7) = 0xFF;
output(systemData);
}
I need to make it only sent once if I press once, how to achieve it?
And why is the data being sent multiple times randomly?
Expected:
Tx : 01010101010101FF
Error Outcome:
Tx : 01010101010101FF
Tx : 01010101010101FF

When you press your button, the sysvar is set to a certain value. You can configure this value in the panel designer in property Pressed of the button.
When you release the button, the sysvar is set to a different value. You can configure this value in the panel designer on property Released of the button.
Your on sysvar event handler gets called once when pressing the button and once when releasing the button.
You could use an if-statement in your event handler to only react on certain values of the sysvar.

Related

Set page item value to show in DA confirm message

I'm using Oracle Apex Version: 20.1
I have a page item (:P303_ADJUSTAMOUNT) that has a default value that's set via sql query. When the user presses the submit button, I have a DA confirm action that shows a popup window to confirm the amount the user is trying to adjust. This works if the user doesn't change the page item value after initialization, as the modal window displays the value that was retrieved from the sql query (the item's default value).
I created another DA on the page item itself to set the value of the page item on the "Lose Focus" event (Set Value --> PL/SQL). I want the DA to set the item's value to whatever the user has entered at the time. Yet when my confirmation message pops up, the page item is still set to the default value and the value I entered disappears. Where am I going wrong here?
Set Value Dynamic Action
Confirmation Message
Update on 04/26/2022:
I finally got my message to be able to display the page item's value and not the page item's session state value. But I have a feeling I'm doing a little extra work to get the desired result.
New code for dynamic action
Action: Execute JavaScript Code
Code:
var msg;
var amt;
msg = "Are you sure you want to insert a singleton for $"
amt = apex.item( "P303_ADJUSTAMOUNT" ).getValue();
apex.message.confirm(msg.concat(amt,"?"), function( okPressed ) {
if( okPressed ) {
apex.submit('ADJUST');
}
});
Desired Result: Update Confirmation Message

I have 3 buttons that can be in either clicked or not-clicked state. How do I keep state that signals if ANY of them are clicked?

This is more of algorithms question. I have 3 buttons:
button1 button2 button3
They can each be in clicked or not-clicked state. When the first is clicked, it goes into clicked state, but if I click it again, it goes back into non-clicked state.
I want to keep a global variable that answers if ANY of the buttons is clicked.
Knowing when to set global variable to clicked is pretty easy:
When I click button1 I can set variable clicked to true.
When I click button2 I can set variable clicked to true.
When I click button3 I can set variable clicked to true.
Now the difficult part is to set global variable to non-clicked:
When I click button1 again it becomes non-clicked, but button2 or button3 can be still clicked, so I can't just set variable to non-clicked.
When I click button2 again it becomes non-clicked, but button1 or button3 can be still clicked, so I can't just set variable to non-clicked.
When I click button3 again it becomes non-clicked, but button1 or button2 can be still clicked, so I can't just set variable to non-clicked.
It's difficult to keep state of non-clicked global status of all buttons.
Any ideas how to solve this problem? Should I somehow use xor? Or some other logical operation?
Set and clear a different bit in the word per button. That way if the word is non-zero, one or more of the buttons is pressed, and you can detect which one(s) by examining the bits.
Hard to see the point.
I figured out answer to my own question.
The answer is to keep global variable with value 0 in it:
int button_counter = 0;
When any button is clicked the following operation is performed:
button_counter = button_counter + 1;
When any button is unclicked the following operation is performed:
button_counter = button_counter - 1;
Now if value of button_counter is 0, then all buttons are unclicked.
If value of button_counter is 1, 2 or 3, then either one, two or three buttons are clicked and they are not all unclicked.
Here's how to check if they're all unclicked:
if (button_counter == 0) {
// all buttons are unclicked
}
else {
// at least 1 button is clicked
}
Thank you all for help!

How to make After Effects UI button to respond immediately while the script is processing

When I run this code in ExtendScript Toolkit (Target app - After Effects CC 2015) the cancel button is not responding until the progress bar has finished.
I would like to make it work so that the cancel button would respond immediately.
I know that pressing the "Esc" key works immediately, so it should be possible to make the cancel button work as well.
testWindow = new Window ("palette", "Processing:", undefined);
pb = testWindow.add("progressBar",undefined, 0);
cancelButton = testWindow.add("button", undefined, "Cancel");
testWindow.show();
cancelButton.onClick = function(){
alert("Cancel");
}
i = 1;
while (i <= 1000000) {
pb.value = Math.round(100*i/1000000);
testWindow.update();
i++
}
I think it has always been so: while a script is running, the user interface is on hold and non responding. Adding a Cancel button somewhere cannot work.
The only way i know for a user to cancel the execution of script is the ESC key.

how to make a terminal prog react to mouse clicks

I am writing a c program to do some calculations.It would really help me if I was able to get responses by clicks of mouse.
How can i do this also If it is not possible then using which functions or libraries of C only would I be able to do that.
Ncurses has support for GPM (mouse library).
Excerpt from Ncurses interfacing with the mouse how-to:
Once a class of mouse events have been enabled, getch() class of functions return KEY_MOUSE every time some mouse event happens. Then the mouse event can be retrieved with getmouse().
The code approximately looks like this:
MEVENT event;
ch = getch();
if(ch == KEY_MOUSE)
if(getmouse(&event) == OK)
. /* Do some thing with the event */
.
.
getmouse() returns the event into the pointer given to it. It's a structure which contains
typedef struct
{
short id; /* ID to distinguish multiple devices */
int x, y, z; /* event coordinates */
mmask_t bstate; /* button state bits */
}
The bstate is the main variable we are interested in. It tells the button state of the mouse.
Then with a code snippet like the following, we can find out what happened.
if(event.bstate & BUTTON1_PRESSED)
printw("Left Button Pressed");

how to add message map to dynamic menu item in MFC

I writing a MFC which has a listview control. When the user right clicks any item , I am generating a dynamic menu item with that text that is selected in listview. Everything is displaying properly, but I do not know how to add a message map to that dynamic menu item.
Any help?
void CMyListDlg::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nIndex = m_List.GetSelectionMark();
CString pString = m_List.GetItemText(nIndex,1);
CMenu menu, * pSubMenu;
int pos=0;
menu.LoadMenu(IDR_MENU1);
pSubMenu = menu.GetSubMenu (0);
pSubMenu->DeleteMenu(0,MF_BYPOSITION);
pSubMenu->InsertMenu(pos,MF_BYPOSITION,NULL,pString);
CPoint oPoint;
GetCursorPos (& oPoint);
pSubMenu-> TrackPopupMenu (TPM_LEFTALIGN, oPoint.x, oPoint.y, this);
*pResult = 0;
}
At the moment you are inserting the menu item with ID = 0 (NULL). That way you can't figure out which command was pressed. You have to assign an ID to the item, the simplest one is to
#define WM_MYMESSAGE WM_USER + 1
then you insert it like this:
pSubMenu->InsertMenu(pos,MF_BYPOSITION,WM_MYMESSAGE,pString);
If you override OnCommand for your window, you get your ID as wParam.
To actually figure out what happened, store some additional information in another class member, like m_nLastItemClicked or ... you get the idea?!
Check the MFCIE sample, it generates a favorite menu from the user's favorite folder and navigates to the favorite url when a favorite menu item is clicked.
Just add ON_COMMAND (and ON_UPDATE_COMMAND_UI if necessary) handlers for the menu items' IDs on your class.

Resources