python webkit signals - python

I would like to use webkit to create a simple web browser with some special functions. In particular, I would like to have a function that adds a word to a file, if I click on that word. Now, I already have the browser, but I could not figure out how I would read out the word at the mouse position. Could someone suggest either a solution, or some material on this?
Thanks,
v923z

The gtk webkit has limited possibility to talk with python.
There is a guide on doing so here:
http://www.aclevername.com/articles/python-webgui/
It involves sending javascript to the browser, and for the browser to communicate with python to change the title of the webpage.

Apparently they fixed ability to use the selected signal, so something like this may work...
mywebview.connect('selection-changed', nameofmyfunction)
and observe arguments passed to nameofmyfunction().

Related

Pywinauto waiting too long to do an action

I need help.
I'm doing a UI automation, and it works properly.
However, it waits for all controls get done, but for example, the textbox I want to send keys is activated.
Because of that, my automation is very slow, and I couldn't find any helpful information in module documentation.
Thank you all
I find out the solution. If you have the same problem, you should always search for controls, with child_window function.
If you use the bracket notation, pywiauto will search all controls from root window, and depending the application, it takes a long time.
However, using child window, you can filter by control type, title and automation id
Global timings for every operation can be changed in module pywinauto.timings:
https://pywinauto.readthedocs.io/en/latest/code/pywinauto.timings.html
But please be careful. Aggressive timings can make some actions unstable.

Load webpage in Python GUI window

I've searched on Google and StackOverflow but am having trouble finding the answer, even though it seems like it should be easy to do.
How can I use Python to load a URL into its own window, rather than in a browser? I imagine this should be trivial in Tkinter or some other GUI package.
Yeah. that's very easy with QWebView in PyQt/PySide
You basically instantiate a new QWebView and pass the url to it
QWebView.load(QUrl('http://www.www.pythoncentral.io'))
you can read more here
http://pythoncentral.io/pyside-pyqt-tutorial-qwebview/
and also in the pyQt docs
http://pyqt.sourceforge.net/Docs/PyQt4/qwebview.html
A new option would be: pywebview
pywebview is a lightweight cross-platform wrapper around a webview
component that allows to display HTML content in its own native GUI
window. It gives you power of web technologies in your desktop
application, hiding the fact that GUI is browser based.
See here:
https://github.com/r0x0r/pywebview

python webkit : hack and custom

