I have a window that can't be minimized.
I have to prevent users to access it while the gui automation.
How to handle this kind of problems with pywinauto?
It works with autoit and the WinSetTrans() function.
Is there something similar in the pywinauto module?
There is no such method in pywinauto, but it's easy to implement. Thank you for the feature request!
So far you may workaround it so:
import win32gui, win32api, win32con
hwnd = app.dlg.ctrl.handle
ex_style = app.dlg.ctrl.ExStyle()
win32gui.SetWindowLong (hwnd, win32con.GWL_EXSTYLE, ex_style | win32con.WS_EX_LAYERED )
win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0,0,0), 180, win32con.LWA_ALPHA)
P.S. It was quickly adapted from the known answer (I didn't check it yet). We will include something like SetTransparent method into pywinauto 0.5.3 (planning this week).
Related
i wanted to make a caps-lock and num-lock indicator using python on windows,
but i dont know how to start with and what all modules and library i need to implement my desired output.
THE OUTPUT i desire is that whenever i press CAPS-LOCK the borders of screen should go green and for *NUM-LOCK** blue.
also, does it require a GUI?
(but i want it to be transparent. i don't want minimise,close and maximise buttons on gui) and this all process should be done in background.
Please guide me on how should i approach this.
THANKS A LOT.
There's the WinApi package for python here.
Not very well documented, but after quick look at demos looks like this code works:
import win32api
import win32con
print(win32api.GetKeyState(win32con.VK_CAPITAL))
For green frame you'll need probably some GUI library (GTK+, Qt), but I don't know which one could achieve such effect.
Edit: I figured you can actually use the same WinApi to draw on the screen.
import win32api
import win32gui
import win32con
pen = win32gui.CreatePen(win32con.PS_SOLID, 7, win32api.RGB(255, 0, 0))
dc = win32gui.GetDC(0)
win32gui.SelectObject(dc, pen)
win32gui.MoveToEx(dc, 0, 0)
win32gui.LineTo(dc, 1920, 0)
This is complex to explain, I hope this will not end up being a vague question getting vague answers.
If this is not the right place to ask this, you may help me to find the proper one.
I have a plugin for Photoshop based on the Listener, so it captures any input from the user.
The plugin creates a python module (called here "ps") containing basically the hInstance and the hwnd of the photoshop window.
Then this plugin, using plain python commands in the plugin for the module like those
PyRun_SimpleString("import Photoshop");
PyRun_SimpleString("Photoshop.showTools()");
will load a special module (here called "Photoshop") that will initialize pyqt and using the QtWinMigrate and the ps module to get the hInstance like this: QMfcApp.pluginInstance(ps.GetPluginInstance()), will start pyqt in photoshop. Here an example code of the Photoshop module using the ps module:
from PyQt4.QtWinMigrate import QMfcApp
from PyQt4.QtGui import QPushButton
import ps #this is implemented in the photoshop plugin (based on the Listener plugin)
#create the plugin instance here
app=QMfcApp.pluginInstance(ps.GetPluginInstance())
def showTools():
box = QPushButton()
box.show()
app.exec_()
Again then, the sequence is like this:
When the plugin starts in photoshop "ps" module is created, then it will load the "Photoshop" module that will load and bind properly pyqt. In the "Photoshop" module I can load any python module, widgets are properly working and everything works really well inside Photoshop.
But now the problem is: using Wacom tablets in Photoshop loose stroke sensitivity, the driver works and everything else works but the pressure sensitivity.
Apparently QMfcApp.pluginInstance will install an event filter to drive the Qt event loop while photoshop still owns the event loop. ( http://doc.qt.digia.com/solutions/4/qtwinmigrate/qmfcapp.html )
and on the paper looks fine to me.. but I could not manage to solve this by myself and I tried, more or less carefully, different approaches:
the listener plugin is not the problem. If Listener plugin runs but python is not initialized sensitivity works fine.
python itself is not a problem. If the listener starts python without gui nor pyqt, then works fine.
as soon as I call pluginInstance which should create the QApplication the issue starts and pressure is lost from the tablet. Even with the small code I wrote before.
Someone may have put pyqt as a plugin somewhere else, since the only purpose of QMfcApp is apparently this one. There is something I can configure to make it work? Is a known issue?
I would rather keep the approach (instead of connecting to photoshop externally like with COM)
I am not able to post the entire code here but let me know if you need something.. I probably can show more.
Thanks a lot for your help
My python application launches a subprocess that creates a pyglet window. When the pyglet window opens, it is in front of all other windows, and takes keyboard focus. I'd like my pyglet window to open in the background, and not take focus. Is this possible?
Stripped-down version of the code I'm using:
import pyglet
pyglet.window.Window()
pyglet.app.run()
I'm using Windows 7, in case that makes a difference..
Reversing focus is OS specific:
pyglet does not provide OS specific window control. So most likely you will have to use an ad-hoc trick for quick&dirty solutions or try to approach it with extensions like pywin32 using Windows API and/or COM to list through the stack of taskbar applications to reverse stealing of focus. You can also try to create your own window (container - which you can manipulate) first - in order to delegate its context to pyglet.
Delaying stealing of focus
On the other hand if according to your program logic you just want to delay actual showing of you application you can play with visibility:
import pyglet
w = pyglet.window.Window()
w.set_visible(False)
pyglet.app.run()
So if you don't want to play with delegation of window context, you can probably do the following:
start your application w/o showing the window
find the focus of the current active window by getting its handle/id
show your window
give back the focus to the previous window
The above assumes working with windows API. I think MSDN had examples on focus changing.. If you know PID of your current window (main application) this should simplify the step 2.
I am thinking this might be more of a windows / window manager issue than your app - will something like this http://pcsupport.about.com/od/windowsxp/ht/stealingfocus02.htm help ??
I'm writing a little program that basically has a bunch of buttons that when you click one, it inputs a certain line of text into an online game I play. It would be a lot easier to use if the GUI would stay on top of the active game window so the user could be playing and then press a button on the panel without having to bring it to the front first.
Any help on how to do this would be great. Thanks
EDIT: Using tkinter
You will need to provide the information on which GUI framework you are using for detailed answer at SO.
On windows you could do something like this with the handle of your window.
import win32gui
import win32con
win32gui.SetWindowPos(hWnd, win32con.HWND_TOPMOST, 0,0,0,0,
win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
Also with Tkinter, you might want to try. I have not tried it though.
root = Tk()
root.wm_attributes("-topmost", 1)
Just wondering if there is any kind of framework or method of making a Gui that will override (Stay on top of) all other windows in python. Including Games or other programs that seem to "Take over" the computers Graphical processes. Any point in the right direction would be much appreciated...
PS. The OS in question is Windows 7, but a cross platform solution would be appreciated.
You need the SetWindowPos function from the Win32 API. Something like the following should work (see the API link for more details):
import win32gui, win32con
hwnd = get_my_window_handle()
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOSIZE)
For a cross-platform solution, you could use wxPython with a wxSTAY_ON_TOP style bit in a main window. I believe that this will give you the behavior you desire on Mac and Unix GUIs as well as Microsoft Windows ones.