I'm looking for an equivalent to the following iOS option: UIApplication.shared.isIdleTimerDisabled = true
That is, I'd like my Watch application to stay alive longer than the quick "sleep"/idle time that gets triggered when you don't move your wrist.
Its not perfect -- the watch will still sleep with inactvity, but this extension does slow it down by tricking the watch do ignore a 'wrist-down' or 'wrist-move' motion: Add the WKExtension inside one of your #IBActions:
#IBAction func mySlidefunction(){
// ... etc ...
WKExtension.shared().isAutorotating = true;
// ... etc ...
}
Related
I am trying to integrate libserialport library to a solution which can use poll, libev and libuv.
while its relatively easy to get the fd for the serial port file from libserialport and watch it using libev or libuv,
uv_poll_init(loop, &poller, serial_port_fd);
uv_poll_start(&poller, UV_READABLE /*| UV_PRIORITIZED*/, cb);
I do not know how to get it working using the default loop using poll.
the main loop is like:
while(!interrupted){
interrupted = service_one_loop();
//// THIS IS ONE PLACE TO poll (serial_port_fd) CODE and call callback function for serial
}
Is there any other way? Something like :
while(!interrupted){
interrupted = service_one_loop();
read_size = sp_nonblocking_read(machine_port, read_buffer, read_buffer_size);
if (read_size >= 0) {
cb();
}
}
Thanks for helping out in advance.
In IPython Notebook / Jupyter, arrow up/down keystrokes within a cell are handled by CodeMirror (as far as I can tell). I use these actions a lot (re-bound to control-p / control-n) to move between cells; but at the end of every cell, the cursor moves to end of line first before jumping to the next cell. This is counter-intuitive and, to me, rather distracting.
Is there any way to configure CodeMirror to make this move down to be just that - a move down?
Thanks!
The moving-to-next-cell behavior is defined by IPython wrapper code, which probably checks whether the cursor is at the end of the current cell, and overrides the default CodeMirror behavior in that case. You'll have to find that handler and somehow replace it with one that checks whether the cursor is on the last line. (I don't know much about IPython, only about CodeMirror, so I can't point you at the proper way to find and override the relevant code. They might have bound the Down key, or they might have overridden the goLineDown command.)
Knowing that I wasn't alone in wanting to skip the "going to end of line" behavior when going down from the last line of a code cell, I investigated that behavior and found out that:
it's CodeMirror that goes to the end of line when you type down in the last line of a code cell (file: codemirror.js ; "methods": findPosV and moveV)
and it's IPython that decides what to do with the "down" event after it has been handled by CodeMirror (file: cell.js ; class: Cell ; method: handle_codemirror_keyevent) ; looking at the code, I saw that IPython ignores the event when not at the last character of the last line.
This essentially confirms Marijin's answer.
The primary goal being to jump to the next cell, I think there's no need to prevent CodeMirror from going to the end of that line. The point is to force IPython to handle the event anyway.
My solution was to change the code from Cell.prototype.handle_codemirror_keyevent to this:
Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
var shortcuts = this.keyboard_manager.edit_shortcuts;
var cur = editor.getCursor();
if((cur.line !== 0) && event.keyCode === 38){
// going up, but not from the first line
// don't do anything more with the event
event._ipkmIgnore = true;
}
var nLastLine = editor.lastLine();
if ((event.keyCode === 40) &&
((cur.line !== nLastLine))
) {
// going down, but not from the last line
// don't do anything more with the event
event._ipkmIgnore = true;
}
// if this is an edit_shortcuts shortcut, the global keyboard/shortcut
// manager will handle it
if (shortcuts.handles(event)) {
return true;
}
return false;
};
This code provides the desired behavior for the "down-arrow" key (almost: the cursor still goes to the end of the line, except that we don't see it, as we're already in another cell at that point), and also handles the "up-arrow" key similarly.
To modify the handle_codemirror_keyevent prototype, you have two possibilities:
You edit the cell.js file and change the code of the prototype to the code I gave above. The file is in <python>/Lib/site-packages/IPython/html/static/notebook/js or something similar depending on you distro
Much better, after the page is loaded, you change that prototype dynamically by doing this:
IPython.Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
<same code as above>
};
You can do that in your custom.js for example, or create an extension to do it (that's what I did).
Is there a way to wait a set amount of time between tests? I need a solution to compensate for server lag. When creating a record, it takes a little bit of time before the record is searchable in my environment.
In the following code example, how would I wait 30 seconds between the first test and the second test and have no wait time between second test and third test?
class MySpec extends GebReportingSpec {
// First Test
def "should create a record named myRecord"() {
given:
to CreateRecordsPage
when:
name_field = "myRecord"
and:
saveButton.click()
then:
at IndexPage
}
// Second Test
def "should find record named myRecord"() {
given:
to SearchPage
when:
search_query = "myRecord"
and:
searchButton.click()
then:
// haven't figured this part out yet, but would look for "myRecord" on the results page
}
// Third Test
def "should delete the record named myRecord"() {
// do the delete
}
}
You probably don't want to wait a set amount of time - it will make your tests slow. You would ideally want to continue as soon as the record is added. You can use Geb's waitFor {} to poll for a condition to be fulfilled.
// Second Test
def "should find record named myRecord"() {
when:
to SearchPage
then:
waitFor(30) {
search_query = "myRecord"
searchButton.click()
//verify that the record was found
}
}
This will poll every half a second for 30 seconds for the condition to be fulfilled passing as soon as it is and failing if it's still not fulfilled after 30 seconds.
To see what options you have for setting waiting time and interval have look at section on waiting in The Book of Geb. You might also want to check out the section on implicit assertions in waitFor blocks.
If your second feature method depends on success of the first one then you should probably consider annotating this specification with #Stepwise.
You should always try to use waitFor and check conditions wherever possible. However if you find there isn't a specific element you can check for, or any other condition to check, you can use this to wait for a specified amount of time:
def sleepForNSeconds(int n) {
def originalMilliseconds = System.currentTimeMillis()
waitFor(n + 1, 0.5) {
(System.currentTimeMillis() - originalMilliseconds) > (n * 1000)
}
}
I had to use this while waiting for some chart library animations to complete before capturing a screenshot in a report.
Thread.sleep(30000)
also does the trick. Of course still agree to "use waitFor whenever possible".
I have problem in ensuring the dialog is closed/released with the following Qt codes.
//Segment 1: To open a 'wait' dialog for some long-running tasks
void MainWindow::ui_showProgressDialog(QString title) {
dlgProgress = new QProgressDialog(title, tr("Cancel"), 0, 0, this);
dlgProgress->setAttribute(Qt::WA_DeleteOnClose); // line 1
dlgProgress->setModal(true);
dlgProgress->show();
connect(voidWatcher, SIGNAL(finished()),
this, SLOT(onPopulationFile()));
}
//Segment 2: Attempts to close the 'wait' dialog
void MainWindow::onPopulationFile() {
qDebug((dlgProgress == NULL) ? "true" : "false");
if (dlgProgress) //
{
qDebug("0");
dlgProgress->close(); // line 2
qDebug("1");
}
qDebug((dlgProgress == NULL) ? "true" : "false");
}
Issue: When I trigger the call 'ui_showProgressDialog' twice, the second call always crash my program. Originally, my code has no line 1 of segment 1, and from the QtCreator, it always crashes on line 2 of segment 2. Debug message shows as follow
// first call to onPopulationFile
false
0
1
false
// second call to onPopulationFile
false
0
*** CRASH ***
I read the documentation that NEVER delete objects from different threads, I'm doubt that the call 'onPopulationFile' is invoked from a non-main thread. So I added the line 1 to segment to let the program decide when the delete the object. But it seems not work. Any suggestion to the problem?
Experiment done: If I replace QProgressDialog with QDialog, the program goes without crashes, and the debug message show
// first call to onPopulationFile
false
0
1
false
// second call to onPopulationFile
false
0
1
false
So,
Why the second null test in segment 2 always fail? [Edit: I have to explicitly set the variable to NULL]
Is there any better way to close the 'wait' dialog?
I try to close/release the dialog as I want release memory as soon as possible. Do I really need to manually delete the dialog?
Platform: Qt Opensource 4.8 (x64), Windows 7 (x64), MinGW (rubenvb 4.7.2)
dlgProgress->setAttribute(Qt::WA_DeleteOnClose); deletes the widget when it is closed. As you are calling dlgProgress->close();, after this line the object it points to has been freed, and dlgProgress is now a invalid pointer.
You need to set dlgProgress to null after any call to close, or event better, use the signal Qobject::destroyed().
EDIT:
Qt::WA_DeleteOnClose specify that the object will be deleted if a close event happens. Not exactly how much time it will take. For instance if they are using QObject::deleteLater(), then the object is not deleted right away. Even if it is not the case , pieces of code like
A* a = new A;
a->dosomething();
delete a;
a->dosomething();
are undefined behavior. The second call to a->dosomething(); may crash (if you are lucky) or may not crash.
I would like to activate sticky keys by pressing 1 button, instead of pressing shift 5 times, which is the default way.
If I were to do
F9::Send {LShift 5}
pressing F9 will yield nothing.
I also tried
F9::
Send {LShift}
sleep 50
Send {LShift}
sleep 50
Send {LShift}
sleep 50
Send {LShift}
sleep 50
Send {LShift}
sleep 50
return
Are there any reasons as to why it's not working?
While there is most likely a way to do a dll call or something complicated, it is also possibly to program similar functionality using AutoHotkey. This would also avoid the sticky keys prompt, and you can do a traytip instead.
stickykeys = 0
F9::
stickykeys:=!stickykeys
Traytip, Sticky Keys, % (stickykeys) ? "On" : "Off"
return
#If stickykeys
*$Shift::
key = 0
Input, key, L1 M
SendInput {Shift Down}{%key%}{Shift Up}
return
*$Ctrl::
key = 0
Input, key, L1 M
SendInput {Ctrl Down}{%key%}{Ctrl Up}
Return
*$Alt::
key = 0
Input, key, L1 M
SendInput {Alt Down}{%key%}{Alt Up}
Return
#If
F9 simply toggles sticky keys on and off.
Note: This is using AHK_L which supports #If
SPI_GETSTICKYKEYS:=0x003A
SPI_SETSTICKYKEYS:=0x003B
SKF_STICKYKEYSON:=0x1
VarSetCapacity(STICKYKEYS,8) ; DWORD cbSize;DWORD dwFlags;
NumPut(8,&STICKYKEYS,"UInt")
F9::
DllCall("SystemParametersInfo","UInt",SPI_GETSTICKYKEYS,"UInt",8,"PTR",&STICKYKEYS,"UInt",0)
dwFlags:=NumGet(&STICKYKEYS,4,"Uint")
If (dwFlags & SKF_STICKYKEYSON)
dwFlags-=SKF_STICKYKEYSON
else dwFlags|=SKF_STICKYKEYSON
ToolTip % "STICKYKEYS are " (dwFlags & SKF_STICKYKEYSON ? "ON" : "OFF")
SetTimer,ToolTipOff,-1000
NumPut(dwFlags,&STICKYKEYS,4,"UInt")
DllCall("SystemParametersInfo","UInt",SPI_SETSTICKYKEYS,"UInt",8,"PTR",&STICKYKEYS,"UInt",0)
Return
ToolTipOff:
The code is from the Autohotkey forums at http://www.autohotkey.com/community/viewtopic.php?f=1&t=93650
A note for anyone wanting to use the code: I think you have to put it at the top of your script for it to work. In my script of hotkeys, placing it in the middle, and pressing F9 to activate sticky keys caused some weird things to happen: The cursor jumped around, some folders were launched, the script exited, etc. I'm guessing that it activated other hotkeys nearby?