How can I set GUI size of spynner python module? - python

I would like to set a particular size for spynner GUI, how can I do that ? (fullscreen)
I know there's QT doc but I don't know any C++ and moreover I need to mix C++ & python

I am not really sure what you mean in your second line, as it doesn't really have anything to do with your question...
"...but I don't know any C++... and I need to mix C++ & python"
No C++ involved here.
If you check out the source code for spynner, and look at the Browser class, you will see that it stores the QWebView widget in an attribute: Browser.webview. It also says this in the docs as well.
https://github.com/makinacorpus/spynner/blob/master/src/spynner/browser.py#L96
So if you want to maximize the webview window, you just need to call showMaximized() on it:
browser = spynner.Browser()
browser.debug_level = spynner.DEBUG
browser.create_webview()
browser.show()
# now maximize the webview
browser.webview.showMaximized()

Related

Cannot find .exe with Pywinauto's find_window(title="program.exe")

Does anyone know the trick to pywinauto's find_window function? I am building an application with kivy, and trying to use pywinauto to bring an .exe to the foreground, using the following code:
SetForegroundWindow(find_window(title='program.exe'))
I simply want to identify a currently open .exe, and bring it to the foreground. I have looked here https://pywinauto.github.io/docs/code/pywinauto.findwindows.html and it seems "title=" is what I want.
Does anyone know how to point to the .exe with pywinauto?
I think title is for window title (i.e. "python - Cannot find..." in case of this tab), are you sure it not more like "process='program.exe'" ?
if it needs to be and int then its pid (process id) and you can use this to get process id by title:
import win32gui,win32process
def get_window_pid(title):
hwnd = win32gui.FindWindow(None, title)
threadid,pid = win32process.GetWindowThreadProcessId(hwnd)
return pid
Eventually have at this answer as it contains really nice class for getting windows Python Window Activation, i dont want to copy paste, but use it and then you can do:
w = WindowMgr()
w.find_window_wildcard(".*Hello.*")
w.set_foreground()
find_window is low level function I wouldn’t recommend to use.
The right thing is Application object connected to the target process. It can be used so:
from pywinauto import Application
app = Application(backend=“uia”).connect(path=“program.exe”)
app.WindowTitle.set_focus()
If you have several app instances, there is a Desktop object to walk all the windows in the system:
from pywinauto import Desktop
Desktop(backend=“win32”).window(title=“Window Title”, found_index=0).set_focus()
You referred to the old docs for version 0.5.4, the latest one is 0.6.4 with two backends available and many bug fixes. The Getting Started Guide link on the main page is a good source to learn the main concept.

How to remove icon from QMessageBox in PyQt5?

I am trying to code a message box that just pops up and says something and has a single button to close it however as I only have a small amount of text in the box the icon/image to the left of it is huge and looks bad. I want to know how to remove it. I am also having trouble making custom message boxes. Tutorials say that this is how you make a custom message box:
box = QMessageBox()
box.setText('text')
box.addButton(QPushButton('Close', self))
box.exec_()
However this just closes my program and returns a 1. My current code uses the about method of QMessageBox():
box = QMessageBox().about(self, 'About', 'This is a test Program')
However this has that large icon in the text window and I can't seem to do anything else to the box as it just stops the program and returns 1 again
I am in desperate need of some decent PyQt documentation. I can't seem to find documentation on much at all unless it is in C++. For instance I cannot seem to find any information of options other than question and about for QmessageBox. So if someone could also show me where some proper documentation lives it would prevent me asking too many questions here
Rather than PyQt documentation, it is better to directly use Qt documentation. You only need to switch your language mindset from Python to C++, there and back. It is not that difficult. :) See e.g. http://doc.qt.io/qt-4.8/qmessagebox.html#addButton or http://doc.qt.io/qt-4.8/qmessagebox.html#about I think this is very detailed documentation, unrivaled by most other frameworks.
Note that there are three overrides of addButton(). From the documentation it seems that you either need to pass two arguments to box.addButton(QPushButton('Close', self), QMessageBox.RejectRole) (you forgot the role!) or better, you use the override which uses standard buttons, then you only pass one argument: box.addButton(QMessageBox.Close).
And one more tip for you: I also find it easier to debug my program with PySide than PyQt because unlike PyQt, PySide catches the exception, prints that to console and keeps running. While PyQt usually just silently crashes leaving you clueless. Most of the time, I am using shims Qt.py https://pypi.python.org/pypi/Qt.py/0.6.9 or qtpy https://pypi.python.org/pypi/QtPy to be able to switch from PyQt to PySide on the fly. It also allows switching between Qt4 and Qt5 bindings easily.

