catching change in spinbox - rtcltk - r

I'm creating a spinbox in R using rtcltk with:
from <- tkwidget(leftFrame, type="spinbox", from=0, to=0.1,
inc=0.001, textvariable=freqFrom,
command = function(){updatePlot()})
This works as intended (updatePlot is called) when I use the arrows of the spinbox, but does not work if I just type something in manually.
How do I catch the "value changed" event?

By default it does not change in this case in case you type in an illegle value (like deleting the last digit), or if the update is time consuming then you would not want it to update between every keystroke when typing in a 3 or 4 digit number.
You can add an update button than calls updatePlot when clicked so that the user would type in the number and when they know they are finished would click the button.
If you really want the update to occur with every keystroke then you can use the tkbind function to call updatePlot (something like tkbind(*spinbox*, "<Key>", updatePlot) where spinbox is the variable pointing to the spinbox).

Related

How to escape from an update message?

I have following message in Progress-4GL:
DEF VAR L-temp AS CHARACTER.
MESSAGE "Give me information" UPDATE L-temp.
This shows an update message, which is fine, but when I try to escape from that message (e.g. I realise that I have clicked on the wrong button, launching this message), I can't hide that message:
How can I solve this (I simply want to remove the message from screen)?I can't add VIEW-AS ALERT-BOX as alert-boxes only can update logical variables and fields. Or is there a simple Show-Dialogbox() for such a case?
Edit
I tried replacing UPDATE by SET and viewing the whole thing as an alert-box, but this seems not to be allowed up (only logical variables and fields seem to be allowed).
Edit 2
Trying with PROMPT-FOR was not a good idea, because this seems to hide the rest of the window, while I want the message to be shown as some kind of a popup in top of the rest of my window/frame.
Edit 3
Also System-Dialog seems not to be a good idea, because all I want is to get a simple string.
It's a bit unfortunate that the 'close window' button does not by default, close the window. Even when a frame is defined as a modal dialog-box, the window-close event needs to be rerouted to close.
define frame frupdate
cinfo as char label "Give me information" with side-labels
with
title "Message Update"
view-as dialog-box
.
on "window-close" of frame frupdate
apply "close" to frame frupdate.
enable all with frame frupdate.
wait-for close of frame frupdate.

When is a widget property available to an iPython / Jupyter cell?

