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


Python Action.is_drag方法代码示例

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


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

示例1: AndroidEvent

# 需要导入模块: from action import Action [as 别名]
# 或者: from action.Action import is_drag [as 别名]

#.........这里部分代码省略.........
        return self

    def is_start(self, event_property):
        return self.status is Status.uninitialized and event_property == TYPE_START_OR_END

    def is_end(self, event_property):
        return self.status is Status.initialized and event_property == TYPE_START_OR_END

    @classmethod
    def recognized(cls, type):
        return type in EVENT_TYPES

    def changed(self, type, time, value):
        if self.status is Status.initialized:
            delta_time = time - self.start_time
            self.changes.append(AndroidEventChange(type, delta_time, time, value))
        else:
            print 'Ignored uninitialized event.'

    def preprocess(self, end_event):
        try:
            self.status = Status.preprocessed
            self.state.end.xml = end_event

            # TODO(johnliu): interpolate a curve, for now just use start and end points.
            start = self.changes.start()
            end = self.changes.end()

            if abs(start.x - end.x) <= 25 and abs(start.y - end.y) <= 25:
                if start.y >= self.device_info['displayHeight']:
                    self.action.init(ACTION_BACK)
                else:
                    self.action.init(ACTION_TOUCH, start.x, start.y)
            else:
                self.action.init(ACTION_DRAG, start, end, self.changes.duration())
        except Exception as e:
            self.status = Status.discarded
            print e

        print 'Got event: %s' % self

    def process(self):
        try:
            self.status = Status.processed

            if not self.action.is_back():
                self.state.start.process(self.changes.start())
                self.state.end.process(self.changes.end())
                if not len(self.state.start.chain) or not len(self.state.end.chain):
                    self.status = Status.discarded
        except Exception as e:
            self.status = Status.discarded
            print e

        print 'Processed: %s' % self

    def delay(self, other):
        if other is None:
            return 0
        start_time = self.changes.max_time()
        end_time = other.changes.min_time()
        return abs(end_time - start_time)

    def call(self):
        if self.status >= Status.processed:
            self.action.call()
        else:
            print 'Event not processed.'

    def __repr__(self):
        text_start = '<AndroidEvent(%s)>'
        text_end = ':\n %s'
        t, m = (None, None)

        if self.status is Status.uninitialized:
            t = 'null'
        if self.status is Status.discarded:
            t = 'discarded'
        if self.status is Status.initialized:
            t = 'unprocessed'

        if self.status >= Status.preprocessed:
            start = self.changes.start()
            end = self.changes.end()
            duration = self.changes.duration()

            t = self.action.type
            if self.action.is_drag():
                m = '\t%s ->\n\t%s \n\tin %f' % (start, end, duration)
            elif self.action.is_touch():
                m = '\t%s' % (start,)
        if self.status is Status.processed:
            if self.action.is_drag():
                m += ', \n\tfrom: %s ->\n\t%s' % (self.state.start.chain[-1], self.state.end.chain[-1])
            elif self.action.is_touch():
                m += ', \n\tin: %s' % self.state.start.chain[-1]

        text = text_start
        if m: text += text_end % m
        return text % t
开发者ID:johnliu,项目名称:chimp,代码行数:104,代码来源:event.py


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