Ejemplo n.º 1
0
    def test_disabled_text(self):
        """
        Check disabled TextBox can be used for pre-formatted output.
        """
        # 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)
        form.add_layout(layout)
        text_box = TextBox(1, as_string=True)
        text_box.disabled = True
        layout.add_widget(text_box)
        form.fix()
        form.register_scene(scene)
        form.reset()

        # Check that input has no effect on the programmed value.
        text_box.value = "A test"
        self.process_keys(form, ["A"])
        form.save()
        self.assertEqual(text_box.value, "A test")

        # Check that we can provide a custom colour.  Since the default palette has no "custom"
        # key, this will throw an exception.
        self.assertEqual(text_box._pick_colours("blah"),
                         form.palette["disabled"])
        with self.assertRaises(KeyError) as cm:
            text_box.custom_colour = "custom"
            text_box._pick_colours("blah")
        self.assertIn("custom", str(cm.exception))
Ejemplo n.º 2
0
 def add_shortcut_panel(self):
     layout0 = Layout([100])
     _header = TextBox(1, as_string=True)
     _header.disabled = True
     _header.custom_colour = "label"
     _header.value = "Press ctrl-a to see a list of shortcuts. Press ctrl-x to quit."
     self.add_layout(layout0)
     layout0.add_widget(_header, 0)
Ejemplo n.º 3
0
    def __init__(self, screen: Any, cache: TopCache, show_details: bool):

        super(TopView, self).__init__(screen,
                                      screen.height,
                                      screen.width,
                                      has_border=True,
                                      can_scroll=False)
        self.cache = cache
        self.show_details = show_details
        self.set_theme("monochrome")
        self.palette["title"] = (
            Screen.COLOUR_BLACK,
            Screen.A_NORMAL,
            Screen.COLOUR_WHITE,
        )

        self.job_count = len(self.cache.jobs)
        self.pool_count = len(self.cache.pools)

        max_widget_height = (int(
            (screen.height - BASE_LINES) / 3) - EXTRA_LINES_PER_WIDGET)

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

        self.onefuzz_reversed = {
            "pools": True,
            "jobs": True,
            "tasks": True,
            "messages": True,
        }

        dimensions = {
            "pools": {
                "height": min(self.pool_count + 1, max_widget_height),
                "setup": self.cache.POOL_FIELDS,
            },
            "jobs": {
                "height": min(self.job_count + 1, max_widget_height),
                "setup": self.cache.JOB_FIELDS,
            },
            "tasks": {
                "height": Widget.FILL_FRAME,
                "setup": self.cache.TASK_FIELDS
            },
            "messages": {
                "height": min(10, max_widget_height),
                "setup": ["Updated", "Type", "Message"],
            },
            "status": {
                "height": 1
            },
        }

        for name in ["status", "pools", "jobs", "tasks", "messages"]:
            if name == "messages" and not self.show_details:
                continue

            titles = dimensions[name].get("setup")

            if titles:
                title = TextBox(1, as_string=True, name=name + "_title")
                title.disabled = True
                title.custom_colour = "label"
                layout.add_widget(title)

            widget = MultiColumnListBox(
                dimensions[name]["height"],
                column_config(titles),
                [],
                titles=titles,
                name=name,
                add_scroll_bar=bool(titles),
            )
            if not titles:
                widget.disabled = True

            layout.add_widget(widget)
            layout.add_widget(Divider())

        layout.add_widget(Label("Press `q` to quit or `r` to reorder."))
        self.fix()