From c0f05a554ef33eac95719a93eb7f227ab1391b69 Mon Sep 17 00:00:00 2001
From: Eva Schiffer <evas@ssec.wisc.edu>
Date: Thu, 19 Aug 2021 14:15:18 -0500
Subject: [PATCH] fixing stats report title in the GUI

---
 pyglance/glance/gui_controller.py    |  9 ++++++++-
 pyglance/glance/gui_statsprovider.py | 18 +++++++++++-------
 pyglance/glance/gui_view.py          | 26 +++++++++++++++++++++-----
 pyglance/glance/report-guistats.txt  | 28 +++++++++++++++++++++++++---
 4 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/pyglance/glance/gui_controller.py b/pyglance/glance/gui_controller.py
index b18c3d2..30d1656 100644
--- a/pyglance/glance/gui_controller.py
+++ b/pyglance/glance/gui_controller.py
@@ -241,7 +241,14 @@ class GlanceGUIController (object) :
         # show the data for whatever's loaded
         self.stats.sendRawData(A_CONST)
         self.stats.sendRawData(B_CONST)
-        
+
+    def userRequestsGlobalAttrs (self) :
+        """
+        the user asked for a display of the global file attributes
+        """
+
+        # TODO, actually send the attrs
+        self.stats.sendGlobalAttrs( )
     
     def userRequestsPlot (self) :
         """
diff --git a/pyglance/glance/gui_statsprovider.py b/pyglance/glance/gui_statsprovider.py
index 70bb0f6..7b8f041 100644
--- a/pyglance/glance/gui_statsprovider.py
+++ b/pyglance/glance/gui_statsprovider.py
@@ -75,15 +75,14 @@ class GlanceGUIStats (object) :
         aDataObject = self.dataModel.getVariableData(A_CONST, aVarName)
         bDataObject = self.dataModel.getVariableData(B_CONST, bVarName)
 
+        # if we only have one file, just make stats for that one
         if aDataObject is None and bDataObject is not None:
-            aDataObject, bDataObject = bDataObject, aDataObject
-
+            return self.sendStatsInfoSingle(bVarName, bDataObject)
         if aDataObject is not None and bDataObject is None:
             return self.sendStatsInfoSingle(aVarName, aDataObject)
 
         return self.sendStatsInfoPair(aVarName, bVarName, aDataObject, bDataObject)
 
-        
     def sendStatsInfoPair(self, aVarName, bVarName, aDataObject, bDataObject):
         """
         send data listeners statistics information 
@@ -115,7 +114,7 @@ class GlanceGUIStats (object) :
         for listener in self.statsListeners :
                 listener.displayStatsData(aVarName, bVarName, renderedText)
 
-    def sendStatsInfoSingle(self, aVarName, aDataObject):
+    def sendStatsInfoSingle(self, varName, dataObject):
         """
         send data listeners statistics information 
         for the currently selected variable
@@ -123,9 +122,9 @@ class GlanceGUIStats (object) :
         LOG.info ("Constructing statistics for one variable")
 
         # do the statistical analysis and collect the data that will be needed to render it nicely
-        tempAnalysis = stats.StatisticalInspectionAnalysis.withDataObjects(aDataObject)
+        tempAnalysis = stats.StatisticalInspectionAnalysis.withDataObjects(dataObject)
         # TODO, these constants should be moved into the gui_constants
-        tempInfo = { 'variable_name': aVarName }
+        tempInfo = { 'variable_name': varName }
         kwargs   = { 'runInfo':    tempInfo,
                      'statGroups': tempAnalysis.dictionary_form() }
 
@@ -136,9 +135,14 @@ class GlanceGUIStats (object) :
 
         # tell my listeners to show the stats data we've collected
         for listener in self.statsListeners :
-                listener.displayStatsData(aVarName, None, renderedText)
+                listener.displayStatsData(varName, None, renderedText)
 
+    def sendGlobalAttrs (self, ) :
+        """
+        Send information on the global attributes to our listeners
+        """
 
+        print ("*** TODO send global attr info!")
     
     def sendRawData (self, fileID) :
         """
