示例#1
0
 def _input_digit(self):
     c = 'x'
     while not c.isdigit():
         if c == '\r':
             return ''
         c = getch()
     sys.stdout.write(c)
     sys.stdout.flush()
     return c
示例#2
0
	def _clear_list(self):
		while True:
			resp = getch("Are you sure to clear the list? [Y/N] ")
			resp = resp.lower()
			print
			if resp == "y":
				self.player.clear()
				return
			elif resp == "n":
				return
示例#3
0
 def _clear_list(self):
     while True:
         resp = getch("Are you sure to clear the list? [Y/N] ")
         resp = resp.lower()
         print
         if resp == "y":
             self.player.clear()
             return
         elif resp == "n":
             return
示例#4
0
def search_log(cl, since, to, query='', full_log=False, result_per_page=10):
    page = 0
    ch = 'n'

    while page == 0 or (len(log_result) > 0 and ch == 'n'):
        log_result = cl.search_log(query, since, to, page=page, result_per_page=result_per_page, full=full_log)
        if len(log_result) > 0:
            print_log_result(log_result, full_log)
            print ('page ' + str(page + 1) + ' press n to next page')
            ch = getch()
            page += 1
示例#5
0
 def manual_control(self):
     print("Use w,a,s,d to move the vehicle. to exit")
     t = 0.2
     speed = 50
     step = 10
     while True:
         print(self.get_readings())
         print('Speed ', speed)
         k = getch()
         cmd = None
         if k == "w":
             cmd = {'command': 'move', 'direction': 'forward',
                    'speed': speed, 'time': t}
         elif k == "s":
             cmd = {'command': 'move', 'direction': 'backward',
                    'speed': speed, 'time': t}
         elif k == "a":
             cmd = {'command': 'move', 'direction': 'counter_clockwise',
                    'speed': speed, 'time': t}
         elif k == "d":
             cmd = {'command': 'move', 'direction': 'clockwise',
                    'speed': speed, 'time': t}
         elif k == 't':
             speed = min(100, speed + step)
         elif k == 'g':
             speed = max(0, speed - step)
         elif k == "q" and self._roofmount is not None:
             cmd = {'command': 'horizontal_position',
                    'position': (self._roofmount.horizontal_position() +
                                 (360 - 15)) % 360}
         elif k == "e" and self._roofmount is not None:
             cmd = {'command': 'horizontal_position',
                    'position': (self._roofmount.horizontal_position() +
                                 15) % 360}
         elif k == "r" and self._roofmount is not None:
             cmd = {'command': 'vertical_position',
                    'position': self._roofmount.vertical_position() + 15}
         elif k == "f" and self._roofmount is not None:
             cmd = {'command': 'vertical_position',
                    'position': self._roofmount.vertical_position() - 15}
         elif k == 'z' and self._roofmount is not None:
             cmd = {'command': 'horizontal_scan', 'vertical_position':
                    self._roofmount.vertical_position(), 'resolution': 1.0}
         elif k == 'p':
             continue
         elif k == "x":
             break
         if cmd is not None:
             self.__execute(cmd)
示例#6
0
 def _input_phone_number(self,
                         prompt,
                         color=(TextFormats.CYAN + TextFormats.UNDERLINE)):
     formatter = AsYouTypeFormatter("US")
     c = 'x'
     print(colorize("${}:$".format(prompt), color))
     while not c.isdigit():
         c = getch()
     while c != '\r':
         while not c.isdigit() and c != '\r':
             c = getch()
         if c == '\r':
             break
         phone_number = formatter.input_digit(c)
         print(phone_number, end='\r')
         c = 'x'
     sys.stdout.write('\n')
     try:
         parse(phone_number, "US")
     except NumberParseException:
         phone_number = self._input_phone_number(
             "Enter valid geographical" + " phone number",
             TextFormats.YELLOW)
     return phone_number
示例#7
0
def search_log(cl, since, to, query='', full_log=False, result_per_page=10):
    page = 0
    ch = 'n'

    while page == 0 or (len(log_result) > 0 and ch == 'n'):
        log_result = cl.search_log(query,
                                   since,
                                   to,
                                   page=page,
                                   result_per_page=result_per_page,
                                   full=full_log)
        if len(log_result) > 0:
            print_log_result(log_result, full_log)
            print('page ' + str(page + 1) + ' press n to next page')
            ch = getch()
            page += 1
