I've created a simple python application running in raspbian using kivy. The application runs already nicely in full screen mode. however I would like to be sure it cannot be interrupted with ctrl-c or any other command using the keyboard, and the application must never lose focus if something happens in the OS (for example some kind of dialog opens - I'm not sure if this actually can happen). I'd appreciate things that should be taken care of.
My app doesn't need to be bullet-proof, but it should endure a "casual user".
You can catch Ctrl+c or other signals with the signal module.
import signal
def signal_handler(signal, frame):
pass
signal.signal(signal.SIGINT, signal_handler)
This code prevent the user to exit by sending the SIGINT signal, corresponding to ctrl + c.
Other signals: https://unix.stackexchange.com/questions/317492/list-of-kill-signals
Related
Is there a way to use Chromium switches after starting it up, or must they be enabled on start up? For example, can switches be passed to the renderer processes, or just to the main process?
I want to turn on paint flashing in Chromium (actually in my Electron app which runs on top of Chromium).
Devtools has a checkbox that turns this on, but I want to be able to turn this on without devtools, and after the app has started.
I know there's a show-paint-rects flag I can use:
chrome.exe --show-paint-rects
In my Electron app, I would need to use app.commandLine.appendSwitch:
app.commandLine.appendSwitch("show-paint-rects");
I also found a ui-show-paint-rects flag that lives in something called the "compositor," but that may be irrelevant for me.
Both of these work, but since Chromium uses a multi-process architecture, I'm hoping that there's a way I can specify that switch, or otherwise, turn on a feature in one process and not have to specify it at startup.
Is there a way to do this in Chromium? (Would be ideal to do this in Electron, but I'm not counting on it)
While executing runAppInBackground() for Android application through Appium the app gets restarted but when executed the same manually couldn't be able to reproduce the same. I Would like to deep dive into implementation of a runAppInBackground() method to reproduce the same issue in a manual way.
You need to look behind the code of runAppInBackground
From java client side (your test code) perspective, it is a single call to Appium server:
POST "/session/:sessionId/appium/app/background"
If you continue looking into where its implemented on server side, you finish with appium-android-driver function.
In short what it does:
Get current activity and package
Press physical Home button
Wait for time you provided as argument (seconds)
Bring up back in focus based on different conditions; from the code you can understand what activity is being started
Basically its a sequence of adb shell commands, that you can run from terminal.
My guess is that step 4 you did manually may differ from what Appium is doing: different activities/arguments for activity been called
Am trying to make a game using easygui but the only way to shut is to shut python down completely because the X button won't work. How do I get it to shut the game?
A method I like to use is this at the end of the script:
raw_input("Press enter to exit...")
When Python runs a program, it brings up the black Command Prompt and then runs the program. To exit the command prompt when the program is done is always done by pressing the ENTER key.
This will only work in the end of the code. It can also work in any part of the code where the game ends.
I am not an expert in Python myself, but after your code is written...just use this:
import sys
sys.exit(0)
Besides, python has got a built-in exit command. Personally I only use exit to shut down python.
have a read:
http://docs.python.org/2/library/sys.html#sys.exit
Just try
print "Game Ended"
"""This area should be for what happens after game ends."""
It should close the easygui window when clicked, but keep the program running.
Hope this works!
I use wscript to launch an application on my machine. I then use this app for 30 seconds before I kill it. I do this using python -
import win32com.client
import time
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("My App")
time.sleep(0.5)
shell.SendKeys('%f')
...
I was wondering if it is possible to ensure that the launched app receives the SendKeys instructions and not another app that I might accidentally give focus to under this 30 second period.
Thanks,
Barry.
Problem
how to guarantee a wsh script SendKeys event goes to a specifically targted application
Workaround
in lieu of a straightforward solution to targeting a specific process with SendKeys you can use the "wait" variant of ShellRun
Example
Change "Before" into "After"
Before
WshShell.Run(run_name)
After
WshShell.Run(run_name,1,true)
I'm on mac osx using zsh. If I start a rails server with "rails s" I can put it in the background by hitting "ctrl-z" in my terminal (zsh).
If I open up a different terminal window then I don't see the rails server if I do "jobs". However, I can see it when I do "ps".
Is there a way I can somehow "unpause" the rails server in this new terminal window?
You can not easily move a process to a new tty. The easiest solution would be to start it in a screen session, detach screen and then resume in the new terminal.
The job is "stopped" by sending it a SIGSTOP.Your C-z doesn't send the job into the background. It "stops" it. You can then move it into the background using the bg shell builtin. However, if you send this process a SIGCONT (kill -CONT <pid>), it should bring the process back to the foreground. This can be done from a different shell.
You will not see it if you type jobs because it is a job controlled by a different shell (the other terminal window and not the one where you typed jobs). Processes however are "global" and can be seen from anywhere using the ps command (as you rightly pointed out).
Update: Looks like I spoke too soon. Apparently, the signal alone isn't enough to bring it back to the foreground. Probably something to do with the shell.