Example #1
0
  def render(self):
    '''
      we can populate the cli with labels and then use 'getch' to capture input given from the cli then handle the input
    '''

    self.__populate()
    while True:
      key = ord(getch.getch())
      # when w or up arw is pressed;
      if key == 119 and self.selected > 0 or key == 65 and self.selected > 0:
        self.selected -= 1
        self.__populate()
      # when s or dwn arw is pressed;
      elif key == 115 and self.selected < len(self.labels) - 1 or key == 66 and self.selected < len(self.labels) - 1:
        self.selected += 1
        self.__populate()
      # when d or right arw is pressed;
      elif key == 100 or key == 67:
        # let's execute the function if it has arguments
        if len(self.items[self.selected][1]) <= 0:
          self.items[self.selected][0]()
        else:
          self.items[self.selected][0](*self.items[self.selected][1])
      elif key == 97 or key == 68:
        if len(self.extra_args) > 0 and self.extra_args[0] == "sub_menu":
          break
        else:
          replit.clear()
          self.__populate()

      replit.clear()
Example #2
0
def key_driver(servo):
    """Drive servos based on keyboard input.

    Loops indefinitely until 'q' (quit) is typed.
    """
    inc = 5

    while True:
        keypress = getch.getch()
        if keypress == 'q':
            go_home(servo)
            servo.close()
            break

        if keypress == 'j':
            RANGES[0] += inc
        elif keypress == 'l':
            RANGES[0] += -1*inc
        elif keypress == 'i':
            RANGES[1] += inc
        elif keypress == 'k':
            RANGES[1] += -1*inc

        for index, target in enumerate(RANGES):
            set_target(servo, index, target)

        servo_str = ""
        for idx, target in enumerate(RANGES):
            servo_str += "Servo {}: {:4}  ".format(idx, target)
        print(servo_str)
Example #3
0
def reader():
    range0 = 90
    range1 = 90

    move(1, range0)
    move(2, range1)

    while True:
        keypress = getch.getch()
        if keypress == 'j':
            range0 += 10
        elif keypress == 'l':
            range0 += -10
        elif keypress == 'i':
            range1 += -10
        elif keypress == 'k':
            range1 += 10

        elif keypress == 'q':
            break

        if range0 > 180:
            range0 = 180
        elif range0 < 0:
            range0 = 0

        if range1 > 165:
            range1 = 165
        elif range1 < 15:
            range1 = 15

        print("Servo 0 set to {}, servo 1 set to {}".format(range0, range1))
        move(1, range0)
        move(2, range1)
Example #4
0
def reader():
    range0 = 90
    range1 = 90

    move(1, range0)
    move(2, range1)

    while True:
        keypress = getch.getch()
        if keypress == 'j':
            range0 += 10
        elif keypress == 'l':
            range0 += -10
        elif keypress == 'i':
            range1 += -10
        elif keypress == 'k':
            range1 += 10

        elif keypress == 'q':
            break

        if range0 > 180:
            range0 = 180
        elif range0 < 0:
            range0 = 0

        if range1 > 165:
            range1 = 165
        elif range1 < 15:
            range1 = 15

        print("Servo 0 set to {}, servo 1 set to {}".format(range0, range1))
        move(1, range0)
        move(2, range1)
Example #5
0
def key_driver(servo):
    """Drive servos based on keyboard input.

    Loops indefinitely until 'q' (quit) is typed.
    """
    inc = 5

    while True:
        keypress = getch.getch()
        if keypress == 'q':
            go_home(servo)
            servo.close()
            break

        if keypress == 'j':
            RANGES[0] += inc
        elif keypress == 'l':
            RANGES[0] += -1 * inc
        elif keypress == 'i':
            RANGES[1] += inc
        elif keypress == 'k':
            RANGES[1] += -1 * inc

        for index, target in enumerate(RANGES):
            set_target(servo, index, target)

        servo_str = ""
        for idx, target in enumerate(RANGES):
            servo_str += "Servo {}: {:4}  ".format(idx, target)
        print(servo_str)