示例#8
0
	def display_list(self, l, operation_type, param=None):
		if l:
			size = len(l)
			max_page = int(math.ceil(size / 10.0))
			page = 0
			to_main = False
			while not to_main:
				if operation_type == "menu":
					print "===================="
				else:
					print "\n"*50+"========= PAGE: %d/%d ===========" % (page+1, max_page)
				for i in range(10):
					if page * 10 + i >= size:
						break
					item = l[page * 10 + i]
					prefix = i + 1 if i < 9 else 0
					if operation_type == "song":
						Library.display_song(item, prefix)
					elif operation_type == "artist":
						Library.display_artist(item, prefix)
					elif operation_type == "menu":
						Menu.display_menu(item, prefix)
				print "===================="
				print "(Nums)选择   (N)下一页   (P)上一页   (B)后退   (M)主菜单\n"
				valid_selection = False
				sys.stdout.write("please select > ")
				while not valid_selection:
					select = getch()
					if select == "b":
						return
					if select == "m":
						return True
					elif select == "n":
						new_page = min(page + 1, max_page - 1)
						if page != new_page:
							page = new_page
							valid_selection = True
						continue
					elif select == "p":
						new_page = max(page - 1, 0)
						if page != new_page:
							page = new_page
							valid_selection = True
						continue
					elif select.isdigit():
						choice_str = select
						select = int(select)
						select = select - 1 if select > 0 else 9
						idx = page * 10 + select
						if idx < size:
							res = l[idx]
							print choice_str
							to_main = self._select(res, operation_type, param)
							valid_selection = True
						else:
							continue
					else:
						pass
			return True
		else:
			with color("pink"):
				print "\n"
				print "\tMMMMMMMMMMMMMMMMMMMMMWNK0kxdooooooodxk0XNWMMMMMMMMMMMMMMMMMM"
				print "\tMMMMMMMMMMMMMMMWWNKkoc;'...............,:lx0NWMMMMMMMMMMMMMM"
				print "\tMMMMMMMMMMMMWNX0d:'.........................;lkXWMMMMMMMMMMM"
				print "\tMMMMMMMMMMWNKkl,........,:clodddddooc:,'.......;d0WMMMMMMMMM"
				print "\tMMMMMMMMWXKkc'......;ldOKXXXXXXXXXXXXXKOxl;......'l0WMMMMMMM"
				print "\tMMMMMMWXKOo'.....'lkKXXXXXXXXXXXXXXXXXXXXXKko;.....,dXMMMMMM"
				print "\tMMMMWNX0k:.....,oOXXXXXXXXXXXXXXXXK0KXXXXXXXX0d;.....:0WMMMM"
				print "\tMMMWNK0x;.....cOXXXXXXK00XXXXXXXKx:':xKXXXXXXXX0o,....,kWMMM"
				print "\tMMMNKKk;....'oKXXXXXXKo,,lOXXXNX0l....:xKXXXXXXXXk:....'xWMM"
				print "\tMMNKKO:....'dKXXXXXXKo...,xXXXXXXKx;....:kKXXXXXXXOc....,OWM"
				print "\tMWKK0o.....oKXXXXXX0l...'dKXXXXXXXX0l'....ckKXXXXXXO:....:KM"
				print "\tWXKKk;....:0XXXXXX0c....lKXXXXXXXXXXKk:....'oKXXXXXXk,....dN"
				print "\tWXKKd'....dXXXXXXO:....c0XXXXXXXXXXXXX0o,..'xXXXXXXXKl....:K"
				print "\tNKK0l....,kXXXXXXOc...;OXXXXXXXXXXXXXXXXOc;dKXXXXXXXXx'...'k"
				print "\tNKK0l....;OXXXXXXX0d,,xXXXXXXXXXXXXXXXXXXK0XXXXXXXXXXk;....d"
				print "\tNKK0l....;OXXXXXXXXXOOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXO;....o"
				print "\tNKK0o....'xXXXXXXXXXXXXXXXXXKKK00OOkkxddollclkXXXXXXXk,....d"
				print "\tWKKKx,....lKXXXXXXXOdoollc::;,,,''..........'xXXXXXXXd....'k"
				print "\tWXKKOc....;kXXXXXXXx'.......................;OXXXXXX0:....:K"
				print "\tMNKK0x,....c0XXXXXXKl.....';::ccllloddc.....lKXXXXXKd.....xW"
				print "\tMWXKK0l.....l0XXXXXXk,....l0XXXXXXXXXXx'....dXXXXXXx,....cXM"
				print "\tMMWXKKOc.....cOXXXXXKo....;OXXXXXXXXXXx'...,kXXXXKd,....;0WM"
				print "\tMMMWXKKOl.....;xKXXXXO:....dXXXXXXXXXXd....:0XXX0l'....;OWMM"
				print "\tMMMMWXKK0o'.....ckKXXXd'...:0XXXXXXXXXd....lKX0d;.....:0WMMM"
				print "\tMMMMMWNKK0x:......:d0X0c...'dXXXXXXXXXo...'dOo;.....'oXMMMMM"
				print "\tMMMMMMMWNKKOd;......,cdl'...c0XXXXXXXXo....,'......c0WMMMMMM"
				print "\tMMMMMMMMMWXKKOd:............'lxxkkxxdl;.........'lONMMMMMMMM"
				print "\tMMMMMMMMMMMWNXK0xl;..........................':dKWMMMMMMMMMM"
				print "\tMMMMMMMMMMMMMMWNXX0koc;'.................':lxKNMMMMMMMMMMMMM"
				print "\tMMMMMMMMMMMMMMMMMWWNNXKOkdolc:::::cclodkOXNWMMMMMMMMMMMMMMMM"
				print "\tMMMMMMMMMMMMMMMMMMMMMMMWWWWWNNNNNNWWMMMMMMMMMMMMMMMMMMMMMMMM"
				print "\n"
			getch("It seems your query does not match any record in our library, press ENTER to continue...  ")
			return
