I develop a software that is for teachers to test their students. The main feature of the software is the cheat prevention it has. I want to achieve that by locking the option to exit the window in any way except a custom exit button in the top of the screen (already developed it and it's functionality). Is there a way to lock the option to exit a window, and make it always on the top?
I want to lock the option to press the windows button, the ctrl-alt-delete buttons, the ctrl-shift-esc, the f4 ext... How do I do that? using python and wxpython for
GUI
You can catch wx.EVT_CLOSE but you can't catch OS-level keyboard shortcuts, like CTRL+ALT+DELETE.
wxPython can only catch keyboard shortcuts that aren't already mapped to the OS. I would focus on catching the close event and just vetoing it as that will prevent the user from closing the application. It won't protect you from the user restarting the OS, but that's about as good as you can do without locking down the user's desktop.
It all depends on how user accounts are set up in Windows.
The part you can do with wx is:
Hide the title bar (using the wxFrame styles).
Or capture the wx.EVT_CLOSE and do nothing (pass or event.Skip())
You need to install and run your application with elevated privileges (Windows) without prompt, so that a user cannot kill the process.
In Windows 10 it is really simple:
How to Create Elevated App Shortcut without UAC Prompt in Windows 10
Good look.
Related
I have a CLI application with no GUI. This application uses CMD to launch and display some information (long-running process -- localhost-server). I want to add a feature where we can hide the window when we don't want to see it and unhide the window when we want to see it.
I tried to achieve that using Python Module Pystray but it only hides GUI applications in the system tray. It does not hide CMD in the system tray.
I wrote a PyGtk app to control some specific functionality on a Pi3. This full screen GUI (via a 2.8" TFT touch screen) is all the user has to interact with the device. There is no mouse, keyboard, SSH, VNC, etc available. Because there is a requirement to get input from the user I need to implement a way to have a virtual keyboard appear when a text box gets focus and then disappear when focus is lost. I researched a number of virtual keyboards and the only one that seems to offer this functionality with Gtk support is Florence. But I cannot get it to automatically show/hide when an input text box gets/loses focus.
Florence relies on the at-spi framework to get event notifications. According to "Florence modes" (http://florence.sourceforge.net/english/usage.html)
You should make sure your applications support at-spi if you intend to use Florence in hidden mode.
and
The auto hide mode requires accessibility to be activated, which means the at-spi registry daemon is running and applications are using it.
Also, according to the FAQ (http://florence.sourceforge.net/english/how-to.html) an environment variable needs to be set.
export GTK_MODULES=gail:atk-bridge
So I configured Florence for auto-hide mode, downloaded at-spi, ran the registry daemon and set the environment variable but no dice. When a text box on the GUI is focused, the keyboard does not appear.
I suppose I have two questions. First, I am not tied to Florence by any means so if there is another solution I am open to implementing it. But second, one thing that is not clear to me is how I can make the PyGtk app "support at-spi." Other than the environment variable how do I make sure my app uses at-spi? None of the documentation is clear to me on that point.
I do not have a raspberry pi (RPi) yet, so this answer might not work on RPi.
It does work on linux, so you might want to test it on RPi.
I installed OnBoard (another virtual keyboard that supports DBus).
Make sure that you OnBoard running but with the virtual keyboard hidden.
The following code will control the visibility of the virtual keyboard:
import dbus
# initialize session bus, you can put the following lines into
# your initialization block, or something or use a class
sess_bus = dbus.SessionBus()
# get the object proxy for the virtual keyboard,
# won't work if OnBoard is not already running
kbd = sess_buss.get_object('org.onboard.Onboard',
'/org/onboard/Onboard/Keyboard')
# display virtual keyboard
kbd.Show()
# hide virtual keyboard
kbd.Hide()
How can I prevent a Python shell/commandline/terminal window from beeing closed, if the user clicks the close button of the Window? I've tried to catch SystemExit exceptions and overriding sys.exit(), no success.
I know, I can do this with a GUI toolkit/framework like PyQt, but importing that (and including it in the final binary of my program) would be no option while it's too big.
It is not possible to do this in the general case.
The terminal window is (generally speaking) a separate process from Python itself (YMMV with IPython and other such things, but this is true if you're running regular Python inside a regular terminal). When the terminal window decides to go away, it is not possible (under most reasonable operating systems and window managers) to prevent it from doing so, because it's a totally different program which just happens to be displaying your input and output.
You can, however, keep your program running after the terminal closes. The terminal will still go away, but the program will keep running in the background. On Unix systems, this is generally done by catching or ignoring the SIGHUP signal using signal.
Depending on your operating system and choice of terminal emulator, it may or may not be possible to configure the terminal to not close. Some terminal emulators under Linux will, by default, warn the user that there is a process running under the terminal when the user tries to close it. This is highly platform-dependent and can't be configured (portably or perhaps at all) from within Python.
I am trying to write a program in python that behaves like a screensaver or screenlock.
I can prevent the interactive user from interacting with other running applications by calling gtk.gdk.keyboard_grab and gtk.gdk.pointer_grab.
However, the user can still press ctrl-alt-F1 to F7 to switch to the console. The user can also press ctrl-alt-esc to run xkill or press ctrl-alt-backspace to restart X.
Is there a way, using only python and GTK (pygtk), to prevent users from doing this?
The application is primarily targeted to run on linux mate.
So, I have a python script running I the background, and I want it to trigger X function whenever a key combination is pressed. How would I implement that? The problem is that the app will be running in the background, so it won't have focus from the OS.
Well, it basicly has nothing to do with python. That heavily depends on the operating system you're working on.
You can use XLib under Linux (http://python-xlib.sourceforge.net/) or wxPython under Windows (http://wxpython.org/docs/api/wx.Window-class.html#RegisterHotKey)
Another idea would be to hook the system keyboard events (through pyHook) and try to catch any hotkeys.