Exemplo n.º 1
0
    def on_buttonBox_accepted(self):

        self.buttonBox.setEnabled(False)

        start_year = int(self.co_start_year.currentText())
        end_year = int(self.co_end_year.currentText())
        increment = int(self.co_every_year.currentText())

        years = range(start_year, end_year + 1, increment)
        # (visualization_type, dataset_name, vals)
        visualizations = get_batch_configuration(project = self.project,
                                                 batch_name = self.batch_name)
        self.batch_processor.set_data(
            visualizations = visualizations,
            source_data_name = self.run_name,
            years = years)

        self.runThread = OpusGuiThread(
                              parentThread = self.mainwindow,
                              parentGuiElement = self,
                              thread_object = self.batch_processor)

        # Use this signal from the thread if it is capable of producing its own status signal
        QObject.connect(self.runThread, SIGNAL("runFinished(PyQt_PyObject)"),
                        self.runFinishedFromThread)
        QObject.connect(self.runThread, SIGNAL("runError(PyQt_PyObject)"),
                        self.runErrorFromThread)

        self.runThread.start()
Exemplo n.º 2
0
    def on_indicatorBox(self):
        indicator_name = str(self.diagnostic_indicator_name.currentText())
        dataset_name = self.diagnostic_dataset_name.currentText()
        indicator_type = str(self.diagnostic_indicator_type.currentText())
        year = str(self.diagnostic_year.currentText())
        if year == '': return
        year = int(year)

        if dataset_name not in self.spatial_datasets and indicator_type == 'map':
            MessageBox.warning(
                mainwindow=self.mainwindow,
                text="That indicator cannot be visualized as a map.",
                detailed_text=(
                    'The dataset %s is either not spatial or cannot be '
                    'rendered as a grid. If the latter, please try '
                    'exporting to an external GIS tool.' % dataset_name))
            return

        cache_directory = self.model.config['cache_directory']
        params = {'indicators': [indicator_name]}
        if indicator_type == 'table':
            indicator_type = 'tab'
            params['output_type'] = 'tab'
        # JLM > commented this out for when implemented animations
#        else:
#            indicator_type = 'mapnik_map'

        visualizations = [(indicator_type, str(dataset_name), params)]

        self.batch_processor = BatchProcessor(self.project)

        self.batch_processor.guiElement = self

        self.batch_processor.set_data(visualizations=visualizations,
                                      source_data_name=self.model.run_name,
                                      years=[year, year],
                                      cache_directory=cache_directory)

        self.diagnosticThread = OpusGuiThread(
            parentThread=self.mainwindow,
            parentGuiElement=self,
            thread_object=self.batch_processor)

        # Use this signal from the thread if it is capable of producing its own status signal
        QObject.connect(self.diagnosticThread,
                        SIGNAL("runFinished(PyQt_PyObject)"),
                        self.visualizationsCreated)
        QObject.connect(self.diagnosticThread,
                        SIGNAL("runError(PyQt_PyObject)"),
                        self.runErrorFromThread)

        self.diagnosticThread.start()
Exemplo n.º 3
0
    def _run_finished(self, success):
        key = self.running_key
        self.running_key = None

        size = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.tabwidget_visualizations.setSizePolicy(size)

        name = '%s/%s/%s' % key
        new_tab = QTabWidget(self.tabwidget_visualizations)
        self.tabwidget_visualizations.addTab(new_tab, name)

        map_widget = None
        tab_widget = None
        for (visualization_type,
             visualizations) in self.batch_processor.get_visualizations():
            if len(visualizations) > 0:
                if visualization_type == 'mapnik_map':
                    viz = visualizations[0]
                    map_widget = ViewImageForm(viz, new_tab)
                    map_widget.setSizePolicy(size)
                elif visualization_type == 'mapnik_animated_map':
                    viz = visualizations[0]
                    map_widget = ViewAnimationForm(viz, new_tab)
                    map_widget.setSizePolicy(size)
                elif visualization_type == 'table_per_year':
                    viz = visualizations[0]
                    tab_widget = ViewTableForm(viz, new_tab)
                    tab_widget.setSizePolicy(size)
#            else:
#                map_widget = self.tabMap
#                tab_widget = self.tabTable

#        if not map_widget or not tab_widget: return