Example #6
0
	def run(self):
		while True:
			kbd_chr     = getch()
			try:
				kbd_val = ord(kbd_chr)
			except:
				pass
			self.queue.put((kbd_chr, kbd_val))#}}}
Example #7
0
def start_fragmap_server(fragmap_callback):
  def html_callback():
    return make_fragmap_page(fragmap_callback())
  server = start_server(html_callback)
  address = 'http://%s:%s' % server.server_address
  os.startfile(address)
  print 'Serving fragmap at %s' %(address,)
  print "Press 'r' to re-launch the page"
  print 'Press any other key to terminate'
  from getch.getch import getch
  while(ord(getch()) == ord('r')):
      os.startfile(address)
  server.shutdown()
Example #8
0
def prompt(message, default=None, characters=None):
    """Prompt for input.

    :param message: The prompt message.
    :param default: Default `None`. The default input value.
    :param characters: Default `None`. Case-insensitive constraint for single-
        character input.
    """
    if isinstance(default, basestring):
        message = "{0} [{1}]".format(message, default)

    if characters:
        puts("{0} ".format(message), newline=False)
    else:
        message = "{0}: ".format(message)

    while True:
        if characters:
            ret_val = getch()

            if default is not None and ret_val in (chr(CR), chr(LF)):
                puts()
                ret_val = default
                break
            if ret_val in characters.lower() or ret_val in characters.upper():
                puts()

                if ret_val not in characters:
                    ret_val = ret_val.swapcase()

                break
            elif isctrl(ret_val) and ctrl(ret_val) in (chr(ETX), chr(EOT)):
                raise KeyboardInterrupt
        else:
            ret_val = raw_input(message).strip() or default

            if ret_val:
                break

    return ret_val
Example #9
0
    print "1"
    time.sleep(1)
    print "go"


    start = time.time()
    times = []

    while(1):
        current = time.time()
        t_off = current-start

        if t_off > 30:
            break

        x = getch()
        print x

        current = time.time()
        t_off = current-start

        times.append( t_off )

    print json.dumps(times)

