How to use the asciimatics.widgets.Layout function in asciimatics

To help you get started, we’ve selected a few asciimatics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tonybaloney / retox / retox / ui.py View on Github external
'''
        super(VirtualEnvironmentFrame, self).__init__(
            screen,
            screen.height // 2,
            screen.width // venv_count,
            x=index * (screen.width // venv_count),
            has_border=True,
            hover_focus=True,
            title=venv_name)
        self.name = venv_name
        self._screen = screen

        # Draw a box for the environment
        task_layout = widgets.Layout([10], fill_frame=False)
        self.add_layout(task_layout)
        completed_layout = widgets.Layout([10], fill_frame=False)
        self.add_layout(completed_layout)
        self._task_view = widgets.ListBox(
            10,
            [],
            name="Tasks",
            label="Running")
        self._completed_view = widgets.ListBox(
            10,
            [],
            name="Completed",
            label="Completed")
        task_layout.add_widget(self._task_view)
        completed_layout.add_widget(self._completed_view)
        self.fix()
github tonybaloney / retox / retox / ui.py View on Github external
:param index: which environment index is this
        :type  index: ``int``
        '''
        super(VirtualEnvironmentFrame, self).__init__(
            screen,
            screen.height // 2,
            screen.width // venv_count,
            x=index * (screen.width // venv_count),
            has_border=True,
            hover_focus=True,
            title=venv_name)
        self.name = venv_name
        self._screen = screen

        # Draw a box for the environment
        task_layout = widgets.Layout([10], fill_frame=False)
        self.add_layout(task_layout)
        completed_layout = widgets.Layout([10], fill_frame=False)
        self.add_layout(completed_layout)
        self._task_view = widgets.ListBox(
            10,
            [],
            name="Tasks",
            label="Running")
        self._completed_view = widgets.ListBox(
            10,
            [],
            name="Completed",
            label="Completed")
        task_layout.add_widget(self._task_view)
        completed_layout.add_widget(self._completed_view)
        self.fix()
github peterbrittain / asciimatics / tests / test_widgets.py View on Github external
def test_multi_column_list_box(self):
        """
        Check MultiColumnListBox works as expected.
        """
        # Create a dummy screen.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        scene = MagicMock(spec=Scene)
        canvas = Canvas(screen, 10, 40, 0, 0)

        # Create the form we want to test.
        form = Frame(canvas, canvas.height, canvas.width, has_border=False)
        layout = Layout([100], fill_frame=True)
        mc_list = MultiColumnListBox(
            Widget.FILL_FRAME,
            [3, "4", ">4", "<4", ">10%", "100%"],
            [
                (["1", "2", "3", "4", "5", "6"], 1),
                (["11", "222", "333", "444", "555", "6"], 2),
                (["111", "2", "3", "4", "5", "6"], 3),
                (["1", "2", "33333", "4", "5", "6"], 4),
                (["1", "2", "3", "4", "5", "6666666666666666666666"], 5),
            ],
            titles=["A", "B", "C", "D", "E", "F"],
            name="mc_list")
        form.add_layout(layout)
        layout.add_widget(mc_list)
        form.fix()
        form.register_scene(scene)
github peterbrittain / asciimatics / tests / test_widgets.py View on Github external
def test_password(self):
        """
        Check that we can do password input on Text widgets.
        """
        # Create a dummy screen.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        scene = MagicMock(spec=Scene)
        canvas = Canvas(screen, 2, 40, 0, 0)

        # Create the form we want to test.
        form = Frame(canvas, canvas.height, canvas.width, has_border=False)
        layout = Layout([100], fill_frame=True)
        form.add_layout(layout)
        text = Text("Password", hide_char="*")
        layout.add_widget(text)
        form.fix()
        form.register_scene(scene)
        form.reset()

        # Check that input still saves off values as expected
        self.process_keys(form, ["1234"])
        form.save()
        self.assertEqual(text.value, "1234")

        # Check that it is drawn with the obscuring character, though.
        form.update(0)
        self.assert_canvas_equals(
            canvas,
github peterbrittain / asciimatics / tests / test_widgets.py View on Github external
def test_value_defaults(self):
        """
        Check Widgets can set default values from code.
        """
        # Now set up the Frame ready for testing
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        scene = Scene([], duration=-1)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = Frame(canvas, canvas.height, canvas.width)
        layout = Layout([100])
        form.add_layout(layout)

        textbox = TextBox(2, label="TB")
        textbox.value = ["Hello"]
        text = Text(label="B")
        text.value = "World"
        listbox = ListBox(2, [("A", 1), ("B", 2), ("C", 3), ("D", 4)], label="LB")
        listbox.value = 3

        layout.add_widget(textbox)
        layout.add_widget(text)
        layout.add_widget(listbox)
        form.fix()
        form.register_scene(scene)
        scene.add_effect(form)
        scene.reset()
github missionpinball / mpf / mpf / core / text_ui.py View on Github external
title_layout.add_widget(title_left, 0)

        title = 'Mission Pinball Framework v{}'.format(mpf._version.__version__)    # noqa
        title_text = Label(title, align="^")
        title_text.custom_colour = "title"
        title_layout.add_widget(title_text, 1)

        exit_label = Label("< CTRL + C > TO EXIT", align=">")
        exit_label.custom_colour = "title_exit"

        title_layout.add_widget(exit_label, 2)

        self.layout = MpfLayout([1, 1, 1, 1], fill_frame=True)
        self.frame.add_layout(self.layout)

        footer_layout = Layout([1, 1, 1])
        self.frame.add_layout(footer_layout)
        self.footer_memory = Label("", align=">")
        self.footer_memory.custom_colour = "footer_memory"
        self.footer_uptime = Label("", align=">")
        self.footer_uptime.custom_colour = "footer_memory"
        self.footer_mc_cpu = Label("")
        self.footer_mc_cpu.custom_colour = "footer_mc_cpu"
        self.footer_cpu = Label("")
        self.footer_cpu.custom_colour = "footer_cpu"
        footer_path = Label(self.machine.machine_path)
        footer_path.custom_colour = "footer_path"
        footer_empty = Label("")
        footer_empty.custom_colour = "footer_memory"

        footer_layout.add_widget(footer_path, 0)
        footer_layout.add_widget(self.footer_cpu, 0)
github kayagoban / shadowlands / shadowlands / sl_frame.py View on Github external
def add_file_browser(self, path='/', height=15, on_change_fn=None, add_divider=True):
        layout = Layout([100])
        self.add_layout(layout)
        browser = FileBrowser(height, path, on_change=on_change_fn)
        layout.add_widget(browser)
        if add_divider: 
            layout.add_widget(Divider(draw_line=False))
        return lambda: browser._value
github missionpinball / mpf / mpf / core / text_ui.py View on Github external
from asciimatics.scene import Scene
from asciimatics.widgets import Frame, Layout, THEMES, Label, Divider, PopUpDialog
from asciimatics.screen import Screen

import mpf._version
from mpf.core.delays import DelayManager
from mpf.core.mpf_controller import MpfController

MYPY = False
if MYPY:   # pragma: no cover
    from mpf.core.machine import MachineController                  # pylint: disable-msg=cyclic-import,unused-import
    from typing import List, Tuple                                  # pylint: disable-msg=cyclic-import,unused-import
    from mpf.devices.ball_device.ball_device import BallDevice      # pylint: disable-msg=cyclic-import,unused-import


class MpfLayout(Layout):

    """Add clear function."""

    def __init__(self, columns, fill_frame=False):
        """Store max_height."""
        super().__init__(columns, fill_frame)
        self.max_height = None

    def clear_columns(self):
        """Clear all columns."""
        self._columns = [[] for _ in self._columns]

    def set_max_height(self, max_height):
        """Set max height."""
        self.max_height = max_height
github kayagoban / shadowlands / shadowlands / sl_transaction_frame.py View on Github external
def __init__(self, dapp, x, y, tx_fn=None, tx_value=0, gas_limit=300000,  **kwargs):
        super(SLTransactionFrame, self).__init__(dapp._screen, x, y, dapp, self._ok_fn, self.close, **kwargs) 
        self.dapp = dapp
        # Add as block listener
        dapp._block_listeners.append(self)

        self._tx_fn = tx_fn
        self.estimated_gas = gas_limit

        layout = Layout([100])
        self.prepend_layout(layout)

        # TODO raise an exception if tx_value is not already a Decimal
        self.tx_value = Decimal(tx_value)
        layout.add_widget(Label("You will send {} ETH".format(self.tx_value)))
        layout.add_widget(Divider(draw_line=False))
        layout.add_widget(Label("Estimated Gas for Tx: {}".format(self.estimated_gas)))
        layout.add_widget(Divider(draw_line=False))
        self.fix()
github cowboy8625 / WordRPG / gui / _backup / asciimatics / _template.py View on Github external
def _init_main( self ):
		layout = Layout( [ 1 ] )
		self.add_layout( layout )
		layout.add_widget( Label( "Main Body" ), 0 )
		#layout.add_widget( TextBox( "Main Body" ), 0 )