本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.mapFromGlobal方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.mapFromGlobal方法的具体用法?Python FigureCanvasQTAgg.mapFromGlobal怎么用?Python FigureCanvasQTAgg.mapFromGlobal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.mapFromGlobal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mapFromGlobal [as 别名]
#.........这里部分代码省略.........
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
### update daytaframe with previously labeled cells
newapdvDF = update_apdv_pos_DF( self.currentPos, self.apdvPosDF, self.tp.value() )
self.apdvPosDF = newapdvDF
print(self.currentPos) # print previously labeled positions
### extract current cells already labeled
self.currentPos = extract_current_apdv_pos( self.apdvPosDF, self.tp.value() + step )
self.tp.setValue( self.tp.value() + step )
self.fName.setText( self.timesDF.ix[ self.timesDF.tidxRel == self.tp.value(), 'fName' ].values[0] )
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onKeyPressOnCanvas1(self, event):
posNameList = [ QtCore.Qt.Key_A, QtCore.Qt.Key_P, QtCore.Qt.Key_D ]
# find the position of the cursor relative to the image in pixel
imgshape = self.channels[self.currentChannel][0].shape
canshape = self.canvas1.size()
cf = imgshape[0]/canshape.width()
refpos = self.canvas1.mapFromGlobal(QtGui.QCursor.pos())
refpos = np.array([ int( refpos.x() * cf ), int( refpos.y() * cf )]) * self.compression
### find the closest cell to the cursor
idx = closer_2Dpos( refpos.astype( np.uint16 ), self.currentPos )
### assign the name to the cell
if any( [ event.key() == cn for cn in posNameList ] ):
self.currentPos.ix[ idx, 'pname' ] = QtGui.QKeySequence(event.key()).toString().lower()
self.updateCanvas1()
self.setFocus()
def onMouseClickOnCanvas1(self, event):
refpos = np.array( [ event.xdata, event.ydata ] ) * self.compression
if event.button == 1:
# create an empty cell in the currentCells df: the only entries are tidx, xyzpos and cname
newpos = create_single_apdv_pos( refpos.astype(np.uint16), self.tp.value() )
self.currentPos = pd.concat( [ self.currentPos, newpos ] )
elif event.button == 3:
# remove a cell (the closest to the cursor at the moment of right-click)
idx = closer_2Dpos( refpos.astype(np.uint16), self.currentPos )
self.currentPos = self.currentPos.drop( [ idx ] )
self.currentPos = self.currentPos.reset_index(drop=True)
self.updateCanvas1()
示例2: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mapFromGlobal [as 别名]
#.........这里部分代码省略.........
def wheelEvent(self,event):
if any([ self.canvas1.underMouse(), self.canvas2.underMouse(), self.canvas3.underMouse() ]):
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onKeyPressOnCanvas2(self, event):
# print(event.key())
cellsname = [ QtCore.Qt.Key_A, QtCore.Qt.Key_B, QtCore.Qt.Key_C, QtCore.Qt.Key_1,
QtCore.Qt.Key_2, QtCore.Qt.Key_3, QtCore.Qt.Key_4, QtCore.Qt.Key_5,
QtCore.Qt.Key_6, QtCore.Qt.Key_T ]
cellspos = [ QtCore.Qt.Key_Q, QtCore.Qt.Key_W ]
# find the position of the cursor relative to the image in pixel
imgshape = self.stacksStraight[self.channel][self.sl.value()].shape
arimg = imgshape[1]/imgshape[0]
canshape = self.canvas2.size()
arcan = canshape.width()/canshape.height()
cf = 1
if arimg>arcan:
cf = imgshape[1]/canshape.width()
origin = ( canshape.height()*cf - imgshape[0] ) / 2.
origin = np.array( [ 0, ( canshape.width()*cf - imgshape[1] ) / 2. ] )
else:
cf = imgshape[0]/canshape.height()
origin = np.array( [ ( canshape.width()*cf - imgshape[1] ) / 2., 0 ] )
refpos = self.canvas2.mapFromGlobal(QtGui.QCursor.pos())
refpos = np.array([refpos.x(),refpos.y()])*cf - origin
refpos = np.append(refpos,self.sl.value())
# find the closest cell to the cursor
bodymask = self.df['rowtype']=='body'
cellmask = self.df['rowtype']=='cell'
tpmask = self.df['tidx'] == (self.tp.value()-self.hatch.value())
idx, cell = closer_cell( refpos, self.df[ cellmask & tpmask ], self.fMetaList[self.tp.value()] )
if any( [ event.key() == cn for cn in cellsname ] ):
self.df.ix[ idx, 'cname' ] = QtGui.QKeySequence(event.key()).toString().lower() + '.'
elif any( [ event.key() == cp for cp in cellspos ] ):
if event.key() == cellspos[0]: self.df.ix[ idx, 'cname' ] += 'a'
elif event.key() == cellspos[1]: self.df.ix[ idx, 'cname' ] += 'p'
elif event.key() == QtCore.Qt.Key_Backspace:
self.df.ix[ idx, 'cname' ] = self.df.ix[ idx, 'cname' ][:-1]
elif event.key() == QtCore.Qt.Key_I:
sideLmask = self.df['cside']=='L'
self.df.ix[ tpmask & cellmask & sideLmask,'cside'] = 'R'
sideRmask = self.df['cside']=='R'
self.df.ix[ tpmask & cellmask & sideRmask,'cside'] = 'L'
elif event.key() == QtCore.Qt.Key_U:
if self.df.ix[idx,'cside']=='L': self.df.ix[ idx,'cside'] = 'R'
示例3: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mapFromGlobal [as 别名]
#.........这里部分代码省略.........
if self.channels[ (idx+1)%len(self.channels) ] == 'CoolLED':
self.CoolLEDBtn.setChecked(True)
if self.channels[ (idx+1)%len(self.channels) ] == '488nm':
self._488nmBtn.setChecked(True)
if self.channels[ (idx+1)%len(self.channels) ] == '561nm':
self._561nmBtn.setChecked(True)
# key press on cropped image
if self.canvas1.underMouse():
self.onKeyPressOnCanvas1(event)
self.setFocus()
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onKeyPressOnCanvas1(self, event):
motherCells = [ QtCore.Qt.Key_1, QtCore.Qt.Key_4, QtCore.Qt.Key_B ]
daughterCells = [ QtCore.Qt.Key_A, QtCore.Qt.Key_P ]
# find the position of the cursor relative to the image in pixel
imgshape = self.stacks[self.currentChannel][self.sl.value()].shape
canshape = self.canvas1.size()
cf = imgshape[0]/canshape.width()
refpos = self.canvas1.mapFromGlobal(QtGui.QCursor.pos())
refpos = np.array([ int( refpos.x() * cf ), int( refpos.y() * cf )])
refpos = np.append(refpos,self.sl.value())
### find the closest cell to the cursor
idx = closer_cell( refpos.astype( np.uint16 ), self.currentCells )
### assign the name to the cell
if any( [ event.key() == cn for cn in motherCells ] ):
# if labeling bckg, add the 1 or 2 to the name
if self.currentCells.ix[ idx, 'cname' ] == 'b_':
self.currentCells.ix[ idx, 'cname' ] += QtGui.QKeySequence(event.key()).toString().lower()
else:
# if not, rename the cell from scratch
if event.key() == QtCore.Qt.Key_B:
self.currentCells.ix[ idx, 'cname' ] = QtGui.QKeySequence(event.key()).toString().lower() + '_'
else:
self.currentCells.ix[ idx, 'cname' ] = QtGui.QKeySequence(event.key()).toString().lower() + '.'
# add the anterior/posterior to the cell name
elif any( [ event.key() == cp for cp in daughterCells ] ):
# don't do it if labeling background (bckg doesn't have a/p!)
if self.currentCells.ix[ idx, 'cname' ] == 'b_':
return
else:
self.currentCells.ix[ idx, 'cname' ] += QtGui.QKeySequence(event.key()).toString().lower()
# remove the last entry of the name with backspace
elif event.key() == QtCore.Qt.Key_Backspace:
self.currentCells.ix[ idx, 'cname' ] = self.currentCells.ix[ idx, 'cname' ][:-1]
if ( event.key() != QtCore.Qt.Key_Left ) and ( event.key() != QtCore.Qt.Key_Right ) and ( event.key() != QtCore.Qt.Key_Up ) and ( event.key() != QtCore.Qt.Key_Down ):
self.updateCanvas1()
示例4: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mapFromGlobal [as 别名]
#.........这里部分代码省略.........
# change slice
elif event.key() == QtCore.Qt.Key_Up:
self.changeSpaceTime( 'space', +1 )
elif event.key() == QtCore.Qt.Key_Down:
self.changeSpaceTime( 'space', -1 )
# key press on cropped image
if self.canvas1.underMouse():
self.onKeyPressOnCanvas1(event)
self.setFocus()
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onKeyPressOnCanvas1(self, event):
motherCells = [ QtCore.Qt.Key_1, QtCore.Qt.Key_4, QtCore.Qt.Key_B ]
daughterCells = [ QtCore.Qt.Key_A, QtCore.Qt.Key_P ]
# find the position of the cursor relative to the image in pixel
imgshape = self.stacks[self.currentChannel][self.sl.value()].shape
canshape = self.canvas1.size()
cf = imgshape[0]/canshape.width()
refpos = self.canvas1.mapFromGlobal(QtGui.QCursor.pos())
refpos = np.array([ int( refpos.x() * cf ), int( refpos.y() * cf )])
refpos = np.append(refpos,self.sl.value())
### find the closest cell to the cursor
idx = closer_cell( refpos.astype( np.uint16 ), self.currentCells )
### assign the name to the cell
if any( [ event.key() == cn for cn in motherCells ] ):
# if labeling bckg, add the 1 or 2 to the name
if self.currentCells.ix[ idx, 'cname' ] == 'b_':
self.currentCells.ix[ idx, 'cname' ] += QtGui.QKeySequence(event.key()).toString().lower()
else:
# if not, rename the cell from scratch
if event.key() == QtCore.Qt.Key_B:
self.currentCells.ix[ idx, 'cname' ] = QtGui.QKeySequence(event.key()).toString().lower() + '_'
else:
self.currentCells.ix[ idx, 'cname' ] = QtGui.QKeySequence(event.key()).toString().lower() + '.'
# add the anterior/posterior to the cell name
elif any( [ event.key() == cp for cp in daughterCells ] ):
# don't do it if labeling background (bckg doesn't have a/p!)
if self.currentCells.ix[ idx, 'cname' ] == 'b_':
return
else:
self.currentCells.ix[ idx, 'cname' ] += QtGui.QKeySequence(event.key()).toString().lower()
# remove the last entry of the name with backspace
elif event.key() == QtCore.Qt.Key_Backspace:
self.currentCells.ix[ idx, 'cname' ] = self.currentCells.ix[ idx, 'cname' ][:-1]
self.updateCanvas1()
self.setFocus()