def do_search(self, query): """搜索歌曲、歌手、专辑 etc. 用法示例: \033[92mfeeluown ☛ search 刘德华\033[0m """ if query.startswith('"'): query = query[1:-1] func = 'search("%s")' % query Client.send(func) data = Client.recv() songs = data.get('result', None) if type(songs) == list: self.songs = songs[:10] Helpers.print_music_list(songs) else: Helpers.print_hint("蛋疼,没有搜到...")
def do_play(self, query): """切换为播放状态或者播放一首特定的歌曲 假设有一首歌的id是: 1314 你可以通过以下命令播放你所指定的这首歌 用法示例: \033[92mfeeluown ☛ play 1314\033[0m 你也可以不加参数,它可以让播放器从暂停状态切换为播放状态: \033[92mfeeluown ☛ play\033[0m """ func = 'play()' if query != '': try: func = 'play(%d)' % int(query) except ValueError: Helpers.print_hint("参数必须是歌曲的 id") return Client.send(func) Client.recv()
root.right_bottom_panel.pack_propagate(0) root.right_bottom_panel.pack(side="bottom", expand=True, fill="x") # File list panel for the Client GUI file_list_panel = Frame(root, borderwidth=1, relief="solid", height=500, width=300) Label(file_list_panel, text="File List:", anchor="w", width=300).pack() file_list_panel.pack_propagate(0) file_list_panel.pack(side="right", expand=True, fill="both") print(sys.argv) c1 = Client(root, sys.argv[1]) # Function to connect client def connect_client(): client = threading.Thread(target=c1.start) client.daemon = True client.start() # Function to disconnect client def disconnect_client(): c1.stop() # Function to print the content on GUI
from sensor import Sensor from socket_client import Client from config_utils import Config from apscheduler.schedulers.blocking import BlockingScheduler def update(sensor, client): client.send(sensor.get_environment()) if __name__ == "__main__": config = Config() interval = config.get_value("interval") sensor_id = config.get_value("sensor_id") host, port = config.get_data_center_config() sensor = Sensor(sensor_id) scheduler = BlockingScheduler() client = Client(host, port, scheduler) client.connect() scheduler.add_job(update, 'interval', seconds=interval, max_instances=100, id='update', args=[sensor, client]) client.update_job_started = True scheduler.start()
import cv2 from config_utils import Config from socket_client import Client from json import loads from random import randint config = Config() video_server_host, video_server_port = config.get_video_server_config() data_center_host, data_center_port = config.get_data_center_config() camera_host = config.get_value("camera_host") image_quality = config.get_value("image_quality") client_of_data_center = Client(data_center_host, data_center_port) client_of_data_center.connect() client_of_video_server = Client(video_server_host, video_server_port) client_of_video_server.connect() def capture(camera_id, camera_host, image_quality): if camera_host == "0": camera_host = 0 cap = cv2.VideoCapture(camera_host) while True: ret, frame = cap.read() encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), image_quality] image = cv2.imencode('.jpg', frame, encode_param)[1] image_byte = image.tobytes() client_of_video_server.send_to_video_server(camera_id, 50, image_byte)
def do_play_preview(self, query): """播放上一个歌曲""" Client.send('play_previous()') Client.recv()
def do_play_next(self, query): """播放下一首歌曲""" Client.send('play_next()') Client.recv()
def do_pause(self, query): """暂停播放歌曲""" Client.send('pause()') Client.recv()
def connect_to_server(self, port=12100): if Client.connect(port=port): return True return False
def do_exit(self, query): """退出cli程序""" Client.close() print(ForeColors.magenta + "😋 bye ~ " + ForeColors.default) sys.exit(0)
def main(argv): """Main function""" try: opts, args = getopt.getopt(argv, 'hi:', ['help', 'input=', 'wdir=', 'std=', 'gainfile=', 'secondgain=', 'finwell=', 'finfield=', 'coords=', 'host=', 'inputgain=', 'template=', '10x', '40x', '63x', 'uvaf', 'gain' ]) except getopt.GetoptError as e: print e usage() sys.exit(2) if not opts: usage() sys.exit(0) imaging_dir = '' working_dir = os.path.dirname(os.path.abspath(__file__)) std_well = 'U00--V00' initialgains_file = os.path.normpath(os.path.join(working_dir, '10x_gain.csv')) last_well = 'U11--V07' last_field = 'X01--Y01' template_file = None coord_file = None input_gain = None host = '' end_10x = False end_40x = False end_63x = False gain_only = False first_job = 1 for opt, arg in opts: if opt in ('-h', '--help'): usage() sys.exit() elif opt in ('-i', '--input'): imaging_dir = os.path.normpath(arg) elif opt in ('--wdir'): working_dir = os.path.normpath(arg) elif opt in ('--std'): std_well = arg # 'U00--V00' elif opt in ('--gainfile'): initialgains_file = os.path.normpath(arg) elif opt in ('--finwell'): last_well = arg # 'U00--V00' elif opt in ('--finfield'): last_field = arg # 'X00--Y00' elif opt in ('--coords'): coord_file = os.path.normpath(arg) # elif opt in ('--host'): host = arg elif opt in ('--inputgain'): input_gain = arg elif opt in ('--template'): template_file = arg elif opt in ('--10x'): end_10x = True elif opt in ('--40x'): end_40x = True elif opt in ('--63x'): end_63x = True elif opt in ('--uvaf'): first_job = 1 elif opt in ('--gain'): gain_only = True else: assert False, 'Unhandled option!' # Paths r_script = os.path.normpath(os.path.join(working_dir, 'gain.r')) # Job names af_job_10x = 'af10xcam' afr_10x = '200' afs_10x = '41' af_job_40x = 'af40x' afr_40x = '105' afs_40x = '106' af_job_63x = 'af63x' afr_63x = '50' afs_63x = '51' g_job_10x = 'gain10x' g_job_40x = 'gain40x' g_job_63x = 'gain63x' pattern_g_10x = 'pattern7' pattern_g_40x = 'pattern8' pattern_g_63x = 'pattern9' job_10x = ['job22', 'job23', 'job24'] pattern_10x = 'pattern10' job_40x = ['job7', 'job8', 'job9'] pattern_40x = 'pattern2' job_63x = ['job10', 'job11', 'job12'] pattern_63x = 'pattern3' job_dummy_10x = 'dummy10x' pattern_dummy_10x = 'pdummy10x' pattern_dummy_40x = 'pdummy40x' pattern = '' pattern_g = pattern_g_10x job_list = [] # Lists and strings for storing command strings. com_list = [] end_com_list = [] com = '' end_com = [] # Booleans etc to control flow. stage1 = True stage2 = True stage3 = True stage4 = False stage5 = False if end_10x: end_40x = False end_63x = False pattern_g = pattern_g_10x job_list = job_10x pattern = pattern_10x elif end_40x: end_10x = False end_63x = False pattern_g = pattern_g_40x job_list = job_40x pattern = pattern_40x if coord_file: end_63x = True coords = read_csv(coord_file, 'fov', ['dxPx', 'dyPx']) else: coords = None if end_63x: end_10x = False end_40x = False stage3 = False stage4 = True pattern_g = pattern_g_63x job_list = job_63x pattern = pattern_63x if gain_only: stage3 = False stage4 = False if input_gain: stage1 = False wells = [] if template_file: template = read_csv(template_file, 'gain_from_well', ['well']) last_well = sorted(template.keys())[-1] # Selected wells from template file. wells = sorted(template.keys()) else: template = None # All wells. for u in range(int(get_wfx(last_well))): for v in range(int(get_wfy(last_well))): wells.append('U0' + str(u) + '--V0' + str(v)) # Selected objective gain job cam command in wells. for well in wells: for i in range(2): com = gen_cam_com(com, pattern_g, well, i, i, 'true', 0, 0) end_com = ['CAM', well, 'E0' + str(2), 'X0{}--Y0{}'.format(i, i) ] com_list.append(com) end_com_list.append(end_com) com = '' if end_10x or end_40x: com = ''.join(com_list) com_list = [] com_list.append(com) end_com_list = [] end_com_list.append(end_com) # commands start_com = '/cli:1 /app:matrix /cmd:startscan\n' stop_com = '/cli:1 /app:matrix /cmd:stopscan\n' stop_cam_com = '/cli:1 /app:matrix /cmd:stopcamscan\n' cstart = camstart_com() # Create socket sock = Client() # Port number port = 8895 # Connect to server sock.connect(host, port) # lists for keeping csv file base path names and # corresponding well names filebases = [] fin_wells = [] # dicts of lists to store wells with gain values for the four channels. gain_dict = defaultdict(list) saved_gains = defaultdict(list) if input_gain: gain_dict = read_csv(input_gain, 'well', ['green', 'blue', 'yellow', 'red'] ) com_result = gen_com(gain_dict, template, job_list, pattern, first_job, end_63x, coords=coords ) com_list = com_result['com'] end_com_list = com_result['end_com'] if stage1 or stage3 or stage4: send_com(com_list, end_com_list, sock, start_com, cstart, stop_cam_com, stop_com, imaging_dir, last_field, end_63x, r_script, initialgains_file, saved_gains, template, job_list, pattern, first_job, coords, stage1=stage1, stage3=stage3, stage4=stage4 ) print('\nExperiment finished!')