使用Python的CSS轻量级渲染器HTML

时间:2022-09-10 19:59:22

Sorry, perhaps I haven't described the problem well first time. All your answers are interesting, but most of them are almost full-featured web browsers, my task is much simpler.

对不起,也许我没有第一次描述这个问题。你的所有答案都很有趣,但大多数都是功能齐全的网页浏览器,我的任务更简单。

I'm planning to write a GUI application using one of the available on linux GUI frameworks (I haven't yet chosen one). I shall use html in my application to render into one of my application frames text with some attributes — different fonts etc, which are stored in CSS.

我打算用一个可用的linux GUI框架编写一个GUI应用程序(我还没有选择一个)。我将在我的应用程序中使用html渲染到我的应用程序框架文本中的一些属性 - 不同的字体等,它们存储在CSS中。

The HTML shall be generated by my application, so the only task is to render a HTML / CSS string. Is there any widget which can do only that render and nothing more — no history, no bookmarks, no URL-loading etc? If there isn't I shall use one of those you advised — it's ok — but I'm just interested if there is just an html-renderer without any extra features.

HTML应由我的应用程序生成,因此唯一的任务是呈现HTML / CSS字符串。是否有任何窗口小部件只能进行渲染,而不是更多 - 没有历史记录,没有书签,没有URL加载等?如果没有,我会使用你建议的那个 - 这没关系 - 但我只是感兴趣,如果只有一个没有任何额外功能的html渲染器。

3 个解决方案

#1


13  

You should use a UI framework:

您应该使用UI框架:

  • Qt: The simplest class to use would be QWebView
  • Qt:最简单的类是QWebView

  • Gtk: pywebkitgtk would be the best answer, but you can find others in the PyGTK page.
  • Gtk:pywebkitgtk是最好的答案,但你可以在PyGTK页面找到其他人。

  • In Tk is the TkHtml widget from here
  • 在Tk中是TkHtml小部件

An other option is to open the OS default web browser through something like this:

另一种选择是通过以下方式打开操作系统默认Web浏览器:

import webbrowser
url = 'http://www.python.org'

# Open URL in a new tab, if a browser window is already open.
webbrowser.open_new_tab(url + '/doc')

# Open URL in new window, raising the window if possible.
webbrowser.open_new(url)

You can find more info about the webbrowser module here. I think that the simplest way would be to use the os browser if you are looking for something very light-weight since it does not depend on a framework and it would work in all platforms. Using Tk may be an other option that is light and will not require to install a 3rd party framework.

您可以在此处找到有关webbrowser模块的更多信息。我认为最简单的方法是使用os浏览器,如果你正在寻找一些非常轻量级的东西,因为它不依赖于框架,它可以在所有平台上运行。使用Tk可能是另一个很轻的选项,不需要安装第三方框架。

#2


0  

Flying Saucer Project -- an XHTML renderer.

Flying Saucer Project - 一个XHTML渲染器。

No, it's not Python. It's -- however -- trivially called from Python.

不,这不是Python。然而,它 - 从Python中简单地调用。

#3


0  

Maybe HulaHop could be interesting for you (can also be combined with Pyjamas). The Mozilla Prism Project might also be relevant.

也许HulaHop对你来说很有趣(也可以与睡衣结合)。 Mozilla棱镜项目也可能具有相关性。

#1


13  

You should use a UI framework:

您应该使用UI框架:

  • Qt: The simplest class to use would be QWebView
  • Qt:最简单的类是QWebView

  • Gtk: pywebkitgtk would be the best answer, but you can find others in the PyGTK page.
  • Gtk:pywebkitgtk是最好的答案,但你可以在PyGTK页面找到其他人。

  • In Tk is the TkHtml widget from here
  • 在Tk中是TkHtml小部件

An other option is to open the OS default web browser through something like this:

另一种选择是通过以下方式打开操作系统默认Web浏览器:

import webbrowser
url = 'http://www.python.org'

# Open URL in a new tab, if a browser window is already open.
webbrowser.open_new_tab(url + '/doc')

# Open URL in new window, raising the window if possible.
webbrowser.open_new(url)

You can find more info about the webbrowser module here. I think that the simplest way would be to use the os browser if you are looking for something very light-weight since it does not depend on a framework and it would work in all platforms. Using Tk may be an other option that is light and will not require to install a 3rd party framework.

您可以在此处找到有关webbrowser模块的更多信息。我认为最简单的方法是使用os浏览器,如果你正在寻找一些非常轻量级的东西,因为它不依赖于框架,它可以在所有平台上运行。使用Tk可能是另一个很轻的选项,不需要安装第三方框架。

#2


0  

Flying Saucer Project -- an XHTML renderer.

Flying Saucer Project - 一个XHTML渲染器。

No, it's not Python. It's -- however -- trivially called from Python.

不,这不是Python。然而,它 - 从Python中简单地调用。

#3


0  

Maybe HulaHop could be interesting for you (can also be combined with Pyjamas). The Mozilla Prism Project might also be relevant.

也许HulaHop对你来说很有趣(也可以与睡衣结合)。 Mozilla棱镜项目也可能具有相关性。