Example #1
0
 def verifyData(self, item):
     """ 
     callback at each table value update. two checks
     - value is integer
     - range is valid with new value
     """
     item_val = item.data(Qt.DisplayRole)
     if item_val == QVariant('None'):
         return
     int_val = item_val.toInt()
     row, col = item.row(), item.column()        
     if int_val[1]:  # is integer            
         # set value
         self.range_values[col][row] = int_val[0]
         
         # allow set range only if is valid 
         range_is_valid = False
         try:
             range_is_valid = self.is_range_valid()
         except SIDDRangeGroupException as err:
             # error means not valid 
             self.ui.lb_notes.setText(err.message)
         except Exception as err:
             # error means not valid
             self.ui.lb_notes.setText(err.message)
         self.ui.buttons.button(QDialogButtonBox.Ok).setEnabled(range_is_valid)
     else:
         # not integer
         # restore
         logUICall.log(get_ui_string('dlg.attr.value.error'), logUICall.WARNING)
         self.ui.table_ranges.setItem(row, col, QTableWidgetItem('%s'%self.range_values[col][row]))
Example #2
0
    def mapEditTheme(self):
        """ event handler for btn_edit - identify item on map """
        cur_layer_name = self.ui.cb_layer_selector.currentText()
        if cur_layer_name.isEmpty():
            return
        try:
            cur_layer_idx = self.LAYER_NAMES.index(cur_layer_name)
            
            # build layer render property Dialog for selected layer  
            dlg_render = QDialog()
            dlg_render.setWindowTitle(get_ui_string('widget.result.renderer.settings'))
            dlg_render.setModal(True)
            dlg_render.setFixedSize(530, 370)
            dlg_render.renderer = QgsRendererV2PropertiesDialog(self.map_layers[cur_layer_idx], self.style, True)
            dlg_render.renderer.setParent(dlg_render)        
            dlg_render.renderer.setGeometry(QRect(10, 10, 510, 325))
            dlg_render.buttonBox = QDialogButtonBox(dlg_render)
            dlg_render.buttonBox.setGeometry(QRect(10, 335, 510, 25))
            dlg_render.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
            dlg_render.buttonBox.accepted.connect(dlg_render.accept)
            dlg_render.buttonBox.accepted.connect(dlg_render.renderer.onOK)
            dlg_render.buttonBox.rejected.connect(dlg_render.reject)
            dlg_render.setVisible(True)

            # get user input and update renderer
            answer = dlg_render.exec_()
            if answer == QDialog.Accepted:
                self.map_layer_renderer[cur_layer_idx] = None
                self.map_layer_renderer[cur_layer_idx] = self.map_layers[cur_layer_idx].rendererV2().clone()             
                self.canvas.refresh()
            dlg_render.destroy()
            del dlg_render
        except Exception as err:
            # thematic is not-critical, allow continue on exception
            logUICall.log(str(err), logUICall.WARNING)
Example #3
0
 def nodeFromIndex(self, index):
     """ (override function) retrieve internal stored node from given index """
     logUICall.log("nodeFromIndx %s" %index, logUICall.DEBUG_L2)
     if index.isValid():  
         return index.internalPointer()  
     else:
         return self.rootItem
Example #4
0
    def editModifier(self):
        """ edit selected modifier """
        mod = self.getSelectedModifier()
        # make sure there is mod selected
        if mod is None:
            logUICall.log(get_ui_string("widget.ms.warning.node.required"),
                          logUICall.WARNING)
            return

        # show edit dialog box for selected modifier
        self.dlgEditMod.setNode(self.ms, mod)
        ans = self.dlgEditMod.exec_()

        # accepted means apply change
        if ans == QDialog.Accepted:
            # NOTE: dlgEditMod already should have performed all the checks on
            #       values/weights pair, we can safely assume that data is clean
            #       to be used
            #[zone_name, bldg_type, startIdx, endIdx, modidx, modifier, node] = mod
            if self.dlgEditMod.node is not None:
                modifier = StatisticModifier(self.dlgEditMod.modifier_name)
                for value, weight in map(None, self.dlgEditMod.values,
                                         self.dlgEditMod.weights):
                    modifier.values[value] = weight
                self.dlgEditMod.node.set_modifier(self.dlgEditMod.modidx,
                                                  modifier)
            self.app.visualizeMappingScheme(self.ms)
