![]() ![]() (Don't do this in real life, okay? This form is a usability and cultural-sensitivity disaster, and would be almost insultingly dumb to show in public.) We'll supply a Qt button that fills out the full name entry, shows the submit button, and prints the full name to the console.This widget is a file selector dialog. There is a submit button, but it is hidden. There will be a full name entry that is disabled the user cannot edit it. ![]() It will show a form that allows the user to enter a first and last name. Now, let's throw caution to the wind and look at a simple example. ![]() Example of Evaluating JavaScript in a QWebView Be careful, validate user input, and block anything that looks too clever. It would be far too simple, for example, to allow the execution of arbitrary JavaScript by naïvely building a string and sending it to evaluateJavaScript. (It is at this point that we collectively grieve over JavaScript's ill-thought-out types.)Īn important caution about evaluateJavaScript: it has all the security implications of JavaScript's built-in eval, and should be used with the discretion that is so seldom displayed by front-end JavaScript coders. I see no better option for functions, but null is especially confusing the only way to detect a null value from evaluateJavaScript is to do the comparison val = null on the JavaScript side before you return it to Python. Note especially the behavior regarding null and functions, as both can cause code that looks right to behave wrong. ![]() undefined becomes None, sensibly enough.Objects are returned as Python dictionaries unless they are functions or arrays functions are returned as useless empty dictionaries, and arrays become Python lists.Because JavaScript lacks separate integer and floating-point datatypes, numbers are consistently converted to Python floats.It appears that strings and booleans just plain work, and numbers, objects, undefined, and null work with caveats: In fact, that information doesn't appear to be available on the web at all, so I did some testing. What values can be returned? The PySide documentation for QWebFrame, like that for PyQt and Qt itself, is not clear on that point. That method accepts a string of JavaScript, evaluates it in the context of the QWebView's content, and returns its value. Presenting a user with web-style content is useful in itself, but that content can be made interactive with JavaScript, which can be initiated from Python code.Ī QWebView contains a QWebFrame object, which is useful to us right now for its evaluateJavaScript method. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |