Situation description: Python 3.7, GTK 3.0, PyGObjects 3.34.0 Webkit2 4.0
(情况说明:Python 3.7,GTK 3.0,PyGObjects 3.34.0 Webkit2 4.0)
I have a dialog window, with GtkNotebook containing 2 tabs.
(我有一个对话框窗口,其中包含2个标签的GtkNotebook。)
1. tab contains editable Webkit webview, the 2. tab contains textview. (1.选项卡包含可编辑的Webkit Web视图,2.选项卡包含textview。)
One of the arguments provided in class consrtructor is valid HTML snippet as string variable (类构造函数中提供的参数之一是有效的HTML代码段,它是字符串变量)
What I would like to get as a result, is that any changes made in any window, are automatically reflected in other.
(我想得到的结果是,在任何窗口中进行的任何更改都会自动反映在其他窗口中。)
Current problem: Using solution provided here , any previous changes that were made in webview are discarded upon switching the notepad tabs.
(当前问题:使用此处提供的解决方案,在切换记事本选项卡时,在webview中进行的任何先前更改都将被丢弃。)
Debugging shows that html obtained with aforementioned call, does not contain changes. (调试显示,通过上述调用获得的html不包含更改。)
Any ideas what might be missing in the logic or handling itself?
(任何想法在逻辑或处理本身中可能缺少什么?)
For reference, the code for the dialog is as follows:
(作为参考,对话框代码如下:)
# -*- coding: utf-8 -*-
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, WebKit2
class DescriptionDialog:
def __init__(self, *args):
# GTK Builder
self._builder = args[0]
self._builder.add_from_file("UI/GUI/description.glade")
self.dialog = self._builder.get_object("descriptionDialog")
self._textView = self._builder.get_object("textview1")
self.webViewContainer = self._builder.get_object("WebViewContainer")
self.browserHolder = WebKit2.WebView()
self.browserHolder.set_editable(True)
self.webViewContainer.add(self.browserHolder)
self.browserHolder.show()
# valid html snippet, held as string
self.__buffer_orig__ = args[2]
self.buffer = args[2]
self.browserHolder.load_html(self.buffer)
self._builder.connect_signals(
{
"onDialogClose": self.onDialogClose,
"pageChangeNotebook": self.onPageChange
})
self.dialog.set_transient_for(self._builder.get_object("MainWindow"))
self.textBuffer = self._builder.get_object("textbuffer1")
self.textBuffer.set_text(self.buffer)
self.dialog.show()
def onDialogClose(self, handler):
self.dialog.hide()
def onPageChange(self, notebook=None, scrolledWindow=None, pageNumber=0):
if pageNumber == 0:
self.buffer = self.textBuffer.get_text(self.textBuffer.get_start_iter(), self.textBuffer.get_end_iter(), True)
self.browserHolder.load_html(self.buffer)
if pageNumber == 1:
self.browserHolder.get_main_resource().get_data(None, self.getDataFromResource, None)
def getDataFromResource(self, resource, result, userData=None):
# Changed html is not returned here
self.buffer = str(resource.get_data_finish(result).decode("utf-8"))
self.textBuffer.set_text(self.buffer)
ask by Kristaps Livmanis translate from so