Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.44 KB | None | 0 0
  1. import curses
  2. import ipaddress
  3.  
  4. class Boxes(object):
  5.     def __init__(self, screen):
  6.         self.screen = screen
  7.         self.y, self.x = screen.getmaxyx()
  8.  
  9.         curses.cbreak()
  10.         curses.curs_set(False)
  11.         curses.start_color()
  12.         curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
  13.         curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_GREEN) # Diago Header
  14.         curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_RED) # Errors
  15.  
  16.  
  17.         screen.immedok(True)
  18.         screen.keypad(1)
  19.         screen.border()
  20.  
  21.         # Creates sub box template
  22.         ## Need to center box
  23.         self.box = curses.newwin((self.y // 4), (self.x // 4), (self.y // 3),
  24.                                                         (self.x // 2 - 30 // 2))
  25.  
  26.  
  27.     def sm_box_input(self, header):
  28.         """
  29.       Required (header, ):
  30.       "header" = |Title of Box|
  31.       """
  32.  
  33.         curses.echo()
  34.         curses.curs_set(True)
  35.  
  36.         self.screen.refresh()
  37.  
  38.         box = self.box
  39.         box.box()
  40.  
  41.         ### Need to Center Text
  42.         box.addstr(1, len(header), header, curses.color_pair(2) | curses.A_BOLD)
  43.         box.addstr(0, 0, "Press Any Key", curses.A_BLINK)
  44.  
  45.         user_input = box.getstr(3, (3 // 2))
  46.  
  47.         del box
  48.         self.screen.touchwin()
  49.  
  50.         curses.curs_set(False)
  51.         curses.noecho()
  52.  
  53.         return user_input
  54.  
  55.  
  56.     def sm_box_dialog(self, type, header, content):
  57.         """
  58.       Required: (type, header, content)
  59.       "type" = 'error' or 'dialog'
  60.       """
  61.         self.screen.refresh()
  62.  
  63.         box = self.box
  64.         box.box()
  65.  
  66.         ### Need to Center Text
  67.         if type is "dialog":
  68.             box.addstr(1, len(header), header, curses.color_pair(2) | curses.A_BOLD)
  69.         elif type is "error":
  70.             box.addstr(1, len(header), header, curses.color_pair(3) | curses.A_BOLD)
  71.         else:
  72.             raise ValueError("Incorrect function value, pelase use 'error', or 'dialog'")
  73.  
  74.         box.addstr(3, (3 // 2), content)
  75.         box.refresh()
  76.  
  77.  
  78.         box.addstr(0, 0, "Press Any Key", curses.A_BLINK)
  79.         self.screen.getch()
  80.  
  81.         del box
  82.         self.screen.touchwin()
  83.  
  84.         return
  85.  
  86.  
  87.  
  88. def main(stdscrn):
  89.     screen = Boxes(stdscrn)
  90.  
  91.     screen.sm_box_dialog('dialog', "Crackers", "Troopers")
  92.     stdscrn.getch()
  93.     curses.endwin()
  94.  
  95. if __name__ == '__main__':
  96.     curses.wrapper(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement