def __init__(self, iface): """Constructor for the dialog. Args: iface: QgsInterface instance. """ QDialog.__init__(self, iface.mainWindow()) self.setupUi(self) # Settings Tab # Show the current value of client_id and client_secret client_id = settings.read('gmeconnector/CLIENT_ID') client_secret = settings.read('gmeconnector/CLIENT_SECRET') if client_id is None: client_id = '' if client_secret is None: client_secret = '' self.lineEdit1.setText(client_id) self.lineEdit2.setText(client_secret) # Other settings self.comboBoxProjects.setEnabled(False) self.checkBoxDefault.stateChanged.connect(self.comboBoxProjects.setEnabled) self.comboBoxFormat.addItem('JPEG', 'image/jpeg') self.comboBoxFormat.addItem('PNG', 'image/png') defaultFormat = settings.read('gmeconnector/WMS_IMAGE_FORMAT') if defaultFormat: defaultIndex = self.comboBoxFormat.findText(defaultFormat) if defaultIndex != -1: self.comboBoxFormat.setCurrentIndex(defaultIndex) self.comboBoxFormat.currentIndexChanged.connect(self.handleFormatChanged) # OAuth help oAuthPage = QWebPage() oAuthPage.setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.webViewOAuth.setPage(oAuthPage) # Load the oauth_help file helpFile = QFile(':/plugins/googlemapsengineconnector/oauth_help.html') helpFile.open(QIODevice.ReadOnly | QIODevice.Text) helpStr = QTextStream(helpFile) helpText = helpStr.readAll() self.webViewOAuth.setHtml(helpText) self.webViewOAuth.linkClicked.connect(self.handleWebLink) # About Tab aboutPage = QWebPage() aboutPage.setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.webViewAbout.setPage(aboutPage) # Load the about.html file and add current version info. aboutFile = QFile(':/plugins/googlemapsengineconnector/about.html') aboutFile.open(QIODevice.ReadOnly | QIODevice.Text) aboutStr = QTextStream(aboutFile) aboutText = aboutStr.readAll() newText = aboutText.format(version='1.0') self.webViewAbout.setHtml(newText) self.webViewAbout.linkClicked.connect(self.handleWebLink)
def webpageScreenshot(self, html): """Take a screenshot of a given html document and return it as a QImage.""" # see http://www.blogs.uni-osnabrueck.de/rotapken/2008/12/03/create-screenshots-of-a-web-page-using-python-and-qtwebkit/ size = self.size() # size = self.collectionView.page().viewportSize() # seems to be wrongly initialized sometimes... webpage = QWebPage() webpage.setLinkDelegationPolicy(QWebPage.DelegateAllLinks) webpage.setViewportSize(size) webpage.mainFrame().setHtml(html) # need to wait for the different elements to have loaded completely if sys.platform == "linux2": while QApplication.hasPendingEvents(): QApplication.processEvents() else: QApplication.processEvents() image = QImage(size, QImage.Format_ARGB32) painter = QPainter(image) webpage.mainFrame().render(painter) painter.end() return image