title: Python, GTK, WebKit - Multiple instances of webview
body: <p>So I've recently begun learning Python, using python, gtk, and webkit to build a browser.</p>
  
  <p>I'm just having trouble with one thing.  For the most part I can figure these kinds of things out, but really having trouble with this one.</p>
  
  <p>I've got a button that adds a new tab.  It gives it it's own 'position' to identify itself for later on when I populate the websites title in the tab label.  Currently, the label defaults to the tab number.  I've got the following code to create the tab and a new instance of Gtk.ScrolledWindow inside of the tabs page, and then I try to add a WebKit WebView inside of the corresponding scrolled window, but it shoots out an error message.</p>
  
  <p>Code:</p>
  
  <pre><code>def on_addtab_clicked(self, widget):
      self.num = self.num + 1
      self.newtablabel = Gtk.Label(self.num)
      self.newpagelabel = Gtk.ScrolledWindow()
      self.notebook.insert_page(self.newpagelabel, self.newtablabel, self.num)
      self.scrolledwindow.add(self.webview)
      print self.notebook.get_current_page()
      print self.num
      self.get_pages()
      self.notebook.show_all()
      self.show_all()
  </code></pre>
  
  <p>Error:</p>
  
  <p>Gtk-WARNING **: Attempting to add a widget with type WebKitWebView to a container of type GtkScrolledWindow, but the widget is already inside a container of type GtkScrolledWindow, please use gtk_widget_reparent()</p>
  
  <p>Do I need to create an entirely new instance of WebKit here?  I'm definitely missing something.  Any help would be greatly appreciated.</p>
  
  <p>Pastebin if you'd like to see the entire code: <a href="http://pastebin.com/vXcLd1tT" rel="nofollow">http://pastebin.com/vXcLd1tT</a></p>
  
  <p>Video of the issue: <a href="https://www.youtube.com/watch?v=XhtJDrWr8t8&amp;feature=youtu.be" rel="nofollow">https://www.youtube.com/watch?v=XhtJDrWr8t8&amp;feature=youtu.be</a></p>
  
  <p>UPDATE:</p>
  
  <p>So I've updated the code to add a new webkit.webview to each new tab that is opened, and it works. You get a right click menu on every page, however, the address bar now won't function.  Is there a way to get the ID of the currently open webview (active one) and push the url request directly to that one?  Then when you switch to a new tab, the url will go to the correct page:</p>
  
  <pre><code>def on_addtab_clicked(self, widget):
      self.num = self.num + 1
      self.newtablabel = Gtk.Label(self.num)
      self.newpagelabel = Gtk.ScrolledWindow()
  self.newpagelabel.add(WebKit.WebView())
  WebKit.WebView().show()
      self.notebook.insert_page(self.newpagelabel, self.newtablabel, self.num)
      print self.notebook.get_current_page()
      print self.num
      self.get_pages()
      self.notebook.show_all()
      self.show_all()
  
  def on_urlentry_activate(self, widget):
      url = widget.get_text()
      if ' ' in url:
          url = 'https://www.google.ca/search?q=' + url
          self.urlentry.set_text(url)
      elif '.' not in url:
          url = 'https://www.google.ca/search?q=' + url
          self.urlentry.set_text(url)
      elif not url.startswith('http'):
          url = 'http://' + url
          self.urlentry.set_text(url)
  
      WebKit.WebView().open(url)
  </code></pre>