QWebView中的地理位置

时间:2014-05-21 20:09:15

标签: python-2.7 geolocation pyqt4 qwebview qwebpage

我正在使用pyqt4的QWebView来显示html文件,这样它就像一个应用程序切换器。我遇到的一个问题是无法授予访问HTML5地理位置。我在同一主题上读到了另一个问题,即QWebPage需要有一个信号,遗憾的是代码与c ++相关,所以我不知道如何将它转换为python,因为我是pyqt4的新手。所以,如果问题不明确;如何让QWebView允许HTML5 GeoLocation?

这是我到目前为止所拥有的

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)

编辑:或者至少告诉我如何将其转换为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 个答案:

没有答案