コード例 #1
0
    def update(self):
        '''
        All actions are delayed until update of TouchEventManager is called, 
        so that in a single
        frame no contradictory actions are performed (for example, touching and
        releasing a button at the same frame should not be allowed because it is 
        not physically possible.)
        this method of TouchEventManager should be called only after all 
        widgets updates are called.
        '''

        # commit all changes
        # if nothing is to be done in this frame, don't send anything.
        if self.command_builder._content == '':
            pass
        else:
            self.command_builder.commit()
            # logger.debug( self.command_builder._content )
            self.command_builder.publish(self.device.connection)

        # refresh the command_builder
        self.command_builder = CommandBuilder()
コード例 #2
0
ファイル: player.py プロジェクト: zhongyujian/fitch
 def __init__(self, device_id: str):
     self.device_id = device_id
     self.mnt = MNTDevice(device_id)
     self.cmd_builder = CommandBuilder()
コード例 #3
0
# In another way, you needn't consider about device's life-cycle.
# context manager will handle it
with safe_device(_DEVICE_ID) as device:
    # single-tap
    device.tap([(400, 600)])
    # multi-tap
    device.tap([(400, 400), (600, 600)])
    # set the pressure, default == 100
    device.tap([(400, 600)], pressure=50)

# ---

# What's more, you can also access low level API for further usage.
with safe_connection(_DEVICE_ID) as connection:
    builder = CommandBuilder()
    builder.down(0, 400, 400, 50)
    builder.commit()
    builder.move(0, 500, 500, 50)
    builder.commit()
    builder.move(0, 800, 400, 50)
    builder.commit()
    builder.up(0)
    builder.commit()

    builder.publish(connection)
    # if you are using MNTDevice object, replace with this:
    # builder.publish(device.connection)

# ---
コード例 #4
0
class TouchEventManager():
    '''
    Manages all touch events in each frame for a single device.

    At each frame, a new CommandBuilder is prepared for all widgets.
    '''
    def __init__(self, device):
        self.device = device
        self.touch_id_max = 10
        self.widget_touch_id = dict()
        self.command_builder = CommandBuilder()

    # touch id methods

    def get_touch_id(self, widget):
        '''
        assigns a touch id to a widget
        '''
        assigned_ids = self.widget_touch_id.values()
        for i in range(self.touch_id_max):
            if i not in assigned_ids:
                self.widget_touch_id[widget] = i
                return i
        logger.error(
            "Cannot assign new touch id to widget {widget_name}".format(
                widget_name=widget.name))

    def reclaim_touch_id(self, widget):
        '''
        reclaim the touch id previously assigned to a widget
        '''
        if self.widget_touch_id[widget] != -1:
            self.widget_touch_id[widget] = -1
            return
        logger.error(
            "Already reclaimed touch id of widget {widget_name}".format(
                widget_name=widget.name))

    # button methods

    def update(self):
        '''
        All actions are delayed until update of TouchEventManager is called, 
        so that in a single
        frame no contradictory actions are performed (for example, touching and
        releasing a button at the same frame should not be allowed because it is 
        not physically possible.)
        this method of TouchEventManager should be called only after all 
        widgets updates are called.
        '''

        # commit all changes
        # if nothing is to be done in this frame, don't send anything.
        if self.command_builder._content == '':
            pass
        else:
            self.command_builder.commit()
            # logger.debug( self.command_builder._content )
            self.command_builder.publish(self.device.connection)

        # refresh the command_builder
        self.command_builder = CommandBuilder()
コード例 #5
0
 def __init__(self, device):
     self.device = device
     self.touch_id_max = 10
     self.widget_touch_id = dict()
     self.command_builder = CommandBuilder()
コード例 #6
0
ファイル: player.py プロジェクト: williamfzc/fitch
 def __init__(self, device_id: str):
     self.device_id = device_id
     self.mnt = MNTDevice(device_id)
     self.cmd_builder = CommandBuilder()
     logger.info("action player inited")