I have done a python webkit navigator, with GTK.
And, as I better know html/css for rendering than others ways, I have done a software using python, wekbit and GTK.
I got some questions. I have read documentation that I found, and did a lot of researchs on google and stackoverflow. I still got lot of questions.
First, in my app, I change the title of the window to communicate between javascript and python. I wish to do the same in my navigator, but I can not (I need title). Is their any others ways ?
I would love to bind javascript events listeners to python, without changing the title.
EDIT
I have found a solution. We can bind some events to python.
You can have more documentation about events in python :
import webkit
help(webkit.WebView)
I have tried with console-message. This events returns me 4 args : webview, webframe, int, msg. What is the int ? In most of messages it is valued to 13... If someone know what it means.
Second, my linux version of my navigator plays really well media element (audio, video...). I assume, it is because linux rulz and depedencies are pretty well installed on my computer.
But on windows it is another things ...
I have seen that I can build webkit for windows with these dependencies.
But I have found some javascript codecs for reading media elements (https://github.com/audiocogs). Should it be better than I inject this javascript, or compiling webkit in my own way ?
Third, can I handle cache settings ? I am pretty sure that now, there is no cache in my browser. (my code is really light now on).
Fourth, can I handle HTTP request ? (cookies, apache auth, ...)
Fifth, I use WebView.zoom_in(), and zoom_out functions. And definitively it has not the same behaviour than firefox or chrome when I zoom_in or zoom_out.
With firefox or chrome, it's like if zoom_out make you have more pixels than before. I mean if you zoom out on chrome, you can have different media queries than before.
With WebView zooms functions, it's like if there is only the font size who change.
How could I do zooms like firefox and chrome ?
Sixth, I could use gecko engine instead of webkit. But I do not know, how to choose between those twos.
It seems that webkit is nicely imported in python and gtk, and linux. But gecko probably too. How could I, in a cleverway, choose ?
Seventh, I got some streaming problems. For instance, if I want to hear some long music, or some videos, and pause them for some times, when I play back the media, my browser bug. There is no error in console, and the webkit.webview is all blank. I can reload, and it works again... How can I handle this error ?
Some relevant samples of my light code :
class nav:
def __init__(self):
self.browser = webkit.WebView()
self.browser.connect("create-web-view",self.set)
self.browser.set_full_content_zoom(True)
self.browser.get_settings().set_property("enable-webaudio",True)
self.browser.open(url)
def on_zoom_in(self, widget):
self.browser.zoom_in()
def on_zoom_out(self, widget):
self.browser.zoom_out()
def on_zoom_n(self, widget):
self.browser.set_zoom_level(1.0)
Thank you,
Not the answers for all the questions you have, but this will help.
There is no need to change the title for communicating between javascript and python. You can alert mechanism. Some examples can be found https://github.com/nhrdl/notesMD - the tool I wrote few days back. In simplest terms, your script uses alert function and python gets the callback. You can parse the text of alert message and decide on action.
Your code has nothing to do with webkit cache. Its function of what pages your application is visiting and what server prefers. Server can ask for some resources to be cached (e.g. images/javascript) and others not to be cached. I know webkit gtk 2 supports some more functions for caching, but don't recall much in Webkit gtk 1. I have seen it caching the files in your home directory though.
For cookies look at python webkit webview remember cookies?. Webkit also has various methods to get request and response and you can listen to various soup events for the things that interest you.
I have not read about python bindings for geco engine. That does not mean it does not exists, only I have not seen it.

how to use favicons in pywebkitgtk

I would like to retrieve the favicon for each web page visited and place it next to the tab label in my notebook containing a webkit webview. However, I am finding nothing regarding how to obtain the favicon in pywebkitgtk, (once I have the icon, I know how to place it). I've seen some functions for doing this in the C version of webkit. Is it possible in python or should I start over in C? If it is possible, what functions are used? Thanks.
I know this is old question, but perhaps this will help. http://webkitgtk.org/reference/webkit2gtk/stable/WebKitFaviconDatabase.html

How to make PowerBuilder UI testing application?

I'm not familiar with PowerBuilder but I have a task to create Automatic UI Test Application for PB. We've decided to do it in Python with pywinauto and iaccesible libraries. The problem is that some UI elements like newly added lists record can not be accesed from it (even inspect32 can't get it).
Any ideas how to reach this elements and make them testable?
I'm experimenting with code for a tool for automating PowerBuilder-based GUIs as well. From what I can see, your best bet would be to use the PowerBuilder Native Interface (PBNI), and call PowerScript code from within your NVO.
If you like, feel free to send me an email (see my profile for my email address), I'd be interested in exchanging ideas about how to do this.
I didn't use PowerBuilder for a while but I guess that the problem that you are trying to solve is similar to the one I am trying to address for people making projects with SCADA systems like Wonderware Intouch.
The problem with such an application is that there is no API to get or set the value of a control. So a pywinauto approach can't work.
I've made a small tool to simulate the user events and to get the results from a screencapture. I am usig PIL and pytesser ORM for the analysis of the screen captures. It is not the easiest way but it works OK.
The tool is open-source and free of charge and can be downloaded from my website (Sorry in french). You just need an account but it's free as well. Just ask.
If you can read french, here is one article about testing Intouch-based applications
Sorry for the self promotion, but I was facing a similar problem with no solution so I've written my own. Anyway, that's free and open-source...
I've seen in AutomatedQa support that they a recipe recommending using msaa and setting some properties on the controls. I do not know if it works.
If you are testing DataWindows (the class is pbdwxxx, e.g. pbdw110) you will have to use a combination of clicking at specific coordinates and sending Tab keys to get to the control you want. Of course you can also send up and down arrow keys to move among rows. The easiest thing to do is to start with a normal control like an SLE and tab into the DataWindow. The problem is that the DataWindow is essentially just an image. There is no control for a given field until you move the focus there by clicking or tabbing. I've also found that the DataWindow's iAccessible interface is a bit strange. If you ask the DataWindow for the object with focus, you don't get the right answer. If you enumerate through all of the children you can find the one that has focus. If you can modify the source I also advise that you set AccessibleName for your DataWindow controls, otherwise you probably won't be able to identify the controls except by position (by DataWindow controls I mean the ones inside the DataWindow, not the DataWindow itself). If it's an MDI application, you may also find it useful to locate the MicroHelp window (class fnhelpxxx, e.g. fnhelp110, find from the main application window) to help determine your current context.
Edited to add:
Sikuli looks very promising for testing PowerBuilder. It works by recognizing objects on the screen from a saved fragment of screenshot. That is, you take a screenshot of the part of the screen you want it to find.

Categories