Thu, 25 Oct 2018 20:06:44 +0200
Some fixes for configuration pages.
--- a/E5Network/E5GoogleMail.py Wed Oct 24 19:59:49 2018 +0200 +++ b/E5Network/E5GoogleMail.py Thu Oct 25 20:06:44 2018 +0200 @@ -24,6 +24,8 @@ from googleapiclient import discovery +from PyQt5.QtCore import QCoreApplication + import Globals @@ -32,6 +34,17 @@ APPLICATION_NAME = 'Eric Python Send Email' +def isCredentialsFileAvailable(): + """ + Module function to check, if the credentials file has been installed. + + @return flag indicating, that the credentials file is there + @rtype bool + """ + return os.path.exists( + os.path.join(Globals.getConfigDir(), CLIENT_SECRET_FILE)) + + def getCredentials(): """ Module function to get the Google credentials. @@ -64,6 +77,14 @@ @return tuple containing a success flag and a result or error message @rtype tuple of (bool, str) """ + # check for secrets file first + if not os.path.exists(os.path.join(Globals.getConfigDir(), + CLIENT_SECRET_FILE)): + return False, QCoreApplication.translate( + "GoogleMailSendMessage", + "The credentials file is not present. Has the Gmail API" + " been enabled?") + try: credentials = getCredentials() http = credentials.authorize(httplib2.Http())
--- a/Preferences/ConfigurationPages/EditorDocViewerPage.py Wed Oct 24 19:59:49 2018 +0200 +++ b/Preferences/ConfigurationPages/EditorDocViewerPage.py Thu Oct 25 20:06:44 2018 +0200 @@ -29,20 +29,31 @@ self.setupUi(self) self.setObjectName("EditorExportersPage") - providers = e5App().getObject("DocuViewer").getProviders() - for provider, text in providers: - self.providerComboBox.addItem(text, provider) - - # set initial values - self.parenthesisCheckBox.setChecked( - Preferences.getDocuViewer("ShowInfoOnOpenParenthesis")) - - provider = Preferences.getDocuViewer("Provider") - self.viewerGroupBox.setChecked(provider != "disabled") + try: + providers = e5App().getObject("DocuViewer").getProviders() + for provider, text in providers: + self.providerComboBox.addItem(text, provider) + + self.infoLabel.clear() + + # set initial values + self.parenthesisCheckBox.setChecked( + Preferences.getDocuViewer("ShowInfoOnOpenParenthesis")) - index = self.providerComboBox.findData(provider) - if index >= 0: - self.providerComboBox.setCurrentIndex(index) + provider = Preferences.getDocuViewer("Provider") + self.viewerGroupBox.setChecked(provider != "disabled") + + index = self.providerComboBox.findData(provider) + if index >= 0: + self.providerComboBox.setCurrentIndex(index) + except KeyError: + # documentation viewer is globally disabled + self.viewerGroupBox.setChecked(False) + self.viewerGroupBox.setEnabled(False) + self.infoLabel.setText(self.tr( + "The Documentation Viewer is disabled globally. Re-enable it" + " on the Interface/Interface configuration page and restart" + " the eric.")) def save(self): """
--- a/Preferences/ConfigurationPages/EditorDocViewerPage.ui Wed Oct 24 19:59:49 2018 +0200 +++ b/Preferences/ConfigurationPages/EditorDocViewerPage.ui Thu Oct 25 20:06:44 2018 +0200 @@ -84,6 +84,16 @@ </widget> </item> <item> + <widget class="QLabel" name="infoLabel"> + <property name="text"> + <string/> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum>
--- a/Preferences/ConfigurationPages/EmailPage.py Wed Oct 24 19:59:49 2018 +0200 +++ b/Preferences/ConfigurationPages/EmailPage.py Thu Oct 25 20:06:44 2018 +0200 @@ -36,6 +36,8 @@ self.setupUi(self) self.setObjectName("EmailPage") + self.__helpDialog = None + # set initial values try: import googleapiclient # __IGNORE_WARNING__ @@ -49,6 +51,17 @@ "<p>The Google Mail Client API is not installed." " Use <code>pip install --upgrade google-api-python-client" "</code> to install it.</p>")) + self.googleHelpButton.setEnabled(False) + Preferences.setUser("UseGoogleMailOAuth2", False) + + from E5Network.E5GoogleMail import isCredentialsFileAvailable + if not isCredentialsFileAvailable(): + # credentials file is not installed + self.googleMailCheckBox.setChecked(False) + self.googleMailCheckBox.setEnabled(False) + self.googleMailInfoLabel.setText(self.tr( + "<p>The credentials file is not present. Has the Gmail API" + " been enabled?</p>")) Preferences.setUser("UseGoogleMailOAuth2", False) self.mailServerEdit.setText(Preferences.getUser("MailServer")) @@ -259,6 +272,28 @@ self.tr("Login Test"), self.tr("""<p>The login test failed.<br>Reason: {0}</p>""") .format(errorStr)) + + @pyqtSlot() + def on_googleHelpButton_clicked(self): + """ + Private slot to show some help text "how to turn on the Gmail API". + """ + if self.__helpDialog is None: + try: + from E5Network.E5GoogleMail import GoogleMailHelp + helpStr = GoogleMailHelp() + except ImportError: + helpStr = self.tr( + "<p>The Google Mail Client API is not installed." + " Use <code>pip install --upgrade google-api-python-client" + "</code> to install it.</p>") + + from E5Gui.E5SimpleHelpDialog import E5SimpleHelpDialog + self.__helpDialog = E5SimpleHelpDialog( + title=self.tr("Gmail API Help"), + helpStr=helpStr, parent=self) + + self.__helpDialog.show() def create(dlg):
--- a/Preferences/ConfigurationPages/EmailPage.ui Wed Oct 24 19:59:49 2018 +0200 +++ b/Preferences/ConfigurationPages/EmailPage.ui Thu Oct 25 20:06:44 2018 +0200 @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>451</width> - <height>593</height> + <height>782</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_3"> @@ -54,6 +54,33 @@ </property> </widget> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="googleHelpButton"> + <property name="toolTip"> + <string>Press to get some help for enabling the Google Mail API</string> + </property> + <property name="text"> + <string>Google Mail API Help</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> </layout> </widget> </item>