def test_delete_setting(self): """Test delete setting.""" set_setting('test_key', 'test_value') self.assertEqual('test_value', get_setting('test_key')) delete_setting('test_key') self.assertIsNone(get_setting('test_key'))
def set_widgets(self): """Set all widgets.""" self.text_test_connection_button = self.test_connection_button.text() self.ok_label.setVisible(False) self.save_button.setEnabled(False) self.test_connection_button.clicked.connect(self.login) self.save_button.clicked.connect(self.save_authtoken) self.clear_button.setText(tr('Clear')) self.clear_button.setEnabled(True) self.clear_button.clicked.connect(self.clear_information) self.url_input.setText(get_url_instance()) # If login information exists if not self.auth_token: self.auth_token = get_authtoken() if self.auth_token: self.test_connection_button.setEnabled(False) self.username_input.setText(get_setting('username')) self.username_input.setReadOnly(True) self.password_input.setReadOnly(True) self.username_input.setStyleSheet( "QLineEdit { background-color: '#d9d9d9'; color: '#5b5b5b'; " "selection-background-color: '#969292'; }") self.password_input.setStyleSheet( "QLineEdit { background-color: '#d9d9d9'; color: '#5b5b5b'; " "selection-background-color: '#969292'; }") self.token_status.setText(tr('Auth token is saved.')) else: self.token_status.setText(tr('Auth token is empty.'))
def organization_projects_spatial_call_finished(self, result): """Function when Organization Project Spatial Api finished. :param result: result of request :type result: (bool, list/dict/str) """ self.save_organizations() if result[0]: # save result to local file organization_slug = result[2] project_slug = result[3] vlayers = Utilities.save_layer(result[1], organization_slug, project_slug) self.progress_bar.setValue(50) download_relationship_and_party = False if self.project['access'] == 'public': # Get organization status, results = self.organisation_api.summary_organization( organization_slug) if status and 'users' in results: for user in results['users']: if user['username'] == get_setting('username'): download_relationship_and_party = True break else: download_relationship_and_party = True relationship_layer_id = None party_layer_id = None if download_relationship_and_party: relationship_layer = self.relationships_layer(vlayers) if relationship_layer: relationship_layer_id = relationship_layer.id() party_layer = self.parties_layer() if party_layer: party_layer_id = party_layer.id() self.progress_bar.setValue(80) QCoreApplication.processEvents() Utilities.save_project_basic_information(self.project, vlayers, relationship_layer_id, party_layer_id) else: pass self.progress_bar.setValue(self.progress_bar.maximum()) self.warning_label.setText(self.loaded_label_string) self.parent.close()
def __init__(self, on_finished=None): """Constructor. :param on_finished: (optional) function that catch result request :type on_finished: Function """ request_url = get_url_instance() + self.api_url if not get_setting('public_project'): request_url += '?permissions=project.update' super(Project, self).__init__(request_url) self.on_finished = on_finished self.connect_get_paginated()
def layer_will_be_removed(self, layer_id): """Function that triggered when layer will be removed. :param layer_id: Removed layer id. :type layer_id: QString """ layer = QgsMapLayerRegistry.instance().mapLayer(layer_id) layer_names = layer.name().split('/') if len(layer_names) > 1 and \ ('relationships' in layer.name() or 'parties' in layer.name()): try: organization_slug, project_slug, attribute = layer_names Utilities.add_tabular_layer( layer, organization_slug, project_slug, attribute ) setting_value = '%s/%s' % ( organization_slug, project_slug ) setting_file = get_setting('layers_added') if setting_file: setting_files = setting_file.split(',') setting_files.remove(setting_value) setting_file = ','.join(setting_files) set_setting('layers_added', setting_file) else: self.project_update_wizard.setEnabled(False) if not get_setting('layers_added'): self.project_update_wizard.setEnabled(False) except ValueError: return
def set_widgets(self): """Set all widgets on the tab.""" self.project_combo_box.currentIndexChanged.connect( self.project_combo_box_changed) checkbox_checked = get_setting('public_project') if checkbox_checked: self.public_projects_checkbox.setCheckState(Qt.Checked) self.public_projects_checkbox.stateChanged.connect( self.public_check_box_changed) icon_path = resources_path('images', 'throbber.gif') movie = QMovie(icon_path) self.throbber_loader.setMovie(movie) movie.start() self.get_available_projects() self.add_contact_label.mousePressEvent = self.add_contact_label_clicked self.set_enabled_add_contact_label(False) self.project_combo_box.setFocus() set_setting('public_project', self.public_projects_checkbox.checkState() == Qt.Checked)
def layer_added(self, layer): """Function that triggered when layer was added. :param layer: Added layer. :type layer: QgsVectorLayer """ # Load csv file layer_names = layer.name().split('/') if len(layer_names) > 2 and \ ('relationships' in layer.name() or 'parties' in layer.name()): try: organization_slug, project_slug, attribute = layer_names Utilities.load_csv_file_to_layer( layer, organization_slug, project_slug, attribute) self.project_update_wizard.setEnabled(True) setting_value = '%s/%s' % ( organization_slug, project_slug ) setting_file = get_setting('layers_added') if not setting_file: set_setting('layers_added', setting_value) else: if setting_value not in setting_file: set_setting( 'layers_added', setting_file + ',' + setting_value ) except ValueError: return
def test_get_setting(self): """Test get setting.""" set_setting('test_key', None) self.assertIsNone(get_setting('test_key'))
def test_set_setting(self): """Test set setting.""" set_setting('test_key', 'test_value') self.assertEqual('test_value', get_setting('test_key'))