Skip to content

Commit

Permalink
bug fix with parentWidget for SARS
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Blumberg committed Jan 9, 2019
1 parent 9ca41a7 commit 715c1f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions sharppy/viz/SPCWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def initData(self):
# initialize swappable insets
for inset, inset_gen in SPCWidget.inset_generators.items():
self.insets[inset] = inset_gen()
# self.insets[inset].setParent(self.text)

self.updateConfig(self.config, update_gui=False)

Expand Down Expand Up @@ -615,11 +616,13 @@ def advanceTime(self, direction):
if prof_col.hasMeta('analogfile'):
match = prof_col.getMeta('analogfile')
dt = prof_col.getCurrentDate()
print("\n\nIN IF:", dt, match)
if dt in match:
self.insets['SARS'].setSelection(match[dt])
else:
self.insets['SARS'].clearSelection()
else:
self.insets['SARS'].setParent(self.text)
self.insets['SARS'].clearSelection()

def advanceHighlight(self, direction):
Expand All @@ -641,6 +644,7 @@ def swapProfCollections(self):
if self.prof_collections[self.pc_idx].hasMeta('analogfile'):
match = self.prof_collections[self.pc_idx].getMeta('analogfile')
dt = prof_col.getCurrentDate()
print(dt, match)
if dt in match:
self.insets['SARS'].setSelection(match[dt])
else:
Expand Down Expand Up @@ -705,6 +709,7 @@ def swapInset(self):
self.insets[self.left_inset] = SPCWidget.inset_generators[self.left_inset]()
self.insets[self.left_inset].setProf(self.default_prof)
self.insets[self.left_inset].setPreferences(update_gui=False, **prefs)
self.insets[self.left_inset].setParent(self.text)

self.left_inset = a.data()
self.left_inset_ob = self.insets[self.left_inset]
Expand All @@ -726,6 +731,7 @@ def swapInset(self):
self.insets[self.right_inset] = SPCWidget.inset_generators[self.right_inset]()
self.insets[self.right_inset].setProf(self.default_prof)
self.insets[self.right_inset].setPreferences(update_gui=False, **prefs)
self.insets[self.right_inset].setParent(self.text)

self.right_inset = a.data()
self.right_inset_ob = self.insets[self.right_inset]
Expand All @@ -748,6 +754,7 @@ class SPCWindow(QMainWindow):
def __init__(self, **kwargs):
parent = kwargs.get('parent', None)
super(SPCWindow, self).__init__(parent=parent)
print("SPCWINDOW PARENT:", parent)
logging.debug("Initialize SPCWindow...")
self.menu_items = []
self.picker_window = parent
Expand Down
13 changes: 12 additions & 1 deletion sharppy/viz/analogues.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def __init__(self):
Parameters
----------
prof: a Profile object
self.view.setDataSource(self.data_sources[self.model], self.run)
'''
## get the surfce based, most unstable, and mixed layer
Expand All @@ -189,7 +190,6 @@ def __init__(self):
self.bg_color = QtGui.QColor('#000000')
self.fg_color = QtGui.QColor('#ffffff')
self.use_left = False

super(plotAnalogues, self).__init__()
self.prof = None

Expand Down Expand Up @@ -468,6 +468,10 @@ def drawSARS(self, qp, **kwargs):
self.ylast = self.tpad

def mousePressEvent(self, e):
try:
print("PARENT1:", self.parentWidget())
except:
print("Parent widget print failed")
if self.prof is None or (len(self.sup_matches[0]) == 0 and len(self.hail_matches[0]) == 0):
return

Expand All @@ -478,6 +482,7 @@ def mousePressEvent(self, e):
for i, bound in enumerate(self.ybounds_sup):
if bound[0] < pos.y() and bound[1] > pos.y():
filematch = sars.getSounding(self.sup_matches[0][i], "supercell")
print(filematch)
self.updatematch.emit(filematch)
## set the rectangle used for showing
## a selected match
Expand All @@ -491,6 +496,7 @@ def mousePressEvent(self, e):
for i, bound in enumerate(self.ybounds_hail):
if bound[0] < pos.y() and bound[1] > pos.y():
filematch = sars.getSounding(self.hail_matches[0][i], "hail")
print(filematch)
self.updatematch.emit(filematch)
## set the rectangle used for showing
## a selected match
Expand All @@ -502,13 +508,16 @@ def mousePressEvent(self, e):
self.plotBackground()
self.plotData()
self.update()
print("PARENT2:", self.parentWidget())
#logging.debug("Calling plotAnaloges.parentWidget().setFocus()")
self.parentWidget().setFocus()

def setSelection(self, filematch):
"""
Load in the SARS analog you've clicked.
"""
match_name = os.path.basename(filematch)
print("\n\nSETSELECION:", match_name, filematch)
if match_name in self.sup_matches[0]:
idx = np.where(self.sup_matches[0] == match_name)[0][0]
lbx = 0.
Expand All @@ -532,6 +541,8 @@ def clearSelection(self):
self.plotBackground()
self.plotData()
self.update()
#print(self.parent, self.parentWidget())
#self.setParent(self.parent)
self.parentWidget().setFocus()


Expand Down
2 changes: 1 addition & 1 deletion sharppy/viz/skew.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def mouseReleaseEvent(self, e):

# Example: 4 {'tmpc': 10.790866472309446} (changed the 4th point of the tmpc profile to the temperature value set in tmpc)
# So, if we want to modify an entire layer of the sounding, we'll have to get creative.
print(drag_idx, {prof_name: tmpc})
#print(drag_idx, {prof_name: tmpc})
self.modified.emit(drag_idx, {prof_name:tmpc})

self.was_right_click = False
Expand Down

0 comments on commit 715c1f1

Please sign in to comment.