def __init__(self, num_rows, num_cols, logger, simulated_terminal=None): """Constructor for WidgetSet """ self._widgets = {} self._keybindings = {} self._simulated_terminal = simulated_terminal if self._simulated_terminal is None: term_size = shutil.get_terminal_size() height = term_size.lines width = term_size.columns else: height = self._simulated_terminal[0] width = self._simulated_terminal[1] self._height = height self._width = width self._height = self._height - 4 self._grid = grid.Grid(num_rows, num_cols, self._height, self._width, logger) self._selected_widget = None self._logger = logger
def __init__(self, num_rows: int, num_cols: int, logger: 'py_cui.debug.PyCUILogger', root: 'py_cui.PyCUI', simulated_terminal: Optional[List[int]] = None): """Constructor for WidgetSet """ self._widgets: Dict[int, Optional['py_cui.widgets.Widget']] = {} self._keybindings: Dict[int, Callable[[], Any]] = {} self._root = root self._simulated_terminal = simulated_terminal if self._simulated_terminal is None: term_size = shutil.get_terminal_size() height = term_size.lines width = term_size.columns else: height = self._simulated_terminal[0] width = self._simulated_terminal[1] self._height = height self._width = width status_bars_height = self._root.title_bar.get_height( ) + self._root.status_bar.get_height() self._height = self._height - status_bars_height - 2 self._grid = grid.Grid(num_rows, num_cols, self._height, self._width, logger) self._selected_widget: Optional[int] = None self._logger = logger
def __init__(self, num_rows, num_cols): """Constructor for WidgetSet """ self.widgets = {} self.keybindings = {} term_size = shutil.get_terminal_size() self.height = term_size.lines self.width = term_size.columns self.height = self.height - 4 self.grid = grid.Grid(num_rows, num_cols, self.height, self.width) self.selected_widget = None
def __init__(self, num_rows, num_cols, auto_focus_buttons=True, exit_key=py_cui.keys.KEY_Q_LOWER): """Constructor for PyCUI class """ self.title = 'PyCUI Window' # When this is not set, the escape character delay is too long for exiting focus mode os.environ.setdefault('ESCDELAY', '25') self.cursor_x = 0 self.cursor_y = 0 term_size = shutil.get_terminal_size() self.height = term_size.lines self.width = term_size.columns self.height = self.height - 4 # Add status and title bar self.title_bar = py_cui.statusbar.StatusBar(self.title, BLACK_ON_WHITE) self.init_status_bar_text = 'Press - {} - to exit. Arrow Keys to move between widgets. Enter to enter focus mode.'.format( py_cui.keys.get_char_from_ascii(exit_key)) self.status_bar = py_cui.statusbar.StatusBar(self.init_status_bar_text, BLACK_ON_WHITE) # Initialize grid, renderer, and widget dict self.grid = grid.Grid(num_rows, num_cols, self.height, self.width) self.renderer = None self.border_characters = None self.stdscr = None self.widgets = {} # Variables for determining selected widget/focus mode self.selected_widget = None self.in_focused_mode = False self.popup = None self.auto_focus_buttons = auto_focus_buttons # CUI blocks when loading popup is open self.loading = False self.stopped = True self.post_loading_callback = None # Top level keybindings. Exit key is 'q' by default self.keybindings = {} self.exit_key = exit_key # Callback to fire when CUI is stopped. self.on_stop = None
import pytest import py_cui.grid as grid import py_cui.errors as err test_grid_A = grid.Grid(3, 3, 800, 600) test_grid_B = grid.Grid(1, 1, 10, 10) test_grid_C = grid.Grid(5, 5, 100, 150) def test_init(): assert test_grid_A.row_height == 266 assert test_grid_A.column_width == 200 assert test_grid_B.row_height == 10 assert test_grid_B.column_width == 10 assert test_grid_C.row_height == 20 assert test_grid_C.column_width == 30 def test_set_num_rows_illegal(): try: test_grid_B.set_num_rows(4) assert False except err.PyCUIOutOfBoundsError: assert True def test_set_num_rows_legal():
import pytest # noqa import py_cui.grid as grid import py_cui.widgets as widgets import py_cui.errors as err import py_cui.debug as dbg logger = dbg.PyCUILogger('PYCUI TEST') test_grid = grid.Grid(5, 7, 90, 210, logger) test_cell_A = widgets.Widget('1', 'TestA', test_grid, 0, 0, 1, 1, 1, 0, logger) test_cell_B = widgets.Widget('2', 'Test B', test_grid, 3, 4, 2, 1, 1, 0, logger) test_cell_C = widgets.Widget('3', 'Test C', test_grid, 1, 2, 1, 3, 1, 0, logger) test_cell_D = widgets.Widget('4', 'Test D -----------------------------------', test_grid, 0, 0, 1, 1, 1, 0, logger) # grid spot width should be 6 x 6, with an overlap of 2 chars on the edges test_grid_over = grid.Grid(3, 3, 20, 20, logger) test_cell_over_A = widgets.Widget('5', 'Test Over A', test_grid_over, 2, 0, 1, 1, 1, 0, logger)
import pytest import py_cui.grid as grid import py_cui.errors as err import py_cui.debug as dbg logger = dbg.PyCUILogger('PYCUI TEST') test_grid_A = grid.Grid(3, 3, 800, 600, logger) test_grid_B = grid.Grid(1, 1, 10, 10, logger) test_grid_C = grid.Grid(5, 5, 100, 150, logger) def test_init(): row_height, col_width = test_grid_A.get_cell_dimensions() assert row_height == 266 assert col_width == 200 row_height, col_width = test_grid_B.get_cell_dimensions() assert row_height == 10 assert col_width == 10 row_height, col_width = test_grid_C.get_cell_dimensions() assert row_height == 20 assert col_width == 30 def test_set_num_rows_illegal(): try: test_grid_B.set_num_rows(4) assert False except err.PyCUIOutOfBoundsError: assert True
import pytest import py_cui.grid as grid import py_cui.widgets as widgets import py_cui.errors as err test_grid = grid.Grid(5, 7, 90, 210) test_cell_A = widgets.Widget('1', 'TestA', test_grid, 0, 0, 1, 1, 1, 0) test_cell_B = widgets.Widget('2', 'Test B', test_grid, 3, 4, 2, 1, 1, 0) test_cell_C = widgets.Widget('3', 'Test C', test_grid, 1, 2, 1, 3, 1, 0) test_cell_D = widgets.Widget('4', 'Test D -----------------------------------', test_grid, 0, 0, 1, 1, 1, 0) # grid spot width should be 6 x 6, with an overlap of 2 chars on the edges test_grid_over = grid.Grid(3, 3, 20, 20) test_cell_over_A = widgets.Widget('5', 'Test Over A', test_grid_over, 2, 0, 1, 1, 1, 0) test_cell_over_B = widgets.Widget('6', 'Test Over B', test_grid_over, 0, 2, 1, 1, 1, 0) test_cell_over_C = widgets.Widget('7', 'Test Over C', test_grid_over, 2, 2, 1, 1, 1, 0) def test_illegal_create_1(): try: test_cell_E = widgets.Widget('8', 'Test E', None, 0, 5, 1, 1, 1, 0) assert False except err.PyCUIMissingParentError: assert True