how to write a desktop application which uses HTML and CSS for user interface and python/perl/c++/java for the processing?
Different languages have different GUI toolkits, but it looks very difficult to achieve attractive user interfaces as good as we can using HTML and CSS with less effort. I don't do my application in javascript as I doubt if it has all the required libraries and I want to do it in python.
How do I use rendering engines like gecko, 开发者_StackOverflow社区webkit etc in python? Which one will be more suited to work with python?.Is there any 'only html/css' rendering engine without javascript?
Will it be easy to write event handlers for DOM events and manipulate DOM in python?
There are a couple of ways you might want to go about this: the most simple would probably be to use something like Adobe AIR, which is basically a Webkit rendering engine with an extended javascript engine, which allows you to program in more complex functionality.
Otherwise you could check out the wxWebConnect project, which is aimed at enabling "developers to quickly integrate advanced Web browser capabilities into their own applications." and is provided as a wxWidgets control library, which is something most python developers should be familiar with. It integrates the Mozilla Gecko rendering engine into your application.
Remote Control Toolkit does this, basically. It allows you to write desktop (programming) style applications that render in a browser display.
Even though it attempts to hide html/css/js details for you, you can extend the system with new widgets or extend existing ones, using basically everything that html(5), css, js offers.
Unlike Pyjamas or GWT, it doesn't compile to javascript. Your code remains serverside and you can basically do anything you are used to do (open files, open connections, keep state, and so on)
To supplement the options already given by others:
Some webkit bindings:
- qtwebkit (for pyqt or pyside)
- wxwebkit (not quite ready yet, but there is a prerelease for wxpython available)
- pywebkitgtk (don't know how easy it is to get it on Windows)
As for gecko/mozilla, you might have a look at PyXPCOM, probably via pyxpcomext. The difference here - if I understand it correctly - is that rather than using mozilla from within python, python gets embedded in mozilla. But it should be possible to make a xulrunner application that can use python.
You should check out Mozilla's XUL project. It allows you to build apps with the ease of HTML and "style" the GUI with actual CSS.
update: This is an old answer, nowadays you want to go with an embedded browser in your app (*webkit projects etc.), but at the time of writing, no such technology existed. The answer is still valid if you don't want to add quite a few megabytes to your packaged app though.
Find a lightweight server, or better - embed one in Your application. That's it.
Java has classes for serving http. Python does it well also.
See how mercurial's hg serve works. [python]
I once did a tiny app that served aspell spellcheck via http on localhost in java with the httprequest class. [worked on win and linux]
Create Your application as a server that outputs some html and uses POST to do actions. Do the interface thing in HTML+CSS+JS. Nice and easy.
After running point the user to localhost:somesillyport or trigger opening localhost:somesillyport in a browser.
If you had asked about one back-end language in particular, I would have left this response as a comment rather than a full-fledged question. However, the question is extremely broad... asking about use of an HTML/CSS interface in one of four back-end languages.
That being the case, you should just do a series of web searches on:
"html renderer" [insert-language-here]
... and spend some time browsing through the various options available for embedding an HTML/CSS interface into a back-end language application.
Ultimately, you are mostly likely going to wind up using Mozilla's Gecko renderer... either in its raw form, or indirectly through one of the numerous libraries that provide dev-friendly wrappers around it.
Speaking of Mozilla technologies, you might also want to check out XULRunner (lets you easily throw together a UI using XML with CSS and JavaScript), or maybe even Prism (takes an app running on an HTTP server and presents it to the user as a desktop app).
If you write in Java take a look at JavaFX. From official website:
The embedded browser enables you to perform the following tasks in your JavaFX applications:
Render HTML content from local and remote URLs Obtain Web history Execute JavaScript commands Perform upcalls from JavaScript to JavaFX Manage web pop-up windows Apply effects to the embedded browser
If you are going to port it to windows I would highly recommend HTMLLayout
- They allow you to write the UI in HTML and CSS and you can have your processing code in C++ to process it.
- It also allows you to write validation scripts in TI script(like Java Script) to validate the inputs before processing it.
- The binary size was just below 1MB so you can easily pack it along with your binaries.
- It was open source/free to use.
- It will also allow you to do TIScript/CSS based animations.
To my knowledge its best for developing GUI applications on Windows.
Check Sciter, it was designed as exactly embeddable HTML/CSS/scripting engine to be used as a UI layer of desktop applications.
You may also find Sciter technology introduction article on CodeProject useful.
Sciter contains TIScript on board that is almost "Python but with JavaScript syntax".
You can embed web browser component into your Java Swing/JavaFX Desktop application that displays GUI built with HTML5+CSS+JavaScript. You can see an article that describes how to do this at http://java.dzone.com/articles/htmlcssjavascript-gui-java-0
One of the Java Swing/JavaFX libraries that allows embedding Chromium into Java applications is JxBrowser. Using JxBrowser API you can load any web page and work with its DOM and JavaScript. You can even call Java methods from JavaScript code and vice versa. For example:
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserFunction;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
public class JavaScriptJavaSample {
public static void main(String[] args) {
Browser browser = new Browser();
browser.registerFunction("MyFunction", new BrowserFunction() {
public JSValue invoke(JSValue... args) {
for (JSValue arg : args) {
System.out.println("arg = " + arg);
}
return JSValue.create("Hello!");
}
});
browser.addLoadListener(new LoadAdapter() {
@Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
Browser browser = event.getBrowser();
JSValue returnValue = browser.executeJavaScriptAndReturnValue(
"MyFunction('Hello JxBrowser!', 1, 2, 3, true);");
System.out.println("return value = " + returnValue);
}
}
});
browser.loadURL("about:blank");
}
}
精彩评论