how to embed a webpage using wx? - python

I need to show a webpage (a complex page with script and stuff, no static html) in a frame or something. It's for a desktop application, I'm using python 2.6 + wxPython 2.8.10.1. I need to catch some events too (mostly about changing page). I've found some samples using the webview module in a gtk application, but I couldn't have it works on wx.

You can embed IE, but I think that's about it. wxWebKit is working on a wx add-on to use WebKit as an embedded browser in wx, but I think it's still a work in progress.

There is a commercial solution for this called wxWebConnect that uses Gecko (the Mozilla engine). I've never used it myself because i'm waiting for the wxWebKit project to be ready to use but it looks pretty good although perhaps a little overkill for your needs.

Related

Is it possible to style Python GUI like you would style HTML with CSS?

I work a lot with HTML & CSS for Web Development, and I've only recently transitioned to Python for software development. I've done some of the basics with Python, my proudest moment being I programmed a calculator through Python using the TKinter, but I'm going to be honest with you it's quite ugly. I know how to change the foreground and background color, but that's about it. I was sort of hoping there was a way to style Python like you would style HTML with CSS. Is something like this possible?
I don't know if this is too broad of a question, but I really just need some sort of answer. Even a link to some sort of YouTube video to get me down the right path would be nice. I would also like to learn how to do other GUI style's like transitions, hover effects, and keyframes, but that's for another question.
Inside of python your options are quite less, but never none. You have options starting from ttk from tkinter, which kind of gives a windows 7 theme and with ttkthemes you get more themes for tkinter. But if your planning to go on for a more modern GUI, using HTML and CSS and JS, then you do have Eel for python. There is also a python wrapper for Qt called PyQt which also provides not so bad design. And also Kivy which can also gives you some kind of modern looks. Using tkinter is mainly for simple projects and it has its own limitations. But one of the limitation is your imagination and designing skill, for example here is a GUI I made with tkinter:
It does not look top of the mark or something, but it kind of looks better than traditional looks with tkinter.
First off, Web Design with CSS is a lot prettier, in Python you have less options.
But there is an editor called QT Designer, it lets you create GUIs and use them in your C++ or Python script. You may give it a try.
Keith Galli made a youtube tutorial on a Python GUI with TKinter which doesn't look that bad, regarding it's made with Python.

Can I put my python GUI made in wxpython on a web browser?

I have a GUI which I wrote in wxpython which runs on my PC.
Now, I want to be able to port the program so that it can run from a browser, and I will be able to access it remotely.
Is it possible to do this with wxpython? If not, is it possible to port the program in some way so that it runs from the browser but isn't the main page? Ideally, I don't want to have to rewrite any of the GUI code.
Thanks
There's been some talk of doing something like this on the wxPython users list, but nothing has come of it that I'm aware of. You can read some more about the stuff that that ticket refers to here:
https://groups.google.com/forum/#!topic/wxpython-users/RPpt9IqzGpo
However, it sounds like it uses wxPython Phoenix, which itself is pretty beta as it doesn't have all the functionality (or widgets) that classic does. If you want to create a web page with Python, you would be better off using a Python web framework such as Django, TurboGears, Sphinx, bottle, flask or one of the others.
If you want to create a web browser with wxPython, try the webview widget.

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()

fast gui on raspberry

I started a project where you can "log in" on a terminal (basically a Raspberry Pi with a touchscreen attached) with a wireless token (for time tracking).
What will be the best and fastest solution to display the status (basically a background picture and 2-3 texts changing depending on the status of the token) on the screen (fullscreen)? I tried it web-based with chromium, which is -very- slow...
It has to be easy to do http request and en-/decoding JSON - and please no C/C++.
Maybe python + wxwidgets?
If you want easy/fast, and all you care about is http, JSON, and displaying an image, then I'd go with Tkinter and the standard library.
You have import json for JSON, and httplib or urrlib2 for http requests. And for a fullscreen Tkinter widget, check out effbot.
You could use Python for this easily with just the standard library (python 2.7.3).
For the GUI you can use Tkinter or Pygame (not standard library) which both support images and text placement (and full screen). It is notable that Tkinter is not thread safe, so that may be a problem if your planning on threading this program.
For the http request you can use httplib.
For the Json related things you can use the json library.
Kindly give QT a try. It has very good GUI tools and supports the C++ and nativeness it requires. We use QT to build interface and deploy it small terminals such as raspberry Pi. It will also allow you to boot straight in to the application as it starts.
Here is a link : http://qt-project.org/wiki/Qt-RaspberryPi

Tkinter: How to make a system tray application?

i have a small application. I want my target users(windows,linux) to be able to start and exit the application from the system tray. I intend to use Tkinter because of its low footprint but, i dont know how to implement it.
Can tkinter do this or are there better alternatives. I need a GUI library that won't change my 1MB program to a 5MB program.
Please sample codes will be appreciated
Thanks
I don't know any direct examples but I found a TCL/Tk extension to use the systray over here http://wiki.tcl.tk/4090 and a page on the wiki giving information on how to use TCL/Tk extensions from Tkinter.
On a more general note, you might want to consider using a more "advanced" toolkit (like wx) that provides things like systray usage etc. natively.

Categories

Resources