def render(self, result=None): unicurses.wclear(self.scr.win) unicurses.waddstr(self.scr.win, self.title, self.scr.attr['ttl']) tdone, ttotal, terror, = 0, 0, 0 mdone, mtotal, mname, mset = 0, 0, None, False for step in self.steps: n, d, t, e, a = step tdone += d ttotal += t terror += e if mdone >= mtotal and d > 0 and not mset: mdone, mtotal, mname = d, t, n else: mset = True self.renderStep(step) unicurses.waddstr(self.scr.win, "\n Total Progress:\n") self.renderProgress(tdone, ttotal) if result != None: timerep = self.drawTime(int(round(time.time() - self.started))) msg = "\n Migration Successful!" unicurses.waddstr(self.scr.win, msg, self.scr.attr['val']) msg = "\n Completed in " + timerep msg += "\n\n Press 'q' to continue.\n\n" unicurses.waddstr(self.scr.win, msg) unicurses.flushinp() while chr(self.scr.getch(self.scr.win)) != 'q': pass elif mname != None: unicurses.waddstr(self.scr.win, "\n " + mname + " Progress:\n") self.renderProgress(mdone, mtotal) if self.current != None: unicurses.waddstr(self.scr.win, self.current + "\n") if self.currentartifact != None: unicurses.waddstr(self.scr.win, self.currentartifact + "\n") unicurses.waddstr(self.scr.win, "\n") else: unicurses.waddstr(self.scr.win, "\n")
def draw_board(self): uc.wclear(self.win_board1) uc.wclear(self.win_baord2) uc.box(self.win_boardarea, 0, 0) uc.wmove(self.win_boardarea, 1, 2) s1 = self.player.board.__str__() s2 = self.player_enemy.board.__str__() for chr in s1: if chr == '~': uc.wattron(self.win_board, uc.COLOR_PAIR(11)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(11)) elif chr == 'O': uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) elif chr == '#': uc.wattron(self.win_board, uc.COLOR_PAIR(13)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(13)) else: uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) uc.wrefresh(self.win_boardarea) uc.update_panels()
def showHelp(self): string = "Type a command key for contextual help: " unicurses.waddstr(self.scr.win, string) while True: try: key = chr(self.scr.getch(self.scr.win)) except ValueError: continue if key in self.keymap and self.keymap[key]['help'] != None: if self.keymap[key]['help'] == False: break unicurses.wclear(self.scr.win) err = self.keymap[key]['stat'] if isinstance(err, basestring): attr = self.scr.attr['err'] unicurses.wmove(self.scr.win, self.scr.h - 1, 0) unicurses.waddnstr(self.scr.win, err, self.scr.w, attr) unicurses.wmove(self.scr.win, 0, 0) title = self.keymap[key]['text'] title = ' ' * (self.scr.w - len(title) - 6) + title + " Help \n" unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl']) unicurses.waddstr(self.scr.win, self.keymap[key]['help']) string = "\n\nPress 'q' to exit help.\n\n" unicurses.waddstr(self.scr.win, string) while chr(self.scr.getch(self.scr.win)) != 'q': pass break
def showHelp(self): string = "Type a command key for contextual help: " unicurses.waddstr(self.scr.win, string) while True: key = chr(self.scr.getch(self.scr.win)) if key in self.keymap and self.keymap[key]['help'] != None: if self.keymap[key]['help'] == False: break unicurses.wclear(self.scr.win) title = self.keymap[key]['text'] title = ' '*(self.scr.w - len(title) - 6) + title + " Help \n" unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl']) unicurses.waddstr(self.scr.win, self.keymap[key]['help']) string = "\n\nPress 'q' to exit help.\n\n" unicurses.waddstr(self.scr.win, string) while chr(self.scr.getch(self.scr.win)) != 'q': pass break
def showHelp(self): string = "Type a command key for contextual help: " unicurses.waddstr(self.scr.win, string) while True: key = chr(self.scr.getch(self.scr.win)) if key in self.keymap and self.keymap[key]['help'] != None: if self.keymap[key]['help'] == False: break unicurses.wclear(self.scr.win) title = self.keymap[key]['text'] title = ' ' * (self.scr.w - len(title) - 6) + title + " Help " unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl']) unicurses.waddstr(self.scr.win, self.keymap[key]['help']) string = "\n\nPress 'q' to exit help.\n\n" unicurses.waddstr(self.scr.win, string) while chr(self.scr.getch(self.scr.win)) != 'q': pass break
def draw_board(self): uc.wclear(self.win_board) offset_x = 2 offset_y = 1 uc.box(self.win_boardarea, 0, 0) uc.wmove(self.win_boardarea, offset_y, offset_x) if self.on_menu: s = self.player.board.__str__() else: s = self.player.board.show_new_ship(self.new_ship_x, self.new_ship_y, self.menu[self.menu_hi].id, self.menu[self.menu_hi].length, self.new_ship_hor) uc.init_pair(11, uc.COLOR_BLUE, uc.COLOR_BLACK) uc.init_pair(12, uc.COLOR_WHITE, uc.COLOR_BLACK) uc.init_pair(13, uc.COLOR_RED, uc.COLOR_BLACK) for chr in s: if chr == '~': uc.wattron(self.win_board, uc.COLOR_PAIR(11)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(11)) elif chr == 'O': uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) elif chr == '#': uc.wattron(self.win_board, uc.COLOR_PAIR(13)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(13)) else: uc.wattron(self.win_board, uc.COLOR_PAIR(12)) uc.waddstr(self.win_board, chr) uc.wattroff(self.win_board, uc.COLOR_PAIR(12)) uc.wbkgd(self.win_statusbar, uc.COLOR_PAIR(11)) uc.wrefresh(self.win_boardarea) uc.update_panels()
def render(self): unicurses.wclear(self.scr.win) if self.scr.msg != None: unicurses.wmove(self.scr.win, self.scr.h - 1, 0) if isinstance(self.scr.msg, basestring): unicurses.waddnstr(self.scr.win, self.scr.msg, self.scr.w) elif isinstance(self.scr.msg, tuple): attr = self.scr.attr[self.scr.msg[0]] msg = self.scr.msg[1] unicurses.waddnstr(self.scr.win, msg, self.scr.w, attr) unicurses.wmove(self.scr.win, 0, 0) unicurses.waddstr(self.scr.win, self.titlebar, self.scr.attr['ttl']) for opt in self.curropts: if opt == None: unicurses.waddstr(self.scr.win, "\n") continue key = opt['key'] + ": " unicurses.waddstr(self.scr.win, key, self.scr.attr['key']) if not isinstance(opt['val'], basestring): pad = 2 if opt['stat'] != True else 0 if opt['wait'] == True or opt['val'] == True: pad += 2 self.dotstr(opt['text'], None, pad) else: unicurses.waddstr(self.scr.win, opt['text']) attr = self.scr.attr['val'] if opt['stat'] != True: attr = self.scr.attr['err'] unicurses.waddstr(self.scr.win, " !", attr) if opt['wait'] == True: unicurses.waddstr(self.scr.win, " ~", self.scr.attr['slp']) elif opt['val'] == True: unicurses.waddstr(self.scr.win, " +", attr) elif opt['val'] == (None, ): unicurses.waddstr(self.scr.win, " unchanged", self.scr.attr['slp']) elif isinstance(opt['val'], (basestring, list)): if len(opt['text']) > 0: unicurses.waddstr(self.scr.win, " ") value = opt['val'] if isinstance(value, list): value = ','.join(value) if '*' in opt['act']: value = '*' * len(value) self.dotstr(value, attr) if unicurses.getyx(self.scr.win)[1] > 0: unicurses.waddstr(self.scr.win, "\n") unicurses.waddstr(self.scr.win, "\n")
def draw_statusbar(self): uc.wclear(self.win_statusbar) s = '[q] quit ' if self.on_menu: s += '[\u2191\u2193] move ' s += '[\u21B5] select ' else: s += '[\u2190\u2191\u2192\u2193] move ' s += '[r] rotate ' s += '[s] suggest ' s += '[\u21B5] commit ' s += f'{self.num_ships_set}/{len(self.player.ship_list)} set' uc.waddstr(self.win_statusbar, s) uc.init_pair(4, uc.COLOR_WHITE, uc.COLOR_BLUE) uc.wbkgd(self.win_statusbar, uc.COLOR_PAIR(4)) uc.wrefresh(self.win_statusbar)
def render(self): unicurses.wclear(self.scr.win) if self.scr.msg != None: unicurses.wmove(self.scr.win, self.scr.h - 1, 0) if isinstance(self.scr.msg, basestring): unicurses.waddnstr(self.scr.win, self.scr.msg, self.scr.w) elif isinstance(self.scr.msg, tuple): attr = self.scr.attr[self.scr.msg[0]] msg = self.scr.msg[1] unicurses.waddnstr(self.scr.win, msg, self.scr.w, attr) unicurses.wmove(self.scr.win, 0, 0) unicurses.waddstr(self.scr.win, self.titlebar, self.scr.attr['ttl']) for opt in self.curropts: if opt == None: unicurses.waddstr(self.scr.win, "\n") continue key = opt['key'] + ": " unicurses.waddstr(self.scr.win, key, self.scr.attr['key']) if not isinstance(opt['val'], basestring): pad = 2 if opt['stat'] != True else 0 if opt['wait'] == True or opt['val'] == True: pad += 2 self.dotstr(opt['text'], None, pad) else: unicurses.waddstr(self.scr.win, opt['text']) attr = self.scr.attr['val'] if opt['stat'] != True: attr = self.scr.attr['err'] unicurses.waddstr(self.scr.win, " !", attr) if opt['wait'] == True: unicurses.waddstr(self.scr.win, " ~", self.scr.attr['slp']) elif opt['val'] == True: unicurses.waddstr(self.scr.win, " +", attr) elif opt['val'] == (None,): unicurses.waddstr(self.scr.win, " unchanged", self.scr.attr['slp']) elif isinstance(opt['val'], (basestring, list)): if len(opt['text']) > 0: unicurses.waddstr(self.scr.win, " ") value = opt['val'] if isinstance(value, list): value = ','.join(value) if '*' in opt['act']: value = '*'*len(value) self.dotstr(value, attr) if unicurses.getyx(self.scr.win)[1] > 0: unicurses.waddstr(self.scr.win, "\n") unicurses.waddstr(self.scr.win, "\n")
def get_messages(): old_messages = '' while True: if kill_thread: break time.sleep(0.05) while True: try: sock = socket.socket() sock.connect((HOST, PORT)) sock.sendall(bytes(channel + chr(0) + chr(2), "utf-8")) recvd = sock.recv(1024).decode().split('||') count = recvd[0] users = recvd[1].split('|') ctypes.windll.kernel32.SetConsoleTitleA(bytes(channel + ": " + str(count) + " user(s) online", "utf-8")) u.wclear(people_win) u.box(people_win) i = 1 u.mvwaddstr(people_win, i, 1, ' Users in #%s:' % channel) for user in users: i += 1 u.mvwaddstr(people_win, i, 1, ' - ' + user) u.wrefresh(people_win) sock = socket.socket() sock.connect((HOST, PORT)) break except (ConnectionRefusedError, ConnectionResetError): u.mvwaddstr(chat_win, 1, 1, "Can't connect.") time.sleep(1) sock.sendall(bytes(channel + chr(0) + chr(1), "utf-8")) incoming_messages = str(sock.recv(4096), "utf-8") if not incoming_messages == old_messages: i = 0 u.wclear(chat_win) draw_boxes() for message in get_latest(incoming_messages.split('\n')): i += 1 u.mvwaddstr(chat_win, i, 1, message[:78]) u.wrefresh(chat_win) old_messages = incoming_messages time.sleep(0.1)
def init_wins(self): '''Creates win and panel objects. ''' uc.wclear(stdscr) self.max_y, self.max_x = uc.getmaxyx(stdscr) self.win_title = uc.newwin(3, self.max_x, 0, 0) #(h, w, starty, startx) self.win_boardarea = uc.newwin(self.max_y-4, self.max_x, 3, 0) self.win_statusbar = uc.newwin(1, self.max_x, self.max_y-1, 0) x, y = self.player.board.str_size() self.win_board1 = uc.newwin(y, x+2, 0, 0) self.win_board2 = uc.newwin(y, x+2, 0, 0) self.pan_board1 = uc.new_panel(self.win_board1) self.pan_board2 = uc.new_panel(self.win_board2) uc.move_panel(self.pan_board1, 0, 0) uc.move_panel(self.pan_board2, 0, 0) uc.wrefresh(stdscr) self.draw_all()
def draw_shipmenu(self): uc.wclear(self.win_shipmenu) offset_x = 2 offset_y = 1 uc.box(self.win_shipmenu, 0, 0) uc.wmove(self.win_shipmenu, offset_y, offset_x) uc.waddstr(self.win_shipmenu, 'ship menu:') offset_y += 2 for ele in self.menu: if (self.on_menu and self.menu_hi == self.menu.index(ele)): uc.wattron(self.win_shipmenu, uc.A_REVERSE) uc.mvwaddstr(self.win_shipmenu, offset_y, offset_x, ele) uc.wattroff(self.win_shipmenu, uc.A_REVERSE) offset_y += 2 else: uc.mvwaddstr(self.win_shipmenu, offset_y, offset_x, ele) offset_y += 2 uc.wrefresh(self.win_shipmenu)
def init_wins(self): uc.wclear(stdscr) self.max_y, self.max_x = uc.getmaxyx(stdscr) border_x = ceil(self.max_x * 2 / 3) c = int(self.max_x % 2 == 1) self.win_title = uc.newwin(3, self.max_x, 0, 0) #(h, w, starty, startx) self.win_boardarea = uc.newwin(self.max_y - 4, border_x, 3, 0) self.win_shipmenu = uc.newwin(self.max_y - 4, self.max_x - border_x, 3, border_x) self.win_statusbar = uc.newwin(1, self.max_x, self.max_y - 1, 0) x, y = self.player.board.str_size() self.win_board = uc.newwin(y, x + 2, 0, 0) self.pan_board = uc.new_panel(self.win_board) uc.move_panel(self.pan_board, 3 + (self.max_y - 3) // 2 - y // 2, (border_x - 3) // 2 - x // 2) uc.wrefresh(stdscr) self.draw()
def showHelp(self): string = "Type a command key for contextual help: " unicurses.waddstr(self.scr.win, string) while True: try: key = chr(self.scr.getch(self.scr.win)) except ValueError: continue if key in self.keymap and self.keymap[key]['help'] != None: if self.keymap[key]['help'] == False: break unicurses.wclear(self.scr.win) err = self.keymap[key]['stat'] if isinstance(err, basestring): attr = self.scr.attr['err'] unicurses.wmove(self.scr.win, self.scr.h - 1, 0) unicurses.waddnstr(self.scr.win, err, self.scr.w, attr) unicurses.wmove(self.scr.win, 0, 0) title = self.keymap[key]['text'] title = ' '*(self.scr.w - len(title) - 6) + title + " Help \n" unicurses.waddstr(self.scr.win, title, self.scr.attr['ttl']) unicurses.waddstr(self.scr.win, self.keymap[key]['help']) string = "\n\nPress 'q' to exit help.\n\n" unicurses.waddstr(self.scr.win, string) while chr(self.scr.getch(self.scr.win)) != 'q': pass break
def reset(): u.wclear(chat_win) u.wclear(input_win) u.wclear(people_win)
try: sock.connect((HOST, PORT)) except WindowsError: print("Can't connect: " + HOST + ':' + str(PORT)) continue break sock.sendall(bytes(channel + chr(0) + chr(3) + chr(0) + args.user, "utf-8")) stdscr = u.initscr() u.curs_set(0) chat_win = u.newwin(25, 90, 0, 0) input_win = u.newwin(5, 90, 25, 0) people_win = u.newwin(30, 30, 0, 90) message_refresh_thread.start() while True: sock = socket.socket() u.wclear(input_win) u.mvwaddstr(input_win, 1, 1, '> ') refresh() u.flushinp() data = u.mvwgetstr(input_win, 1, 3) send = True # if len(data.split()) > 1: # if data.split()[0] == ":send": # file = data.split()[1] # if os.path.exists(file) and not os.path.isdir(file): # bdata = open(file, 'rb').read() # sock.connect((HOST, PORT)) # sock.sendall(bytes(channel + chr(0) + chr(5) + chr(0) + file + chr(0) + str(bdata) + "\n", "utf-8")) # sock.close() # send = False if data in [":exit", "^C", ":quit", ":q"]: