Ejemplo n.º 1
0
    def add_custom_menu_items_for_node(self, node, menu):
        if node.get('type') == 'scenario':
            node_executable = (node.get('executable') == 'True')
            menu.addAction(self.actExecutable)

            # Workaround: disabled items do not show check marks
            if node.get('inherited') is None:
                self.actExecutable.setEnabled(True)
                self.actExecutable.setText('Executable')
                self.actExecutable.setChecked(node_executable)
            else:
                self.actExecutable.setDisabled(True)
                self.actExecutable.setText(
                    'Executable: %s' % ('Yes' if node_executable else 'No'))

            if node_executable:
                menu.addAction(self.actRunScenario)
            if node.find('models_to_run') is None:
                #if there isn't a child node models_to_run
                menu.addAction(self.actModelsToRun)
        elif node.get('type') in ['selectable', 'model_choice']:
            menu.addAction(self.actMoveNodeUp)
            menu.addAction(self.actMoveNodeDown)
        elif node.tag == 'models_to_run':  # special case of a selectable list
            models_menu = QMenu(menu)
            models_menu.setTitle('Add model to run')
            models_menu.setIcon(IconLibrary.icon('add'))
            available_model_names = get_model_names(self.project)
            for model_name in available_model_names:
                cb = lambda x=model_name, y=self.selected_index(
                ): self.addModel(y, x)
                action = self.create_action('model', model_name, cb)
                models_menu.addAction(action)
            menu.addMenu(models_menu)
    def process_custom_menu(self, point):
        ''' See XmlController for documentation '''
        item = self.select_item_at(point)
        if not item:
            return
        menu = QMenu()
        node = item.node

        if node.get('executable') == 'True':
            menu.addAction(self.actRunScenario)
        elif node.get('type') in ['selectable', 'model_choice']:
            menu.addAction(self.actMoveNodeUp)
            menu.addAction(self.actMoveNodeDown)
        elif node.tag == 'models_to_run': # special case of a selectable list
            models_menu = QMenu(menu)
            models_menu.setTitle('Add model to run')
            models_menu.setIcon(IconLibrary.icon('add'))
            available_model_names = get_model_names(self.project)
            for model_name in available_model_names:
                cb = lambda x = model_name, y = self.selected_index(): self.addModel(y, x)
                action = self.create_action('model', model_name, cb)
                models_menu.addAction(action)
            menu.addMenu(models_menu)

        self.add_default_menu_items_for_node(node, menu)

        if not menu.isEmpty():
            menu.exec_(QCursor.pos())
