示例#1
0
 def test_userptr_segfault(self):
     panel = curses.panel.new_panel(self.stdscr)
     class A:
         def __del__(self):
             panel.set_userptr(None)
     panel.set_userptr(A())
     panel.set_userptr(None)
示例#2
0
 def test_userptr_segfault(self):
     w = curses.newwin(10, 10)
     panel = curses.panel.new_panel(w)
     class A:
         def __del__(self):
             panel.set_userptr(None)
     panel.set_userptr(A())
     panel.set_userptr(None)
示例#3
0
 def test_userptr_segfault(self):
     w = curses.newwin(10, 10)
     panel = curses.panel.new_panel(w)
     class A:
         def __del__(self):
             panel.set_userptr(None)
     panel.set_userptr(A())
     panel.set_userptr(None)
示例#4
0
def set_user_ptrs(panels):
    # Set the PANEL_DATA structures for individual panels
    for panel_i, panel in enumerate(panels):
        win = panel.window()
        y, x = win.getbegyx()
        h, w = win.getmaxyx()
        label = "Window Number {}".format(panel_i + 1)
        label_color = 1 + panel_i % 3
        panel_next = panels[(panel_i + 1) % len(panels)]
        panel.set_userptr(PanelData(x, y, w, h, label, label_color,
                                    panel_next))
示例#5
0
 def setdata(self, name, data):
     """
     Set the user data pointer of the panel to data. Can be any Python object.
     """
     panel = self.__panels[name]
     panel.set_userptr(data)
示例#6
0
 def __del__(self):
     panel.set_userptr(None)
示例#7
0
def main():
    # Initialize curses
    stdscr = curses.initscr()
    curses.start_color()
    curses.cbreak()
    curses.noecho()
    stdscr.keypad(True)

    # Initialize all the colors
    curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLACK)
    curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK)

    NB = 3

    my_wins = init_wins(NB)

    # Attach a panel to each window           Order is bottom up
    my_panels = [
        curses.panel.new_panel(my_wins[0]),  # Push 0, order: stdscr-0
        curses.panel.new_panel(my_wins[1]),  # Push 1, order: stdscr-0-1
        curses.panel.new_panel(my_wins[2]),  # Push 2, order: stdscr-0-1-2
    ]
    my_panels.extend(
        [curses.panel.new_panel(my_wins[i]) for i in range(3, len(my_wins))])

    # Initialize panel datas saying that nothing is hidden
    panel_datas = [PanelData(False) for _ in range(NB)]

    for panel, panel_data in zip(my_panels, panel_datas):
        panel.set_userptr(panel_data)

    # Update the stacking order. 2nd panel will be on top
    curses.panel.update_panels()

    # Show it on the screen
    stdscr.attron(curses.color_pair(4))
    stdscr.addstr(
        curses.LINES - 3, 0,
        "Show or Hide a window with 'a'(first window)  'b'(Second Window)  'c'(Third Window)"
    )
    stdscr.addstr(curses.LINES - 2, 0, "F1 to Exit")

    stdscr.attroff(curses.color_pair(4))
    curses.doupdate()

    while True:
        ch = stdscr.getch()
        if ch == curses.KEY_F1:
            break
        elif ch == ord("a"):
            temp = my_panels[0].userptr()
            if temp.hide:
                my_panels[0].show()
            else:
                my_panels[0].hide()
            temp.hide = not temp.hide
        elif ch == ord("b"):
            temp = my_panels[1].userptr()
            if temp.hide:
                my_panels[1].show()
            else:
                my_panels[1].hide()
            temp.hide = not temp.hide
        elif ch == ord("c"):
            temp = my_panels[2].userptr()
            if temp.hide:
                my_panels[2].show()
            else:
                my_panels[2].hide()
            temp.hide = not temp.hide
        curses.panel.update_panels()
        curses.doupdate()
    curses.endwin()
示例#8
0
 def __del__(self):
     panel.set_userptr(None)