Example #5
0
File: wdg_data.py Project: gem/sidd
    def setPopGridFile(self, filename):
        """ 
        do following with given path to population grid file
        1. show path  
        2. show all fields for selection of field with population count        
        3. show projection
        4. set path in project
        5. additional updates in other tabs
        """
        # update UI
        logUICall.log('\tset pop grid file to %s ...' % filename,logUICall.DEBUG_L2)
        self.ui.txt_pop_select_file.setText(filename)
        
        logUICall.log('\tupdate combo box ...',logUICall.DEBUG_L2)
        fields = shapefile_fields(filename)
        self.ui.cb_pop_pop_field.clear()
        self.ui.cb_pop_pop_field.addItems([' '] + fields)

        self.ui.cb_pop_proj.clear()
        self.ui.cb_pop_proj.addItem (shapefile_projection(filename))
        
        # update project if project exists
        if self.project is not None:
            self.project.popgrid_file = filename
            self.app.refreshPreview()
Example #6
0
File: wdg_data.py Project: gem/sidd
 def setFootprintHtField(self, ht_field):
     # update project if project exists
     if self.project is not None:
         logUICall.log('\tset zone field %s ...' % ht_field, logUICall.DEBUG_L2)
         # update project if project exists
         if self.project is not None:
             self.project.fp_ht_field = str(ht_field)   
Example #7
0
File: wdg_data.py Project: gem/sidd
    def setZonesFile(self, filename):
        """ 
        do following with given path to homogeneous file
        1. show path  
        2. show all fields for selection of field with zone identifier
        3. show all fields for selection of field with building count
        4. show projection
        5. set path in project
        6. additional updates in other tabs
        """
        # update UI
        logUICall.log('\tset zones file to %s ...' % filename,logUICall.DEBUG_L2)
        self.ui.txt_zones_select_file.setText(filename)
        
        logUICall.log('\tupdate combo box ...',logUICall.DEBUG_L2)
        fields = shapefile_fields(filename)
        self.ui.cb_zones_class_field.clear()
        self.ui.cb_zones_count_field.clear()
        self.ui.cb_zones_class_field.addItems([' '] + fields)
        self.ui.cb_zones_count_field.addItems([' '] + fields)

        self.ui.cb_zones_proj.clear()
        self.ui.cb_zones_proj.addItem (shapefile_projection(filename))
        
        # update project if project exists
        if self.project is not None:
            self.project.zone_file = filename
            self.app.refreshPreview()
Example #8
0
 def nodeFromIndex(self, index):
     """ (override function) retrieve internal stored node from given index """
     logUICall.log("nodeFromIndx %s" % index, logUICall.DEBUG_L2)
     if index.isValid():
         return index.internalPointer()
     else:
         return self.rootItem
Example #9
0
File: wdg_data.py Project: gem/sidd
 def setPopField(self, pop_field):
     # update project if project exists
     if self.project is not None:
         logUICall.log('\tset population field %s ...' % pop_field, logUICall.DEBUG_L2)
         # update project if project exists
         if self.project is not None:
             self.project.pop_field = str(pop_field)            
Example #10
0
    def data(self, index, role):
        """ return data to be displayed in a cell """
        if role == Qt.DisplayRole:
            logUICall.log("retrieving data %s %s" % (index.column(), index.row()), logUICall.DEBUG_L2)
            if index.column() == 0:
                # first column, show value
                value = self.values[index.row()]
                if value is not None:
                    return QString(value)
                else:
                    return ""
            else:
                # second column, show weight
                return QString("%.2f" % self.weights[index.row()])
        elif role == Qt.ToolTipRole:
            # construct data for display in tooltip
            if index.column() == 0:
                value = self.values[index.row()]
                if value is not None:
                    return build_attribute_tooltip(self.valid_codes, self.parser.parse(value))
            else:
                return QVariant("")

        else:
            return QVariant()
Example #11
0
File: msdb_dao.py Project: gem/sidd
 def get_ms_in_region_type(self, region, ms_type):
     logUICall.log('get_ms_in_region_type %s %s' % (region, ms_type),
                   logUICall.DEBUG_L2)
     if not self.initialized:
         return []
     else:
         return self.get_list(self.sql['GET_MSNAME'], [region, ms_type])
Example #12
0
File: wdg_data.py Project: gem/sidd
 def setPopToBldg(self):
     if self.project is not None:
         pop_to_ratio = self.ui.txt_pop_bldg_ratio.text()
         logUICall.log('\tset population to building %s ...' % pop_to_ratio, logUICall.DEBUG_L2)
         # update project if project exists
         if self.project is not None:
             self.project.pop_to_bldg = float(pop_to_ratio)            