Ejemplo n.º 3
0
    def process_custom_menu(self, point):
        ''' See XmlController for documentation '''
        item = self.select_item_at(point)
        if not item:
            return
        menu = QMenu()
        node = item.node

        if node.get('executable') == 'True':
            menu.addAction(self.actRunScenario)
        elif node.get('type') in ['selectable', 'model_choice']:
            menu.addAction(self.actMoveNodeUp)
            menu.addAction(self.actMoveNodeDown)
        elif node.tag == 'models_to_run':  # special case of a selectable list
            models_menu = QMenu(menu)
            models_menu.setTitle('Add model to run')
            models_menu.setIcon(IconLibrary.icon('add'))
            available_model_names = get_model_names(self.project)
            for model_name in available_model_names:
                cb = lambda x=model_name, y=self.selected_index(
                ): self.addModel(y, x)
                action = self.create_action('model', model_name, cb)
                models_menu.addAction(action)
            menu.addMenu(models_menu)

        self.add_default_menu_items_for_node(node, menu)

        if not menu.isEmpty():
            menu.exec_(QCursor.pos())
 def add_custom_menu_items_for_node(self, node, menu):
     if node.get('type') == 'scenario':
         node_executable = (node.get('executable') == 'True')
         menu.addAction(self.actExecutable)
         
         # Workaround: disabled items do not show check marks
         if node.get('inherited') is None:
             self.actExecutable.setEnabled(True)
             self.actExecutable.setText('Executable')
             self.actExecutable.setChecked(node_executable)
         else:
             self.actExecutable.setDisabled(True)
             self.actExecutable.setText('Executable: %s' % ('Yes' if node_executable else 'No'))
             
         if node_executable:
             menu.addAction(self.actRunScenario)
         if node.find('models_to_run') is None:  
             #if there isn't a child node models_to_run
             menu.addAction(self.actModelsToRun)                
     elif node.get('type') in ['selectable', 'model_choice']:
         menu.addAction(self.actMoveNodeUp)
         menu.addAction(self.actMoveNodeDown)
     elif node.tag == 'models_to_run': # special case of a selectable list
         models_menu = QMenu(menu)
         models_menu.setTitle('Add model to run')
         models_menu.setIcon(IconLibrary.icon('add'))
         available_model_names = get_model_names(self.project)
         for model_name in available_model_names:
             cb = lambda x = model_name, y = self.selected_index(): self.addModel(y, x)
             action = self.create_action('model', model_name, cb)
             models_menu.addAction(action)
         menu.addMenu(models_menu)
 def addModel(self, models_to_run_list_index, model_name):
     '''
     Add a model to a models_to_run list.
     @param scenario_index (QModelIndex): index of the list to insert under
     @param models_name (String): name of model to add
     '''
     unique_name = get_unique_name(model_name, get_model_names(self.project))
     attribs = {'type': 'selectable', 'return_value': model_name, 'name': unique_name}
     model_node = Element('selectable', attribs)
     model_node.text = 'True'
     last_row_num = self.model.rowCount(models_to_run_list_index)
     self.model.insertRow(last_row_num, models_to_run_list_index, model_node)
     # Validate models to run
     update_models_to_run_lists()
 def validate_models_to_run(self):
     '''
     Goes through all scenarios in the XmlController and makes sure that
     the models in their 'models_to_run' list actually is present in the
     project.
     '''
     model_names = get_model_names(self.project)
     self.missing_models = set()
     scenarios_nodes = self._root_node.findall('scenario')
     for scenario_node in scenarios_nodes:
         models_to_run_lists = [node for node in scenario_node.findall('selectable') if
                                node.get('name') == 'models_to_run']
         # validate all models to run lists of this scenario
         for mtr_list in models_to_run_lists:
             for model_name in mtr_list:
                 if not model_name in model_names:
                     self.missing_models.add(model_name)
Ejemplo n.º 7
0
 def validate_models_to_run(self):
     '''
     Goes through all scenarios in the XmlController and makes sure that
     the models in their 'models_to_run' list actually is present in the
     project.
     '''
     model_names = get_model_names(self.project)
     self.missing_models = set()
     scenarios_nodes = self._root_node.findall('scenario')
     for scenario_node in scenarios_nodes:
         models_to_run_lists = [
             node for node in scenario_node.findall('selectable')
             if node.get('name') == 'models_to_run'
         ]
         # validate all models to run lists of this scenario
         for mtr_list in models_to_run_lists:
             for model_name in mtr_list:
                 if not model_name in model_names:
                     self.missing_models.add(model_name)
Ejemplo n.º 8
0
 def addModel(self, models_to_run_list_index, model_name):
     '''
     Add a model to a models_to_run list.
     @param scenario_index (QModelIndex): index of the list to insert under
     @param models_name (String): name of model to add
     '''
     unique_name = get_unique_name(model_name,
                                   get_model_names(self.project))
     attribs = {
         'type': 'selectable',
         'return_value': model_name,
         'name': unique_name
     }
     model_node = Element('selectable', attribs)
     model_node.text = 'True'
     last_row_num = self.model.rowCount(models_to_run_list_index)
     self.model.insertRow(last_row_num, models_to_run_list_index,
                          model_node)
     # Validate models to run
     update_models_to_run_lists()