else:
    files = ['onsets-1', 'onsets-2', 'onsets-3', 'onsets-4', 'onsets-5']
    g_time_list = []
    for i, fname in enumerate( files ):
        """
        with open(fname + '.json') as f:
Example #10
0
if __name__ == '__main__':
    try:
        #supported keys:
        #(a,d) -> Control ROLL
        #(w,x) -> control PITCH
        #(q,e) -> control THROTTLE
        #(s) -> reset all channels (roll,pitch,throttle -> 0)
        #(0) -> exit

        rospy.init_node('keyboard_control', anonymous=True)
        pub = rospy.Publisher('/pid_input',controller_msg,queue_size=10)

        msgObject = controller_msg()
        msgObject.x = msgObject.y = msgObject.z = msgObject.t = 0
        while not rospy.is_shutdown():
            k = getch.getch()
            if k=="e":
                    print "up pressed - Throttle +"
                    msgObject.z += 0.1
            elif k=='q':
                    print "down pressed - Throttle -"
                    msgObject.z -= 0.1

            elif k=='d':
                    print "right pressed - Roll +"
                    msgObject.y += 0.1
            elif k=='a':
                    print "left pressed - Roll -"
                    msgObject.y -= 0.1
            elif k=='w':
                    print "left pressed - Pitch +"
Example #11
0
        req_move.Velocity.Zoom._x = speed
        ptz.ContinuousMove(req_move)

    def zoom_out(self, speed=0.5):
        self.stop()
        req_move.Velocity.PanTilt._x = 0.0
        req_move.Velocity.PanTilt._y = 0.0
        req_move.Velocity.Zoom._x = -speed
        ptz.ContinuousMove(req_move)


cam = Continious_Ptz('192.168.11.12', 80, 'admin', 'Supervisor')
print 'Press ESC to exit'
speed = 0.5
while True:
    key = ord(getch())
    if key == 27:  #ESC
        break
    elif key == 56:  #Up
        cam.move_up(speed)
    elif key == 50:  #Down
        cam.move_down(speed)
    elif key == 54:  #Right
        cam.move_right(speed)
    elif key == 52:  #Left
        cam.move_left(speed)
    elif key == 53:  #Home
        cam.move_home()
    elif key == 57:  #Right Up
        cam.move_right_up(speed)
    elif key == 55:  #Left Up
Example #12
0
def main():
    if 'FRAGMAP_DEBUG' in os.environ:
        debug_parser = debug.parse_args(extendable=True)
        parent_parsers = [debug_parser]
    else:
        parent_parsers = []

    # Parse command line arguments
    argparser = argparse.ArgumentParser(
        prog='fragmap',
        description='Visualize a timeline of Git commit changes on a grid',
        parents=parent_parsers)
    inspecarg = argparser.add_argument_group(
        'input', 'Specify the input commits or patch file')
    inspecarg.add_argument('-u',
                           '--until',
                           metavar='END_COMMIT',
                           action='store',
                           required=False,
                           dest='until',
                           help='Which commit to show until, inclusive.')
    inspecarg.add_argument(
        '-n',
        metavar='NUMBER_OF_COMMITS',
        action='store',
        help=
        'How many previous commits to show. Uncommitted changes are shown in addition to these.'
    )
    inspecarg.add_argument(
        '-s',
        '--since',
        metavar='START_COMMIT',
        action='store',
        help='Which commit to start showing from, exclusive.')
    argparser.add_argument('--no-color',
                           action='store_true',
                           required=False,
                           help='Disable color coding of the output.')
    argparser.add_argument(
        '-l',
        '--live',
        action='store_true',
        required=False,
        help='Keep running and enable refreshing of the displayed fragmap')
    outformatarg = argparser.add_mutually_exclusive_group(required=False)
    argparser.add_argument(
        '-f',
        '--full',
        action='store_true',
        required=False,
        help='Show the full fragmap, disabling deduplication of the columns.')
    outformatarg.add_argument(
        '-w',
        '--web',
        action='store_true',
        required=False,
        help=
        'Generate and open an HTML document instead of printing to console. Implies -f'
    )

    args = argparser.parse_args()
    # Load commits
    cl = CommitLoader()
    if args.until and not args.since:
        print('Error: --since/-s must be used if --until/-u is used')
        exit(1)
    max_count = None
    if args.n:
        max_count = int(args.n)
    if not (args.until or args.since or args.n):
        max_count = 3
    lines_printed = [0]
    columns_printed = [0]

    def serve():
        def erase_current_line():
            print('\r' + ' ' * columns_printed[0] + '\r', end='')

        # Make way for status updates from below operations
        erase_current_line()
        selection = CommitSelection(since_ref=args.since,
                                    until_ref=args.until,
                                    max_count=max_count,
                                    include_staged=not args.until,
                                    include_unstaged=not args.until)
        is_full = args.full or args.web
        debug.get('console').debug(selection)
        diff_list = cl.load(os.getcwd(), selection)
        debug.get('console').debug(diff_list)
        # Erase each line and move cursor up to overwrite previous fragmap
        erase_current_line()
        for i in range(lines_printed[0]):
            print(ANSI_UP, end='')
            erase_current_line()
        print('... Generating fragmap\r', end='')
        fm = make_fragmap(diff_list, not is_full, False)
        print('                      \r', end='')
        return fm

    fragmap = serve()
    if args.web:
        if args.live:
            start_fragmap_server(serve)
        else:
            open_fragmap_page(fragmap, args.live)
    else:
        lines_printed[0], columns_printed[0] = print_fragmap(
            fragmap, do_color=not args.no_color)
        if args.live:
            while True:
                print('Press Enter to refresh', end='')
                import sys
                key = getch()
                if ord(key) != 0xd:
                    break
                fragmap = serve()
                lines_printed[0], columns_printed[0] = print_fragmap(
                    fragmap, do_color=not args.no_color)
            print('')