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 set_panel_order(self):
     if self.is_active_window("popup"):
         uc.top_panel(self._panels["popup"])
     elif self.is_active_window("search_results"):
         uc.top_panel(self._panels["search_results"])
     elif self.is_active_window("select_device"):
         uc.top_panel(self._panels["select_device"])
     else:
         for panel_name, panel in self._panels.items():
             if panel_name not in ["search_results", "select_device", "popup"]:
                 uc.top_panel(panel)
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 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()
my_panels[0] = uni.new_panel(my_wins[0])
#my_panels[1] = uni.new_panel(my_wins[1])
#my_panels[2] = uni.new_panel(my_wins[2])

uni.set_panel_userptr(my_panels[0], my_panels[1])
#uni.set_panel_userptr(my_panels[1], my_panels[2])
#uni.set_panel_userptr(my_panels[2], my_panels[0])

uni.update_panels()

# Turn on color text for header
#uni.attron(uni.COLOR_PAIR(4))
#uni.mvaddstr(0, int(NCOLS / 2) - 2, "Use tab to browse through the windows (Q to Exit)")
# Turn off
#uni.attroff(uni.COLOR_PAIR(4))
uni.doupdate()

top = my_panels[2]

ch = -1
while ((ch != uni.CCHAR('q')) and (ch != uni.CCHAR('Q'))):
    ch = uni.getch()
    if ch == 9:
        top = uni.panel_userptr(top)
        uni.top_panel(top)
    uni.update_panels()
    uni.doupdate()

uni.endwin()
Exemple #6
0
    def __init__(self):
        self.turn =1
        
        #Create debugging display
        debug_win = uc.newwin(15, 30, 0, 0)
        uc.box(debug_win)
        uc.wmove(debug_win, 1, 1)
        uc.waddstr(debug_win, "Debug:")
        uc.wmove(debug_win, 2, 1)

        debug_pnl = uc.new_panel(debug_win)
        uc.move_panel(debug_pnl, glob.CAM_HEIGHT, 32)

        #Generate the world
        self.world = Map(glob.N_HEX_ROWS, glob.N_HEX_COLS, debug_win)

        #map_height: 3 + 2*(rows-1) + 2 for border
        #map_width: 5 + 4*cols + 2 for border
        map_win = uc.newwin(glob.CAM_HEIGHT, glob.CAM_WIDTH, 0, 0)


        self.painter = Painter(glob.N_HEX_ROWS, glob.N_HEX_COLS, map_win)
        self.painter.updateAllTiles(self.world)

        #Put world window into a panel
        map_pnl = uc.new_panel(map_win)
        uc.move_panel(map_pnl, 1, 1)

        uc.top_panel(debug_pnl)

        self.status_win = uc.newwin(10, 30, 0, 0)
        uc.box(self.status_win)
        uc.wmove(self.status_win, 1, 1)
        uc.waddstr(self.status_win, "Turn " + str(self.turn))

        status_pnl = uc.new_panel(self.status_win)
        uc.move_panel(status_pnl, glob.CAM_HEIGHT, 2)

        self.tile_window = TileWindow()

        self.painter.drawWindow()
        showChanges()

        
        
        #input loop
        while True:
            sys.stdout.flush()
            ch = uc.getch()
            uc.waddstr(debug_win, str(ch))
            #Exit Key
            if ch == Key.ESC:
                break
            #Movement Keys
            elif ch == Key.E:
                self.movePlayer(HexDir.UL)
            elif ch == Key.R:
                self.movePlayer(HexDir.UR)
            elif ch == Key.S:
                self.movePlayer(HexDir.L)
            elif ch == Key.G:
                self.movePlayer(HexDir.R)
            elif ch == Key.D:
                self.movePlayer(HexDir.DL)
            elif ch == Key.F:
                self.movePlayer(HexDir.DR)
            #End Turn Key
            elif ch == Key.SPACE:
                self.incrementTurn()
            #Camera Scrolling Keys
            #TBD: Remaining order checks
            elif ch == uc.KEY_UP:
                self.painter.moveCamera(0, -1*glob.CAM_SPEED)
            elif ch == uc.KEY_DOWN:
                self.painter.moveCamera(0, glob.CAM_SPEED)
            elif ch == uc.KEY_LEFT:
                self.painter.moveCamera(-1*glob.CAM_SPEED, 0)
            elif ch == uc.KEY_RIGHT:
                self.painter.moveCamera(glob.CAM_SPEED, 0)
            #Toggle drawing borders
            elif ch == Key.B:
                self.painter.draw_borders = not self.painter.draw_borders
                self.painter.updateAllTileBorders(self.world)
                self.painter.drawWindow()