當前位置: 首頁>>代碼示例>>Python>>正文


Python builtins.ord方法代碼示例

本文整理匯總了Python中builtins.ord方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.ord方法的具體用法?Python builtins.ord怎麽用?Python builtins.ord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在builtins的用法示例。


在下文中一共展示了builtins.ord方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_from

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def get_from(self, x, y):
        """
        Get the character at the specified location.

        :param x: The column (x coord) of the character.
        :param y: The row (y coord) of the character.

        :return: A 4-tuple of (ascii code, foreground, attributes, background)
                 for the character at the location.
        """
        # Convert to buffer coordinates
        y -= self._start_line
        if y < 0 or y >= self._buffer_height or x < 0 or x >= self.width:
            return None
        cell = self._buffer.get(x, y)
        return ord(cell[0]), cell[1], cell[2], cell[3] 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:18,代碼來源:screen.py

示例2: test_empty_frame

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def test_empty_frame(self):
        """
        Check empty Frames still work.
        """
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        scene = MagicMock(spec=Scene)
        form = TestFrame3(canvas)
        form.register_scene(scene)
        form.reset()

        # Check all keyboard events get swallowed
        self.assertIsNone(form.process_event(KeyboardEvent(ord("A"))))

        # Check Mouse events over the Frame are swallowed and others allowed
        # to bubble down the input stack.
        self.assertIsNone(
            form.process_event(MouseEvent(20, 5, MouseEvent.LEFT_CLICK)))
        self.assertIsNotNone(
            form.process_event(MouseEvent(5, 5, MouseEvent.LEFT_CLICK)))

        # Check form data is empty.
        form.save()
        self.assertEqual(form.data, {}) 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:26,代碼來源:test_widgets.py

示例3: test_background

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def test_background(self):
        """
        Check Background widget works as expected.
        """
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        scene = MagicMock(spec=Scene)
        canvas = Canvas(screen, 10, 40, 0, 0)
        form = Background(canvas, bg=7)
        form.register_scene(scene)
        form.reset()

        # Check that the widget is rendered correctly.
        form.update(0)
        for y in range(canvas.height):
            for x in range(canvas.width):
                char, _, _, bg = canvas.get_from(x, y)
                self.assertEquals(char, ord(" "))
                self.assertEquals(bg, 7)

        # Check properties
        self.assertEquals(form.stop_frame, 0)
        self.assertGreater(form.frame_update_count, 1000) 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:24,代碼來源:test_widgets.py

示例4: ctrl

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def ctrl(char):
        """
        Calculate the control code for a given key.  For example, this converts
        "a" to 1 (which is the code for ctrl-a).

        :param char: The key to convert to a control code.
        :return: The control code as an integer or None if unknown.
        """
        # Convert string to int... assuming any non-integer is a string.
        # TODO: Consider asserting a more rigorous test without falling back to past basestring.
        if not isinstance(char, int):
            char = ord(char.upper())

        # Only deal with the characters between '@' and '_'
        return char & 0x1f if 64 <= char <= 95 else None 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:17,代碼來源:screen.py

示例5: _unhandled_event_default

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def _unhandled_event_default(event):
        """
        Default unhandled event handler for handling simple scene navigation.
        """
        if isinstance(event, KeyboardEvent):
            c = event.key_code
            if c in (ord("X"), ord("x"), ord("Q"), ord("q")):
                raise StopApplication("User terminated app")
            if c in (ord(" "), ord("\n"), ord("\r")):
                raise NextScene() 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:12,代碼來源:screen.py

示例6: test_label_colours

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def test_label_colours(self):
        """
        Check Label custom colour works.
        """
        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([1])
        form.add_layout(layout)
        label = Label("Some text")
        label.custom_colour = "disabled"
        layout.add_widget(label)
        form.fix()
        form.register_scene(scene)
        scene.add_effect(form)
        scene.reset()

        # Check that the label is rendered in the correct colour palette.
        for effect in scene.effects:
            effect.update(0)
        self.assertEqual(label.custom_colour, "disabled")
        self.assertEqual(canvas.get_from(1, 1), (ord("S"), 0, 1, 4))

        # Cheeky test that Labels always pass on events.
        event = object()
        self.assertEqual(event, label.process_event(event)) 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:29,代碼來源:test_widgets.py

