Guest User

cursus

a guest
Dec 28th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. import curses
  2. from curses import wrapper
  3. from curses.textpad import Textbox, rectangle
  4.  
  5. class Window():
  6.     def __init__(self, height, width, start_y, start_x):
  7.         self.height = height
  8.         self.width = width
  9.         self.start_y = start_y
  10.         self.start_x = start_x
  11.    
  12.     def update(self, h, w, sy, sx):
  13.         self.height = h
  14.         self.width = w
  15.         self.start_y = sy
  16.         self.start_x = sx
  17.  
  18. class Ui():
  19.     def __init__(self, stdscr):
  20.         self.stdscr = stdscr
  21.         self.y, self.x = self.stdscr.getmaxyx()
  22.         self.sb_dim = Window(self.y - 3, self.x // 5, 1, 1)
  23.         self.side_bar = curses.newwin(self.sb_dim.height, self.sb_dim.width, self.sb_dim.start_y, self.sb_dim.start_x)
  24.         self.user_text = None
  25.  
  26.     def run(self):
  27.         self.print_screen()
  28.  
  29.         while True:
  30.             c = self.stdscr.getch()
  31.            
  32.             if c == ord('q'):
  33.                 break
  34.             elif c == curses.KEY_RESIZE:
  35.                 try:
  36.                     self.resize()
  37.                     self.print_screen()
  38.                 except Exception as e:
  39.                     print(e)
  40.  
  41.     def resize(self):
  42.         self.y, self.x = self.stdscr.getmaxyx()
  43.         self.sb_dim.update(self.y - 3, self.x // 5, 1, 1)
  44.  
  45.  
  46.     def print_screen(self):
  47.         self.stdscr.clear()
  48.         self.stdscr.addstr(0, 1, f"{self.x}, {self.y}")
  49.         rectangle(self.stdscr, self.sb_dim.start_y, self.sb_dim.start_x, self.sb_dim.height, self.sb_dim.width)
  50.  
  51.         self.stdscr.refresh()
  52.  
  53. def main(stdscr):
  54.     ui = Ui(stdscr)
  55.     ui.run()
  56.  
  57. if __name__ == "__main__":
  58.     wrapper(main)
Advertisement
Add Comment
Please, Sign In to add comment