Example #13
0
File: wdg_data.py Project: gem/sidd
 def setZoneField(self, zone_field):        
     # update project if project exists
     if self.project is not None:
         logUICall.log('\tset zone field %s ...' % zone_field, logUICall.DEBUG_L2)
         # update project if project exists
         if self.project is not None:
             self.project.zone_field = str(zone_field)            
Example #14
0
 def data(self, index, role):
     """ return data to be displayed in a cell """
     if role == Qt.DisplayRole:
         logUICall.log('retrieving data %s %s' % (index.column(), index.row()),
                          logUICall.DEBUG_L2)
         if (index.column() == 0):
             # first column, show value
             value = self.values[index.row()]
             if value is not None:
                 return QString(value)
             else:
                 return ""
         else:
             # second column, show weight
             return QString('%.2f'% self.weights[index.row()])
     elif role == Qt.ToolTipRole:
         # construct data for display in tooltip            
         if (index.column() == 0):
             value = self.values[index.row()]            
             if value is not None:
                 return build_attribute_tooltip(self.valid_codes, self.parser.parse(value))
         else:
             return QVariant("")            
     
     else:
         return QVariant()
Example #15
0
File: msdb_dao.py Project: gem/sidd
 def __init__(self, dbpath):
     """ initialize """
     try:
         logUICall.log('opening ms db file %s ' % (dbpath), logUICall.INFO)
         self.conn = sqlite3.connect(dbpath)
         self.initialized = True
     except:
         self.initialized = False
Example #16
0
 def __init__(self, dbpath):
     """ initialize """
     try:
         logUICall.log('opening ms db file %s ' % (dbpath), logUICall.INFO)
         self.conn = sqlite3.connect(dbpath)
         self.initialized = True
     except:
         self.initialized = False
Example #17
0
 ###############################
 def set_project(self, project):
     ''' set project to preview. force refresh view on set'''        
     self._project = project
     if project is None:
         return
     self.refreshView()
     self.canvas.zoomToFullExtent()
Example #18
0
File: msdb_dao.py Project: gem/sidd
 def get_ms(self, region, ms_type, ms_name):
     logUICall.log('get_ms %s %s %s' % (region, ms_type, ms_name),
                   logUICall.DEBUG_L2)
     if not self.initialized:
         return []
     else:
         return self.get_list(self.sql['GET_MS'],
                              [region, ms_type, ms_name],
                              first_column=False)[0]
Example #19
0
 def set_project(self, project):
     ''' set project to preview. force refresh view on set'''
     self._project = project
     if project is None:
         return
     self.refreshView()
     self.canvas.zoomToFullExtent()
     logUICall.log("Project preview initialized sucessfully",
                   logUICall.INFO)
Example #20
0
 def save_ms(self, region, ms_name, source, date, datasource, quality, notes, ms_xml):
     logUICall.log('get_ms %s %s %s %s %s %s %s %s' % (region, ms_name, source,
                                                       date, datasource, quality,
                                                       notes, ms_xml[0:20]), 
                   logUICall.DEBUG_L2)
     rowid = int(self.get_list(self.sql['GET_MAX_MS_ID'])[0]) + 1
     return self.exec_sql(self.sql['INSERT_MS'], [rowid, region, ms_name,
                                                  source, date, datasource,
                                                  quality, notes, ms_xml], True)
Example #21
0
 def getSelectedCell(self):
     """ return selected cell in table_ms_level """
     selectedIndexes = self.ui.table_ms_level.selectedIndexes()
     if (len(selectedIndexes) <= 0):
         logUICall.log('Please select node first.', logUICall.WARNING)            
         return None       
     if not selectedIndexes[0].isValid():
         logUICall.log('Select node does not support this function.', logUICall.WARNING)
         return None
     return selectedIndexes[0]    
Example #22
0
 @pyqtSlot()
 def exportData(self):
     """ 
     event handler for btn_export
     - do export data 
     """
     export_path = str(self.ui.txt_export_select_path.text())
     if export_path == "":
         logUICall.log(get_ui_string("app.error.path.is.null"), logUICall.WARNING)
         return
