My computer isn't asleep, but the dispaly turns off after 15 minutes. I don't want my display to never sleep, but I need the display to automatically turn back on to process some other tasks.
I'm not sure if PyAutoGui is the right tool to use for this task. The following code does execute, but is not waking my display from sleep when it is set to sleep after 60 seconds:
import time
import pyautogui
# pyautogui.FAILSAFE = False
time.sleep(90)
pyautogui.press('shift')
for i in range(1, 200):
pyautogui.moveTo(i, i)
Thoughts?
Related
I'm relatively new to using Octave. I'm working on a project that requires me to collect the RGB values of all the pixels in a particular image and compare them to a list of other values. This is a time-consuming process that takes about half a minute to run. As I make edits to my code and test it, I find it annoying that I need to wait for 30 seconds to see if my updates work or not. Is there a way where I can run the code once at first to load the data I need and then set up an artificial starting point so that when I rerun the code (or input something into the command window) it only runs a desired section (the section after the time-consuming part) leaving the untouched data intact?
You may set your variable to save into a global variable,
and then use clear -v instead of clear all.
clear all is a kind of atomic bomb, loved by many users. I have never understood why. Hopefully, it does not close the session: Still some job for quit() ;-)
To illustrate the proposed solution:
>> a = rand(1,3)
a =
0.776777 0.042049 0.221082
>> global a
>> clear -v
>> a
error: 'a' undefined near line 1, column 1
>> global a
>> a
a =
0.776777 0.042049 0.221082
Octave works in an interactive session. If you run your script in a new Octave session each time, you will have to re-compute all your values each time. But you can also start Octave and then run your script at the interactive terminal. At the end of the script, the workspace will contain all the variables your script used. You can type individual statements at the interactive terminal prompt, which use and modify these variables, just like running a script one line at the time.
You can also set breakpoints. You can set a breakpoint at any point in your script, then run your script. The script will run until the breakpoint, then the interactive terminal will become active and you can work with the variables as they are at that point.
If you don't like the interactive stuff, you can also write a script this way:
clear
if 1
% Section 1
% ... do some computations here
save my_data
else
load my_data
end
% Section 2
% ... do some more computations here
When you run the script, Section 1 will be run, and the results saved to file. Now change the 1 to 0, and then run the script again. This time, Section 1 will be skipped, and the previously saved variables will be loaded.
I have a Dash app with a standard layout which I run with standard invocation:
#wsgi.py
from __init__ import app
from __init__ import server
if __name__ == "__main__":
app.run_server(port=5000, debug = True)
I would like to run a once-a-day updater script for some calculations with a general schematic like this:
#one of the application pages .py
def update_df_daily_loop():
while True:
if time since last update > 24h:
run update
last updated = now
else:
sleep for 15 minutes
#tried invoking the thread like this - but it blocks the server from starting
thread0 = threading.Thread(target=update_df_daily_loop)
thread0.start()
thread0.join()
Where should I put the invokation? If I just run it as a thread it blocks the server from ever starting.
proc foo {} {
# do something
# sleep for 5sec
# do something
# sleep for 5sec
# do something
}
I want as soon as we enter foo, progressbar should appear and running horizontally,
along with that foo code should also be running,
and as everything in foo finishes, progressbar should show 100% horizontally and disappear .
How to do that?
The widget you're looking for is a ttk::progressbar (Tcl) or tkinter.ttk.Progressbar (Python). You'll need to decide whether to use it in determinate or indeterminate mode and stuff like that.
There's one key tricky thing about using a progress bar: you need to keep the event loop running while you're displaying it. This means you need to either put the work in a separate thread or call update periodically. Both options have their tricky aspects:
When using a separate worker thread, that thread must not touch the GUI at all. Instead, it has to send messages to the GUI thread asking it to do the update.
When using periodic update calls (once every quarter second or so is usually enough) you need to be very careful to not recursively enter full event loop processing (see the TkDocs page on the event loop for a discussion). This often involves doing things like disabling buttons while the processing is going on.
Were you instead after a progress bar in a terminal, those are comparatively simple because you don't have to manage an event loop; the terminal itself will do that for you.
If you have a good idea of the time it takes to do what you have to do you can use the after command to update the progress bar at regular intervals.
# pop up progress bar for a calibration that takes 20 seconds
toplevel .progress
label .progress.calib -text "Calibrating ..."
ttk::progressbar .progress.bar \
-variable ::progress \
-length 300
grid .progress.calib
grid .progress.bar
wm geometry .progress +180+180
#
# wait 20 seconds and update the progress every 0.5 s
#
set wait_time 20000
# use a variable to wait until the progressbar is complete
after 20100 "destroy .progress"
# create updates every 0.5 second
for {set i 500} {$i <= $wait_time} {incr i 500} {
after $i "set ::progress [expr $i*100/$wait_time]"
}
# do your stuff in less than 20 seconds
...
I have a java program which sends a results (as seen in a console) via HTTP to a browser. The real results are nicely formatted by tabs and newlines, as seen below:
./src/yse4 : The YSE emulator in use
[-w] - [w]rap around at tracefile end and begin anew at time zero.
[-f filename] - [-f tracefile to use from]
/home/Downloads/yse.wzt/tracefiles/capacity.3Mbps_400RTT_PER_0.0001.txt
File name: tracefiles/capacity.3Mbps_400RTT_PER_0.0001.txt
200 Forwarding Delay (ms)
200 Reversed Delay (ms)
3000000 Download Capacity (Mbps)
3000000 Upload Capacity (Mbps)
0.0001 Packet Error Rate (PER)
at=eth1
an=eth0
But when I send it as HTML, of course it does not recognize tabs and newlines. I manually add <br> at the end of each line, but still tabs are missing, and the browser shows it as below:
./src/yse4 : The YSE emulator in use
[-w] - [w]rap around at tracefile end and begin anew at time zero.
[-f filename] - [-f tracefile to use from]
/home/Downloads/yse.wzt/tracefiles/capacity.3Mbps_400RTT_PER_0.0001.txt
File name: tracefiles/capacity.3Mbps_400RTT_PER_0.0001.txt
200 Forwarding Delay (ms)
200 Reversed Delay (ms)
3000000 Download Capacity (Mbps)
3000000 Upload Capacity (Mbps)
0.0001 Packet Error Rate (PER)
at=eth1
an=eth0
How can I format it as HTML to be seen nicely? Maybe any library exists for that?
You can return an HTML Table containing two rows and format the table as you want
HTML Table
This script is supposed to press Z every 50 um..units of time when I press Q until I press W.
What I have trouble doing is making it pause(stops pressing z) whenever chrome is not in focus and resumes when it comes back into focus again.
Thank you. Below is the script that does what I said in the first sentence.
q::
stop = 0
Loop
{
SendInput, z
Sleep 50 ;adjust for speed of repetition
if stop
break
}
return
w::
stop = 1
return
Try adding a WinWaitActive command after the sleep command.