示例7: test_inline_colours

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def test_inline_colours(self):
        """
        Check inline colours work 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)
        form.add_layout(layout)
        text_box = TextBox(3, as_string=True, parser=AsciimaticsParser())
        layout.add_widget(text_box)
        listbox = ListBox(2, [("P", 1), ("${9,2}Q", 2), ("R", 3), ("S", 4)], parser=AsciimaticsParser())
        layout.add_widget(listbox)
        mc_list = MultiColumnListBox(
            Widget.FILL_FRAME,
            [3, "100%"],
            [(["1", "\x1B[32m2"], 1)],
            titles=["A", "B"],
            parser=AnsiTerminalParser())
        layout.add_widget(mc_list)
        form.fix()
        form.register_scene(scene)
        form.reset()

        # Check that the Asciimatics colour parsing worked.
        text_box.value = "A${1}B"
        form.update(0)
        self.assertEqual(canvas.get_from(0, 0), (ord("A"), 7, 2, 4))
        self.assertEqual(canvas.get_from(1, 0), (ord("B"), 1, 0, 4))
        self.assertEqual(canvas.get_from(0, 3), (ord("P"), 3, 1, 4))
        self.assertEqual(canvas.get_from(0, 4), (ord("Q"), 9, 2, 4))

        # Check that the Ansi terminal colour parsing worked.
        self.assertEqual(canvas.get_from(0, 5), (ord("A"), 7, 1, 4))
        self.assertEqual(canvas.get_from(3, 5), (ord("B"), 7, 1, 4))
        self.assertEqual(canvas.get_from(0, 6), (ord("1"), 3, 1, 4))
        self.assertEqual(canvas.get_from(3, 6), (ord("2"), 2, 1, 4)) 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:43,代碼來源:test_widgets.py

示例8: __init__

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def __init__(self, height, width):
        """
        :param height: Height of the buffer to create.
        :param width: Width of the buffer to create.
        """
        super(_DoubleBuffer, self).__init__()
        self._height = height
        self._width = width
        self._double_buffer = None
        line = [(ord(u" "), Screen.COLOUR_WHITE, 0, 0, 1) for _ in range(self._width)]
        self._screen_buffer = [line[:] for _ in range(self._height)]
        self.clear(Screen.COLOUR_WHITE, 0, 0) 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:14,代碼來源:screen.py

示例9: clear

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def clear(self, fg, attr, bg):
        """
        Clear the double-buffer.

        This does not clear the screen buffer and so the next call to deltas will still show all changes.

        :param fg: The foreground colour to use for the new buffer.
        :param attr: The attribute value to use for the new buffer.
        :param bg: The background colour to use for the new buffer.
        """
        line = [(ord(u" "), fg, attr, bg, 1) for _ in range(self._width)]
        self._double_buffer = [line[:] for _ in range(self._height)] 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:14,代碼來源:screen.py

示例10: paint

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def paint(self, text, x, y, colour=7, attr=0, bg=0, transparent=False,
              colour_map=None):
        """
        Paint multi-colour text at the defined location.

        :param text: The (single line) text to be printed.
        :param x: The column (x coord) for the start of the text.
        :param y: The line (y coord) for the start of the text.
        :param colour: The default colour of the text to be displayed.
        :param attr: The default cell attribute of the text to be displayed.
        :param bg: The default background colour of the text to be displayed.
        :param transparent: Whether to print spaces or not, thus giving a
            transparent effect.
        :param colour_map: Colour/attribute list for multi-colour text.

        The colours and attributes are the COLOUR_xxx and A_yyy constants
        defined in the Screen class.
        colour_map is a list of tuples (foreground, attribute, background) that
        must be the same length as the passed in text (or None if no mapping is
        required).
        """
        if colour_map is None:
            self.print_at(text, x, y, colour, attr, bg, transparent)
        else:
            offset = next_offset = 0
            current = ""
            for c, m in zip_longest(str(text), colour_map):
                if m:
                    if len(current) > 0:
                        self.print_at(current, x + offset, y, colour, attr, bg, transparent)
                        offset = next_offset
                        current = ""
                    if len(m) > 0 and m[0] is not None:
                        colour = m[0]
                    if len(m) > 1 and m[1] is not None:
                        attr = m[1]
                    if len(m) > 2 and m[2] is not None:
                        bg = m[2]
                if c:
                    current += c
                    next_offset += wcwidth(c) if ord(c) >= 256 else 1
            if len(current) > 0:
                self.print_at(current, x + offset, y, colour, attr, bg, transparent) 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:45,代碼來源:screen.py

示例11: get_event

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def get_event(self):
            """
            Check for an event without waiting.
            """
            # Spin through notifications until we find something we want.
            key = 0
            while key != -1:
                # Get the next key
                key = self._screen.getch()

                if key == curses.KEY_RESIZE:
                    # Handle screen resize
                    self._re_sized = True
                elif key == curses.KEY_MOUSE:
                    # Handle a mouse event
                    _, x, y, _, bstate = curses.getmouse()
                    buttons = 0
                    # Some Linux modes only report clicks, so check for any
                    # button down or click events.
                    if (bstate & curses.BUTTON1_PRESSED != 0 or
                            bstate & curses.BUTTON1_CLICKED != 0):
                        buttons |= MouseEvent.LEFT_CLICK
                    if (bstate & curses.BUTTON3_PRESSED != 0 or
                            bstate & curses.BUTTON3_CLICKED != 0):
                        buttons |= MouseEvent.RIGHT_CLICK
                    if bstate & curses.BUTTON1_DOUBLE_CLICKED != 0:
                        buttons |= MouseEvent.DOUBLE_CLICK
                    return MouseEvent(x, y, buttons)
                elif key != -1:
                    # Handle any byte streams first
                    logger.debug("Processing key: %x", key)
                    if self._unicode_aware and key > 0:
                        if key & 0xC0 == 0xC0:
                            self._bytes_to_return = struct.pack(b"B", key)
                            self._bytes_to_read = bin(key)[2:].index("0") - 1
                            logger.debug("Byte stream: %d bytes left",
                                         self._bytes_to_read)
                            continue
                        elif self._bytes_to_read > 0:
                            self._bytes_to_return += struct.pack(b"B", key)
                            self._bytes_to_read -= 1
                            if self._bytes_to_read > 0:
                                continue
                            else:
                                key = ord(self._bytes_to_return.decode("utf-8"))

                    # Handle a genuine key press.
                    logger.debug("Returning key: %x", key)
                    if key in self._KEY_MAP:
                        return KeyboardEvent(self._KEY_MAP[key])
                    elif key != -1:
                        return KeyboardEvent(key)

            return None 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:56,代碼來源:screen.py

示例12: print_at

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import ord [as 別名]
def print_at(self, text, x, y, colour=7, attr=0, bg=0, transparent=False):
        """
        Print the text at the specified location using the specified colour and attributes.

        :param text: The (single line) text to be printed.
        :param x: The column (x coord) for the start of the text.
        :param y: The line (y coord) for the start of the text.
        :param colour: The colour of the text to be displayed.
        :param attr: The cell attribute of the text to be displayed.
        :param bg: The background colour of the text to be displayed.
        :param transparent: Whether to print spaces or not, thus giving a
            transparent effect.

        The colours and attributes are the COLOUR_xxx and A_yyy constants
        defined in the Screen class.
        """
        # Trim text to the buffer vertically.  Don't trim horizontally as we don't know whether any
        # of these characters are dual-width yet.  Handle it on the fly below...
        if y < 0 or y >= self._buffer_height or x > self.width:
            return

        if len(text) > 0:
            j = 0
            for i, c in enumerate(text):
                # Handle under-run and overrun of double-width glyphs now.
                #
                # Note that wcwidth uses significant resources, so only call when we have a
                # unicode aware application.  The rest of the time assume ASCII.
                width = wcwidth(c) if self._unicode_aware else 1
                if x + i + j < 0:
                    x += (width - 1)
                    continue
                if x + i + j + width > self.width:
                    return

                # Now handle the update.
                if c != " " or not transparent:
                    # Fix up orphaned double-width glyphs that we've just bisected.
                    if x + i + j - 1 >= 0 and self._buffer.get(x + i + j - 1, y)[4] == 2:
                        self._buffer.set(x + i + j - 1, y, (ord("x"), 0, 0, 0, 1))

                    self._buffer.set(x + i + j, y, (ord(c), colour, attr, bg, width))
                    if width == 2:
                        j += 1
                        if x + i + j < self.width:
                            self._buffer.set(x + i + j, y, (ord(c), colour, attr, bg, 0))

                    # Now fix up any glyphs we may have bisected the other way.
                    if x + i + j + 1 < self.width and self._buffer.get(x + i + j + 1, y)[4] == 0:
                        self._buffer.set(x + i + j + 1, y, (ord("x"), 0, 0, 0, 1)) 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:52,代碼來源:screen.py


注:本文中的builtins.ord方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。