In my code I have a GridLayout with rows of Button - TextInput. I also have a dictionary with keys representing indices and values storing CefBrowsers. Whenever a button is pressed, the GridLayout is restructured so that the button is replaced by the associated CefBrowser. Or if one hasn't been made yet, then a new browser is constructed and added to the dictionary.
Every browser made is stored in this Dictionary (as deleting/removing the browsers from the Grid doesn't seem to prevent them from running in the background. Ex: Audio continues to play) so whenever a certain button is pressed, each currently existing browser is supposed to change its URL to a "blank site."
For some reason, though, any calls to change the URL of any CefBrowser only changes the URL of the first created browser. Any ideas why? Or how I can change this?
Relevant Code:
def replaceButton(self, instance):
browserNumber = instance.getIndex()/2
try:
browser = self.activeBrowsers[browserNumber]
browser.change_url(instance.getURL())
except KeyError: #browser doesn't already exist
self.activeBrowsers[browserNumber] = CefBrowser(start_url=instance.getURL(), size_hint_x=1,
size_hint_y=None)
browser = self.activeBrowsers[browserNumber]
self.feed.replace(instance.getIndex(), browser)
def restartFeed(self):
self.feed.empty()
for browser in self.activeBrowsers.values():
print(browser)
browser.change_url('http://blank.org/')
self.readData()
I can imagine the replaceButton method not working because of a logical error, but I've checked the individual Browser objects in restartFeed, and although each one is unique, again, only the first one seems to change its URL.
EDIT: this was fixed in cefpython v31.
Unfortunately, this is a bug in CEFPython. You can only use one Browser
instance because certain methods (such as LoadUrl
and ExecuteJavascript
) always affect the first Browser
created. :(
https://code.google.com/p/cefpython/issues/detail?id=97
It looks like a fix has been found and is scheduled for the next release. You could try downloading and building CEFPython from source, applying the patch in that issue link if necessary.
A workaround for this is to create each Browser
with the correct starting URL, then destroy and recreate the Browser
to change the URL. But that's very inefficient.