def __init__(self, main_interface): self.game_interface = main_interface self.x = 130 self.y = 0 self.width = 20 self.height = 50 self.game_menu_interface_window = newwin(self.height, self.width, self.y, self.x) self.game_menu_interface_panel = new_panel( self.game_menu_interface_window) self.buttons = [] self.buttons_list = [ "MAIN MENU", "TASKS", "FASTER", "SLOWER", "BUILD TOWER", "READY", "PAUSE" ] self._init_buttons() self.topics_pointer = 0 self.locked_buttons = [1, 2, 3, 5] self.to_stay_lock = [] self.last_point = -1 self.enabled = True self.blocked = False wbkgd(self.game_menu_interface_window, CYAN_WHITE) update_panels() doupdate()
def _activate(self): box(self.button_window) mvwaddstr(self.button_window, ((self.height + 1) // 2) - 1, (self.width - len(self.name)) // 2 + 1, self.name) wbkgd(self.button_window, BLUE_WHITE) wrefresh(self.button_window) update_panels() doupdate()
def main(): if not curses.has_colors(): print("Your terminal emulator needs to have colors.") return 0 ## Curses normal init sequence stdscr = curses.initscr() curses.noecho() # no echo, but we still see the cursor curses.curs_set(False) #turns off the cursor drawing stdscr.keypad(True) # allows special keys and arrow keys try: curses.start_color() curses.update_panels() curses.doupdate() while True: key = curses.getch() if key == 27: break curses.update_panels() curses.doupdate() except Exception as e: stdscr.addstr(0, 0, str(e)) stdscr.getch() finally: curses.endwin() return 0
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 write(scrid, text, ypos, xpos, color="white"): uni.setsyx(ypos, xpos) uni.waddstr(scrid, text) uni.setsyx(0, 0) uni.refresh() uni.update_panels() uni.doupdate()
def refresh(self): if self.enabled and not self.blocked: self.draw() box(self.game_field_window) wrefresh(self.game_field_window) update_panels() doupdate()
def draw_boardareaarea(self): uc.werase(self.win_board) uc.box(self.win_boardarea, 0, 0) uc.wmove(self.win_boardarea, 1, 2) 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) 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.wrefresh(self.win_boardarea) uc.update_panels()
def draw(self): if self.game_interface.game_initialized: self.field_data_pull = self.game_interface.game.game_map x = 1 y = 1 for line in self.field_data_pull: for cell in line: if cell == ':': mvwaddstr(self.game_field_window, y, x, cell, GREEN_YELLOW) elif cell == '~': mvwaddstr(self.game_field_window, y, x, cell, BLUE_WHITE) elif cell == '#': mvwaddstr(self.game_field_window, y, x, cell, BLACK_RED) elif cell == 'C': mvwaddstr(self.game_field_window, y, x, cell, BLUE_WHITE) else: mvwaddstr(self.game_field_window, y, x, cell, WHITE_BLACK) x += 1 x = 1 y += 1 wrefresh(self.game_field_window) if self.selector: self.selector.refresh_for_draw() update_panels() doupdate()
def draw(self): """Draw window and all child widgets.""" uni.clrtobot() uni.refresh() # Requires all child widgets to have a show method [w.show() for w in self.widgets] uni.update_panels() uni.doupdate()
def show(self, render_fn=None): """Show the widget.""" # Call render() method if exists if hasattr(self, "render"): self.render() if hasattr(self, "panel"): uni.show_panel(self.panel) uni.update_panels()
def refresh(self): if self.enabled: for button in self.buttons: button.refresh() box(self.game_menu_interface_window) wrefresh(self.game_menu_interface_window) update_panels() doupdate()
def __init__(self, main_interface): self.game_interface = main_interface self.enabled = True self.x = 0 self.y = 0 self.width = 130 self.height = 5 self.game_stat_window = newwin(self.height, self.width, self.y, self.x) self.game_stat_panel = new_panel(self.game_stat_window) wbkgd(self.game_stat_window, CYAN_RED) update_panels() doupdate()
def building(self, key): if not self.selector: self.selector = GameFieldSelector(self, self.game_field_window) self.selector.key_event(key) if key == 10: if self.selector.building_zone_free: self.game_interface.game.add_tower(self.selector.x - 1, self.selector.y - 1) self.exit_building() elif key == 27: self.exit_building() wrefresh(self.game_field_window) update_panels() doupdate()
def __init__(self, main_interface, width, height): self.enabled = True self.game_interface = main_interface self.y = 15 self.x = 50 self.width = width self.height = height self.menu_window = newwin(height, width, self.y, self.x) self.topics = ["NEW GAME", "RESUME GAME", "LOAD GAME", "SAVE GAME", "SETTINGS", "EXIT"] self.topics_pointer = 0 self.locked_topics = [1, 2, 3, 4] self.to_stay_lock = [] self.panel = new_panel(self.menu_window) update_panels() doupdate()
def refresh(self): if self.enabled: x = 2 y = 2 box(self.game_stat_window, 0, 0) mvwaddstr(self.game_stat_window, y, x, " " * 127) if self.game_interface.game_initialized: for param in self.game_interface.game.player.strings_info: wattron(self.game_stat_window, A_REVERSE) mvwaddstr(self.game_stat_window, y, x, param, RED_WHITE) wattroff(self.game_stat_window, A_REVERSE) x += 5 + len(param) wrefresh(self.game_stat_window) update_panels() doupdate()
def main(): ## Curses normal init sequence stdscr = curses.initscr() curses.noecho() # no echo, but we still see the cursor curses.curs_set(False) #turns off the cursor drawing stdscr.keypad(True) # allows special keys and arrow keys try: curses.start_color() window = curses.newwin(3, 20, 5, 5) window.addstr(1, 1, "Hey there!") window.box() window2 = curses.newwin(3, 20, 4, 4) window2.addstr(1, 1, "Hey there, again!") window2.box() panel = curses.new_panel(window) panel2 = curses.new_panel(window2) #curses.move_panel(panel, 10, 30) curses.update_panels() curses.doupdate() top_p = None while True: key = curses.getch() if key == 27: break top_p = panel if top_p is panel2 else panel2 curses.top_panel(top_p) curses.update_panels() curses.doupdate() except Exception as e: stdscr.addstr(0, 0, str(e)) stdscr.getch() finally: curses.endwin() return 0
def show_submenu(self, key): self.open_submenu = self.menukeys[key] self.selection = self.open_submenu.panel self.selection.show() uni.update_panels() # Listen for keypress with submenu open while True: c = uni.wgetch(self.win) if c in QUIT_KEYS: self.reset() break elif c in self.open_submenu.actions: # option_keys uni.mvaddstr(win.maxy, 0, "DEBUG: Character pressed: {0}".format(c)) uni.refresh() self.open_submenu.action(c)
def __init__(self, main_interface): self.game_interface = main_interface self.enabled = True self.blocked = False self.x = 0 self.y = 5 self.point_x = 1 self.point_y = 1 self.width = 130 self.height = 45 self.field_data_pull = None self.game_field_window = newwin(self.height, self.width, self.y, self.x) self.game_field_panel = new_panel(self.game_field_window) self.selector = None wbkgd(self.game_field_window, CYAN_RED) update_panels() doupdate()
def __init__(self, items, stdscreen): self.width = 30 self.height = 10 self.startx = int((80 - self.width) / 2) self.starty = int((24 - self.height) / 2) self.window = uni.newwin(self.height, self.width, self.starty, self.startx) #stdscreen.subwin(0,0) #self.window.keypad(1) uni.keypad(self.window, True) self.panel = uni.new_panel(self.window) #.panel.new_panel(self.window) #self.panel.hide() #uni.hide_panel(self.panel) uni.update_panels() #uni.panel.update_panels() self.position = 0 self.items = items self.items.append(('exit', 'exit'))
def __init__(self, main_interface, width, height): self.enabled = True self.game_interface = main_interface self.y = 15 self.x = 50 self.width = width self.height = height self.menu_window = newwin(height, width, self.y, self.x) self.topics = [ "NEW GAME", "RESUME GAME", "LOAD GAME", "SAVE GAME", "SETTINGS", "EXIT" ] self.topics_pointer = 0 self.locked_topics = [1, 2, 3, 4] self.to_stay_lock = [] self.panel = new_panel(self.menu_window) update_panels() doupdate()
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 _refresh(self): x = 2 y = 2 box(self.menu_window, 0, 0) for i in range(0, len(self.topics)): if self.topics_pointer == i: wattron(self.menu_window, A_REVERSE) mvwaddstr(self.menu_window, y, x, self.topics[i]) wattroff(self.menu_window, A_REVERSE) elif i in self.locked_topics: wattron(self.menu_window, A_UNDERLINE) mvwaddstr(self.menu_window, y, x, self.topics[i]) wattroff(self.menu_window, A_UNDERLINE) else: mvwaddstr(self.menu_window, y, x, self.topics[i]) y += 1 wrefresh(self.menu_window) update_panels() doupdate()
def main(): if not curses.has_colors(): print("Your terminal emulator needs to have colors.") return 0 ## Curses normal init sequence stdscr = curses.initscr() curses.noecho() # no echo, but we still see the cursor curses.curs_set(False) #turns off the cursor drawing stdscr.keypad(True) # allows special keys and arrow keys try: curses.start_color() avatar = Player(stdscr, "@", curses.COLOR_RED, curses.COLOR_BLACK, curses.A_BOLD) curses.attron(curses.color_pair(1)) curses.vline("|", 10) curses.hline("-", 10) curses.attroff(curses.color_pair(1)) while True: key = curses.getch() avatar.move(key) if key == 27: break curses.update_panels() curses.doupdate() except Exception as e: stdscr.addstr(0, 0, str(e)) stdscr.getch() finally: curses.endwin() return 0
def main(): ## Curses normal init sequence stdscr = curses.initscr() curses.noecho() # no echo, but we still see the cursor curses.curs_set(False) #turns off the cursor drawing stdscr.keypad(True) # allows special keys and arrow keys try: curses.start_color() curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_GREEN) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_GREEN) dude = curses.newwin(1, 1, 10, 30) curses.waddstr(dude, "@", curses.color_pair(2) + curses.A_BOLD) dude_panel = curses.new_panel(dude) grass = curses.newwin(10, 50, 5, 5) grass.bkgd(" ", curses.color_pair(1)) grass_panel = curses.new_panel(grass) curses.top_panel(dude_panel) curses.update_panels() curses.doupdate() while True: key = curses.getch() if key == 27: break curses.update_panels() curses.doupdate() except Exception as e: stdscr.addstr(0, 0, str(e)) stdscr.getch() finally: curses.endwin() return 0
def __init__(self, main_interface): self.game_interface = main_interface self.x = 130 self.y = 0 self.width = 20 self.height = 50 self.game_menu_interface_window = newwin(self.height, self.width, self.y, self.x) self.game_menu_interface_panel = new_panel(self.game_menu_interface_window) self.buttons = [] self.buttons_list = ["MAIN MENU", "TASKS", "FASTER", "SLOWER", "BUILD TOWER", "READY", "PAUSE"] self._init_buttons() self.topics_pointer = 0 self.locked_buttons = [1, 2, 3, 5] self.to_stay_lock = [] self.last_point = -1 self.enabled = True self.blocked = False wbkgd(self.game_menu_interface_window, CYAN_WHITE) update_panels() doupdate()
def render(self): # Set the panel order based on what action is going on. self.set_panel_order() # Update the panel size incase the terminal size changed. self.update_panel_size() # Clear the screen. uc.erase() # Draw all of the panels. self.render_user_panel() self.render_track_panel() self.render_player_panel() self.render_footer() self.render_search_panel() self.render_select_device_panel() self.render_popup_panel() # Required. uc.update_panels() uc.doupdate()
def display(self): #self.panel.top() uni.top_panel(self.panel) uni.show_panel(self.panel) #self.panel.show() uni.clear() #self.window.clear() while True: uni.refresh() #self.window.refresh() uni.doupdate() for index, item in enumerate(self.items): if index == self.position: mode = uni.A_REVERSE else: mode = uni.A_NORMAL msg = '%d. %s' % (index, item[0]) uni.mvaddstr(1 + index, 1, msg, mode) key = uni.getch() if key in [uni.KEY_ENTER, ord('\n')]: if self.position == len(self.items) - 1: break else: self.items[self.position][1]() elif key == uni.KEY_UP: self.navigate(-1) elif key == uni.KEY_DOWN: self.navigate(1) uni.clear() #self.window.clear() uni.hide_panel(self.panel) #self.panel.hide() uni.update_panels() #panel.update_panels() uni.doupdate()
def showChanges(): uc.update_panels() uc.doupdate()
def reset(self): if self.selection: self.selection.hide() uni.update_panels() uni.refresh()
def hide(self): """Hide the widget.""" uni.hide_panel(self.panel) uni.update_panels()
menu = uni.newwin(menu_height, maxx, 0, 0) starty, startx = uni.getbegyx(menu) height, width = uni.getmaxyx(menu) # Box line uni.box(menu, 0, 0) #uni.bkgd(uni.COLOR_PAIR(1)) # Box label #uni.wattron(menu, uni.COLOR_PAIR(0)) #uni.mvwaddstr(menu, 0, 2, "Garin") uni.mvwaddstr(menu, 1, 1, "File") uni.mvwaddstr(menu, 1, len("File") + 2, "Edit") #uni.wattroff(menu, uni.COLOR_PAIR(0)) uni.refresh() #uni.bkgd(uni.COLOR_PAIR(1)) #win_show(my_wins[0], label, 0) panel = uni.new_panel(menu) #uni.set_panel_userptr(panel, panel) uni.update_panels() uni.doupdate() while True: keypress = uni.getch() if keypress == 113: break
def show_changes(self): curses.update_panels() curses.doupdate()