Example #23
0
    @pyqtSlot(QPoint, QObject)
    def showInfo(self, point, mouseButton):
        """
        event handler for toolInfo
        @see QGIS tutorial for detail
        point-polygon search on currently selected layer  
        """
        cur_layer_name = self.ui.cb_layer_selector.currentText()
        if cur_layer_name.isEmpty():
            return
        try:
            cur_layer_idx = self.LAYER_NAMES.index(cur_layer_name)
            cur_layer = self.map_layers[cur_layer_idx]
            
            # if layer is not in same projection as map canvas
            # need to project query point
            if cur_layer.crs() != self.canvas.mapRenderer().destinationCrs():
                transform = QgsCoordinateTransform(self.canvas.mapRenderer().destinationCrs(), cur_layer.crs())
                point = transform.transform(point)
            
            # do query
            provider = cur_layer.dataProvider() 
            provider.rewind()
            feature = QgsFeature()
            colonIndexes = provider.attributeIndexes()
        
            # search using point as center of rectangle polygon
            search_buffer_x = self.canvas.extent().width() * self.SEARCH_BUFFER / self.canvas.width()
            search_buffer_y = self.canvas.extent().height() * self.SEARCH_BUFFER / self.canvas.height()
            provider.select(colonIndexes,
                            QgsRectangle(point.x()-search_buffer_x,
                                         point.y()-search_buffer_y,
                                         point.x()+search_buffer_x,
                                         point.y()+search_buffer_y),
                            True)
            # get selected and display in result detail dialog box 
            selected = []        
            while provider.nextFeature(feature):            
                # for polygons, only show geometry containing query point            
                if cur_layer.geometryType() == QGis.Polygon:                
                    if feature.geometry() is not None and not feature.geometry().contains (point):
                        continue
                selected.append(feature.attributeMap())

            if len(selected)>0:
                # display result if exists
                if cur_layer_idx == self.EXPOSURE:
                    self.dlgResultDetail.showExposureData(provider.fields(), selected)                    
                else:
                    self.dlgResultDetail.showInfoData(provider.fields(), selected)
                self.dlgResultDetail.exec_()
            else:
                logUICall.log(get_ui_string("widget.result.info.notfound"), logUICall.WARNING)
        except Exception as err:
            # point-in-polygon search is not critical, continue on error 
Example #24
0
File: msdb_dao.py Project: gem/sidd
 def exec_sql(self, sql, param, require_commit=False):
     try:
         c = self.conn.cursor()
         c.execute(sql, param)
         if require_commit:
             self.conn.commit()
         c.close()
     except Exception as e:
         logUICall.log(e, logUICall.ERROR)
         return False
     return True
Example #25
0
 def exportData(self):
     """ 
     event handler for btn_export
     - do export data 
     """
     export_path = str(self.ui.txt_export_select_path.text())
     if export_path == "":
         logUICall.log(get_ui_string("app.error.path.is.null"),
                       logUICall.WARNING)
         return
     self.app.exportResults(self.export_format, export_path)
Example #26
0
    def rowCount(self, parent):
        """ (override function) retrieve number of children from a given parent node """
        logUICall.log("rowCount %s" % (parent), logUICall.DEBUG_L2)
        if parent is None:
            return len(self.root_node.children)
        if not parent.isValid():  # invalid case treated same as root node
            return len(self.root_node.children)

        # find children
        item = parent.internalPointer()
        return len(item.children)
Example #27
0
File: msdb_dao.py Project: gem/sidd
 def save_ms(self, region, ms_name, source, date, datasource, quality,
             notes, ms_xml):
     logUICall.log(
         'get_ms %s %s %s %s %s %s %s %s' %
         (region, ms_name, source, date, datasource, quality, notes,
          ms_xml[0:20]), logUICall.DEBUG_L2)
     rowid = int(self.get_list(self.sql['GET_MAX_MS_ID'])[0]) + 1
     return self.exec_sql(self.sql['INSERT_MS'], [
         rowid, region, ms_name, source, date, datasource, quality, notes,
         ms_xml
     ], True)
Example #28
0
 def rowCount(self, parent):
     """ (override function) retrieve number of children from a given parent node """
     logUICall.log("rowCount %s" % (parent), logUICall.DEBUG_L2)
     if parent is None:
         return len(self.root_node.children)
     if not parent.isValid(): # invalid case treated same as root node
         return len(self.root_node.children)
     
     # find children
     item = parent.internalPointer()
     return len(item.children)
Example #29
0
 def exec_sql(self, sql, param, require_commit=False):
     try:
         c = self.conn.cursor()                        
         c.execute(sql, param)            
         if require_commit:
             self.conn.commit()
         c.close()
     except Exception as e:
         logUICall.log(e, logUICall.ERROR)
         return False
     return True           
