class OptionsDialog(QtGui.QDialog, Ui_OptionsDialogBase): """Options dialog for the InaSAFE plugin.""" def __init__(self, iface, dock=None, parent=None): """Constructor for the dialog. :param iface: A Quantum GIS QGisAppInterface instance. :type iface: QGisAppInterface :param parent: Parent widget of this dialog :type parent: QWidget :param dock: Optional dock widget instance that we can notify of changes to the keywords. :type dock: Dock """ QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version())) # Save reference to the QGIS interface and parent self.iface = iface self.parent = parent self.dock = dock self.keywordIO = KeywordIO() # Set up things for context help myButton = self.buttonBox.button(QtGui.QDialogButtonBox.Help) myButton.clicked.connect(self.show_help) self.grpNotImplemented.hide() self.adjustSize() self.restore_state() # hack prevent showing use thread visible and set it false see #557 self.cbxUseThread.setChecked(True) self.cbxUseThread.setVisible(False) def restore_state(self): """Reinstate the options based on the user's stored session info. """ mySettings = QtCore.QSettings() # myFlag = mySettings.value( # 'inasafe/useThreadingFlag', False) # hack set use thread to false see #557 myFlag = False self.cbxUseThread.setChecked(myFlag) myFlag = bool(mySettings.value( 'inasafe/visibleLayersOnlyFlag', True)) self.cbxVisibleLayersOnly.setChecked(myFlag) myFlag = bool(mySettings.value( 'inasafe/setLayerNameFromTitleFlag', True)) self.cbxSetLayerNameFromTitle.setChecked(myFlag) myFlag = bool(mySettings.value( 'inasafe/setZoomToImpactFlag', True)) self.cbxZoomToImpact.setChecked(myFlag) # whether exposure layer should be hidden after model completes myFlag = bool(mySettings.value( 'inasafe/setHideExposureFlag', False)) self.cbxHideExposure.setChecked(myFlag) myFlag = bool(mySettings.value( 'inasafe/clipToViewport', True)) self.cbxClipToViewport.setChecked(myFlag) myFlag = bool(mySettings.value( 'inasafe/clipHard', False)) self.cbxClipHard.setChecked(myFlag) myFlag = bool(mySettings.value( 'inasafe/useSentry', False)) self.cbxUseSentry.setChecked(myFlag) myFlag = bool(mySettings.value( 'inasafe/showIntermediateLayers', False)) self.cbxShowPostprocessingLayers.setChecked(myFlag) myRatio = float(mySettings.value( 'inasafe/defaultFemaleRatio', DEFAULTS['FEM_RATIO'])) self.dsbFemaleRatioDefault.setValue(myRatio) myPath = mySettings.value( 'inasafe/keywordCachePath', self.keywordIO.default_keyword_db_path()) self.leKeywordCachePath.setText(myPath) myFlag = bool(mySettings.value( 'inasafe/devMode', False)) self.cbxDevMode.setChecked(myFlag) myFlag = bool(mySettings.value( 'inasafe/useNativeZonalStats', False)) self.cbxNativeZonalStats.setChecked(myFlag) def save_state(self): """Store the options into the user's stored session info. """ mySettings = QtCore.QSettings() mySettings.setValue('inasafe/useThreadingFlag', False) mySettings.setValue('inasafe/visibleLayersOnlyFlag', self.cbxVisibleLayersOnly.isChecked()) mySettings.setValue('inasafe/setLayerNameFromTitleFlag', self.cbxSetLayerNameFromTitle.isChecked()) mySettings.setValue('inasafe/setZoomToImpactFlag', self.cbxZoomToImpact.isChecked()) mySettings.setValue('inasafe/setHideExposureFlag', self.cbxHideExposure.isChecked()) mySettings.setValue('inasafe/clipToViewport', self.cbxClipToViewport.isChecked()) mySettings.setValue('inasafe/clipHard', self.cbxClipHard.isChecked()) mySettings.setValue('inasafe/useSentry', self.cbxUseSentry.isChecked()) mySettings.setValue('inasafe/showIntermediateLayers', self.cbxShowPostprocessingLayers.isChecked()) mySettings.setValue('inasafe/defaultFemaleRatio', self.dsbFemaleRatioDefault.value()) mySettings.setValue('inasafe/keywordCachePath', self.leKeywordCachePath.text()) mySettings.setValue('inasafe/devMode', self.cbxDevMode.isChecked()) mySettings.setValue('inasafe/useNativeZonalStats', self.cbxNativeZonalStats.isChecked()) def show_help(self): """Show context help for the options dialog.""" show_context_help('options') def accept(self): """Method invoked when OK button is clicked.""" self.save_state() self.dock.read_settings() self.close() @pyqtSignature('') # prevents actions being handled twice def on_toolKeywordCachePath_clicked(self): """Auto-connect slot activated when cache file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker myFilename = QtGui.QFileDialog.getSaveFileName( self, self.tr('Set keyword cache file'), self.keywordIO.default_keyword_db_path(), self.tr('Sqlite DB File (*.db)')) self.leKeywordCachePath.setText(myFilename)
class OptionsDialog(QtGui.QDialog, Ui_OptionsDialogBase): """Options dialog for the InaSAFE plugin.""" def __init__(self, iface, dock=None, parent=None): """Constructor for the dialog. :param iface: A Quantum GIS QGisAppInterface instance. :type iface: QGisAppInterface :param parent: Parent widget of this dialog :type parent: QWidget :param dock: Optional dock widget instance that we can notify of changes to the keywords. :type dock: Dock """ QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version())) # Save reference to the QGIS interface and parent self.iface = iface self.parent = parent self.dock = dock self.keyword_io = KeywordIO() # Set up things for context help button = self.buttonBox.button(QtGui.QDialogButtonBox.Help) button.clicked.connect(self.show_help) self.grpNotImplemented.hide() self.adjustSize() self.restore_state() # hack prevent showing use thread visible and set it false see #557 self.cbxUseThread.setChecked(True) self.cbxUseThread.setVisible(False) def restore_state(self): """Reinstate the options based on the user's stored session info. """ settings = QtCore.QSettings() # flag = settings.value( # 'inasafe/useThreadingFlag', False) # hack set use thread to false see #557 flag = False self.cbxUseThread.setChecked(flag) flag = bool(settings.value( 'inasafe/visibleLayersOnlyFlag', True, type=bool)) self.cbxVisibleLayersOnly.setChecked(flag) flag = bool(settings.value( 'inasafe/set_layer_from_title_flag', True, type=bool)) self.cbxSetLayerNameFromTitle.setChecked(flag) flag = bool(settings.value( 'inasafe/setZoomToImpactFlag', True, type=bool)) self.cbxZoomToImpact.setChecked(flag) # whether exposure layer should be hidden after model completes flag = bool(settings.value( 'inasafe/setHideExposureFlag', False, type=bool)) self.cbxHideExposure.setChecked(flag) flag = bool(settings.value( 'inasafe/clip_to_viewport', True, type=bool)) self.cbxClipToViewport.setChecked(flag) flag = bool(settings.value( 'inasafe/clip_hard', False, type=bool)) self.cbxClipHard.setChecked(flag) flag = bool(settings.value( 'inasafe/useSentry', False, type=bool)) self.cbxUseSentry.setChecked(flag) flag = bool(settings.value( 'inasafe/show_intermediate_layers', False, type=bool)) self.cbxShowPostprocessingLayers.setChecked(flag) ratio = float(settings.value( 'inasafe/defaultFemaleRatio', DEFAULTS['FEM_RATIO'], type=float)) self.dsbFemaleRatioDefault.setValue(ratio) path = settings.value( 'inasafe/keywordCachePath', self.keyword_io.default_keyword_db_path(), type=str) self.leKeywordCachePath.setText(path) path = settings.value('inasafe/northArrowPath', '', type=str) self.leNorthArrowPath.setText(path) path = settings.value( 'inasafe/organisationLogoPath', ':/plugins/inasafe/bnpb_logo_64.png', type=str) self.leOrganisationLogoPath.setText(path) flag = bool(settings.value( 'inasafe/showOrganisationLogoInDockFlag', True, type=bool)) self.organisation_on_dock_checkbox.setChecked(flag) path = settings.value('inasafe/reportTemplatePath', '', type=str) self.leReportTemplatePath.setText(path) disclaimer = settings.value('inasafe/reportDisclaimer', '', type=str) self.txtDisclaimer.setPlainText(disclaimer) flag = bool( settings.value('inasafe/developer_mode', False, type=bool)) self.cbxDevMode.setChecked(flag) flag = bool( settings.value('inasafe/use_native_zonal_stats', False, type=bool)) self.cbxNativeZonalStats.setChecked(flag) def save_state(self): """Store the options into the user's stored session info. """ settings = QtCore.QSettings() settings.setValue( 'inasafe/useThreadingFlag', False) settings.setValue( 'inasafe/visibleLayersOnlyFlag', self.cbxVisibleLayersOnly.isChecked()) settings.setValue( 'inasafe/set_layer_from_title_flag', self.cbxSetLayerNameFromTitle.isChecked()) settings.setValue( 'inasafe/setZoomToImpactFlag', self.cbxZoomToImpact.isChecked()) settings.setValue( 'inasafe/setHideExposureFlag', self.cbxHideExposure.isChecked()) settings.setValue( 'inasafe/clip_to_viewport', self.cbxClipToViewport.isChecked()) settings.setValue( 'inasafe/clip_hard', self.cbxClipHard.isChecked()) settings.setValue( 'inasafe/useSentry', self.cbxUseSentry.isChecked()) settings.setValue( 'inasafe/show_intermediate_layers', self.cbxShowPostprocessingLayers.isChecked()) settings.setValue( 'inasafe/defaultFemaleRatio', self.dsbFemaleRatioDefault.value()) settings.setValue( 'inasafe/keywordCachePath', self.leKeywordCachePath.text()) settings.setValue( 'inasafe/northArrowPath', self.leNorthArrowPath.text()) settings.setValue( 'inasafe/organisationLogoPath', self.leOrganisationLogoPath.text()) settings.setValue( 'inasafe/showOrganisationLogoInDockFlag', self.organisation_on_dock_checkbox.isChecked()) settings.setValue( 'inasafe/reportTemplatePath', self.leReportTemplatePath.text()) settings.setValue( 'inasafe/reportDisclaimer', self.txtDisclaimer.toPlainText()) settings.setValue( 'inasafe/developer_mode', self.cbxDevMode.isChecked()) settings.setValue( 'inasafe/use_native_zonal_stats', self.cbxNativeZonalStats.isChecked()) @staticmethod def show_help(): """Show context help for the options dialog.""" show_context_help('options') def accept(self): """Method invoked when OK button is clicked.""" self.save_state() self.dock.read_settings() self.close() @pyqtSignature('') # prevents actions being handled twice def on_toolKeywordCachePath_clicked(self): """Auto-connect slot activated when cache file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getSaveFileName( self, self.tr('Set keyword cache file'), self.keyword_io.default_keyword_db_path(), self.tr('Sqlite DB File (*.db)')) self.leKeywordCachePath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolNorthArrowPath_clicked(self): """Auto-connect slot activated when north arrow tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getOpenFileName( self, self.tr('Set north arrow image file'), '', self.tr('Portable Network Graphics files (*.png *.PNG)')) self.leNorthArrowPath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolOrganisationLogoPath_clicked(self): """Auto-connect slot activated when logo file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getOpenFileName( self, self.tr('Set organisation logo file'), '', self.tr('Portable Network Graphics files (*.png *.PNG)')) self.leOrganisationLogoPath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolReportTemplatePath_clicked(self): """Auto-connect slot activated when report file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker dir_name = QtGui.QFileDialog.getExistingDirectory( self, self.tr('Templates directory'), '', QtGui.QFileDialog.ShowDirsOnly) self.leReportTemplatePath.setText(dir_name)
class OptionsDialog(QtGui.QDialog, Ui_OptionsDialogBase): """Options dialog for the InaSAFE plugin.""" def __init__(self, iface, dock=None, parent=None): """Constructor for the dialog. :param iface: A Quantum GIS QGisAppInterface instance. :type iface: QGisAppInterface :param parent: Parent widget of this dialog :type parent: QWidget :param dock: Optional dock widget instance that we can notify of changes to the keywords. :type dock: Dock """ QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version())) # Save reference to the QGIS interface and parent self.iface = iface self.parent = parent self.dock = dock self.keyword_io = KeywordIO() self.defaults = get_defaults() # Set up things for context help button = self.buttonBox.button(QtGui.QDialogButtonBox.Help) button.clicked.connect(self.show_help) self.grpNotImplemented.hide() self.adjustSize() self.restore_state() # hack prevent showing use thread visible and set it false see #557 self.cbxUseThread.setChecked(True) self.cbxUseThread.setVisible(False) # Set up listener for various UI self.custom_org_logo_checkbox.toggled.connect( self.set_organisation_logo) self.custom_north_arrow_checkbox.toggled.connect(self.set_north_arrow) self.custom_templates_dir_checkbox.toggled.connect( self.set_templates_dir) self.custom_org_disclaimer_checkbox.toggled.connect( self.set_org_disclaimer) def restore_state(self): """Reinstate the options based on the user's stored session info. """ settings = QtCore.QSettings() # flag = settings.value( # 'inasafe/useThreadingFlag', False) # hack set use thread to false see #557 flag = False self.cbxUseThread.setChecked(flag) flag = bool(settings.value( 'inasafe/visibleLayersOnlyFlag', True, type=bool)) self.cbxVisibleLayersOnly.setChecked(flag) flag = bool(settings.value( 'inasafe/set_layer_from_title_flag', True, type=bool)) self.cbxSetLayerNameFromTitle.setChecked(flag) flag = bool(settings.value( 'inasafe/setZoomToImpactFlag', True, type=bool)) self.cbxZoomToImpact.setChecked(flag) # whether exposure layer should be hidden after model completes flag = bool(settings.value( 'inasafe/setHideExposureFlag', False, type=bool)) self.cbxHideExposure.setChecked(flag) flag = bool(settings.value( 'inasafe/clip_to_viewport', True, type=bool)) self.cbxClipToViewport.setChecked(flag) flag = bool(settings.value( 'inasafe/clip_hard', False, type=bool)) self.cbxClipHard.setChecked(flag) flag = bool(settings.value( 'inasafe/useSentry', False, type=bool)) self.cbxUseSentry.setChecked(flag) flag = bool(settings.value( 'inasafe/show_intermediate_layers', False, type=bool)) self.cbxShowPostprocessingLayers.setChecked(flag) ratio = self.defaults['FEMALE_RATIO'] self.dsbFemaleRatioDefault.setValue(ratio) path = settings.value( 'inasafe/keywordCachePath', self.keyword_io.default_keyword_db_path(), type=str) self.leKeywordCachePath.setText(path) flag = bool(settings.value( 'inasafe/template_warning_verbose', True, type=bool)) self.template_warning_checkbox.setChecked(flag) # Restore Organisation Logo Path org_logo_path = settings.value( 'inasafe/organisation_logo_path', default_organisation_logo_path(), type=str) custom_org_logo_flag = ( org_logo_path != default_organisation_logo_path()) self.custom_org_logo_checkbox.setChecked(custom_org_logo_flag) self.leOrganisationLogoPath.setText(org_logo_path) # Restore Show Organisation Logo in Dock Flag flag = bool(settings.value( 'inasafe/showOrganisationLogoInDockFlag', True, type=bool)) self.organisation_on_dock_checkbox.setChecked(flag) # Restore North Arrow Image Path north_arrow_path = settings.value( 'inasafe/north_arrow_path', default_north_arrow_path(), type=str) custom_north_arrow_flag = ( north_arrow_path != default_north_arrow_path()) self.custom_north_arrow_checkbox.setChecked(custom_north_arrow_flag) self.leNorthArrowPath.setText(north_arrow_path) # Restore Report Template Directory Path report_template_dir = settings.value( 'inasafe/reportTemplatePath', '', type=str) custom_templates_dir_flag = (report_template_dir != '') self.custom_templates_dir_checkbox.setChecked( custom_templates_dir_flag) self.leReportTemplatePath.setText(report_template_dir) # Restore Disclaimer org_disclaimer = settings.value( 'inasafe/reportDisclaimer', disclaimer(), type=str) custom_org_disclaimer_flag = (org_disclaimer != disclaimer()) self.custom_org_disclaimer_checkbox.setChecked( custom_org_disclaimer_flag) self.txtDisclaimer.setPlainText(org_disclaimer) flag = bool( settings.value('inasafe/developer_mode', False, type=bool)) self.cbxDevMode.setChecked(flag) flag = bool( settings.value('inasafe/use_native_zonal_stats', False, type=bool)) self.cbxNativeZonalStats.setChecked(flag) # Restore ISO19115 metadata tab value = self.defaults['ISO19115_ORGANIZATION'] self.iso19115_organization_le.setText(value) value = self.defaults['ISO19115_URL'] self.iso19115_url_le.setText(value) value = self.defaults['ISO19115_EMAIL'] self.iso19115_email_le.setText(value) value = self.defaults['ISO19115_TITLE'] self.iso19115_title_le.setText(value) value = self.defaults['ISO19115_LICENSE'] self.iso19115_license_le.setText(value) def save_state(self): """Store the options into the user's stored session info. """ settings = QtCore.QSettings() settings.setValue( 'inasafe/useThreadingFlag', False) settings.setValue( 'inasafe/visibleLayersOnlyFlag', self.cbxVisibleLayersOnly.isChecked()) settings.setValue( 'inasafe/set_layer_from_title_flag', self.cbxSetLayerNameFromTitle.isChecked()) settings.setValue( 'inasafe/setZoomToImpactFlag', self.cbxZoomToImpact.isChecked()) settings.setValue( 'inasafe/setHideExposureFlag', self.cbxHideExposure.isChecked()) settings.setValue( 'inasafe/clip_to_viewport', self.cbxClipToViewport.isChecked()) settings.setValue( 'inasafe/clip_hard', self.cbxClipHard.isChecked()) settings.setValue( 'inasafe/useSentry', self.cbxUseSentry.isChecked()) settings.setValue( 'inasafe/show_intermediate_layers', self.cbxShowPostprocessingLayers.isChecked()) settings.setValue( 'inasafe/defaultFemaleRatio', self.dsbFemaleRatioDefault.value()) settings.setValue( 'inasafe/keywordCachePath', self.leKeywordCachePath.text()) settings.setValue( 'inasafe/template_warning_verbose', self.template_warning_checkbox.isChecked()) settings.setValue( 'inasafe/north_arrow_path', self.leNorthArrowPath.text()) settings.setValue( 'inasafe/organisation_logo_path', self.leOrganisationLogoPath.text()) settings.setValue( 'inasafe/showOrganisationLogoInDockFlag', self.organisation_on_dock_checkbox.isChecked()) settings.setValue( 'inasafe/reportTemplatePath', self.leReportTemplatePath.text()) settings.setValue( 'inasafe/reportDisclaimer', self.txtDisclaimer.toPlainText()) settings.setValue( 'inasafe/developer_mode', self.cbxDevMode.isChecked()) settings.setValue( 'inasafe/use_native_zonal_stats', self.cbxNativeZonalStats.isChecked()) # save metadata values settings.setValue( 'inasafe/ISO19115_ORGANIZATION', self.iso19115_organization_le.text()) settings.setValue( 'inasafe/ISO19115_URL', self.iso19115_url_le.text()) settings.setValue( 'inasafe/ISO19115_EMAIL', self.iso19115_email_le.text()) settings.setValue( 'inasafe/ISO19115_TITLE', self.iso19115_title_le.text()) settings.setValue( 'inasafe/ISO19115_LICENSE', self.iso19115_license_le.text()) @staticmethod def show_help(): """Show context help for the options dialog.""" show_context_help('options') def accept(self): """Method invoked when OK button is clicked.""" self.save_state() self.dock.read_settings() self.close() @pyqtSignature('') # prevents actions being handled twice def on_toolKeywordCachePath_clicked(self): """Auto-connect slot activated when cache file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getSaveFileName( self, self.tr('Set keyword cache file'), self.keyword_io.default_keyword_db_path(), self.tr('Sqlite DB File (*.db)')) self.leKeywordCachePath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolNorthArrowPath_clicked(self): """Auto-connect slot activated when north arrow tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getOpenFileName( self, self.tr('Set north arrow image file'), '', self.tr('Portable Network Graphics files (*.png *.PNG)')) if file_name != '': self.leNorthArrowPath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolOrganisationLogoPath_clicked(self): """Auto-connect slot activated when logo file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getOpenFileName( self, self.tr('Set organisation logo file'), '', self.tr('Portable Network Graphics files (*.png *.PNG)')) if file_name != '': self.leOrganisationLogoPath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolReportTemplatePath_clicked(self): """Auto-connect slot activated when report file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker dir_name = QtGui.QFileDialog.getExistingDirectory( self, self.tr('Templates directory'), '', QtGui.QFileDialog.ShowDirsOnly) self.leReportTemplatePath.setText(dir_name) def set_organisation_logo(self): """Auto-connect slot activated when org logo checkbox is toggled.""" settings = QtCore.QSettings() if self.custom_org_logo_checkbox.isChecked(): # Use previous org logo path path = settings.value( 'inasafe/organisation_logo_path', default_organisation_logo_path(), type=str) else: # Set organisation path line edit to default one path = default_organisation_logo_path() self.leOrganisationLogoPath.setText(path) def set_north_arrow(self): """Auto-connect slot activated when north arrow checkbox is toggled.""" settings = QtCore.QSettings() if self.custom_north_arrow_checkbox.isChecked(): # Show previous north arrow path path = settings.value( 'inasafe/north_arrow_path', default_north_arrow_path(), type=str) else: # Set the north arrow line edit to default one path = default_north_arrow_path() self.leNorthArrowPath.setText(path) def set_templates_dir(self): """Auto-connect slot activated when templates dir checkbox is toggled. """ settings = QtCore.QSettings() if self.custom_templates_dir_checkbox.isChecked(): # Show previous templates dir path = settings.value( 'inasafe/reportTemplatePath', '', type=str) else: # Set the template report dir to '' path = '' self.leReportTemplatePath.setText(path) def set_org_disclaimer(self): """Auto-connect slot activated when org disclaimer checkbox is toggled. """ settings = QtCore.QSettings() if self.custom_org_disclaimer_checkbox.isChecked(): # Show previous organisation disclaimer org_disclaimer = settings.value( 'inasafe/reportDisclaimer', disclaimer(), type=str) else: # Set the organisation disclaimer to the default one org_disclaimer = disclaimer() self.txtDisclaimer.setPlainText(org_disclaimer)
class OptionsDialog(QtGui.QDialog, Ui_OptionsDialogBase): """Options dialog for the InaSAFE plugin.""" def __init__(self, iface, dock=None, parent=None): """Constructor for the dialog. :param iface: A Quantum GIS QGisAppInterface instance. :type iface: QGisAppInterface :param parent: Parent widget of this dialog :type parent: QWidget :param dock: Optional dock widget instance that we can notify of changes to the keywords. :type dock: Dock """ QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version())) # Save reference to the QGIS interface and parent self.iface = iface self.parent = parent self.dock = dock self.helpDialog = None self.keywordIO = KeywordIO() # Set up things for context help myButton = self.buttonBox.button(QtGui.QDialogButtonBox.Help) QtCore.QObject.connect(myButton, QtCore.SIGNAL('clicked()'), self.show_help) self.grpNotImplemented.hide() self.adjustSize() self.restore_state() # hack prevent showing use thread visible and set it false see #557 self.cbxUseThread.setChecked(True) self.cbxUseThread.setVisible(False) def restore_state(self): """Reinstate the options based on the user's stored session info. """ mySettings = QtCore.QSettings() # myFlag = mySettings.value( # 'inasafe/useThreadingFlag', False).toBool() # hack set use thread to false see #557 myFlag = False self.cbxUseThread.setChecked(myFlag) myFlag = mySettings.value('inasafe/visibleLayersOnlyFlag', True).toBool() self.cbxVisibleLayersOnly.setChecked(myFlag) myFlag = mySettings.value('inasafe/setLayerNameFromTitleFlag', True).toBool() self.cbxSetLayerNameFromTitle.setChecked(myFlag) myFlag = mySettings.value('inasafe/setZoomToImpactFlag', True).toBool() self.cbxZoomToImpact.setChecked(myFlag) # whether exposure layer should be hidden after model completes myFlag = mySettings.value('inasafe/setHideExposureFlag', False).toBool() self.cbxHideExposure.setChecked(myFlag) myFlag = mySettings.value('inasafe/clipToViewport', True).toBool() self.cbxClipToViewport.setChecked(myFlag) myFlag = mySettings.value('inasafe/clipHard', False).toBool() self.cbxClipHard.setChecked(myFlag) myFlag = mySettings.value('inasafe/useSentry', False).toBool() self.cbxUseSentry.setChecked(myFlag) myFlag = mySettings.value('inasafe/showIntermediateLayers', False).toBool() self.cbxShowPostprocessingLayers.setChecked(myFlag) myRatio = mySettings.value('inasafe/defaultFemaleRatio', DEFAULTS['FEM_RATIO']).toDouble() self.dsbFemaleRatioDefault.setValue(myRatio[0]) myPath = mySettings.value( 'inasafe/keywordCachePath', self.keywordIO.default_keyword_db_path()).toString() self.leKeywordCachePath.setText(myPath) myFlag = mySettings.value('inasafe/devMode', False).toBool() self.cbxDevMode.setChecked(myFlag) def save_state(self): """Store the options into the user's stored session info. """ mySettings = QtCore.QSettings() mySettings.setValue('inasafe/useThreadingFlag', False) mySettings.setValue('inasafe/visibleLayersOnlyFlag', self.cbxVisibleLayersOnly.isChecked()) mySettings.setValue('inasafe/setLayerNameFromTitleFlag', self.cbxSetLayerNameFromTitle.isChecked()) mySettings.setValue('inasafe/setZoomToImpactFlag', self.cbxZoomToImpact.isChecked()) mySettings.setValue('inasafe/setHideExposureFlag', self.cbxHideExposure.isChecked()) mySettings.setValue('inasafe/clipToViewport', self.cbxClipToViewport.isChecked()) mySettings.setValue('inasafe/clipHard', self.cbxClipHard.isChecked()) mySettings.setValue('inasafe/useSentry', self.cbxUseSentry.isChecked()) mySettings.setValue('inasafe/showIntermediateLayers', self.cbxShowPostprocessingLayers.isChecked()) mySettings.setValue('inasafe/defaultFemaleRatio', self.dsbFemaleRatioDefault.value()) mySettings.setValue('inasafe/keywordCachePath', self.leKeywordCachePath.text()) mySettings.setValue('inasafe/devMode', self.cbxDevMode.isChecked()) def show_help(self): """Show context help for the options dialog.""" show_context_help('options') def accept(self): """Method invoked when OK button is clicked.""" self.save_state() self.dock.read_settings() self.close() @pyqtSignature('') # prevents actions being handled twice def on_toolKeywordCachePath_clicked(self): """Auto-connect slot activated when cache file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker myFilename = QtGui.QFileDialog.getSaveFileName( self, self.tr('Set keyword cache file'), self.keywordIO.default_keyword_db_path(), self.tr('Sqlite DB File (*.db)')) self.leKeywordCachePath.setText(myFilename)
class OptionsDialog(QtGui.QDialog, Ui_OptionsDialogBase): """Options dialog for the InaSAFE plugin.""" def __init__(self, iface, dock=None, parent=None): """Constructor for the dialog. :param iface: A Quantum GIS QGisAppInterface instance. :type iface: QGisAppInterface :param parent: Parent widget of this dialog :type parent: QWidget :param dock: Optional dock widget instance that we can notify of changes to the keywords. :type dock: Dock """ QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version())) # Save reference to the QGIS interface and parent self.iface = iface self.parent = parent self.dock = dock self.keyword_io = KeywordIO() self.defaults = get_defaults() # Set up things for context help button = self.buttonBox.button(QtGui.QDialogButtonBox.Help) button.clicked.connect(self.show_help) self.grpNotImplemented.hide() self.adjustSize() self.restore_state() # hack prevent showing use thread visible and set it false see #557 self.cbxUseThread.setChecked(True) self.cbxUseThread.setVisible(False) # Set up listener for various UI self.custom_org_logo_checkbox.toggled.connect( self.set_organisation_logo) self.custom_north_arrow_checkbox.toggled.connect(self.set_north_arrow) self.custom_templates_dir_checkbox.toggled.connect( self.set_templates_dir) self.custom_org_disclaimer_checkbox.toggled.connect( self.set_org_disclaimer) def restore_state(self): """Reinstate the options based on the user's stored session info. """ settings = QtCore.QSettings() # flag = settings.value( # 'inasafe/useThreadingFlag', False) # hack set use thread to false see #557 flag = False self.cbxUseThread.setChecked(flag) flag = bool( settings.value('inasafe/visibleLayersOnlyFlag', True, type=bool)) self.cbxVisibleLayersOnly.setChecked(flag) flag = bool( settings.value('inasafe/set_layer_from_title_flag', True, type=bool)) self.cbxSetLayerNameFromTitle.setChecked(flag) flag = bool( settings.value('inasafe/setZoomToImpactFlag', True, type=bool)) self.cbxZoomToImpact.setChecked(flag) # whether exposure layer should be hidden after model completes flag = bool( settings.value('inasafe/setHideExposureFlag', False, type=bool)) self.cbxHideExposure.setChecked(flag) flag = bool(settings.value('inasafe/clip_to_viewport', True, type=bool)) self.cbxClipToViewport.setChecked(flag) flag = bool(settings.value('inasafe/clip_hard', False, type=bool)) self.cbxClipHard.setChecked(flag) flag = bool(settings.value('inasafe/useSentry', False, type=bool)) self.cbxUseSentry.setChecked(flag) flag = bool( settings.value('inasafe/show_intermediate_layers', False, type=bool)) self.cbxShowPostprocessingLayers.setChecked(flag) ratio = self.defaults['FEMALE_RATIO'] self.dsbFemaleRatioDefault.setValue(ratio) path = settings.value('inasafe/keywordCachePath', self.keyword_io.default_keyword_db_path(), type=str) self.leKeywordCachePath.setText(path) flag = bool( settings.value('inasafe/template_warning_verbose', True, type=bool)) self.template_warning_checkbox.setChecked(flag) # Restore Organisation Logo Path org_logo_path = settings.value('inasafe/organisation_logo_path', default_organisation_logo_path(), type=str) custom_org_logo_flag = (org_logo_path != default_organisation_logo_path()) self.custom_org_logo_checkbox.setChecked(custom_org_logo_flag) self.leOrganisationLogoPath.setText(org_logo_path) # Restore Show Organisation Logo in Dock Flag flag = bool( settings.value('inasafe/showOrganisationLogoInDockFlag', True, type=bool)) self.organisation_on_dock_checkbox.setChecked(flag) # Restore North Arrow Image Path north_arrow_path = settings.value('inasafe/north_arrow_path', default_north_arrow_path(), type=str) custom_north_arrow_flag = (north_arrow_path != default_north_arrow_path()) self.custom_north_arrow_checkbox.setChecked(custom_north_arrow_flag) self.leNorthArrowPath.setText(north_arrow_path) # Restore Report Template Directory Path report_template_dir = settings.value('inasafe/reportTemplatePath', '', type=str) custom_templates_dir_flag = (report_template_dir != '') self.custom_templates_dir_checkbox.setChecked( custom_templates_dir_flag) self.leReportTemplatePath.setText(report_template_dir) # Restore Disclaimer org_disclaimer = settings.value('inasafe/reportDisclaimer', disclaimer(), type=str) custom_org_disclaimer_flag = (org_disclaimer != disclaimer()) self.custom_org_disclaimer_checkbox.setChecked( custom_org_disclaimer_flag) self.txtDisclaimer.setPlainText(org_disclaimer) flag = bool(settings.value('inasafe/developer_mode', False, type=bool)) self.cbxDevMode.setChecked(flag) flag = bool( settings.value('inasafe/use_native_zonal_stats', False, type=bool)) self.cbxNativeZonalStats.setChecked(flag) # Restore ISO19115 metadata tab value = self.defaults['ISO19115_ORGANIZATION'] self.iso19115_organization_le.setText(value) value = self.defaults['ISO19115_URL'] self.iso19115_url_le.setText(value) value = self.defaults['ISO19115_EMAIL'] self.iso19115_email_le.setText(value) value = self.defaults['ISO19115_TITLE'] self.iso19115_title_le.setText(value) value = self.defaults['ISO19115_LICENSE'] self.iso19115_license_le.setText(value) def save_state(self): """Store the options into the user's stored session info. """ settings = QtCore.QSettings() settings.setValue('inasafe/useThreadingFlag', False) settings.setValue('inasafe/visibleLayersOnlyFlag', self.cbxVisibleLayersOnly.isChecked()) settings.setValue('inasafe/set_layer_from_title_flag', self.cbxSetLayerNameFromTitle.isChecked()) settings.setValue('inasafe/setZoomToImpactFlag', self.cbxZoomToImpact.isChecked()) settings.setValue('inasafe/setHideExposureFlag', self.cbxHideExposure.isChecked()) settings.setValue('inasafe/clip_to_viewport', self.cbxClipToViewport.isChecked()) settings.setValue('inasafe/clip_hard', self.cbxClipHard.isChecked()) settings.setValue('inasafe/useSentry', self.cbxUseSentry.isChecked()) settings.setValue('inasafe/show_intermediate_layers', self.cbxShowPostprocessingLayers.isChecked()) settings.setValue('inasafe/defaultFemaleRatio', self.dsbFemaleRatioDefault.value()) settings.setValue('inasafe/keywordCachePath', self.leKeywordCachePath.text()) settings.setValue('inasafe/template_warning_verbose', self.template_warning_checkbox.isChecked()) settings.setValue('inasafe/north_arrow_path', self.leNorthArrowPath.text()) settings.setValue('inasafe/organisation_logo_path', self.leOrganisationLogoPath.text()) settings.setValue('inasafe/showOrganisationLogoInDockFlag', self.organisation_on_dock_checkbox.isChecked()) settings.setValue('inasafe/reportTemplatePath', self.leReportTemplatePath.text()) settings.setValue('inasafe/reportDisclaimer', self.txtDisclaimer.toPlainText()) settings.setValue('inasafe/developer_mode', self.cbxDevMode.isChecked()) settings.setValue('inasafe/use_native_zonal_stats', self.cbxNativeZonalStats.isChecked()) # save metadata values settings.setValue('inasafe/ISO19115_ORGANIZATION', self.iso19115_organization_le.text()) settings.setValue('inasafe/ISO19115_URL', self.iso19115_url_le.text()) settings.setValue('inasafe/ISO19115_EMAIL', self.iso19115_email_le.text()) settings.setValue('inasafe/ISO19115_TITLE', self.iso19115_title_le.text()) settings.setValue('inasafe/ISO19115_LICENSE', self.iso19115_license_le.text()) @staticmethod def show_help(): """Show context help for the options dialog.""" show_context_help('options') def accept(self): """Method invoked when OK button is clicked.""" self.save_state() self.dock.read_settings() self.close() @pyqtSignature('') # prevents actions being handled twice def on_toolKeywordCachePath_clicked(self): """Auto-connect slot activated when cache file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getSaveFileName( self, self.tr('Set keyword cache file'), self.keyword_io.default_keyword_db_path(), self.tr('Sqlite DB File (*.db)')) self.leKeywordCachePath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolNorthArrowPath_clicked(self): """Auto-connect slot activated when north arrow tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getOpenFileName( self, self.tr('Set north arrow image file'), '', self.tr('Portable Network Graphics files (*.png *.PNG)')) if file_name != '': self.leNorthArrowPath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolOrganisationLogoPath_clicked(self): """Auto-connect slot activated when logo file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getOpenFileName( self, self.tr('Set organisation logo file'), '', self.tr('Portable Network Graphics files (*.png *.PNG)')) if file_name != '': self.leOrganisationLogoPath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolReportTemplatePath_clicked(self): """Auto-connect slot activated when report file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker dir_name = QtGui.QFileDialog.getExistingDirectory( self, self.tr('Templates directory'), '', QtGui.QFileDialog.ShowDirsOnly) self.leReportTemplatePath.setText(dir_name) def set_organisation_logo(self): """Auto-connect slot activated when org logo checkbox is toggled.""" settings = QtCore.QSettings() if self.custom_org_logo_checkbox.isChecked(): # Use previous org logo path path = settings.value('inasafe/organisation_logo_path', default_organisation_logo_path(), type=str) else: # Set organisation path line edit to default one path = default_organisation_logo_path() self.leOrganisationLogoPath.setText(path) def set_north_arrow(self): """Auto-connect slot activated when north arrow checkbox is toggled.""" settings = QtCore.QSettings() if self.custom_north_arrow_checkbox.isChecked(): # Show previous north arrow path path = settings.value('inasafe/north_arrow_path', default_north_arrow_path(), type=str) else: # Set the north arrow line edit to default one path = default_north_arrow_path() self.leNorthArrowPath.setText(path) def set_templates_dir(self): """Auto-connect slot activated when templates dir checkbox is toggled. """ settings = QtCore.QSettings() if self.custom_templates_dir_checkbox.isChecked(): # Show previous templates dir path = settings.value('inasafe/reportTemplatePath', '', type=str) else: # Set the template report dir to '' path = '' self.leReportTemplatePath.setText(path) def set_org_disclaimer(self): """Auto-connect slot activated when org disclaimer checkbox is toggled. """ settings = QtCore.QSettings() if self.custom_org_disclaimer_checkbox.isChecked(): # Show previous organisation disclaimer org_disclaimer = settings.value('inasafe/reportDisclaimer', disclaimer(), type=str) else: # Set the organisation disclaimer to the default one org_disclaimer = disclaimer() self.txtDisclaimer.setPlainText(org_disclaimer)
class OptionsDialog(QtGui.QDialog, Ui_OptionsDialogBase): """Options dialog for the InaSAFE plugin.""" def __init__(self, iface, dock=None, parent=None): """Constructor for the dialog. :param iface: A Quantum GIS QGisAppInterface instance. :type iface: QGisAppInterface :param parent: Parent widget of this dialog :type parent: QWidget :param dock: Optional dock widget instance that we can notify of changes to the keywords. :type dock: Dock """ QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.setWindowTitle(self.tr('InaSAFE %s Options' % get_version())) # Save reference to the QGIS interface and parent self.iface = iface self.parent = parent self.dock = dock self.keyword_io = KeywordIO() # Set up things for context help button = self.buttonBox.button(QtGui.QDialogButtonBox.Help) button.clicked.connect(self.show_help) self.grpNotImplemented.hide() self.adjustSize() self.restore_state() # hack prevent showing use thread visible and set it false see #557 self.cbxUseThread.setChecked(True) self.cbxUseThread.setVisible(False) def restore_state(self): """Reinstate the options based on the user's stored session info. """ settings = QtCore.QSettings() # flag = settings.value( # 'inasafe/useThreadingFlag', False) # hack set use thread to false see #557 flag = False self.cbxUseThread.setChecked(flag) flag = bool(settings.value('inasafe/visibleLayersOnlyFlag', True)) self.cbxVisibleLayersOnly.setChecked(flag) flag = bool(settings.value('inasafe/set_layer_from_title_flag', True)) self.cbxSetLayerNameFromTitle.setChecked(flag) flag = bool(settings.value('inasafe/setZoomToImpactFlag', True)) self.cbxZoomToImpact.setChecked(flag) # whether exposure layer should be hidden after model completes flag = bool(settings.value('inasafe/setHideExposureFlag', False)) self.cbxHideExposure.setChecked(flag) flag = bool(settings.value('inasafe/clip_to_viewport', True)) self.cbxClipToViewport.setChecked(flag) flag = bool(settings.value('inasafe/clip_hard', False)) self.cbxClipHard.setChecked(flag) flag = bool(settings.value('inasafe/useSentry', False)) self.cbxUseSentry.setChecked(flag) flag = bool(settings.value('inasafe/show_intermediate_layers', False)) self.cbxShowPostprocessingLayers.setChecked(flag) ratio = float( settings.value('inasafe/defaultFemaleRatio', DEFAULTS['FEM_RATIO'])) self.dsbFemaleRatioDefault.setValue(ratio) path = settings.value('inasafe/keywordCachePath', self.keyword_io.default_keyword_db_path()) self.leKeywordCachePath.setText(path) path = settings.value('inasafe/mapsLogoPath', '') self.leMapsLogoPath.setText(path) path = settings.value('inasafe/reportTemplatePath', '') self.leReportTemplatePath.setText(path) flag = bool(settings.value('inasafe/developer_mode', False)) self.cbxDevMode.setChecked(flag) flag = bool(settings.value('inasafe/use_native_zonal_stats', False)) self.cbxNativeZonalStats.setChecked(flag) def save_state(self): """Store the options into the user's stored session info. """ settings = QtCore.QSettings() settings.setValue('inasafe/useThreadingFlag', False) settings.setValue('inasafe/visibleLayersOnlyFlag', self.cbxVisibleLayersOnly.isChecked()) settings.setValue('inasafe/set_layer_from_title_flag', self.cbxSetLayerNameFromTitle.isChecked()) settings.setValue('inasafe/setZoomToImpactFlag', self.cbxZoomToImpact.isChecked()) settings.setValue('inasafe/setHideExposureFlag', self.cbxHideExposure.isChecked()) settings.setValue('inasafe/clip_to_viewport', self.cbxClipToViewport.isChecked()) settings.setValue('inasafe/clip_hard', self.cbxClipHard.isChecked()) settings.setValue('inasafe/useSentry', self.cbxUseSentry.isChecked()) settings.setValue('inasafe/show_intermediate_layers', self.cbxShowPostprocessingLayers.isChecked()) settings.setValue('inasafe/defaultFemaleRatio', self.dsbFemaleRatioDefault.value()) settings.setValue('inasafe/keywordCachePath', self.leKeywordCachePath.text()) settings.setValue('inasafe/mapsLogoPath', self.leMapsLogoPath.text()) settings.setValue('inasafe/reportTemplatePath', self.leReportTemplatePath.text()) settings.setValue('inasafe/developer_mode', self.cbxDevMode.isChecked()) settings.setValue('inasafe/useNativeZonalStats', self.cbxNativeZonalStats.isChecked()) def show_help(self): """Show context help for the options dialog.""" show_context_help('options') def accept(self): """Method invoked when OK button is clicked.""" self.save_state() self.dock.read_settings() self.close() @pyqtSignature('') # prevents actions being handled twice def on_toolKeywordCachePath_clicked(self): """Auto-connect slot activated when cache file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getSaveFileName( self, self.tr('Set keyword cache file'), self.keyword_io.default_keyword_db_path(), self.tr('Sqlite DB File (*.db)')) self.leKeywordCachePath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolMapsLogoPath_clicked(self): """Auto-connect slot activated when logo file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getOpenFileName( self, self.tr('Set map logo file'), '', self.tr('Portable Network Graphics files (*.png *.PNG)')) self.leMapsLogoPath.setText(file_name) @pyqtSignature('') # prevents actions being handled twice def on_toolReportTemplatePath_clicked(self): """Auto-connect slot activated when report file tool button is clicked. """ # noinspection PyCallByClass,PyTypeChecker file_name = QtGui.QFileDialog.getOpenFileName( self, self.tr('Set report template'), '', self.tr('QGIS Composer templates (*.qpt *.QPT)')) self.leReportTemplatePath.setText(file_name)