Geo Location in QWebView

216 Views Asked by At

I'm using pyqt4's QWebView to display html files, this way it works like an app switcher. One problem I've run into is not being able to grant access HTML5 Geo Location. I read in another question on the same topic that there need to be a signal with QWebPage unfortunately the code pertained to c++ so I'm not sure how to convert it to python as I'm new to pyqt4. So if the question is not clear; How do I get QWebView to allow HTML5 GeoLocation?

This is what I have so far

class HTML_handler(QtWebKit.QWebView):

def __init__(self):
    super(HTML_handler,self).__init__()
    self.initUI()
def initUI(self):
    page = webpage()


    page.mainFrame().setUrl(QtCore.QUrl("file:///home/dev/Documents/WebPages/weather.html"))
    self.setPage(page) 

    #self.load(QtCore.QUrl("file:///home/dev/Documents/WebPages/weather.html")) //method before introducing QWebPage
    self.setWindowFlags(QtCore.Qt.FramelessWindowHint) #| QtCore.Qt.WindowStaysOnTopHint)
    self.loadApps()

    self.show() #FullScreen()


class webpage(QtWebKit.QWebPage):

    trigger = QtCore.pyqtSignal(); //not used because can\'t figure how to

    def __init__(self):
       super(webpage,self).__init__()

    def featurePermissionRequested(self, *args, **kwargs): //QWebPage signal, not being used correctly though
        self.setFeaturePermission(QtWebKit.QWebPage.PermissionGrantedByUser)

EDIT: Or atleast show me how to convert this to python

class WebPage : public QWebPage
{
   Q_OBJECT

public:
    WebPage(QObject* parent = 0) :
        QWebPage(parent)
    {
        connect(this, SIGNAL(featurePermissionRequested(QWebFrame*, QWebPage::Feature)), SLOT(permissionRequested(QWebFrame*, QWebPage::Feature)));
    }

    virtual ~WebPage()
    {
    }

private slots:
    void permissionRequested(QWebFrame* frame, QWebPage::Feature feature)
    {
        setFeaturePermission(frame, feature, PermissionGrantedByUser);
    }
};
0

There are 0 best solutions below