Example #30
0
File: wdg_data.py Project: gem/sidd
 def resetUI(self, resetFP=False, resetZone=False, resetSurvey=False, resetPop=False, resetOutput=False):
     """
     helper method to reset appropriate UI elements
     """
     if resetFP:
         logUICall.log('\treset footprint inputs ...',logUICall.DEBUG_L2)
         self.ui.radio_fp_no_data.setChecked(True)
         self.ui.txt_fp_select_file.setEnabled(False)
         self.ui.txt_fp_select_file.setText('')
         self.ui.btn_fp_select_file.setEnabled(False)
         self.ui.cb_fp_story_field.setEnabled(False)
         self.ui.cb_fp_story_field.clear()
         self.ui.cb_fp_proj.setEnabled(False)
         self.ui.cb_fp_proj.clear()
     
     if resetZone:
         logUICall.log('\treset zones inputs  ...',logUICall.DEBUG_L2)
         self.ui.radio_zones_no_data.setChecked(True)
         self.ui.txt_zones_select_file.setEnabled(False)
         self.ui.txt_zones_select_file.setText('')
         self.ui.btn_zones_select_file.setEnabled(False)
         self.ui.cb_zones_class_field.setEnabled(False)
         self.ui.cb_zones_class_field.clear()
         self.ui.cb_zones_count_field.setEnabled(False)
         self.ui.cb_zones_count_field.clear()
         self.ui.cb_zones_proj.setEnabled(False)
         self.ui.cb_zones_proj.clear()
         self.ui.txt_pop_bldg_ratio.setEnabled(False)
         self.ui.txt_pop_bldg_ratio.clear()
     
     if resetSurvey:
         logUICall.log('\treset survey inputs ...',logUICall.DEBUG_L2)
         self.ui.radio_svy_no_data.setChecked(True)
         self.ui.txt_svy_select_file.setEnabled(False)
         self.ui.txt_svy_select_file.setText('')
         self.ui.btn_svy_select_file.setEnabled(False)
     
     if resetPop:
         logUICall.log('\treset popgrid inputs ...',logUICall.DEBUG_L2)
         self.ui.radio_pop_no_data.setChecked(True)
         self.ui.txt_pop_select_file.setEnabled(False)
         self.ui.txt_pop_select_file.setText('')
         self.ui.btn_pop_select_file.setEnabled(False)
         self.ui.cb_pop_pop_field.clear()
         self.ui.cb_pop_pop_field.setEnabled(False)
         self.ui.cb_pop_proj.clear()
         self.ui.cb_pop_proj.setEnabled(False)            
         
     if resetOutput:
         logUICall.log('\treset output inputs ...',logUICall.DEBUG_L2)
         self.ui.radio_aggr_zones.setChecked(False)
         self.ui.radio_aggr_grid.setChecked(False)
Example #31
0
 def setMSOption(self):
     """ adjust options when option radio button is selected """
     sender = self.sender()
     if sender.isChecked():
         if sender == self.ui.radioEmptyMS:
             self.build_option = self.BUILD_EMPTY
             self.attributeList.setEnabled(False)                
         elif sender == self.ui.radioBuildMS:
             self.build_option = self.BUILD_FROM_SURVEY
             self.attributeList.setEnabled(True)                
         else:
             logUICall.log('\tdo nothing. should not even be here',
                           logUICall.WARNING)
Example #32
0
 def setMSOption(self):
     """ adjust options when option radio button is selected """
     sender = self.sender()
     if sender.isChecked():
         if sender == self.ui.radioEmptyMS:
             self.build_option = self.BUILD_EMPTY
             self.attributeList.setEnabled(False)
         elif sender == self.ui.radioBuildMS:
             self.build_option = self.BUILD_FROM_SURVEY
             self.attributeList.setEnabled(True)
         else:
             logUICall.log('\tdo nothing. should not even be here',
                           logUICall.WARNING)
