当前位置: 首页>>代码示例>>Python>>正文


Python Navigation.get_translation方法代码示例

本文整理汇总了Python中navigation.Navigation.get_translation方法的典型用法代码示例。如果您正苦于以下问题:Python Navigation.get_translation方法的具体用法?Python Navigation.get_translation怎么用?Python Navigation.get_translation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在navigation.Navigation的用法示例。


在下文中一共展示了Navigation.get_translation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GLWidget

# 需要导入模块: from navigation import Navigation [as 别名]
# 或者: from navigation.Navigation import get_translation [as 别名]
class GLWidget(QtOpenGL.QGLWidget):
    # initial window size
    w, h = 1024, 768
    
    isInitialized = False
    
    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)
        self.parent = parent
        self.setMouseTracking(True)
        
        self.nav = Navigation()
        self.navInterface = NavigationInterface(self.nav)
        self.dataDisplay = DataDisplay()
        
        # self.navigateSignal.connect(self.navigateEvent)
        SIGNALS.navigateSignal.connect(self.navigateEvent)

    def minimumSizeHint(self):
        return QtCore.QSize(50, 50)

    def sizeHint(self):
        return QtCore.QSize(self.w, self.h)
    
    # get position coordinates
    def coord(self, pos):
        return (pos.x(), pos.y())
    
    # get normalized coordinates
    def norm(self, pair):
        return (pair[0]/float(self.w), pair[1]/float(self.h))
    
    def ncoord(self, pos):
        return self.norm(self.coord(pos))
        
    def initializeGL(self):
        self.dataDisplay.initialize()
        self.isInitialized = True
        
    def paintGL(self):
        tx, ty = self.nav.get_translation()
        sx, sy = self.nav.get_scale()
        self.dataDisplay.transform(tx, ty, sx, sy)
        self.dataDisplay.paint()
    
    # handle window resizing
    def resizeGL(self, w, h):
        self.w, self.h = w, h
        self.dataDisplay.resize(w, h)
        
    def focusInEvent(self):
        pass
        
    def focusOutEvent(self):
        self.keyReleaseEvent(None)
        
    def navigateEvent(self):
        self.updateGL()
        
    def mousePressEvent(self, event):
        x, y = self.ncoord(event.pos())
        self.navInterface.mousePress(x, y, event.button())
            
    def mouseReleaseEvent(self, event):
        self.navInterface.mouseRelease()

    def mouseMoveEvent(self, event):
        x, y = self.ncoord(event.pos())
        self.navInterface.mouseMove(x, y)
        self.parent.statusbar.showMessage("%g, %g" % self.getMousePosition(x, y))
        if self.navInterface.mouseButton:
            SIGNALS.navigateSignal.emit()

    def getMousePosition(self, x, y):
        """
        convert mouse coordinates => data coordinates
        """
        tx, ty = self.nav.get_translation(False)
        sx, sy = self.nav.get_scale()
        # x = .5 * (1. - 1./sx) - tx + x/sx# + self.nav.offsetx
        # y = .5 * (1. - 1./sy) - ty + y/sy
        x, y = self.nav.get_data_coordinates(x, y)
        
        # inverse data normalization
        xmin, xmax, ymin, ymax = self.dataDisplay.get_bounds()
        x = xmin + x * (xmax - xmin)
        y = ymin + y * (ymax - ymin)
        y = -y
        return x, y
   
    def wheelEvent(self, event):
        self.navInterface.mouseWheel(event.delta())
        SIGNALS.navigateSignal.emit()
 
    def keyPressEvent(self, e):
        key = ""
        if e.key() == QtCore.Qt.Key_Control:
            key = KEY_CTRL
        if e.key() == QtCore.Qt.Key_Shift:
            key = KEY_SHIFT
#.........这里部分代码省略.........
开发者ID:ggoret,项目名称:codecamp-esrf-2014,代码行数:103,代码来源:glwidget.py


注:本文中的navigation.Navigation.get_translation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。