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.
Related
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.
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()
I've used Tkinter or wxWidgets for some projects: this opens a new window in graphical mode (GUI) in which you can do what you want.
Can I ask Python to open a new text-mode window (let's say 80x25 terminal), independant from the terminal where I run myscript.py,
in the same way that a Tkinter window is independant from the current terminal where I run myscript.py?
What do I want to achieve? Having a GUI, but in textmode! (this might sound tricky because G in GUI means graphical!)
Does tkInter, wxWidget, pyglet, etc. have a feature to open a text-mode terminal-look GUI? With 80x25 text display?
For this you will need to make a seperate script but it works.
Use this code in your launcher script.
from sys import executable
from subprocess import Popen, CREATE_NEW_CONSOLE
Popen([executable, 'myscript.py'], creationflags=CREATE_NEW_CONSOLE)
input('Enter to exit from this launcher script...')
Source
The Windows 7 Control Panel "Notification Area Icons" allows you to customize which system tray icons are visible. For each of the icons, it shows two things:
an application name
a subtitle
It looks like the subtitle comes from the tooltip text, because I can set that.
But what about the application name? I'm writing a GUI in PySide and can't figure out what incantations I need to do, to set this to something other than "python.exe".
python.exe will always show up if the module is run under the python executable, regardless of via a shortcut or not. It also shows up in task manager under the process name python.exe.
To circumvent this, it is necessary to create a custom executable to run the python script under it's own name. This doesn't have to be a monolithic exe packer such as py2exe, but can be something a little more discrete.
Using effbot.org's open source ExeMaker for instance, the following steps will result in what you want.
After downloading exemaker, simply run it from the command line with
exemaker scriptname.py
and it'll create scriptname.exe.
You may then run scriptname.exe by double clicking it, and it shall run the python script under it's own name.
The advantage of this small tool is that any changes made to the python script do not require recompilation of the exe - they are effective immediately.
This is because you are launching your application using Python.exe. In your case the main application running is Python.exe, so the Notification Area Icons will always show you Python.exe as running application.
When you are done with the development of your application, use pyinstaller or py2exe to package your application. After this process you will have a exe file for your application, when you will run your application, the name in the Notification Area Icons for your application will be same as you will set for your main window title.
I did not really test it but it may work. Create a link to your .py file and choose the name. If you run that link it should show the name of the link.
PS: On command prompt title bar it works fine
I am making an application using PySide. I want to embed a Terminal Emulator (like the Linux Konsole, or xterm). I want to have it in the application and not open up as a new window.
Does anyone know of any Python libraries that can do this? And how would I incorporate it, would I have to use a special QWidget to run it properly?
I also would like to be able to run linux commands. How can this be done?
You can create the terminal with the python subprocess. I put down a little more info here Terminal like app in PySide .
To embed it in your application just add the widget to the layout.