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


Python Circle.x方法代码示例

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


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

示例1: ClickRecorder

# 需要导入模块: from circle import Circle [as 别名]
# 或者: from circle.Circle import x [as 别名]
class ClickRecorder(QtGui.QWidget):
    def requestFileName(self):
        if len(sys.argv) < 2:
            sys.exit(0)
        else:
            self.fileName = sys.argv[1]

    # read content of test setup file and calculate random
    def readTestSetup(self):
        # read input
        with open(self.fileName) as f:
            content = f.read()

        if not content:
            # print "File is empty"
            sys.exit(0)

        userLines = content.split()

        # split description and comma-separated values, take values
        # and convert to int
        self.userId = userLines[0].split(":")[1]
        widths = map(int, userLines[1].split(":")[1].split(","))
        distances = map(int, userLines[2].split(":")[1].split(","))

        self.filename = "user" + self.userId

        # calculate possible combinations of distances and widths
        self.distWidthCombis = list(itertools.product(distances, widths))

        # randomize order of combinations of distance and width
        random.shuffle(self.distWidthCombis)

    def __init__(self):
        super(ClickRecorder, self).__init__()
        self.requestFileName()
        self.readTestSetup()
        self.initUI()
        self.setupStartRect()
        self.setupTrial()
        self.setupLogging()

    def setupStartRect(self):
        self.marginTop = self.res.height() / 3
        self.marginLeft = 100
        self.startCircle = Circle(50, self.marginLeft, self.marginTop)

    def setupCircle(self):
        width = self.distWidthCombis[self.trialsCount][1]
        distance = self.distWidthCombis[self.trialsCount][0]
        marginLeft = self.marginLeft + self.startCircle.diameter + distance
        self.circle = Circle(width, marginLeft - width / 2, self.marginTop)
        self.update()

    def setupTrial(self):
        self.circle = None
        self.errors = 0
        self.maxTrialsRepetition = 4
        self.maxTrialsCount = 16
        self.experimentOver = False
        self.trialsRepetition = 0
        self.trialsCount = 0

    def initUI(self):
        self.setWindowTitle("A Study about Fitts's Law")
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.showFullScreen()
        self.show()
        self.res = QtGui.QDesktopWidget().screenGeometry()

    def paintEvent(self, event):
        qp = QtGui.QPainter()
        qp.begin(self)
        qp.setRenderHint(qp.Antialiasing)
        qp.setBrush(QtGui.QColor(255, 255, 255))
        qp.drawRect(event.rect())
        self.drawState(event, qp)
        if self.experimentOver is True:
            pass
        else:
            self.drawCircles(event, qp)
        qp.end()

    # handle mouse press event
    def mousePressEvent(self, event):
        # check only left buton click
        if event.button() == QtCore.Qt.LeftButton:
            # start circle is hit and there's no target circle right now
            if self.startCircle.isClicked(event.pos()) and self.circle is None:
                self.setupCircle()
                self.initPosX = event.pos().x()
                self.initPosY = event.pos().y()
                self.targetPosX = self.circle.x()
                self.targetPosY = self.circle.y()
                self.start = int(round(time.time() * 1000))
            # there's a target circle
            elif self.circle is not None:
                self.clickPosX = event.pos().x()
                self.clickPosY = event.pos().y()

#.........这里部分代码省略.........
开发者ID:CrazyCrud,项目名称:interactiondesign-python,代码行数:103,代码来源:fitts_law_test.py


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