def set_widgets(self): """Set widgets on the Subcategory tab.""" self.clear_further_steps() # Set widgets purpose = self.parent.step_kw_purpose.selected_purpose() self.lstSubcategories.clear() self.lblDescribeSubcategory.setText('') self.lblIconSubcategory.setPixmap(QPixmap()) self.lblSelectSubcategory.setText( get_question_text('%s_question' % purpose['key'])) for i in self.subcategories_for_layer(): item = QListWidgetItem(i['name'], self.lstSubcategories) item.setData(QtCore.Qt.UserRole, i['key']) self.lstSubcategories.addItem(item) # Check if layer keywords are already assigned key = self.parent.step_kw_purpose.selected_purpose()['key'] keyword = self.parent.get_existing_keyword(key) # Overwrite the keyword if it's KW mode embedded in IFCW mode if self.parent.parent_step: keyword = self.parent.get_parent_mode_constraints()[1]['key'] # Set values based on existing keywords or parent mode if keyword: subcategories = [] for index in xrange(self.lstSubcategories.count()): item = self.lstSubcategories.item(index) subcategories.append(item.data(QtCore.Qt.UserRole)) if keyword in subcategories: self.lstSubcategories.setCurrentRow( subcategories.index(keyword)) self.auto_select_one_item(self.lstSubcategories)
def set_widgets(self): """Set widgets on the Field tab.""" self.clear_further_steps() purpose = self.parent.step_kw_purpose.selected_purpose() subcategory = self.parent.step_kw_subcategory.selected_subcategory() unit = self.parent.step_kw_unit.selected_unit() if purpose == layer_purpose_aggregation: question_text = field_question_aggregation elif self.parent.step_kw_layermode.\ selected_layermode() == layer_mode_continuous and unit: subcategory_unit_relation = get_question_text( '%s_%s_question' % (subcategory['key'], unit['key'])) if 'MISSING' in subcategory_unit_relation: subcategory_unit_relation = self.tr( '{subcategory} in {unit} unit').format( subcategory=subcategory['name'].lower(), unit=unit['plural_name']) question_text = field_question_subcategory_unit % ( purpose['name'], subcategory['name'], unit['name'], subcategory_unit_relation) else: question_text = field_question_subcategory_classified % ( subcategory['name']) self.lblSelectField.setText(question_text) self.lstFields.clear() default_item = None for field in self.parent.layer.dataProvider().fields(): field_name = field.name() item = QListWidgetItem(field_name, self.lstFields) item.setData(QtCore.Qt.UserRole, field_name) # Select the item if it match the unit's default_attribute if unit and 'default_attribute' in unit \ and field_name == unit['default_attribute']: default_item = item # For continuous data, gray out id, gid, fid and text fields if self.parent.step_kw_layermode.\ selected_layermode() == layer_mode_continuous and unit: field_type = field.type() if field_type > 9 or re.match( '.{0,2}id$', field_name, re.I): item.setFlags(item.flags() & ~QtCore.Qt.ItemIsEnabled) if default_item: self.lstFields.setCurrentItem(default_item) self.lblDescribeField.clear() # Set values based on existing keywords (if already assigned) field_keyword = self.parent.field_keyword_for_the_layer() inasafe_field = self.parent.get_existing_keyword('inasafe_fields') if inasafe_field: field = inasafe_field.get(field_keyword) if field: fields = [] for index in xrange(self.lstFields.count()): fields.append(str(self.lstFields.item(index).text())) if field in fields: self.lstFields.setCurrentRow(fields.index(field)) self.auto_select_one_item(self.lstFields)
def set_widgets(self): """Set widgets on the Field tab.""" self.clear_further_steps() purpose = self.parent.step_kw_purpose.selected_purpose() subcategory = self.parent.step_kw_subcategory.selected_subcategory() unit = self.parent.step_kw_unit.selected_unit() if purpose == layer_purpose_aggregation: question_text = field_question_aggregation elif self.parent.step_kw_layermode.\ selected_layermode() == layer_mode_continuous and unit: # unique values, continuous or categorical data subcategory_unit_relation = get_question_text( '%s_%s_question' % (subcategory['key'], unit['key'])) question_text = field_question_subcategory_unit % ( purpose['name'], subcategory['name'], unit['name'], subcategory_unit_relation) else: question_text = field_question_subcategory_classified % ( subcategory['name']) self.lblSelectField.setText(question_text) self.lstFields.clear() default_item = None for field in self.parent.layer.dataProvider().fields(): field_name = field.name() item = QListWidgetItem(field_name, self.lstFields) item.setData(QtCore.Qt.UserRole, field_name) # Select the item if it match the unit's default_attribute if unit and 'default_attribute' in unit \ and field_name == unit['default_attribute']: default_item = item # For continuous data, gray out id, gid, fid and text fields if self.parent.step_kw_layermode.\ selected_layermode() == layer_mode_continuous and unit: field_type = field.type() if field_type > 9 or re.match( '.{0,2}id$', field_name, re.I): item.setFlags(item.flags() & ~QtCore.Qt.ItemIsEnabled) if default_item: self.lstFields.setCurrentItem(default_item) self.lblDescribeField.clear() # Set values based on existing keywords (if already assigned) field_keyword = self.parent.field_keyword_for_the_layer() field = self.parent.get_existing_keyword(field_keyword) if field: fields = [] for index in xrange(self.lstFields.count()): fields.append(str(self.lstFields.item(index).text())) if field in fields: self.lstFields.setCurrentRow(fields.index(field)) self.auto_select_one_item(self.lstFields)
def set_widgets(self): """Set widgets on the Field tab.""" self.clear_further_steps() purpose = self.parent.step_kw_purpose.selected_purpose() subcategory = self.parent.step_kw_subcategory.selected_subcategory() unit = self.parent.step_kw_unit.selected_unit() # Set mode # Notes(IS) I hard coded this one, need to fix it after it's working. LOGGER.debug(self.parent.field_keyword_for_the_layer()) if (self.parent.field_keyword_for_the_layer() == population_count_field['key']): self.mode = MULTI_MODE else: self.mode = SINGLE_MODE if purpose == layer_purpose_aggregation: question_text = field_question_aggregation elif self.parent.step_kw_layermode.\ selected_layermode() == layer_mode_continuous and unit: subcategory_unit_relation = get_question_text( '%s_%s_question' % (subcategory['key'], unit['key'])) if 'MISSING' in subcategory_unit_relation: subcategory_unit_relation = self.tr( '{subcategory} in {unit} unit').format( subcategory=subcategory['name'].lower(), unit=unit['plural_name']) question_text = field_question_subcategory_unit % ( purpose['name'], subcategory['name'], unit['name'], subcategory_unit_relation) else: question_text = field_question_subcategory_classified % ( subcategory['name']) if self.mode == SINGLE_MODE: question_text += tr('\nYou can select 1 field only.') self.lstFields.setSelectionMode(QAbstractItemView.SingleSelection) elif self.mode == MULTI_MODE: question_text += tr( '\nYou can select more than 1 field. InaSAFE will sum up the ' 'value of the fields that you choose.') self.lstFields.setSelectionMode( QAbstractItemView.ExtendedSelection) self.lblSelectField.setText(question_text) self.lstFields.clear() default_item = None for field in self.parent.layer.dataProvider().fields(): field_name = field.name() item = QListWidgetItem(field_name, self.lstFields) item.setData(QtCore.Qt.UserRole, field_name) # Select the item if it match the unit's default_attribute if unit and 'default_attribute' in unit \ and field_name == unit['default_attribute']: default_item = item # For continuous data, gray out id, gid, fid and text fields if self.parent.step_kw_layermode.\ selected_layermode() == layer_mode_continuous and unit: field_type = field.type() if field_type > 9 or re.match('.{0,2}id$', field_name, re.I): continue # Don't show unmatched field type if default_item: self.lstFields.setCurrentItem(default_item) self.lblDescribeField.clear() # Set values based on existing keywords (if already assigned) field_keyword = self.parent.field_keyword_for_the_layer() inasafe_field_keywords = self.parent.get_existing_keyword( 'inasafe_fields') if inasafe_field_keywords: fields = inasafe_field_keywords.get(field_keyword) if isinstance(fields, basestring): fields = [fields] if fields: option_fields = [] for index in xrange(self.lstFields.count()): option_fields.append(str( self.lstFields.item(index).text())) for field in fields: if field in option_fields: self.lstFields.item( option_fields.index(field)).setSelected(True) self.auto_select_one_item(self.lstFields) if self.selected_fields(): self.parent.pbnNext.setEnabled(True) else: self.parent.pbnNext.setEnabled(False)
def test_get_missing_question_text(self): """Test how the wizard copes with importing missing texts.""" constant = '_dummy_missing_constant' expected_text = '<b>MISSING CONSTANT: %s</b>' % constant text = get_question_text(constant) self.assertEqual(text, expected_text)
def set_widgets(self): """Set widgets on the Field tab.""" self.clear_further_steps() purpose = self.parent.step_kw_purpose.selected_purpose() subcategory = self.parent.step_kw_subcategory.selected_subcategory() unit = self.parent.step_kw_unit.selected_unit() # Set mode # Notes(IS) I hard coded this one, need to fix it after it's working. LOGGER.debug(self.parent.field_keyword_for_the_layer()) if (self.parent.field_keyword_for_the_layer() == population_count_field['key']): self.mode = MULTI_MODE else: self.mode = SINGLE_MODE if purpose == layer_purpose_aggregation: question_text = field_question_aggregation elif self.parent.step_kw_layermode.\ selected_layermode() == layer_mode_continuous and unit: subcategory_unit_relation = get_question_text( '%s_%s_question' % (subcategory['key'], unit['key'])) if 'MISSING' in subcategory_unit_relation: subcategory_unit_relation = self.tr( '{subcategory} in {unit} unit').format( subcategory=subcategory['name'].lower(), unit=unit['plural_name']) question_text = field_question_subcategory_unit % ( purpose['name'], subcategory['name'], unit['name'], subcategory_unit_relation) else: question_text = field_question_subcategory_classified % ( subcategory['name']) if self.mode == SINGLE_MODE: question_text += tr('\nYou can select 1 field only.') self.lstFields.setSelectionMode(QAbstractItemView.SingleSelection) elif self.mode == MULTI_MODE: question_text += tr( '\nYou can select more than 1 field. InaSAFE will sum up the ' 'value of the fields that you choose.') self.lstFields.setSelectionMode( QAbstractItemView.ExtendedSelection) self.lblSelectField.setText(question_text) self.lstFields.clear() default_item = None for field in self.parent.layer.dataProvider().fields(): field_name = field.name() item = QListWidgetItem(field_name, self.lstFields) item.setData(QtCore.Qt.UserRole, field_name) # Select the item if it match the unit's default_attribute if unit and 'default_attribute' in unit \ and field_name == unit['default_attribute']: default_item = item # For continuous data, gray out id, gid, fid and text fields if self.parent.step_kw_layermode.\ selected_layermode() == layer_mode_continuous and unit: field_type = field.type() if field_type > 9 or re.match( '.{0,2}id$', field_name, re.I): continue # Don't show unmatched field type if default_item: self.lstFields.setCurrentItem(default_item) self.lblDescribeField.clear() # Set values based on existing keywords (if already assigned) field_keyword = self.parent.field_keyword_for_the_layer() inasafe_field_keywords = self.parent.get_existing_keyword( 'inasafe_fields') if inasafe_field_keywords: fields = inasafe_field_keywords.get(field_keyword) if isinstance(fields, basestring): fields = [fields] if fields: option_fields = [] for index in xrange(self.lstFields.count()): option_fields.append( str(self.lstFields.item(index).text())) for field in fields: if field in option_fields: self.lstFields.item(option_fields.index( field)).setSelected(True) self.auto_select_one_item(self.lstFields) if self.selected_fields(): self.parent.pbnNext.setEnabled(True) else: self.parent.pbnNext.setEnabled(False)