Ejemplo n.º 1
0
 def _add_plot_4(self):
     """ """
     try:
         app_tools.ToolManager().show_tool_by_name('Graph plotter') # Show tool if hidden.
         graphtool = app_tools.ToolManager().get_tool_by_name('Graph plotter')
         graphtool.clear_plot_data()
         # Filtered data should be used.
         self._main_activity.update_filter() # Must be done before create_filtered_dataset().
         analysisdata = self._analysisdata.create_filtered_dataset()
         if not analysisdata:
             return # Can't plot from empty dataset
         # Which parameter is selected?
         selectedparameter = str(self._parameter_list.currentText())
         # 
         plotdata = toolbox_utils.GraphPlotData(
                                 title = selectedparameter, 
                                 x_type = 'text',
                                 y_type = 'float',
                                 x_label = '',
                                 y_label = '')
         #
         self._add_plot_bbbbbbbbb(selectedparameter, analysisdata, plotdata)
         # Plot.
         graphtool.set_chart_selection(chart = 'Bar chart',
                                     combined = True, stacked = False, y_log_scale = False)
         graphtool.set_plot_data(plotdata)
         #
     except Exception as e:
         debug_info = self.__class__.__name__ + ', row  ' + str(sys._getframe().f_lineno)
         toolbox_utils.Logging().error('Exception: (' + debug_info + '): ' + str(e))
    def _plot_graph(self):
        """ """
        try:
            # Show the Graph plotter tool if hidden.
            app_tools.ToolManager().show_tool_by_name('Graph plotter')
            graphtool = app_tools.ToolManager().get_tool_by_name(
                'Graph plotter')
            graphtool.clear_plot_data()
            # Filtered data should be used.
            self._main_activity.update_filter(
            )  # Must be done before create_filtered_dataset().
            analysisdata = self._analysisdata.create_filtered_dataset()
            if not analysisdata:
                return  # Can't create a report from an empty dataset.
            # Which parameter is selected?
            selectedparameter = str(self._parameter_list.currentText())
            # Split by.
            split_on_year = self._splitby_year_checkbox.isChecked()
            split_on_season = self._splitby_season_checkbox.isChecked()
            split_on_month = self._splitby_month_checkbox.isChecked()
            split_on_station = self._splitby_station_checkbox.isChecked()
            split_on_visit = self._splitby_visit_checkbox.isChecked()
            split_on_depth = self._splitby_depth_checkbox.isChecked()
            split_on_taxon = self._splitby_taxon_checkbox.isChecked()
            # Graph data.
            self._graph_plot_data = toolbox_utils.GraphPlotData(
                title=selectedparameter, y_type='float', y_label='')
            # Create subplots.
            self._extract_plot_values(analysisdata, selectedparameter,
                                      split_on_year, split_on_season,
                                      split_on_month, split_on_station,
                                      split_on_visit, split_on_depth,
                                      split_on_taxon)
            # View in the graph-plot tool.
            graphtool.set_chart_selection(chart='Boxplot chart',
                                          combined=True,
                                          stacked=False,
                                          y_log_scale=False)
            graphtool.set_plot_data(self._graph_plot_data)

        #
        except Exception as e:
            debug_info = self.__class__.__name__ + ', row  ' + str(
                sys._getframe().f_lineno)
            toolbox_utils.Logging().error('Exception: (' + debug_info + '): ' +
                                          str(e))
