PyGTK - webkit.WebView 不适用于 Ubuntu 11.04

发布于 2024-12-07 06:20:06 字数 1365 浏览 6 评论 0原文

下面是代码片段:

import gtk, webkit, os

w = gtk.Window()
w.set_title("Example Editor")
w.connect("destroy", gtk.main_quit)
w.resize(500, 500)

editor = webkit.WebView()
editor.load_html_string("<p>This is a <b>test</b>", "file:///")
editor.set_editable(True)

def on_action(action):
  editor.execute_script(
    "document.execCommand('%s', false, false);" % action.get_name())

actions = gtk.ActionGroup("Actions")
actions.add_actions([
  ("bold", gtk.STOCK_BOLD, "_Bold", "<ctrl>B", None, on_action),
  ("italic", gtk.STOCK_ITALIC, "_Italic", "<ctrl>I", None, on_action),
  ("underline", gtk.STOCK_UNDERLINE, "_Underline", "<ctrl>U", None, on_action),
])

ui_def = """
<toolbar name="toolbar_format">
  <toolitem action="bold" />
  <toolitem action="italic" />
  <toolitem action="underline" />
</toolbar>
"""

ui = gtk.UIManager()
ui.insert_action_group(actions)
ui.add_ui_from_string(ui_def)

vb = gtk.VBox()
vb.pack_start(ui.get_widget("/toolbar_format"), False)
vb.pack_start(editor, True)

w.add(vb)
w.show_all()

gtk.main()

上面的例子是简单的测试编辑器,由 gtk webkit view 设计。

在 Ubuntu 10.04 中,编辑器可编辑且光标在 webkitview 上可见,但在 ubuntu 11.04 上切换后,编辑器不可编辑且光标不可见。

注意:我使用的是 Ubuntu 11.04 的经典 gnome(不是 unity)

可能是什么问题?我该如何解决这个问题?

任何帮助将不胜感激,

提前致谢!

here is code snippets:

import gtk, webkit, os

w = gtk.Window()
w.set_title("Example Editor")
w.connect("destroy", gtk.main_quit)
w.resize(500, 500)

editor = webkit.WebView()
editor.load_html_string("<p>This is a <b>test</b>", "file:///")
editor.set_editable(True)

def on_action(action):
  editor.execute_script(
    "document.execCommand('%s', false, false);" % action.get_name())

actions = gtk.ActionGroup("Actions")
actions.add_actions([
  ("bold", gtk.STOCK_BOLD, "_Bold", "<ctrl>B", None, on_action),
  ("italic", gtk.STOCK_ITALIC, "_Italic", "<ctrl>I", None, on_action),
  ("underline", gtk.STOCK_UNDERLINE, "_Underline", "<ctrl>U", None, on_action),
])

ui_def = """
<toolbar name="toolbar_format">
  <toolitem action="bold" />
  <toolitem action="italic" />
  <toolitem action="underline" />
</toolbar>
"""

ui = gtk.UIManager()
ui.insert_action_group(actions)
ui.add_ui_from_string(ui_def)

vb = gtk.VBox()
vb.pack_start(ui.get_widget("/toolbar_format"), False)
vb.pack_start(editor, True)

w.add(vb)
w.show_all()

gtk.main()

Above example is simple test editor, designed by gtk webkit view.

In Ubuntu 10.04, editor is editable and cursor is visible on webkitview but after switching on ubuntu 11.04, editor is not editable and cursor is not visible.

Note: I'm using classic gnome of Ubuntu 11.04 (not unity)

What could be the problem ? How could I solve this?

any help would be appreciable,

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷默言语 2024-12-14 06:20:07

我遇到了与上述相同的问题,但是我使用的是 Ubuntu 11.10 (Gnome3)

如果我将 content editable=true 属性添加到 p 标记,它会按预期工作。

self.editor.load_html_string("<p contenteditable=\"true\">This is a test", "file:///")

contenteditable=true 是继承的,因此所有子项都是可编辑的。

I have the same issue as described above, however I'm using Ubuntu 11.10 (Gnome3)

If I add the content editable=true attribute to the p tag, it works as expected.

self.editor.load_html_string("<p contenteditable=\"true\">This is a test", "file:///")

contenteditable=true is inherited, so all child are editable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文