def populateCodeCombo( combo, code_group, showAny=False, special=None, category=None ): codes = SystemCode.codeGroup( code_group ) rows = [(c.code, c.value) for c in codes if category==None or c.category==category] rows.sort( key=lambda x:unicode(x[1]).upper() ) if special: rows[0:0]=special if showAny: rows.insert(0,(None, '(Any)')) QtUtils.populateCombo(combo,rows) combo.setCurrentIndex(0)
def _populateDropDownLists( self ): codes = SystemCode.codeGroup('NSTS') official = ' '.join([c.code for c in codes if c.category=='OFFC']) unofficial = ' '.join([c.code for c in codes if c.category=='UOFC']) unpublished = ' '.join([c.code for c in codes if c.category=='NPUB']) FormUtils.populateCodeCombo(self.uSearchNameStatus,'NSTS',True, [(official,'(Official)'), (unofficial,'(Unofficial)'), (unpublished,'(Unpublished)') ]) FormUtils.populateCodeCombo(self.uSearchFeatClass,'FCLS',True) self.uSearchFeatClass.currentIndexChanged.connect( self._populateFeatTypeDropdown )
def _populateDropDownLists(self): codes = SystemCode.codeGroup("NSTS") official = " ".join([c.code for c in codes if c.category == "OFFC"]) unofficial = " ".join([c.code for c in codes if c.category == "UOFC"]) unpublished = " ".join([c.code for c in codes if c.category == "NPUB"]) FormUtils.populateCodeCombo( self.uSearchNameStatus, "NSTS", True, [ (official, "(Official)"), (unofficial, "(Unofficial)"), (unpublished, "(Unpublished)"), ], ) FormUtils.populateCodeCombo(self.uSearchFeatClass, "FCLS", True) self.uSearchFeatClass.currentIndexChanged.connect( self._populateFeatTypeDropdown)
def _populateResultList( self, listCtl, resultSet ): results = [] ftypes = {} for c in SystemCode.codeGroup('FTYP'): ftypes[c.code] = c.value+' ('+SystemCode.lookup('FCLS',c.category,'')+')' try: for row in resultSet: r=dict() r['name_id'] = row.name_id r['name'] = row.name r['name_status'] = SystemCode.lookup('NSTS',row.name_status) r['feat_type'] = ftypes.get(row.feat_type) results.append(r) except: handleException() results=[] listCtl.setList(results, adaptor=self._adaptor, columns=['name','name_status','feat_type'], headers=['Name','Status','Feature Type']) listCtl.clearSelection()
def _populateResultList(self, listCtl, resultSet): results = [] ftypes = {} for c in SystemCode.codeGroup("FTYP"): ftypes[c.code] = (c.value + " (" + SystemCode.lookup("FCLS", c.category, "") + ")") try: for row in resultSet: r = dict() r["name_id"] = row.name_id r["name"] = row.name r["name_status"] = SystemCode.lookup("NSTS", row.name_status) r["feat_type"] = ftypes.get(row.feat_type) results.append(r) except: handleException() results = [] listCtl.setList( results, adaptor=self._adaptor, columns=["name", "name_status", "feat_type"], headers=["Name", "Status", "Feature Type"], ) listCtl.clearSelection()
def _doSearch(self, clear=False): text = "" if not clear: text = str(self.uSearchText.text()) feat_type = None name_status = None not_pub = False extents = None maxResults = 100 if self._advanced and not clear: feat_type = None fclass = QtUtils.comboValue(self.uSearchFeatClass) if fclass: feat_type = QtUtils.comboValue(self.uSearchFeatType) if feat_type: feat_type = str(feat_type) else: codes = SystemCode.codeGroup("FTYP") feat_type = " ".join(c.code for c in codes if c.category == str(fclass)) name_status = QtUtils.comboValue(self.uSearchNameStatus) name_status = str(name_status) if name_status else None not_pub = self.uSearchUnpublished.isChecked() maxResults = self.uSearchMaxResults.value() if self.uSearchMapExtent.isChecked(): extents = self._controller.mapExtentsNZGD2000() searchDef = { "text": text, "feat_type": feat_type, "name_status": name_status, "not_pub": not_pub, "extents": extents, "maxResults": maxResults, } if searchDef == self._searchDef: return try: self._searchDef = searchDef results = [] if not clear: if self._advanced: results = Name.search2( name=text, ftype=feat_type, status=name_status, notpublished=not_pub, extentWkt=extents, maxresults=maxResults, ) elif text: results = Name.search(name=text, maxresults=maxResults) self._populateResultList(self.uSearchResults, results) self._controller.setSearchResults(results) if not clear: status = (str(len(results)) + " match" + ("es" if len(results) == 1 else "") + " found") if len(results) > 0: status += ". Click name to open, Shift+Click to open in new window" self.uSearchStatus.setText(status) except: self._populateResultList(self.uSearchResults, []) self._controller.setSearchResults([]) msg = str(sys.exc_info()[1]) QMessageBox.information(self, "Search error", msg) self.uSearchStatus.setText(msg)
def _doSearch( self, clear=False ): text = '' if not clear: text = unicode(self.uSearchText.text()) feat_type=None name_status=None not_pub=False extents=None maxResults=100 if self._advanced and not clear: feat_type = None fclass=QtUtils.comboValue(self.uSearchFeatClass) if fclass: feat_type=QtUtils.comboValue(self.uSearchFeatType) if feat_type: feat_type = str(feat_type) else: codes = SystemCode.codeGroup( 'FTYP' ) feat_type=' '.join(c.code for c in codes if c.category==str(fclass)) name_status=QtUtils.comboValue(self.uSearchNameStatus) name_status = str(name_status) if name_status else None not_pub=self.uSearchUnpublished.isChecked() maxResults = self.uSearchMaxResults.value() if self.uSearchMapExtent.isChecked(): extents=self._controller.mapExtentsNZGD2000() searchDef = { 'text': text, 'feat_type': feat_type, 'name_status': name_status, 'not_pub': not_pub, 'extents': extents, 'maxResults': maxResults } if searchDef == self._searchDef: return try: self._searchDef = searchDef results = [] if not clear: if self._advanced: results = Name.search2( name=text, ftype=feat_type, status=name_status, notpublished=not_pub, extentWkt=extents, maxresults=maxResults) elif text: results = Name.search(name=text,maxresults=maxResults) self._populateResultList( self.uSearchResults,results) self._controller.setSearchResults(results) if not clear: status = str(len(results))+' match' + ( 'es' if len(results) == 1 else '') + ' found' if len(results) > 0: status += '. Click name to open, Shift+Click to open in new window' self.uSearchStatus.setText( status ) except: self._populateResultList( self.uSearchResults,[]) self._controller.setSearchResults([]) msg = str(sys.exc_info()[1]) QMessageBox.information(self,"Search error",msg) self.uSearchStatus.setText(msg)