示例#9
0
 def display_list(self, l, operation_type, param=None):
     if l:
         size = len(l)
         max_page = int(math.ceil(size / 10.0))
         page = 0
         to_main = False
         while not to_main:
             if operation_type == "menu":
                 print "===================="
             else:
                 print "\n" * 50 + "========= PAGE: %d/%d ===========" % (
                     page + 1, max_page)
             for i in range(10):
                 if page * 10 + i >= size:
                     break
                 item = l[page * 10 + i]
                 prefix = i + 1 if i < 9 else 0
                 if operation_type == "song":
                     Library.display_song(item, prefix)
                 elif operation_type == "artist":
                     Library.display_artist(item, prefix)
                 elif operation_type == "menu":
                     Menu.display_menu(item, prefix)
             print "===================="
             print "(Nums)选择   (N)下一页   (P)上一页   (B)后退   (M)主菜单\n"
             valid_selection = False
             sys.stdout.write("please select > ")
             while not valid_selection:
                 select = getch()
                 if select == "b":
                     return
                 if select == "m":
                     return True
                 elif select == "n":
                     new_page = min(page + 1, max_page - 1)
                     if page != new_page:
                         page = new_page
                         valid_selection = True
                     continue
                 elif select == "p":
                     new_page = max(page - 1, 0)
                     if page != new_page:
                         page = new_page
                         valid_selection = True
                     continue
                 elif select.isdigit():
                     choice_str = select
                     select = int(select)
                     select = select - 1 if select > 0 else 9
                     idx = page * 10 + select
                     if idx < size:
                         res = l[idx]
                         print choice_str
                         to_main = self._select(res, operation_type, param)
                         valid_selection = True
                     else:
                         continue
                 else:
                     pass
         return True
     else:
         with color("pink"):
             print "\n"
             print "\tMMMMMMMMMMMMMMMMMMMMMWNK0kxdooooooodxk0XNWMMMMMMMMMMMMMMMMMM"
             print "\tMMMMMMMMMMMMMMMWWNKkoc;'...............,:lx0NWMMMMMMMMMMMMMM"
             print "\tMMMMMMMMMMMMWNX0d:'.........................;lkXWMMMMMMMMMMM"
             print "\tMMMMMMMMMMWNKkl,........,:clodddddooc:,'.......;d0WMMMMMMMMM"
             print "\tMMMMMMMMWXKkc'......;ldOKXXXXXXXXXXXXXKOxl;......'l0WMMMMMMM"
             print "\tMMMMMMWXKOo'.....'lkKXXXXXXXXXXXXXXXXXXXXXKko;.....,dXMMMMMM"
             print "\tMMMMWNX0k:.....,oOXXXXXXXXXXXXXXXXK0KXXXXXXXX0d;.....:0WMMMM"
             print "\tMMMWNK0x;.....cOXXXXXXK00XXXXXXXKx:':xKXXXXXXXX0o,....,kWMMM"
             print "\tMMMNKKk;....'oKXXXXXXKo,,lOXXXNX0l....:xKXXXXXXXXk:....'xWMM"
             print "\tMMNKKO:....'dKXXXXXXKo...,xXXXXXXKx;....:kKXXXXXXXOc....,OWM"
             print "\tMWKK0o.....oKXXXXXX0l...'dKXXXXXXXX0l'....ckKXXXXXXO:....:KM"
             print "\tWXKKk;....:0XXXXXX0c....lKXXXXXXXXXXKk:....'oKXXXXXXk,....dN"
             print "\tWXKKd'....dXXXXXXO:....c0XXXXXXXXXXXXX0o,..'xXXXXXXXKl....:K"
             print "\tNKK0l....,kXXXXXXOc...;OXXXXXXXXXXXXXXXXOc;dKXXXXXXXXx'...'k"
             print "\tNKK0l....;OXXXXXXX0d,,xXXXXXXXXXXXXXXXXXXK0XXXXXXXXXXk;....d"
             print "\tNKK0l....;OXXXXXXXXXOOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXO;....o"
             print "\tNKK0o....'xXXXXXXXXXXXXXXXXXKKK00OOkkxddollclkXXXXXXXk,....d"
             print "\tWKKKx,....lKXXXXXXXOdoollc::;,,,''..........'xXXXXXXXd....'k"
             print "\tWXKKOc....;kXXXXXXXx'.......................;OXXXXXX0:....:K"
             print "\tMNKK0x,....c0XXXXXXKl.....';::ccllloddc.....lKXXXXXKd.....xW"
             print "\tMWXKK0l.....l0XXXXXXk,....l0XXXXXXXXXXx'....dXXXXXXx,....cXM"
             print "\tMMWXKKOc.....cOXXXXXKo....;OXXXXXXXXXXx'...,kXXXXKd,....;0WM"
             print "\tMMMWXKKOl.....;xKXXXXO:....dXXXXXXXXXXd....:0XXX0l'....;OWMM"
             print "\tMMMMWXKK0o'.....ckKXXXd'...:0XXXXXXXXXd....lKX0d;.....:0WMMM"
             print "\tMMMMMWNKK0x:......:d0X0c...'dXXXXXXXXXo...'dOo;.....'oXMMMMM"
             print "\tMMMMMMMWNKKOd;......,cdl'...c0XXXXXXXXo....,'......c0WMMMMMM"
             print "\tMMMMMMMMMWXKKOd:............'lxxkkxxdl;.........'lONMMMMMMMM"
             print "\tMMMMMMMMMMMWNXK0xl;..........................':dKWMMMMMMMMMM"
             print "\tMMMMMMMMMMMMMMWNXX0koc;'.................':lxKNMMMMMMMMMMMMM"
             print "\tMMMMMMMMMMMMMMMMMWWNNXKOkdolc:::::cclodkOXNWMMMMMMMMMMMMMMMM"
             print "\tMMMMMMMMMMMMMMMMMMMMMMMWWWWWNNNNNNWWMMMMMMMMMMMMMMMMMMMMMMMM"
             print "\n"
         getch(
             "It seems your query does not match any record in our library, press ENTER to continue...  "
         )
         return