I'm getting ready to create a communications widget for use in a Jupyter application. I'm trying to understand when the widget's "value" property can be accessed ... it looks like the "value" can be read anytime, but won't match the widget model "value" until cell execution stops (i.e., the widget's browser state isn't updated back to the widget's kernel state).
To test this, I tried creating a small slider widget, waiting for 10 seconds, and then reading the widget "value" property ... all in the same cell. In the 10 seconds, the user (i.e., me) has time to change the slider to something like "5".
Here's a small test that can be run in a cell. When the sleep() happens, I move the slider to value "5".
from ipywidgets import *
import time
slider = IntSlider(
value=7,
min=1,
max=10.0,
step=1,
description="Input:",
)
display(slider)
time.sleep(10) # move slider to 5
print("done " + str(slider.value))
I expected "done 5" but got "done 7", implying to me that "value" is updated only after the cell completes.
Is this always true? And is there a way to force synchronization between the widget's browser state and its state in the kernel?
(I do get the expected "done 5" if I move the print() to the following cell.)
Thanks!
There is basically at present no way to automatically force code running in a cell
to wait for an event or change in a widget. Things like time.sleep(3) will only
freeze the cell and a slider created in the same cell will not display until the
sleep is complete.
The user could create a slider in cell 1 and then execute a sleep in cell 2 and then adjust the slider and the code in cell 2 may see the change after the sleep
but in this case the synchronization is directed by the user and is not automatic.
You can also start Python code from a widget event, but the Python code does not "run in a cell" and the "prints" will not go to the standard cell output area but
the output can be captured in other ways,.
In the following screenshot I use the "Output" widget to capture output from a widget event
The basic problem is that all communication between widgets and kernels is via
one-way messages -- there are no "return values" or "acknowledgements" of any kind.
Please see https://github.com/AaronWatters/jp_proxy_widget/blob/master/notebooks/Tutorial.ipynb for more discussion.
As it turns out, there does seem to be a library that uses something like asyncio to achieve an inline wait. It's called jupyter-ui-poll at https://github.com/Kirill888/jupyter-ui-poll. The author says it's available on PyPI at https://pypi.org/project/jupyter-ui-poll/
Very promising! ... otherwise, I'm forced to agree with you.

at selection-screen output VS on radiobutton group

I'm writting a report in which I have two radiobuttons of the group 'tab'. Depending on their value, I must set some screen fields to no-display, else, display them correctly.
I can make it work perfectly by using the event at selection-screen output. , but it refuses to work when using at selection-screen on radiobutton group tab -to test one, I comment out the other.
The code in both is exactly the same, so could someone help me understand the difference in the two events so I get why only one works?
events below, only the second one works.
at selection-screen on radiobutton group tab.
go_controller->modify_screen( ).
at selection-screen output.
go_controller->modify_screen( ).
They both call the same method
method modify_screen.
loop at screen.
case screen-group1.
when 'TAB'.
if use_otab = abap_false.
screen-invisible = 1.
screen-active = 0.
screen-input = 0.
p_int = abap_false.
p_nat = abap_false.
free p_table[].
else.
screen-active = 1.
screen-invisible = 0.
screen-input = 1.
endif.
modify screen.
endcase.
endloop.
endmethod.
Via debug, I see that both of the events are reached correctly, nevertheless, only the second one works.
Because it is designed like this: AT SELECTION-SCREEN ON... is a "process after input" (PAI) event. PAI is designed to react on user actions. At the end of PAI, the next dynpro is determined (even if it may be the same as the actual), and then the "process before output" (PBO) of the dynpro is processed. This is the preparation of the screen elements for the user. Only in PBO, the modification of the SCREEN table has an influence on the visibility or editability of the screen elements.
So, in reporting you are supposed to use at selection-screen output. to influence the visibility or editability of the parameters and select-options.

qt app that takes in textedit barcode scanned, how to change focus between two fields

So for me the plan is like this:
I scan a barcode, it gets in first textedit;
I scan another barcode, it gets in the second textedit,
in this case i use focus and keyboard event.
my problem is when i scan first code it is fine but when I scan the second code, some of letters go to second texedit some go to first texedit.
I don't understand what is the problem
here is my code
void CWidget::keyPressEvent(QKeyEvent *event)
{
if(focusWidget() == ui->lePath && !ui->lePath->text().isEmpty())
{
ui->leInformation->setFocus(); //leInformation second edit
ui->leInformation->setFocusPolicy(Qt::StrongFocus);
ui->leInformation->KeyPressEvent(event);
}
else
{
ui->lePath->setFocus(); //lePath - first edit text, first code scanned //goes here
ui->lePath->setFocusPolicy(Qt::StrongFocus);
ui->lePath->KeyPressEvent(event);
}
}
like is a strange think cause sometimes works sometimes no, if both codes scanned have digits they work but if the second scanned code has uppercase letters they go from the first uppercase letters they are wrote to first edit. but if they are lowercase they are fine again. I m thinking it is a problem with keyboard event how they deal with uppercase. somehow maybe with shift, and they change between two edits.
if there is someone who has an idea on how i can properly write that keyboard event, please help thanks
here B should have been on the second. I'm being sure on how uppercase are being entered on keyboard event is about shift + letter and shift moves you to the other edit but how i can change this

Receiving integral sign when using confirm dialog in atom-editor

For some reason, when I use the following code in package I'm trying to contribute to, an integral sign (∫) appears in the active document when a button is selected on the dialog.
checkAutoSave: ()->
if atom.workspace.getActiveTextEditor().isModified()
if atom.config.get('build.saveOnBuild') is true
atom.workspace.getActiveTextEditor().save()
return 1
else if atom.config.get('build.promptToSaveOnBuild') is true
diaDirection = atom.confirm
message: 'Do you want to save the current file before building?'
detailedMessage: 'This message can be turned off in the Build settings.'
buttons: ['Yes', 'No', 'Cancel Build']
switch diaDirection
when 0
atom.workspace.getActiveTextEditor().save()
return 1
when 1
return 0
when 2
return -1
else #Current File wasn't changed.
return 0
I have tried narrowing it down and I am 100% it has something to do with the dialog. The problem does not exists without the dialog call. The Integral sign appears in the document regardless of the button pressed.
I've had a similar problem a while ago - see here for more details.
The action I wanted to trigger in the editor was bound to Ctrl+Alt+B, which by default inserts the integral sign on Mac OS X. The integral sign was inserted into the currently open document when I opened a standard alert box from my package's code.
I didn't found out why, but it looks similar to your problem. In the end, I resolved it by removing the alert and using an Atom view instead for showing the message. As soon as I did this, the integral sign was no longer inserted into the document.
It looks like there's an issue with the key binding and preventing event propagation when using some dialogs. In some cases, the key event is handed to the OS and it inserts the character associated with the pressed key.
Maybe you can try using an Atom view instead of the confirm dialog, and it will resolve your issue as well.

Resources