Ejemplo n.º 3
0
 def _add_subplot_data(self):
     """ """
     try:
         # Show the Graph plotter tool if hidden. 
         app_tools.ToolManager().show_tool_by_name('Graph plotter')
         graphtool = app_tools.ToolManager().get_tool_by_name('Graph plotter')
         #
         # Selected columns.
         x_selected_column = str(self._x_axis_column_list.currentText())
         y_selected_column = str(self._y_axis_column_list.currentText())
         z_selected_column = str(self._z_axis_column_list.currentText())
         # Selected parameters.
         x_selected_param = str(self._x_axis_parameter_list.currentText())
         y_selected_param = str(self._y_axis_parameter_list.currentText())
         z_selected_param = str(self._z_axis_parameter_list.currentText())
         # Selected types.
         x_selected_type = str(self._x_axistype_list.currentText())
         y_selected_type = str(self._y_axistype_list.currentText())
         z_selected_type = str(self._z_axistype_list.currentText())
         #
         plotdatainfo = self._graph_plot_data.get_plot_data_info()
         #
         plotdatainfo['x_label'] = x_selected_column if x_selected_column != 'parameter:' else x_selected_param
         plotdatainfo['x_type'] = x_selected_type
         plotdatainfo['x_format'] = ''
         #
         plotdatainfo['y_label'] = y_selected_column if y_selected_column != 'parameter:' else y_selected_param
         plotdatainfo['y_type'] = y_selected_type
         plotdatainfo['y_format'] = ''
         #
         plotdatainfo['z_label'] = z_selected_column if z_selected_column != 'parameter:' else z_selected_param
         plotdatainfo['z_type'] = z_selected_type
         plotdatainfo['z_format'] = ''
         #
         # Add plot data.
         x_data, y_data, z_data = self._get_plot_data()
         #
         if x_data and (x_selected_type == 'float'):
             for index, item in enumerate(x_data):
                 try:
                     value = item.replace(',', '.').replace(' ', '') # Try/except if already float.
                 except: 
                     pass
                 try:
                     x_data[index] = float(value)
                 except:
                     x_data[index] = 0.0
         if y_data and (y_selected_type == 'float'):
             for index, item in enumerate(y_data):
                 try:
                     value = item.replace(',', '.').replace(' ', '') # Try/except if already float.
                 except: 
                     pass
                 try:
                     y_data[index] = float(value)
                 except:
                     y_data[index] = 0.0
         if z_data and (z_selected_type == 'float'):
             for index, item in enumerate(z_data):
                 try:
                     value = item.replace(',', '.').replace(' ', '') # Try/except if already float.
                 except: 
                     pass
                 try:
                     z_data[index] = float(value)
                 except:
                     z_data[index] = 0.0
         
         plot_name = y_selected_column if y_selected_column != 'parameter:' else y_selected_param
 #         plot_name = y_selected_column if y_selected_column != 'parameter:' else y_selected_param + ' / ' + \
 #                     x_selected_column if x_selected_column != 'parameter:' else x_selected_param
         #
         try:
             self._graph_plot_data.add_plot(
                             plot_name = plot_name, 
                              x_label = x_selected_column if x_selected_column != 'parameter:' else x_selected_param,
                              x_array = x_data,
                              y_label = y_selected_column if y_selected_column != 'parameter:' else y_selected_param,
                              y_array = y_data, 
                              z_label = z_selected_column if z_selected_column != 'parameter:' else z_selected_param,
                              z_array = z_data) 
         except UserWarning as e:
             QtWidgets.QMessageBox.warning(self._main_activity, 'Warning', str(e))
 
         # View in Graph plotter tool.
         graphtool.set_plot_data(self._graph_plot_data)
     #
     except Exception as e:
         debug_info = self.__class__.__name__ + ', row  ' + str(sys._getframe().f_lineno)
         toolbox_utils.Logging().error('Exception: (' + debug_info + '): ' + str(e))
    def initialise(self):
        # Load app settings.
        self._ui_settings = QtCore.QSettings()
        # Logging. Always log to plankton_toolbox_log.txt. Use the Log tool when  
        # it is available.
        self._logfile = codecs.open('plankton_toolbox_log.txt', mode = 'w', encoding = 'cp1252')
        self._logfile.write('Plankton Toolbox. ' +
                             time.strftime('%Y-%m-%d %H:%M:%S') )
        self._logfile.write('')
        self._logtool = None # Should be initiated later.
        toolbox_utils.Logging().set_log_target(self)
        # Setup main window.
        self._createActions()
        self._createMenu()
        self._createStatusBar()
        self._activity = None
        self._createCentralWidget()
        # Set up activities and tools.
        self._toolmanager = app_tools.ToolManager()
        self._toolmanager.set_parent(self)
        self._toolmanager.init_tools()
        #
        toolbox_utils.Logging().log('Plankton Toolbox. Version: ' + self._version + '.')
        # Log if user _settings.txt is used.
        data_path = app_framework.ToolboxUserSettings().get_path_to_plankton_toolbox_data()
        counter_path = app_framework.ToolboxUserSettings().get_path_to_plankton_toolbox_counter()
        if (data_path != 'plankton_toolbox_data') or (counter_path != 'plankton_toolbox_counter'):
            toolbox_utils.Logging().log('')
            toolbox_utils.Logging().log('User settings in "plankton_toolbox_data/user_settings.txt": ')
            toolbox_utils.Logging().log('- Path to data dictionary: ' + data_path)
            toolbox_utils.Logging().log('- Path to counter dictionary: ' + counter_path)
        #
        self._activitymanager = app_activities.ActivityManager()
        self._activitymanager.set_parent(self)
        self._activitymanager.init_activities()
        # Add tools to selector.
        self._create_contentSelectors()
        # Load last used window positions.
        size = self._ui_settings.value('MainWindow/Size', QtCore.QSize(900, 600)) #.toSize()
        position = self._ui_settings.value('MainWindow/Position', QtCore.QPoint(100, 80)) #.toPoint()

        # Check if outside windows. New, including Windows 10.
        # print("DEBUG position x: ", position.x())
        # print("DEBUG position y: ", position.y())
        # print("DEBUG size w: ", size.width())
        # print("DEBUG size h: ", size.height())
        fit_in_screen = False
        screen_x = 0
        screen_y = 0
        screen_width = 1920
        screen_height = 1020
        for screen in QtWidgets.QApplication.screens():
            # print("DEBUG: ", screen.name())
            # print("DEBUG x: ", screen.availableGeometry().x())
            # print("DEBUG y: ", screen.availableGeometry().y())
            # print("DEBUG w: ", screen.availableGeometry().width())
            # print("DEBUG h: ", screen.availableGeometry().height())
            screen_x = screen.availableGeometry().x()
            screen_y = screen.availableGeometry().y()
            screen_width = screen.availableGeometry().width()
            screen_height = screen.availableGeometry().height()
            screen_x_max = screen_x + screen_width
            screen_y_max = screen_y + screen_height

            if ((position.x() + size.width()) <= (screen_x_max + 20)) and \
                ((position.y() + size.height()) <= (screen_y_max + 20)):

                if (position.x() >= (screen_x - 20)) and (position.y() >= (screen_y - 20)):
                    fit_in_screen = True
                    break

        if fit_in_screen == False:
            size.setWidth(900)
            size.setHeight(600)
            position.setX(100)
            position.setY(80)

        try:   
            self.setGeometry(self._ui_settings.value('MainWindow/Geometry'))
            self.restoreState(self._ui_settings.value('MainWindow/State'))
        except:
            pass # May contain None at first start on new computer.

        self.resize(size)
        self.move(position)  
        # Tell the user.
        app_tools.ToolManager().show_tool_by_name('Toolbox logging') # Show the log tool if hidden.
        
        # Load resources when the main event loop has started.
#         if app_framework.ToolboxSettings().get_value('Resources:Load at startup'):
#             QtCore.QTimer.singleShot(10, app_framework.ToolboxResources().loadAllResources)
        QtCore.QTimer.singleShot(1000, self._loadResources)