开发者

PyGTK - webkit.WebView not working with Ubuntu 11.04

开发者 https://www.devze.com 2023-04-09 04:12 出处:网络
here is code snippets: import gtk, webkit, os w = gtk.Window(开发者_运维技巧) w.set_title(\"Example Editor\")

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号