pywebkitgtk: Headless + full DOM interaction possible?

I am currently using the Python Webkit DOM Bindings to interact with a website programmatically and that's working for me.
The only problem is that it insists on opening a GTK window to display the page. Has somebody figured out a way to prevent it from opening a window? I.e. to use it in a headless way?
I'm initializing the view like this:
wv = pywebkitgtk.WebView(1024, 768, url=url)
which implicitly opens the GTK window and then I have an onload event-handler to manipulate the DOM.
I first thought of subclassing WebView, but that's not possible because it is a compiled class.
Any other ideas?
I'm the developer responsible for pythonwebkit, and I have a great deal of expertise covering these areas across several platforms. Realistically, you really, really want a completely "headless" WebKit port. In pythonwebkit that actually shouldn't be too hard to do, as there are only three "entry point" functions (one for window, one for document, and one for XMLHTTPRequest).
Really, somebody should do a proper "completely headless" port of WebKit. There already is an example program which is pretty close in WebKit's source tree, maybe that will get you started.
I've been using PyQT. PyQTWebView runs on Webkit and works great. Check out Ghost.py to get started, or use PyQT's API directly. Runs fully headless, and supports a decently recent build of Webkit.
You could try using Xvfb. I like using the command line and setting my display manually, but if you don't like that you could use this: http://cgoldberg.github.io/xvfbwrapper/
Can you get a handle to the GTK window and then call window.hide()? Otherwise, you might just have to use the full Webkit library.
Create a window and add the webview there, and never show the window..
I have webviews running without showing them, and can call a show_all if I need to show them.
web_view = pywebkitgtk.WebView()
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
sw = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
sw.add(web_view)
window.add(sw)
#window.show_all()

Python widget/cursor detection?

Beginner python learner here. I have a question that I have tried to Google but I just can't come up with the proper way to ask in just a few words (partly because I don't know the right terminology.)
How do I get python to detect other widgets? For example, if I wanted a script to check and see when I click my mouse if that click put focus on an entry widget on a (for example) website. I've been trying to get it to work in Tkinter and I can't figure out even where to begin.
I've seen this:
focus_displayof(self)
Return the widget which has currently the focus on the
display where this widget is located.
But the return value for that function seems to be some ambiguous long number I can't decipher, plus it only works in its own application.
Any direction would be much appreciated. :)
Do you mean inside your own GUI code, or some other application's/website's?
Sounds like you're looking for a GUI driver, or GUI test/automation driver. There are tons of these, some great, some awful, many abandoned. If you tell us more about what you want that will help narrow down the choices.
Is this for testing, or automation, or are you going to drive the mouse and button yourself and just want something to observe what is going on under the hood in the GUI?
>How do I get Python to detect other widgets?
On a machine, or in a browser? If in a machine, which platform: Linux/Windows (which)/Mac?
If in a browser, which browser (and major version)?
> But the return value for that function seems to be some ambiguous long number I can't decipher
Using longs as resource handles is par for the course, although good GUI drivers also work with string/regex matching on window and button names.
> plus it only works in its own application.
What do you mean, and what are you expecting it to return you? You should be able to look up that GUI object and access its title. Look for a GUI driver that works with window and button names.
Here is one list, read it through and see what sounds useful. I have used AutoIt under Win32, it's great, widely-used and actively-maintained; it can be called from Python (via subprocess).
Here are comparisons by the author of PyWinAuto on his and similar tools. Give a read to his criticisms of its structure from 2010. If none of these is what you want, at least you now have the vocabulary to tell us what would be...

highlighting a window in GNOME's window list

In order to indicate activity, some applications (e.g. Pidgin) highlight their entry in GNOME's Window List panel widget (e.g. via bold font or flashing color). This indication is reset automatically when the window is activated.
I have a terminal application for which I would like to achieve the same thing (preferably via Perl, but Python would work too) - but I have no idea where to start. I imagine I'd first have to find the terminal window (based on window title) and then trigger some kind of GTK action.
Any help would be greatly appreciated!
In a GTK application, use gtk_window_set_urgency_hint(). If you have a terminal application, you can't really do that - with libwnck you can get information about other application's windows, but as far as I know you can't get a GtkWindow pointer to another application's window.
May I suggest using the terminal beep? Of course this isn't a sure way to attract the user's attention, but some terminals are able to flash the title bar instead of beeping, or such things.
I'm not really into GTK programming, but as far as i know you want to set an "URGENT"-Flag for the Window which should be highlighted. Maybe this will get you any further. :)

Categories

Resources