def test_one_washoff(self): """Test all options""" test_text = "Residential TSS EXP 0.1 1 0 0 " self.my_options = Washoff() self.my_options.set_text(test_text) # --Test get_text through matches actual_text = self.my_options.get_text() # display purpose assert self.my_options.matches(test_text)
def cmdOK_Clicked(self): section = self._main_form.project.landuses land_uses_list = section.value[0:] for land_use in land_uses_list: if land_use.land_use_name == self.land_use_id: # put this back in place land_use.land_use_name = self.tblGeneral.item(0, 0).text() land_use.comment = self.tblGeneral.item(1, 0).text() land_use.last_swept = self.tblGeneral.item(3, 0).text() land_use.street_sweeping_availability = self.tblGeneral.item( 4, 0).text() land_use.street_sweeping_interval = self.tblGeneral.item( 5, 0).text() section = self._main_form.project.buildup buildup_list = section.value[0:] pollutant_count = -1 for pollutant in self.local_pollutant_list: pollutant_count += 1 buildup_found = False for buildup in buildup_list: if buildup.land_use_name == self.land_use_id and pollutant == buildup.pollutant: # put this back in place buildup_found = True combobox = self.tblBuildup.cellWidget(0, pollutant_count) buildup.function = BuildupFunction[combobox.currentText()] buildup.max_buildup = self.tblBuildup.item( 1, pollutant_count).text() buildup.rate_constant = self.tblBuildup.item( 2, pollutant_count).text() buildup.power_sat_constant = self.tblBuildup.item( 3, pollutant_count).text() combobox = self.tblBuildup.cellWidget(4, pollutant_count) buildup.normalizer = Normalizer[combobox.currentText()] buildup.scaling_factor = self.tblBuildup.item( 5, pollutant_count).text() combobox = self.tblBuildup.cellWidget(6, pollutant_count) buildup.timeseries = combobox.currentText() if not buildup_found: # add new record new_buildup = Buildup() new_buildup.land_use_name = self.land_use_id new_buildup.pollutant = pollutant combobox = self.tblBuildup.cellWidget(0, pollutant_count) new_buildup.function = BuildupFunction[combobox.currentText()] new_buildup.max_buildup = self.tblBuildup.item( 1, pollutant_count).text() new_buildup.rate_constant = self.tblBuildup.item( 2, pollutant_count).text() new_buildup.power_sat_constant = self.tblBuildup.item( 3, pollutant_count).text() combobox = self.tblBuildup.cellWidget(4, pollutant_count) new_buildup.normalizer = Normalizer[combobox.currentText()] new_buildup.scaling_factor = self.tblBuildup.item( 5, pollutant_count).text() combobox = self.tblBuildup.cellWidget(6, pollutant_count) new_buildup.timeseries = combobox.currentText() if section.value == '': section.value = [] section.value.append(new_buildup) section = self._main_form.project.find_section("WASHOFF") washoff_list = section.value[0:] pollutant_count = -1 for pollutant in self.local_pollutant_list: pollutant_count += 1 washoff_found = False for washoff in washoff_list: if washoff.land_use_name == self.land_use_id and pollutant == washoff.pollutant: # put this back in place washoff_found = True combobox = self.tblWashoff.cellWidget(0, pollutant_count) washoff.function = WashoffFunction[combobox.currentText()] washoff.coefficient = self.tblWashoff.item( 1, pollutant_count).text() washoff.exponent = self.tblWashoff.item( 2, pollutant_count).text() washoff.cleaning_efficiency = self.tblWashoff.item( 3, pollutant_count).text() washoff.bmp_efficiency = self.tblWashoff.item( 4, pollutant_count).text() if not washoff_found: # add new record new_washoff = Washoff() new_washoff.land_use_name = self.land_use_id new_washoff.pollutant = pollutant combobox = self.tblWashoff.cellWidget(0, pollutant_count) new_washoff.function = WashoffFunction[combobox.currentText()] new_washoff.coefficient = self.tblWashoff.item( 1, pollutant_count).text() new_washoff.exponent = self.tblWashoff.item( 2, pollutant_count).text() new_washoff.cleaning_efficiency = self.tblWashoff.item( 3, pollutant_count).text() new_washoff.bmp_efficiency = self.tblWashoff.item( 4, pollutant_count).text() if section.value == '': section.value = [] section.value.append(new_washoff) self.close()
def set_from(self, land_use): if not isinstance(land_use, Landuse): land_use = self.section.value[land_use] if isinstance(land_use, Landuse): # this is the land_use we want to edit self.editing_item = land_use led = QLineEdit(land_use.name) self.tblGeneral.setItem(0,0,QTableWidgetItem(led.text())) led = QLineEdit(land_use.comment) self.tblGeneral.setItem(1,0,QTableWidgetItem(led.text())) led = QLineEdit(land_use.last_swept) self.tblGeneral.setItem(3,0,QTableWidgetItem(led.text())) led = QLineEdit(land_use.street_sweeping_availability) self.tblGeneral.setItem(4,0,QTableWidgetItem(led.text())) led = QLineEdit(land_use.street_sweeping_interval) self.tblGeneral.setItem(5,0,QTableWidgetItem(led.text())) self.tblGeneral.setCurrentCell(0,0) local_column = -1 for pollutant in self.local_pollutant_list: local_column += 1 pollutant_found = False for buildup in self.project.buildup.value: if buildup.land_use_name == land_use.name and buildup.pollutant == pollutant: # this is the land_use we want to edit pollutant_found = True break if not pollutant_found: buildup = Buildup() buildup.land_use_name = land_use.name buildup.pollutant = pollutant self.project.buildup.value.append(buildup) combobox = QComboBox() ui.convenience.set_combo_items(type(buildup.function), combobox) ui.convenience.set_combo(combobox, buildup.function) # BuildupFunction.POW self.tblBuildup.setCellWidget(0, local_column, combobox) led = QLineEdit(buildup.max_buildup) self.tblBuildup.setItem(1, local_column,QTableWidgetItem(led.text())) led = QLineEdit(buildup.rate_constant) self.tblBuildup.setItem(2, local_column,QTableWidgetItem(led.text())) led = QLineEdit(buildup.power_sat_constant) self.tblBuildup.setItem(3, local_column,QTableWidgetItem(led.text())) combobox = QComboBox() ui.convenience.set_combo_items(type(buildup.normalizer), combobox) ui.convenience.set_combo(combobox, buildup.normalizer) # Normalizer.AREA self.tblBuildup.setCellWidget(4, local_column, combobox) led = QLineEdit(buildup.scaling_factor) self.tblBuildup.setItem(5, local_column, QTableWidgetItem(led.text())) combobox = QComboBox() combobox.addItem('') selected_index = 0 for value in self.project.timeseries.value: combobox.addItem(value.name) if buildup.timeseries == value.name: selected_index = int(combobox.count())-1 combobox.setCurrentIndex(selected_index) self.tblBuildup.setCellWidget(6, local_column, combobox) self.tblBuildup.setCurrentCell(0,0) local_column = -1 for pollutant in self.local_pollutant_list: local_column += 1 pollutant_found = False for washoff in self.project.washoff.value: if washoff.land_use_name == land_use.name and washoff.pollutant == pollutant: # this is the land_use we want to edit pollutant_found = True break if not pollutant_found: washoff = Washoff() washoff.land_use_name = land_use.name washoff.pollutant = pollutant self.project.washoff.value.append(washoff) combobox = QComboBox() ui.convenience.set_combo_items(type(washoff.function), combobox) ui.convenience.set_combo(combobox, washoff.function) # WashoffFunction.EXP self.tblWashoff.setCellWidget(0,local_column, combobox) led = QLineEdit(washoff.coefficient) self.tblWashoff.setItem(1,local_column,QTableWidgetItem(led.text())) led = QLineEdit(washoff.exponent) self.tblWashoff.setItem(2,local_column,QTableWidgetItem(led.text())) led = QLineEdit(washoff.cleaning_efficiency) self.tblWashoff.setItem(3,local_column,QTableWidgetItem(led.text())) led = QLineEdit(washoff.bmp_efficiency) self.tblWashoff.setItem(4,local_column,QTableWidgetItem(led.text())) self.tblWashoff.setCurrentCell(0,0)
def cmdOK_Clicked(self): new_name = self.tblGeneral.item(0,0).text() pollutant_count = -1 for pollutant in self.local_pollutant_list: pollutant_count += 1 buildup_found = False for buildup in self.project.buildup.value: if buildup.land_use_name == self.editing_item.name and pollutant == buildup.pollutant: # put this back in place buildup_found = True orig_land_use_name = buildup.land_use_name orig_function = buildup.function orig_max_buildup = buildup.max_buildup orig_rate_constant = buildup.rate_constant orig_power_sat_constant = buildup.power_sat_constant orig_normalizer = buildup.normalizer orig_scaling_factor = buildup.scaling_factor orig_timeseries = buildup.timeseries combobox = self.tblBuildup.cellWidget(0,pollutant_count) buildup.land_use_name = new_name buildup.function = BuildupFunction[combobox.currentText()] buildup.max_buildup = self.tblBuildup.item(1,pollutant_count).text() buildup.rate_constant = self.tblBuildup.item(2,pollutant_count).text() buildup.power_sat_constant = self.tblBuildup.item(3,pollutant_count).text() combobox = self.tblBuildup.cellWidget(4,pollutant_count) buildup.normalizer = Normalizer[combobox.currentText()] buildup.scaling_factor = self.tblBuildup.item(5,pollutant_count).text() combobox = self.tblBuildup.cellWidget(6,pollutant_count) buildup.timeseries = combobox.currentText() if orig_land_use_name != buildup.land_use_name or \ orig_function != buildup.function or \ orig_max_buildup != buildup.max_buildup or \ orig_rate_constant != buildup.rate_constant or \ orig_power_sat_constant != buildup.power_sat_constant or \ orig_normalizer != buildup.normalizer or \ orig_scaling_factor != buildup.scaling_factor or \ orig_timeseries != buildup.timeseries and buildup.function == BuildupFunction.EXP: self._main_form.mark_project_as_unsaved() if not buildup_found: # add new record new_buildup = Buildup() new_buildup.land_use_name = new_name new_buildup.pollutant = pollutant combobox = self.tblBuildup.cellWidget(0,pollutant_count) new_buildup.function = BuildupFunction[combobox.currentText()] new_buildup.max_buildup = self.tblBuildup.item(1,pollutant_count).text() new_buildup.rate_constant = self.tblBuildup.item(2,pollutant_count).text() new_buildup.power_sat_constant = self.tblBuildup.item(3,pollutant_count).text() combobox = self.tblBuildup.cellWidget(4,pollutant_count) new_buildup.normalizer = Normalizer[combobox.currentText()] new_buildup.scaling_factor = self.tblBuildup.item(5,pollutant_count).text() combobox = self.tblBuildup.cellWidget(6,pollutant_count) new_buildup.timeseries = combobox.currentText() if self.project.buildup.value == '': self.project.buildup.value = [] self.project.buildup.value.append(new_buildup) self._main_form.mark_project_as_unsaved() pollutant_count = -1 for pollutant in self.local_pollutant_list: pollutant_count += 1 washoff_found = False for washoff in self.project.washoff.value: if washoff.land_use_name == self.editing_item.name and pollutant == washoff.pollutant: # put this back in place washoff_found = True orig_land_use_name = washoff.land_use_name orig_function = washoff.function orig_coefficient = washoff.coefficient orig_exponent = washoff.exponent orig_cleaning_efficiency = washoff.cleaning_efficiency orig_bmp_efficiency = washoff.bmp_efficiency combobox = self.tblWashoff.cellWidget(0,pollutant_count) washoff.land_use_name = new_name washoff.function = WashoffFunction[combobox.currentText()] washoff.coefficient = self.tblWashoff.item(1,pollutant_count).text() washoff.exponent = self.tblWashoff.item(2,pollutant_count).text() washoff.cleaning_efficiency = self.tblWashoff.item(3,pollutant_count).text() washoff.bmp_efficiency = self.tblWashoff.item(4,pollutant_count).text() if orig_land_use_name != washoff.land_use_name or \ orig_function != washoff.function or \ orig_coefficient != washoff.coefficient or \ orig_exponent != washoff.exponent or \ orig_cleaning_efficiency != washoff.cleaning_efficiency or \ orig_bmp_efficiency != washoff.bmp_efficiency: self._main_form.mark_project_as_unsaved() if not washoff_found: # add new record new_washoff = Washoff() new_washoff.land_use_name = new_name new_washoff.pollutant = pollutant combobox = self.tblWashoff.cellWidget(0,pollutant_count) new_washoff.function = WashoffFunction[combobox.currentText()] new_washoff.coefficient = self.tblWashoff.item(1,pollutant_count).text() new_washoff.exponent = self.tblWashoff.item(2,pollutant_count).text() new_washoff.cleaning_efficiency = self.tblWashoff.item(3,pollutant_count).text() new_washoff.bmp_efficiency = self.tblWashoff.item(4,pollutant_count).text() if self.project.washoff.value == '': self.project.washoff.value = [] self.project.washoff.value.append(new_washoff) self._main_form.mark_project_as_unsaved() # put this back in place orig_name = self.editing_item.name orig_comment = self.editing_item.comment orig_last_swept = self.editing_item.last_swept orig_street_sweeping_availability = self.editing_item.street_sweeping_availability orig_street_sweeping_interval = self.editing_item.street_sweeping_interval self.editing_item.name = new_name self.editing_item.comment = self.tblGeneral.item(1,0).text() self.editing_item.last_swept = self.tblGeneral.item(3,0).text() self.editing_item.street_sweeping_availability = self.tblGeneral.item(4,0).text() self.editing_item.street_sweeping_interval = self.tblGeneral.item(5,0).text() if orig_name != self.editing_item.name or \ orig_comment != self.editing_item.comment or \ orig_last_swept != self.editing_item.last_swept or \ orig_street_sweeping_availability != self.editing_item.street_sweeping_availability or \ orig_street_sweeping_interval != self.editing_item.street_sweeping_interval: self._main_form.mark_project_as_unsaved() if self.new_item: # We are editing a newly created item and it needs to be added to the project self._main_form.add_item(self.new_item) self._main_form.mark_project_as_unsaved() else: pass # TODO: self._main_form.edited_? self.close()