How to set focus on embed object in QWebView

179 views Asked by At

I have a QWebView window that opens my local .html file.

This local .html file has an embed flash movie - .swf

It works nice, when I click on it, it gives me keyboard focus.

So, there's my problem, I want it to have focus right after launching my app, not how it behaves right now with this mouse click needed.

I tried modifying .html file with following:

<body onLoad="window.document.IP.focus();">

as mentioned in Adobe official solution

Besides that I tried:

<script>
window.onload = function() {
  var input = document.getElementById("IP").focus();
}
</script>

where "IP":

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=43,0,0,0" id="IP" width="1024" height="768" align="middle">
[...]
<embed src="IP.swf" quality="best" salign="lt" bgcolor="#ffffff" width="1024" height="768" swliveconnect="true" id="IP" name="IP" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer_pl">
</object>

Stackoverflow Q1

Stackoverflow Q2

Edit 1.

class PlayFlash(QWebView):
    def __init__(self):
        # QWebView
        self.view = QWebView.__init__(self)
        self.setWindowFlag(Qt.FramelessWindowHint)
        self.resize(1024, 768)
        self.move(0, 0)
        # enable flashplayer plugin
        self._settings = QWebSettings.globalSettings()
        self._settings.setAttribute(QWebSettings.PluginsEnabled, True)
        self.setFocusPolicy(Qt.StrongFocus)
        self.mouse = Controller()
        self.timer = QTimer()
        self.timer.setInterval(2000)
        self.timer.timeout.connect(self.focusOnFlash)
        self.timer.start()
        self.timer_count = 0
if __name__ == "__main__":
    # plugin path
    os.environ['QTWEBKIT_PLUGIN_PATH'] = os.path.abspath('/home/kamil/gitlab/PlayFlash')
    app = QApplication(sys.argv)
    view = PlayFlash()
    view.load("file:///home/kamil/gitlab/PlayFlash/PlayFlash.html")
    # view.load("https://pythonspot.com")
    view.show()
    view.setFocus()
    view.focusOnFlash()
    app.exec_()

I had to add a timer that executes simulated click to get focus on that swf embed in html. Without that it does not have focus.

0

There are 0 answers