diff --git a/pyglance/glance/gui_view.py b/pyglance/glance/gui_view.py
index 2c3f1f4..046ab6c 100644
--- a/pyglance/glance/gui_view.py
+++ b/pyglance/glance/gui_view.py
@@ -226,19 +226,24 @@ class GlanceGUIView (QWidget) :
         layoutToUse.addWidget(self.imageSelectionDropDown, currentRow, 1, 1, 2)
         
         currentRow += 1
-        
+
+        # set up a button that shows the global attributes
+        #self.gAttrsButton = QPushButton("Global Attrs.")
+        #self.gAttrsButton.clicked.connect(self.reportDisplayGlobalAttrsClicked) # TODO
+        #layoutToUse.addWidget(self.gAttrsButton, currentRow, 0, 1, 1)
+
         # set up a button that shows the numerical data
-        self.rawDataButton = QPushButton("Display Data")
+        self.rawDataButton = QPushButton("Show Data")
         self.rawDataButton.clicked.connect(self.reportDisplayRawDataClicked)
         layoutToUse.addWidget(self.rawDataButton, currentRow, 1, 1, 1)
         
         # set up a button that shows stats
-        self.statsButton = QPushButton("Display Statistics")
+        self.statsButton = QPushButton("Show Statistics")
         self.statsButton.clicked.connect(self.reportDisplayStatsClicked)
         layoutToUse.addWidget(self.statsButton, currentRow, 2, 1, 1)
         
         # set up the button at the bottom that creates plots
-        self.displayButton = QPushButton("Display Plot")
+        self.displayButton = QPushButton("Create Plot")
         self.displayButton.clicked.connect(self.reportDisplayPlotClicked)
         layoutToUse.addWidget(self.displayButton, currentRow, 3, 1, 2)
         
@@ -829,7 +834,18 @@ class GlanceGUIView (QWidget) :
         # now report to our listeners that the user wants a plot
         for listener in self.userUpdateListeners :
             listener.userRequestsPlot()
-    
+
+    def reportDisplayGlobalAttrsClicked(self):
+        """
+        the user clicked the show global attributes button
+        """
+
+        # make sure the focus isn't in a line-edit box
+        self.gAttrsButton.setFocus()
+
+        for listener in self.userUpdateListeners:
+            listener.userRequestsGlobalAttrs()
+
     def _extra_number_validation (self, string_that_should_be_a_number) :
         """
         try to validate the string that should be a number
diff --git a/pyglance/glance/report-guistats.txt b/pyglance/glance/report-guistats.txt
index 398ccc2..6cca38d 100644
--- a/pyglance/glance/report-guistats.txt
+++ b/pyglance/glance/report-guistats.txt
@@ -6,12 +6,34 @@ Created by Eva Schiffer Nov 2011.
 Copyright (c) 2011 University of Wisconsin SSEC. All rights reserved.
 </%doc>
 
+<%!
+    import glance.constants as constants
+%>
+
 <%inherit file="report-variable.txt"/>
 
+## replace our basic title with this
+<%block name="title">
+
+    % if constants.VARIABLE_TECH_NAME_KEY in runInfo and constants.VARIABLE_B_TECH_NAME_KEY in runInfo :
+        % if runInfo[constants.VARIABLE_TECH_NAME_KEY] == runInfo[constants.VARIABLE_B_TECH_NAME_KEY] :
+            ${runInfo[constants.VARIABLE_TECH_NAME_KEY]} Comparison Statistics
+        % else :
+            ${runInfo[constants.VARIABLE_TECH_NAME_KEY]} vs ${runInfo[constants.VARIABLE_B_TECH_NAME_KEY]} Comparison Statistics
+        % endif
+    % endif
+    % if constants.VARIABLE_TECH_NAME_KEY in runInfo and constants.VARIABLE_B_TECH_NAME_KEY not in runInfo :
+        ${runInfo[constants.VARIABLE_TECH_NAME_KEY]} Statistics
+    % endif
+    % if constants.VARIABLE_TECH_NAME_KEY not in runInfo and constants.VARIABLE_B_TECH_NAME_KEY in runInfo :
+        ${runInfo[constants.VARIABLE_B_TECH_NAME_KEY]} Statistics
+    % endif
+</%block>
+
 <%block name="htmlContent">
-    
-    <h3>${self.title()}</h3>
-    
+
+    <h2>${self.title()}</h2>
+
     ${self.stats()}
     
 </%block>
-- 
GitLab