#        self.tabMap = map_widget
#        self.tabTable = tab_widget

        if tab_widget:
            new_tab.addTab(tab_widget, "Table")

        if map_widget:
            new_tab.addTab(map_widget, "Map")

        self.already_browsed[key] = (tab_widget, map_widget)

        #        self.lblViewIndicator.setText(QString(key[1]))
        #        self.lblViewRun.setText(QString(key[0]))
        #        self.lblViewYear.setText(QString(repr(key[2])))

        swap = self.queued_results is not None and self.queued_results[
            0] == 'swap'

        if self.queued_results is not None and not swap:
            self.running_key = self.queued_results[0]

            logger.log_note(
                'Generating queued results for %s on run %s for year %i' %
                self.running_key)
            self.batch_processor = self.queued_results[1]
            self.queued_results = None

            runThread = OpusGuiThread(parentThread=get_mainwindow_instance(),
                                      parentGuiElement=self,
                                      thread_object=self.batch_processor)

            # Use this signal from the thread if it is capable of producing its own status signal
            QObject.connect(runThread, SIGNAL("runFinished(PyQt_PyObject)"),
                            self._run_finished)
            QObject.connect(runThread, SIGNAL("runError(PyQt_PyObject)"),
                            self._run_error)
            runThread.start()
        else:
            #            if swap:
            #                (map_widget, tab_widget) = self.queued_results[1]
            #
            ##                self.swap_visualizations(map_widget, tab_widget)
            #                name = '%s/%s/%s'%key
            #        #        self.swap_visualizations(map_widget, tab_widget)
            #                self.add_visualization(map_widget = map_widget, tab_widget = tab_widget, name = name)

            self.queued_results = None

            self.generating_results = False
            self.pb_generate_results.setText('Results Generated')
Exemplo n.º 4
0
    def on_pb_generate_results_clicked(self):
        run_name = self.current_run
        indicator_name = self.current_indicator
        indicator_dataset = self.current_indicator_dataset
        start_year = int(self.current_year)
        end_year = start_year

        if run_name is None or indicator_name is None or start_year is None:
            return

        key = (run_name, indicator_name, start_year)

        if key in self.already_browsed:
            if not self.generating_results:
                (tab_widget, map_widget) = self.already_browsed[key]
                #                self.swap_visualizations(map_widget, tab_widget)
                self.pb_generate_results.setText('Results Generated')
            else:
                self.queued_results = ('swap', (map_widget, tab_widget))
            return

        self.pb_generate_results.setEnabled(False)
        self.pb_generate_results.setText('Generating Results...')

        indicator_nodes = get_available_indicator_nodes(self.project)

        dataset = None
        for indicator_node in indicator_nodes:
            ind_dataset, name = get_variable_dataset_and_name(indicator_node)
            if name == indicator_name and ind_dataset == indicator_dataset:
                dataset = ind_dataset
                break

        if dataset is None:
            raise Exception('Could not find dataset for indicator %s' %
                            indicator_name)

        table_params = {
            'name': None,
            'output_type': 'tab',
            'indicators': [indicator_name],
        }

        map_params = {'name': None, 'indicators': [indicator_name]}

        visualizations = [('table_per_year', dataset, table_params),
                          ('mapnik_map', dataset, map_params)]

        batch_processor = BatchProcessor(self.project)
        batch_processor.guiElement = self

        batch_processor.set_data(visualizations=visualizations,
                                 source_data_name=run_name,
                                 years=range(start_year, end_year + 1))

        if not self.generating_results:
            self.generating_results = True
            logger.log_note(
                'Generating results for %s on run %s for year %indicator_node'
                % (run_name, indicator_name, start_year))
            self.running_key = key
            self.batch_processor = batch_processor
            batch_processor_thread = OpusGuiThread(
                parentThread=get_mainwindow_instance(),
                parentGuiElement=self,
                thread_object=self.batch_processor)

            # Use this signal from the thread if it is capable of producing its own status signal
            self.connect(batch_processor_thread,
                         SIGNAL("runFinished(PyQt_PyObject)"),
                         self._run_finished)
            self.connect(batch_processor_thread,
                         SIGNAL("runError(PyQt_PyObject)"), self._run_error)

            batch_processor_thread.start()
        else:
            self.queued_results = (key, batch_processor)