Example #33
0
File: wdg_data.py Project: gem/sidd
 def setSurveyDataType(self, checked=False):
     """ control UI based on survey data radio button selected """
     sender = self.sender()
     if sender.isChecked():            
         if sender == self.ui.radio_svy_no_data:
             logUICall.log('\tno survey data ...', logUICall.DEBUG_L2)
             # update UI
             self.resetUI(resetSurvey=True)
             
             # update project if project exists
             if self.project is not None:
                 self.project.survey_type = SurveyTypes.None
                 self.project.survey_file = ''
                 self.app.refreshPreview()
         elif sender == self.ui.radio_svy_complete:
             logUICall.log('\cwith complete survey data ...', logUICall.DEBUG_L2)
             # update UI
             self.ui.txt_svy_select_file.setEnabled(True)
             self.ui.btn_svy_select_file.setEnabled(True)
             
             # update project if project exists
             if self.project is not None:
                 self.project.survey_type = SurveyTypes.CompleteSurvey
         elif sender == self.ui.radio_svy_sampled:
             logUICall.log('\twith sampled survey data ...', logUICall.DEBUG_L2)
             # update UI
             self.ui.txt_svy_select_file.setEnabled(True)
             self.ui.btn_svy_select_file.setEnabled(True)
             
             # update project if project exists
             if self.project is not None:
                 self.project.survey_type = SurveyTypes.SampledSurvey
         else:
             logUICall.log('\tdo nothing. should not even be here',
                           logUICall.WARNING)
Example #34
0
File: msdb_dao.py Project: gem/sidd
 def get_list(self, sql, param=[], first_column=True):
     results = []
     try:
         c = self.conn.cursor()
         c.execute(sql, param)
         for row in c:
             if first_column:
                 results.append(row[0])
             else:
                 results.append(row)
         c.close()
     except Exception as e:
         logUICall.log(e, logUICall.ERROR)
     return results
Example #35
0
 def get_list(self, sql, param=[], first_column=True):
     results = []
     try:
         c = self.conn.cursor()                        
         c.execute(sql, param)            
         for row in c:     
             if first_column:
                 results.append(row[0])
             else:
                 results.append(row)
         c.close()
     except Exception as e:
         logUICall.log(e, logUICall.ERROR)
     return results   
Example #36
0
 def changeTab(self):
     """
     event handler for menu item in menu 
     - switch view to tab according to menu item pushed 
     """
     sender = self.sender()
     if sender == self.ui.actionData_Input:
         self.showTab(self.TAB_DATA)
     elif sender == self.ui.actionMapping_Schemes:
         self.showTab(self.TAB_MS)            
     elif sender == self.ui.actionResult:
         self.showTab(self.TAB_RESULT)
     else:
         logUICall.log('\tdo nothing. should not even be here', logUICall.WARNING)
Example #37
0
 def rowCount(self, parent):
     """ (override function) retrieve number of children from a given parent node """
     logUICall.log("rowCount %s" % (parent), logUICall.DEBUG_L2)
     #if parent.column() > 0: # there is only one column
     #    return 0
     if not parent.isValid(): # invalid case treated same as root node
         return len(self.zones)
     
     # find children
     parentItem = parent.internalPointer()        
     if parentItem == self.rootNode:
         # root node, return number of zones
         logUICall.log("\tparent is root", logUICall.DEBUG_L2)
         return len(self.zones)
     elif isinstance(parentItem, MappingSchemeZone):
         # zone node (first level under root node)
         # get top level from statistic tree
         logUICall.log("\tparent is zone: %s" % (parentItem.name), logUICall.DEBUG_L2)
         stats = self.ms.get_assignment(parentItem)
         return len(stats.get_tree().children)
     else:
         # statistic node
         # get appropriate number of children for given node
         logUICall.log("\tparent is node: %s" % (parentItem.value), logUICall.DEBUG_L2)
         return len(parentItem.children)
Example #38
0
    def rowCount(self, parent):
        """ (override function) retrieve number of children from a given parent node """
        logUICall.log("rowCount %s" % (parent), logUICall.DEBUG_L2)
        #if parent.column() > 0: # there is only one column
        #    return 0
        if not parent.isValid():  # invalid case treated same as root node
            return len(self.zones)

        # find children
        parentItem = parent.internalPointer()
        if parentItem == self.rootNode:
            # root node, return number of zones
            logUICall.log("\tparent is root", logUICall.DEBUG_L2)
            return len(self.zones)
        elif isinstance(parentItem, MappingSchemeZone):
            # zone node (first level under root node)
            # get top level from statistic tree
            logUICall.log("\tparent is zone: %s" % (parentItem.name),
                          logUICall.DEBUG_L2)
            stats = self.ms.get_assignment(parentItem)
            return len(stats.get_tree().children)
        else:
            # statistic node
            # get appropriate number of children for given node
            logUICall.log("\tparent is node: %s" % (parentItem.value),
                          logUICall.DEBUG_L2)
            return len(parentItem.children)
