def getPromptSprite(self): promptSprite = Prompt(self.result) if DEBUG: pass # print "scaling promptSprite to W:{}, H:{}".format(0.6 * self.width, 0.3 * self.height) promptSprite.image = pygame.transform.scale( promptSprite.image, (int(self.width), int(self.height))) # promptSprite.center = (0.5 * self.width, 0.5 * self.height) return promptSprite
def create_prompts(subs_file): prompts = [] with open(subs_file, 'r', encoding='iso8859_9') as f: chunks = f.read().split('\n\n') for chunk in chunks: if chunk == '': continue lines = chunk.split('\n') prompts.append(Prompt(lines[0], lines[1], lines[2:])) return prompts
def dial(self, dest, agi_handler): """ Place the call. Returns nothing. Use the DIALSTATUS dialplan variable to find out how the call ended. """ if (self.__sip_proxy == None): self.__sip_proxy = agi_handler.sipProxy() if (self.__call_id != None): agi_handler.setVariable('_SIP_FORCE_CALLID', self.__call_id) if (not self.__misc_vars_set): agi_handler.setVariable('CALLERID(all)', "%s <%s>" % (self.__calleridname, self.__cli)) self.__misc_vars_set = True arg = ("SIP/%s:%s:%s:%s@%s" + get_arg_delimiter() + get_arg_delimiter()) % (dest, self.__password, self.__md5secret, self.__authname, self.__sip_proxy) if self.allow_disconnect_by_caller: arg += 'H' if self.allow_disconnect_by_called_party: arg += 'h' if self.continue_on_hangup: arg += 'g' if (self.__max_duration != None and self.__max_duration > 0): arg += 'L(%d' % (self.__max_duration * 1000) if (self.__warn_time != None): arg += ':%d' % (self.__warn_time * 1000) arg += ')' if (self.__warn_phrase != None): try: prompts = agi_handler.speechSynth().promptFileSequence(self.__warn_phrase, True) aggregate_prompt = Prompt(self.__tmp_dir) for fname in prompts: aggregate_prompt.appendFile(fname) agi_handler.setVariable("_LIMIT_WARNING_FILE", aggregate_prompt.basename()) except PromptException: pass # Phrase cannot be built for hdr in self.__hdr_by_name.values(): hdr.apply(agi_handler) agi_handler.execApp('Dial', arg)
def checkWinner(self, xcoord, ycoord): # if the user clicks a mine, change the reset button image and end the game if self.buttonDict[str(xcoord) + "," + str(ycoord)].cget( "state") == "disabled" and self.boardList[ycoord - 1][xcoord - 1] == "m": self.buttonReset.config(image=self.dead) # disable all the buttons for x in range(1, int(self.columns) + 1): for y in range(1, int(self.rows) + 1): if self.boardList[y - 1][x - 1] == "m" and self.buttonDict[ str(x) + "," + str(y)].getImage() != self.mine: self.buttonDict[str(x) + "," + str(y)].config(image=self.revealMine) self.buttonDict[str(x) + "," + str(y)].config(state="disabled") # stop the stopwatch self.stopwatch.stop() # show a messagebox messagebox.showinfo("LOSER", "Sorry! You lost!") else: # make an empty list checkerList = [] # for each button in buttonDict, if the state is normal, add it to checkerList for item in self.buttonDict: if self.buttonDict[item].cget("state") == "normal": checkerList.append(item) # check if length of the checkerList is equal to the number of mines, i.e. the only non-disabled buttons are all mines if len(checkerList) == self.mines: # change the image for the reset button self.buttonReset.config(image=self.glasses) # stop the stopwatch self.stopwatch.stop() # show messageboxes messagebox.showinfo("YOU WIN!", "Congratulations! You won!") messagebox.showinfo( "TIME TAKEN", "You took " + str(int(self.stopwatch.getTime())) + " seconds to win the game!") time = self.findMinTime() # make a Prompt window, asking the user for his or her name if (self.mines == 10 and self.rows == 10 and self.columns == 10 ) or (self.mines == 20 and self.rows == 10 and self.columns == 20) or (self.mines == 50 and self.rows == 25 and self.columns == 20): root2 = Tk() root2.title("High Scorers") reader = Prompt(root2, time, self.mines, self.rows, self.columns) # if there are more buttons with a normal state than the number of mines, set checkerList equal to an empty list else: checkerList = []
def processBar(num, total): # 进度条 rate = num / total rate_num = int(rate * 100) pretty = Prompt.random_color('✈') if rate_num == 100: r = '\r{}{}%\n'.format( pretty * int(rate_num / 5), rate_num, ) else: r = '\r{}{}%'.format( pretty * int(rate_num / 5), rate_num, ) sys.stdout.write(r) sys.stdout.flush
def main(self): sk = socket.socket() # 创建客户套接字 sk.connect((self.ip, self.port)) # 尝试连接服务器 while True: content = input('>>>').strip() sk.send(repr(content).encode('utf-8')) # 发送数据 ret = sk.recv(self.max) # 最大接收1024字节 msg = ret.decode('utf-8') # 接收的信息解码 # print(msg) # 打印接收信息 print(time.strftime('%Y-%m-%d %H:%M:%S')) print(Prompt.interlacing_color('女:' + msg)) if content.upper() == 'Q': # 判断接收的信息是否为q sk.send(repr(content).encode('utf-8')) # 发送q给服务器 sk.close() # 关闭客户套接字 break # 跳出while循环
def main(self): sk = socket.socket() # 创建套接字 sk.bind((self.ip, self.port)) # 把地址绑定到套接字 sk.listen() # 监听连接 conn, addr = sk.accept() # 等待接受客户端连接 # print(addr) # 打印客户端IP和端口号 while True: ret = conn.recv(self.max) # 最大接收1024字节 msg = ret.decode('utf-8') # 接收的信息解码 # print(msg) # 打印接收信息 print(time.strftime('%Y-%m-%d %H:%M:%S')) print(Prompt.interlacing_color('男:' + msg)) if msg.upper() == 'Q': # 判断接收的信息是否为q conn.close() # 关闭客户端套接字 sk.close() # 关闭服务器套接字,不再接收请求 break # 退出while循环 content = input('>>>').strip() conn.send(repr(content).encode('utf-8')) # 给客户端发送消息
if __name__ == '__main__': if len(sys.argv) <= 2: print( "Ce client nécessite le port et le format de message transmis, sois xml ou Json." ) sys.exit(1) host = '138.197.156.251' port = int(sys.argv[1]) fileManager = FileManager() if (sys.argv[2] == "xml"): protocole = Protocole_xml(fileManager) elif (sys.argv[2] == "json"): protocole = Protocole_json(fileManager) else: print("Protocole invalide") sys.exit(1) connexion = Connexion(host, port) client = Client(connexion, protocole, fileManager) try: if (sys.argv[3] == "prompt"): prompt = Prompt(client) except: client.automatedSyncronisation()
dic_len = sk.recv(4) dic_len = struct.unpack('i', dic_len)[0] dic = sk.recv(dic_len) str_dic = dic.decode('utf-8') dic = json.loads(str_dic) md5 = hashlib.md5() with open(dic['filename'], 'wb') as f: # 使用wb更严谨一些,虽然可以使用ab content_size = 0 while True: content = sk.recv(dic['buffer_size']) # 接收指定大小 f.write(content) # 写入文件 content_size += len(content) # 接收大小 md5.update(content) # 摘要 processBar(content_size, dic['filesize']) # 执行进度条函数 if content_size == dic['filesize']: break # 当接收的总大小等于文件大小时,终止循环 md5 = md5.hexdigest() print(md5) # 打印md5值 if dic['filename_md5'] == str(md5): print(Prompt.display('md5校验正确--下载成功', 'green')) else: print(Prompt.display('文件验证失败', 'red')) os.remove(dic['filename']) # 删除文件 sk.close() # 关闭连接 end_time = time.time() # 结束时间 print('本次下载花费了{}秒'.format(end_time - start_time))
def main(argv): parametro = ' usage: ulftp.py -u <user> -p <password> -s <server> -r <port>[optional]' diretorioAtual = '' usuario = '' senha = '' servidor ='' porta = 21 ftpDados = FTP() try: opts, args = getopt.getopt(argv,"hu:p:s:c:r:") except getopt.GetoptError: print 'there are invalid parameters' print'' print parametro print '' sys.exit(2) for opt,arg in opts: if opt == '-h': print '' print '2015 - Software developed by Ulisses de Castro' print 'this is a basic ftp client' print '' print 'beta version 001' print '' print parametro print '' print 'This help' print '===============================' print '-u => user to connect' print '-p => password to connect' print '-s => FTP server' print '-r => port optional default 21' print '===============================' print '' sys.exit() elif opt in ("-u"): usuario = arg elif opt in ("-p"): senha = arg elif opt in ("-s"): servidor = arg elif opt in("-c"): diretorioAtual = arg elif opt in("-r"): if arg != '': porta = arg else: print 'there are invalid parameters' print'' print parametro print '' if usuario !='' and senha !='' and servidor !='': try: print '' prompt = Prompt() prompt.open(servidor,porta,usuario,senha) prompt.prompt ='>$ ' prompt.cmdloop('Starting prompt...') except Exception, e: print str(e) sys.exit(2)