示例#10
0
            didson.length = len(data)
            didson.data = array.array('b', data)
            lc.publish('HAUV_DIDSON_CLIENT', didson.encode())
            fc.write(data)
            fc.flush


def myexit(s):
    exit()


def nop(s):
    return


if __name__ == '__main__':

    # UDP connection
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    s.bind(('', 700))

    listener = threading.Thread(target=listen, args=(s, ))
    listener.start()

    cmd = {'q': myexit}
    while 1:
        c = util.getch()
        cmd.get(c, nop)(s)
示例#11
0
            print '-' * 20
            print msg



if __name__ == '__main__':
    argv = sys.argv
    url = None
    if len(argv) >= 2:
        url = argv[1]
    fm = DoubanFM(debug=False, url=url)
    hint = 'Command: Q[uit]\tn[ext]\tb[an]\tr[ed]\t[u]nred\tp[ause]\tP[lay]\th[elp]'
    print '😻  豆瓣FM'
    fm.play()
    while True:
        c = getch()
        if c == 'Q':
            set_skype_status('')
            break
        elif c == 'n':
            fm.pass_song()
        elif c == 'b':
            fm.ban_song()
        elif c == 'r':
            fm.red_song()
        elif c == 'u':
            fm.unred_song()
        elif c == 'p':
            fm.pause()
        elif c == 'P':
            fm.play()