Python PyGtk virtual keyboard support with at-spi - python

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()

Related

How to add CMD to System Tray?

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.

Python tkinter application in Win10 tablet mode does not open virtual keyboard clickin on Entry fields

I have setup a kiosk as Win10 in tablet mode because it has to work only with the touch screen. Programs and standard applications installed by Win10 work perfectly but a simple test app designed in Python using tkinter does not. it is a simple application with a n entry field and a butto to convert temperature from Fahreneit to Celsius degrees. When I click on the entry field it does not open the virtual keyboard. Of course I can open the virtual keyboard using the icon on the bar but I want to open it automatically. MAy be a tkinter problem or do I need a not obvious Win10 setup?
Thanks.

How to make a window unexitable

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.

Pygame error "Video system not initialized" on ubuntu server with only terminal

I'm using pygame on a PC (PC-104) with ubuntu server, for this reason it only has terminal, not UI.
On my laptop the code works perfecly, running the code on the terminal "eg: python game.py", but on the PC104 it gives "Video system not initialized", I read the error is shown because it is a way to use events on a system without UI?
Thanks.
Thank for your answer jsbueno. I was able to found a solution a few weeks ago but forget to answer the question.
I wasn't able to run any pygame script with any other library than X11. But I found that one can run the script with no graphics library. Just setting the SDL_VIDEOLIBRARY enviroment variable to "dummy".
This is posible on bash but I prefer to do it on python:
os.environ["SDL_VIDEODRIVER"] = "dummy"
With this I was able to run the pygame script, detect joystick events, etc.
It is possible to run pygame programs in a system without X11 if you set it to use framebuffer or vgalib - the docs even talk about using aalib (which would display graphics using ascii art on the terminal.)
This part of the documentation has it:
Pygame will select from one of several internal display backends when
it is initialized. The display mode will be chosen depending on the
platform and permissions of current user. Before the display module is
initialized the environment variable SDL_VIDEODRIVER can be set to
control which backend is used. The systems with multiple choices are
listed here.
Windows : windib, directx
Unix : x11, dga, fbcon, directfb,
ggi, vgl, svgalib, aalib
So, what you have to do is set the SDL_VIDEODRIVER environment variable before starting your code. And being shure the proper lib. is installed.
For more information:
http://www.pygame.org/docs/ref/display.html

How do I register global system keyboard hotkeys on Mac OS X in wxPython/Python 2.7?

I'm writing a GUI-based app in Python 2.7 using wxPython 2.8. I'm trying to run everything on a Mac, and unfortunately it seems that wxPython's wx.Window.RegisterHotKey() method only works on Windows. I would like to be able to set a global hotkey or key combination while the application is running, and have that key combination get passed on to the application itself, even when it doesn't have focus. How can I allow my application to be notified when a (user-defined) global hotkey/combination is pressed on Mac OS X, even when the app doesn't have focus?
When the app has focus, you should be able to use wxPython's AcceleratorTable:
http://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/
http://www.blog.pythonlibrary.org/2010/12/02/wxpython-keyboard-shortcuts-accelerators/
I don't have a Mac, so for you'll have to try asking on the wxPython mailing list or the wx-mac mailing list for help about registering a hotkey outside of wx.
This is currently not available on platforms other than Win32. I have an open ticket for it on the WX tracker:
http://trac.wxwidgets.org/ticket/12354
You'll find a link to how to accomplish this with Objective C, and you should be able to do it with PyObjC, but both WXPython and the outlined method for capturing hotkeys on OSX require running in an event loop in the main thread.

Categories

Resources