Example #39
0
 def get_regions(self):
     logUICall.log('get_regions', logUICall.DEBUG_L2)
     undefined_region = 'Undefined-Region'
     if not self.initialized:
         return []
     else:
         regions = self.get_list( self.sql['GET_REGIONS'] )
         # add undefined region to allow user to store 
         # mapping schemes not associated with any region
         try:
             regions.remove(undefined_region)                
         except:
             pass
         regions.insert(0, undefined_region)
         return regions
Example #40
0
File: msdb_dao.py Project: gem/sidd
 def get_regions(self):
     logUICall.log('get_regions', logUICall.DEBUG_L2)
     undefined_region = 'Undefined-Region'
     if not self.initialized:
         return []
     else:
         regions = self.get_list(self.sql['GET_REGIONS'])
         # add undefined region to allow user to store
         # mapping schemes not associated with any region
         try:
             regions.remove(undefined_region)
         except:
             pass
         regions.insert(0, undefined_region)
         return regions
Example #41
0
 def changeTab(self):
     """
     event handler for menu item in menu 
     - switch view to tab according to menu item pushed 
     """
     sender = self.sender()
     if sender == self.ui.actionData_Input:
         self.showTab(self.TAB_DATA)
     elif sender == self.ui.actionMapping_Schemes:
         self.showTab(self.TAB_MS)
     elif sender == self.ui.actionResult:
         self.showTab(self.TAB_RESULT)
     else:
         logUICall.log('\tdo nothing. should not even be here',
                       logUICall.WARNING)
Example #42
0
File: wdg_data.py Project: gem/sidd
 def setSurveyFile(self, filename):
     """ 
     do following with given path to survey file
     1. show path 
     2. set path in project
     3. additional updates in other tabs
     """
     # update UI
     logUICall.log('\tset survey file to %s' % filename,logUICall.DEBUG_L2)
     self.ui.txt_svy_select_file.setText(filename)
     
     # update project if project exists
     if self.project is not None:
         self.project.survey_file = filename
         self.project.survey = None
         self.app.refreshPreview()
Example #43
0
 def parent(self, index):
     """ (override function) find parent for given node """        
     logUICall.log("parent %s" % (index), logUICall.DEBUG_L2)
     if index is None: # invalid node, no parent
         return QModelIndex()        
     if not index.isValid(): # invalid node, no parent
         return QModelIndex()
     
     # find parent of given node
     childItem = index.internalPointer()
     if childItem is None or childItem.parent is None:
         # root node, no parent
         return QModelIndex()
     else:
         row_idx = childItem.parent.children.index(childItem)
         return self.createIndex(row_idx, 0, childItem.parent)
Example #44
0
    def parent(self, index):
        """ (override function) find parent for given node """
        logUICall.log("parent %s" % (index), logUICall.DEBUG_L2)
        if index is None:  # invalid node, no parent
            return QModelIndex()
        if not index.isValid():  # invalid node, no parent
            return QModelIndex()

        # find parent of given node
        childItem = index.internalPointer()
        if childItem is None or childItem.parent is None:
            # root node, no parent
            return QModelIndex()
        else:
            row_idx = childItem.parent.children.index(childItem)
            return self.createIndex(row_idx, 0, childItem.parent)
Example #45
0
File: wdg_mod.py Project: gem/sidd
 def deleteModifier(self):
     """ delete selected modifier from mapping scheme. update table view """
     mod = self.getSelectedModifier()
     # make sure there is mod selected
     if mod is None:
         logUICall.log(get_ui_string("widget.ms.warning.node.required"), logUICall.WARNING)
         return
     # confirm delete 
     answer = QMessageBox.warning(self,
                                  get_ui_string("app.confirm.title"),
                                  get_ui_string("widget.mod.warning.delete"),
                                  QMessageBox.Yes | QMessageBox.No)
     if answer == QMessageBox.Yes:
         # see MSTableModel about data in mod variable
         modidx, src_node = mod[4], mod[6]
         if src_node is not None:
             # remove modifier
             src_node.remove_modifier(modidx)
         self.app.visualizeMappingScheme(self.ms)
