Changeset 3327

Show
Ignore:
Timestamp:
05/11/08 23:44:42 (2 months ago)
Author:
travis
Message:

(travis) hooking up logic for indicator group functionality

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/opus_gui/config/resultsmanager/opusxmlaction_results.py

    r3321 r3327  
    2121from opus_gui.config.managerbase.cloneinherited import CloneInheritedGui 
    2222from opus_gui.config.managerbase.clonenode import CloneNodeGui 
     23from opus_gui.results.xml_helper_methods import elementsByAttributeValue, get_child_values 
    2324 
    2425class OpusXMLAction_Results(object): 
     
    8586 
    8687 
    87         self.actViewDocumentation = QAction(self.applicationIcon, "View documentation", self.xmlTreeObject.parent) 
    88         QObject.connect(self.actViewDocumentation, SIGNAL("triggered()"), self.viewDocumentation) 
     88#        self.actViewDocumentation = QAction(self.applicationIcon, "View documentation", self.xmlTreeObject.parent) 
     89#        QObject.connect(self.actViewDocumentation, SIGNAL("triggered()"), self.viewDocumentation) 
    8990 
    9091        self.actRemoveNode = QAction(self.removeIcon, 
     
    159160        model = self.currentIndex.model() 
    160161        document = model.domDocument 
    161         name = 'untitled indicator group' 
     162        name = 'INDICATOR_GROUP_NAME' 
    162163 
    163164        newNode = model.create_node(document = document,  
     
    165166                                    type = 'indicator_group',  
    166167                                    value = '') 
    167  
    168168        model.insertRow(0, 
    169169                self.currentIndex, 
     
    173173        model.emit(SIGNAL("layoutChanged()")) 
    174174 
     175         
     176    def beforeAddIndicatorToGroupShown(self): 
     177        print "AddIndicatorToGroup about to be shown" 
     178         
     179        domDocument = self.xmlTreeObject.parent.toolboxStuff.doc 
     180        node_list = elementsByAttributeValue(domDocument = domDocument,  
     181                                              attribute = 'type',  
     182                                              value = 'indicator') 
     183         
     184        self.indicator_group_menu.clear() 
     185        for element, node in node_list: 
     186            indicator = QString(element.nodeName()) 
     187            act_indicator = QAction(self.acceptIcon,  
     188                                    element.nodeName(), 
     189                                    self.indicator_group_menu) 
     190            callback = lambda indicator=indicator: self.addIndicatorToGroup(indicator) 
     191            QObject.connect(act_indicator, SIGNAL("triggered()"), callback)  
     192            self.indicator_group_menu.addAction(act_indicator) 
    175193             
     194    def addIndicatorToGroup(self, indicator): 
     195        print "adding indicator to group..." 
     196        print "addIndicatorToGroup pressed with column = %s and item = %s" % \ 
     197              (self.currentColumn, self.currentIndex.internalPointer().node().toElement().tagName()) 
     198        model = self.currentIndex.model() 
     199        document = model.domDocument 
     200 
     201        newNode = model.create_node(document = document,  
     202                                    name = indicator,  
     203                                    type = 'indicator_group_member',  
     204                                    value = '') 
     205        model.insertRow(0, 
     206                self.currentIndex, 
     207                newNode) 
     208 
     209        general_node = document.elementsByTagName(QString('general')).item(0) 
     210        available_datasets = get_child_values(parent = general_node,  
     211                                 child_names = ['available_datasets']) 
     212         
     213        datasets = '|'.join(str(available_datasets['available_datasets'])[1:-1].split("','")) 
     214 
     215        visualizations = [ 
     216            'Map (per indicator per year)', 
     217            'Chart (per indicator, spans years)', 
     218            'Table (per indicator, spans years)', 
     219            'Table (per year, spans indicators)'] 
     220        visualizations = '|'.join(visualizations) 
     221             
     222        visualization_node = model.create_node(document = document,  
     223                                    name = 'visualization_type',  
     224                                    type = 'string',  
     225                                    value = '', 
     226                                    choices = visualizations)  
     227                
     228        dataset_node = model.create_node(document = document,  
     229                                    name = 'dataset_name',  
     230                                    type = 'string',  
     231                                    value = '', 
     232                                    choices = datasets) 
     233 
     234        parent = self.currentIndex.parent()         
     235        child_index = model.findElementIndexByName(indicator, parent)[0] 
     236        if child_index.isValid(): 
     237            for node in [dataset_node, visualization_node]: 
     238                model.insertRow(0, 
     239                                child_index, 
     240                                node) 
     241        else: 
     242            print "No valid node was found..." 
     243             
     244        self.currentIndex.model().markAsDirty()         
     245        model.emit(SIGNAL("layoutChanged()")) 
     246 
     247    def beforeRunIndicatorGroupShown(self): 
     248        print "AddIndicatorToGroup about to be shown" 
     249         
     250        domDocument = self.xmlTreeObject.parent.toolboxStuff.doc 
     251        node_list = elementsByAttributeValue(domDocument = domDocument,  
     252                                              attribute = 'type',  
     253                                              value = 'source_data') 
     254         
     255        self.run_indicator_group_menu.clear() 
     256        for element, node in node_list: 
     257            simulation_run = QString(element.nodeName()) 
     258            act_simulation_run = QAction(self.acceptIcon,  
     259                                    element.nodeName(), 
     260                                    self.run_indicator_group_menu) 
     261            callback = lambda simulation_run=simulation_run: self.indicatorGroupRun(simulation_run) 
     262            QObject.connect(act_simulation_run, SIGNAL("triggered()"), callback)  
     263            self.run_indicator_group_menu.addAction(act_simulation_run) 
     264                 
     265    def indicatorGroupRun(self, simulation_run): 
     266        print "indicatorGroupRun pressed with column = %s and item = %s" % \ 
     267              (self.currentColumn, self.currentIndex.internalPointer().node().toElement().tagName()) 
     268        if not self.xmlTreeObject.model.dirty: 
     269            self.xmlTreeObject.parent.resultManagerStuff.addRunIndicatorGroupForm( 
     270                selected_item = self.currentIndex.internalPointer().node().toElement().tagName(), 
     271                simulation_run = simulation_run) 
     272        else: 
     273            # Prompt the user to save... 
     274            QMessageBox.warning(self.xmlTreeObject.parent, 
     275                                "Warning", 
     276                                "Please save changes to project before generating results") 
     277                       
    176278    def generateResults(self): 
    177279        print "generateResults pressed with column = %s and item = %s" % \ 
     
    294396                    self.menu.addAction(self.actAddNewIndicatorGroup) 
    295397                elif domElement.attribute(QString("type")) == QString("indicator"): 
    296                     self.menu.addAction(self.actViewDocumentation) 
     398#                    self.menu.addAction(self.actViewDocumentation) 
    297399                    self.menu.addAction(self.actGenerateResults) 
    298400                elif domElement.attribute(QString("type")) == QString("indicator_result"): 
     
    306408                    visualization_menu.addAction(self.actViewResultAsAdvanced) 
    307409                    self.menu.addMenu(visualization_menu) 
    308  
     410                     
     411                elif domElement.attribute(QString("type")) == QString("indicator_group"): 
     412                    self._build_indicator_group_menu() 
     413                     
     414                     
    309415                if self.menu: 
    310416                    # Last minute chance to add items that all menues should have 
     
    330436        return 
    331437 
    332  
     438    def _build_indicator_group_menu(self): 
     439        #needs to be called when indicator_group right clicked on... 
     440        self.indicator_group_menu = QMenu(self.xmlTreeObject.parent) 
     441        self.indicator_group_menu.setTitle(QString("Add indicator to group...")) 
     442        QObject.connect(self.indicator_group_menu, SIGNAL('aboutToShow()'), self.beforeAddIndicatorToGroupShown) 
     443        self.menu.addMenu(self.indicator_group_menu) 
     444 
     445         
     446        self.run_indicator_group_menu = QMenu(self.xmlTreeObject.parent) 
     447        self.run_indicator_group_menu.setTitle(QString('Run indicator group on...')) 
     448        QObject.connect(self.run_indicator_group_menu, SIGNAL('aboutToShow()'), self.beforeRunIndicatorGroupShown) 
     449         
     450        self.menu.addMenu(self.run_indicator_group_menu)