I created a page, where I pasted Web Browser component, so I connected to the page from perspective Module (for example ‘/main’).
In this ‘/main’ page I have the button and when I press this button the page opens in new tab.
In Vision the new tab opens in popup…
How should I set width and height parameters to this popup? It opens very-very small…
You’ll need to translate this Java code to Jython. Also, the underlying implementation is going to change from JxBrowser 6 to JxBrowser 7 in a future Ignition 8 release, which as the article mentions will change how this has to be done.
If you’re on 7.9.13 or .14, the web browser component has an initialize extension function that’s perfect for this.
Translating Java to Jython is actually pretty easy; mostly you just need to drop extra syntax; Python doesn’t type variables or parameters, nor require strict function signatures; although a tradeoff is the increased verbosity of not having anonymous classes. Something like this; untested, but should work:
from javax.swing import JFrame
from java.awt.event import WindowAdapter
from com.teamdev.jxbrowser.chromium.events import DisposeListener
from com.teamdev.jxbrowser.chromium.swing import BrowserView
from com.teamdev.jxbrowser.chromium import PopupContainer, PopupHandler
class MyWindowAdapter(WindowAdapter):
def windowClosing(self, e):
browser.dispose();
class MyDisposeListener(DisposeListener):
def __init__(self, frame):
self.frame = frame
def onDisposed(self, event):
self.frame.setVisible(False)
def invokedLater():
BrowserView browserView = BrowserView(browser)
browserView.setPreferredSize(initialBounds.getSize())
frame = JFrame("Popup")
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
frame.add(browserView, BorderLayout.CENTER)
frame.pack()
frame.setLocation(initialBounds.getLocation())
frame.setVisible(True)
frame.addWindowListener(MyWindowAdapter())
browser.addDisposeListener(MyDisposeListener(frame))
class MyPopupContainer(PopupContainer):
def insertBrowser(self, browser, initialBounds):
system.gui.invokeLater(invokedLater)
class MyPopupHandler(PopupHandler):
def handlePopup(self, params):
return MyPopupContainer()
browser.setPopupHandler(MyPopupHandler())
Okay, so you don’t have the initialize hook, which makes this slightly harder, but you can still run the same code. In propertyChange, put all the code behind an if event.propertyName == "componentRunning":, then change the browser on the last line to event.source.browser.
Blockquote
Traceback (most recent call last):
File "event:propertyChange", line 45, in
AttributeError: 'NoneType' object has no attribute 'setPopupHandler'
source.browser.setPopupHandler(MyPopupHandler()) also doesn't work...