Example #46
0
    def parent(self, index):
        """ (override function) find parent for given node """
        logUICall.log("parent %s" % (index), logUICall.DEBUG_L2)
        if not index.isValid():  # invalid node, no parent
            return QModelIndex()

        # find parent of given node
        childItem = index.internalPointer()

        if childItem == self.rootNode:
            # root node, no parent
            logUICall.log("\tchild is root. invalid", logUICall.DEBUG_L2)
            return QModelIndex()
        elif isinstance(childItem, MappingSchemeZone):
            # zone node, parent is root
            logUICall.log("\tchild is zone. parent is root",
                          logUICall.DEBUG_L2)
            return self.createIndex(0, 0, self.rootNode)

        elif isinstance(childItem, StatisticNode):
            # statistic node
            # get node's parent from node's internal pointer
            # if parent node is top node is statistic tree
            # then replace that zone associated with the statistic
            # (see MappingScheme definition for relationship of zone and statistic)
            parentItem = childItem.parent
            if (parentItem.level == 0):
                # top level, get zone
                logUICall.log("\tchild is node level 1. parent is zone",
                              logUICall.DEBUG_L2)
                for idx, zone in enumerate(self.zones):
                    if zone.name == parentItem.value:
                        return self.createIndex(idx, 0, zone)
                return QModelIndex()
            else:
                # not top level, get node's parent
                logUICall.log("\tchild is node below level 1. parent is node",
                              logUICall.DEBUG_L2)
                row_idx = parentItem.parent.children.index(parentItem)
                return self.createIndex(row_idx, 0, parentItem)
        else:
            return QModelIndex()
Example #47
0
 def deleteModifier(self):
     """ delete selected modifier from mapping scheme. update table view """
     mod = self.getSelectedModifier()
     # make sure there is mod selected
     if mod is None:
         logUICall.log(get_ui_string("widget.ms.warning.node.required"),
                       logUICall.WARNING)
         return
     # confirm delete
     answer = QMessageBox.warning(
         self, get_ui_string("app.confirm.title"),
         get_ui_string("widget.mod.warning.delete"),
         QMessageBox.Yes | QMessageBox.No)
     if answer == QMessageBox.Yes:
         # see MSTableModel about data in mod variable
         modidx, src_node = mod[4], mod[6]
         if src_node is not None:
             # remove modifier
             src_node.remove_modifier(modidx)
         self.app.visualizeMappingScheme(self.ms)
Example #48
0
    def data(self, index, role):
        """
        (override function) retrieve appropriate data to show in UI given a index
        currently only DisplayRole is implemented
        """
        logUICall.log("data %s" % (index), logUICall.DEBUG_L2)
        if index is None:  # invalid case, nothing to display
            return self.root_node
        if not index.isValid():  # invalid case, nothing to display
            return self.root_node

        item = index.internalPointer()
        if role == Qt.DisplayRole:
            # construct data to show in tree UI
            return '%s' % (item.value)
        elif role == Qt.CheckStateRole:
            return item.checked
        elif role == Qt.UserRole:
            return item
        else:
            return None
Example #49
0
 def data(self, index, role):
     """
     (override function) retrieve appropriate data to show in UI given a index
     currently only DisplayRole is implemented
     """
     logUICall.log("data %s" % (index), logUICall.DEBUG_L2)
     if index is None:  # invalid case, nothing to display
         return self.root_node
     if not index.isValid():  # invalid case, nothing to display
         return self.root_node
     
     item = index.internalPointer()
     if role == Qt.DisplayRole:
         # construct data to show in tree UI
         return '%s' % (item.value)
     elif role == Qt.CheckStateRole:
         return item.checked
     elif role == Qt.UserRole:
         return item
     else:
         return None
Example #50
0
    def setPopGridType(self, checked=False):
        """ control UI based on zone data radio button selected """
        sender = self.sender()
        if sender.isChecked():
            if sender == self.ui.radio_pop_no_data:
                logUICall.log('\tno zone data ...', logUICall.DEBUG_L2)
                # update UI
                self.resetUI(resetPop=True)
                
                # update project if project exists
                if self.project is not None:
                    self.project.popgrid_type = PopGridTypes.None
                    self.project.popgrid_file = ''
                    self.project.pop_field = ''
                    self.project.pop_to_bldg = ''
                    self.app.refreshPreview()
                    
            elif sender == self.ui.radio_pop_grid:
                logUICall.log('\tpopulation grid...', logUICall.DEBUG_L2)
                # update UI
                self.ui.txt_pop_select_file.setEnabled(True)
                self.ui.btn_pop_select_file.setEnabled(True)
                self.ui.cb_pop_pop_field.setEnabled(True)
                self.ui.cb_pop_proj.setEnabled(True)
                self.ui.txt_pop_bldg_ratio.setEnabled(True)

                # update project if project exists
                if self.project is not None:
                    self.project.popgrid_type = PopGridTypes.Grid
            else:
                logUICall.log('\tdo nothing. should not even be here',
                              logUICall.WARNING)