当前位置: 首页>>代码示例>>Python>>正文


Python Style.from_dict方法代码示例

本文整理汇总了Python中prompt_toolkit.styles.Style.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Style.from_dict方法的具体用法?Python Style.from_dict怎么用?Python Style.from_dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prompt_toolkit.styles.Style的用法示例。


在下文中一共展示了Style.from_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_all_ui_styles

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def get_all_ui_styles():
    """
    Return a dict mapping {ui_style_name -> style_dict}.
    """
    return {
        'default': Style.from_dict(default_ui_style),
        'blue': Style.from_dict(blue_ui_style),
    }
开发者ID:jonathanslenders,项目名称:ptpython,代码行数:10,代码来源:style.py

示例2: main

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def main():
    style = Style.from_dict({
        'hello': '#ff0066',
        'world': '#44ff44 italic',
    })

    # Print using a a list of text fragments.
    text_fragments = FormattedText([
        ('class:hello', 'Hello '),
        ('class:world', 'World'),
        ('', '\n'),
    ])
    print(text_fragments, style=style)

    # Print using an HTML object.
    print(HTML(
        '<hello>hello</hello> <world>world</world>\n'),
        style=style)

    # Print using an HTML object with inline styling.
    print(HTML(
        '<style fg="#ff0066">hello</style> '
        '<style fg="#44ff44"><i>world</i></style>\n'))

    # Print using ANSI escape sequences.
    print(ANSI(
        '\x1b[31mhello \x1b[32mworld\n'))
开发者ID:jonathanslenders,项目名称:python-prompt-toolkit,代码行数:29,代码来源:print-formatted-text.py

示例3: test_style_from_dict

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def test_style_from_dict():
    style = Style.from_dict({
        'a': '#ff0000 bold underline italic',
        'b': 'bg:#00ff00 blink reverse',
    })

    # Lookup of class:a.
    expected = Attrs(color='ff0000', bgcolor='', bold=True, underline=True,
                     italic=True, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:a') == expected

    # Lookup of class:b.
    expected = Attrs(color='', bgcolor='00ff00', bold=False, underline=False,
                     italic=False, blink=True, reverse=True, hidden=False)
    assert style.get_attrs_for_style_str('class:b') == expected

    # Test inline style.
    expected = Attrs(color='ff0000', bgcolor='', bold=False, underline=False,
                     italic=False, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('#ff0000') == expected

    # Combine class name and inline style (Whatever is defined later gets priority.)
    expected = Attrs(color='00ff00', bgcolor='', bold=True, underline=True,
                     italic=True, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('class:a #00ff00') == expected

    expected = Attrs(color='ff0000', bgcolor='', bold=True, underline=True,
                     italic=True, blink=False, reverse=False, hidden=False)
    assert style.get_attrs_for_style_str('#00ff00 class:a') == expected
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:31,代码来源:test_style.py

示例4: __init__

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
    def __init__(self, ipython_shell, *a, **kw):
        kw['_completer'] = create_completer(kw['get_globals'], kw['get_globals'],
                                            ipython_shell.magics_manager,
                                            ipython_shell.alias_manager)
        kw['_lexer'] = create_lexer()
        kw['_validator'] = IPythonValidator(
            get_compiler_flags=self.get_compiler_flags)

        super(IPythonInput, self).__init__(*a, **kw)
        self.ipython_shell = ipython_shell

        self.all_prompt_styles['ipython'] = IPythonPrompt(ipython_shell.prompts)
        self.prompt_style = 'ipython'

        # UI style for IPython. Add tokens that are used by IPython>5.0
        style_dict = {}
        style_dict.update(default_ui_style)
        style_dict.update({
            'pygments.prompt':        '#009900',
            'pygments.prompt-num':     '#00ff00 bold',
            'pygments.out-prompt':     '#990000',
            'pygments.out-prompt-num':  '#ff0000 bold',
        })

        self.ui_styles = {
            'default': Style.from_dict(style_dict),
        }
        self.use_ui_colorscheme('default')
开发者ID:jonathanslenders,项目名称:ptpython,代码行数:30,代码来源:ipython.py

示例5: get_all_code_styles

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def get_all_code_styles():
    """
    Return a mapping from style names to their classes.
    """
    result = dict((name, style_from_pygments_cls(get_style_by_name(name))) for name in get_all_styles())
    result['win32'] = Style.from_dict(win32_code_style)
    return result
开发者ID:jonathanslenders,项目名称:ptpython,代码行数:9,代码来源:style.py

示例6: test_with_style

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def test_with_style():
    f = _Capture()
    style = Style.from_dict({
        'hello': '#ff0066',
        'world': '#44ff44 italic',
    })
    tokens = FormattedText([
        ('class:hello', 'Hello '),
        ('class:world', 'world'),
    ])
    pt_print(tokens, style=style, file=f)
    assert b'\x1b[0;38;5;197mHello' in f.data
    assert b'\x1b[0;38;5;83;3mworld' in f.data
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:15,代码来源:test_print_formatted_text.py

示例7: main

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def main():
    # Example 1: fixed text.
    text = prompt('Say something: ', bottom_toolbar='This is a toolbar')
    print('You said: %s' % text)

    # Example 2: fixed text from a callable:
    def get_toolbar():
        return 'Bottom toolbar: time=%r' % time.time()

    text = prompt('Say something: ', bottom_toolbar=get_toolbar,
                  refresh_interval=.5)
    print('You said: %s' % text)

    # Example 3: Using HTML:
    text = prompt('Say something: ', bottom_toolbar=HTML(
        '(html) <b>This</b> <u>is</u> a <style bg="ansired">toolbar</style>'))
    print('You said: %s' % text)

    # Example 4: Using ANSI:
    text = prompt('Say something: ', bottom_toolbar=ANSI(
        '(ansi): \x1b[1mThis\x1b[0m \x1b[4mis\x1b[0m a \x1b[91mtoolbar'))
    print('You said: %s' % text)

    # Example 5: styling differently.
    style = Style.from_dict({
        'bottom-toolbar':      '#aaaa00 bg:#ff0000',
        'bottom-toolbar.text': '#aaaa44 bg:#aa4444',
    })

    text = prompt('Say something: ', bottom_toolbar='This is a toolbar',
                  style=style)
    print('You said: %s' % text)

    # Example 6: Using a list of tokens.
    def get_bottom_toolbar():
        return [
            ('', ' '),
            ('bg:#ff0000 fg:#000000', 'This'),
            ('', ' is a '),
            ('bg:#ff0000 fg:#000000', 'toolbar'),
            ('', '. '),
        ]

    text = prompt('Say something: ', bottom_toolbar=get_bottom_toolbar)
    print('You said: %s' % text)

    # Example 7: multiline fixed text.
    text = prompt('Say something: ', bottom_toolbar='This is\na multiline toolbar')
    print('You said: %s' % text)
开发者ID:jonathanslenders,项目名称:python-prompt-toolkit,代码行数:51,代码来源:bottom-toolbar.py

示例8: __init__

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
    def __init__(self, player):
        self.player = player
        self.playerClans = ' '.join(self.player.clantags)
        if len(self.player.clantags) > 0 : 
            self.playerName = FormattedText([
                ('#ffffff', player.aspect['name']),
                ('', ' '),
                ('#cc00cc', self.playerClans, "utf-8"),
            ]) 
        else: 
            self.playerClans =  self.playerName = FormattedText([
                ('#ffffff', player.aspect['name']),
            ]) 
        self.result = None

        self.mainRadiosRows = []
        self.listOfItems = []
        self.populateMainRadios() # declares self.mainRadios
        self.currentRadios = self.mainRadios
        self.description = self.mainRadios.description # description is whataver is in the description box on the right
        self.requestingConfirmation = False
        
        self.bindings = KeyBindings()
        self.bindings.add('right' )(focus_next)
        self.bindings.add('tab' )(focus_next)
        self.bindings.add('s-tab')(focus_previous)
        self.bindings.add('left')(focus_previous)
        self.bindings.add('c-m')(self.handleEnter)
        self.bindings.add('escape')(self.handleEscape)

        self.style = Style.from_dict({
            'dialog.body':        'bg:#000000 #ffcccc', #background color, text color
        })

        self.application = Application(
            layout=Layout(
                self.getRootContainer(),
                focused_element=self.mainRadios,
            ),
            key_bindings=self.bindings,
            style=self.style,
            mouse_support=True,
            full_screen=True,
            )
开发者ID:DreamTeamXtreme,项目名称:Adventure,代码行数:46,代码来源:inventoryUI.py

示例9: main

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
def main():
    # Printing a manually constructed list of (Token, text) tuples.
    text = [
        (Token.Keyword, 'print'),
        (Token.Punctuation, '('),
        (Token.Literal.String.Double, '"'),
        (Token.Literal.String.Double, 'hello'),
        (Token.Literal.String.Double, '"'),
        (Token.Punctuation, ')'),
        (Token.Text, '\n'),
    ]

    print_formatted_text(PygmentsTokens(text))

    # Printing the output of a pygments lexer.
    tokens = list(pygments.lex('print("Hello")', lexer=PythonLexer()))
    print_formatted_text(PygmentsTokens(tokens))

    # With a custom style.
    style = Style.from_dict({
        'pygments.keyword': 'underline',
        'pygments.literal.string': 'bg:#00ff00 #ffffff',
    })
    print_formatted_text(PygmentsTokens(tokens), style=style)
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:26,代码来源:pygments-tokens.py

示例10: checkboxlist_dialog

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
from prompt_toolkit.shortcuts import checkboxlist_dialog, message_dialog
from prompt_toolkit.styles import Style

results = checkboxlist_dialog(
    title="CheckboxList dialog",
    text="What would you like in your breakfast ?",
    values=[
        ("eggs", "Eggs"),
        ("bacon", "Bacon"),
        ("croissants", "20 Croissants"),
        ("daily", "The breakfast of the day")
    ],
    style=Style.from_dict({
        'dialog': 'bg:#cdbbb3',
        'button': 'bg:#bf99a4',
        'checkbox': '#e8612c',
        'dialog.body': 'bg:#a9cfd0',
        'dialog shadow': 'bg:#c98982',
        'frame.label': '#fcaca3',
        'dialog.body label': '#fd8bb6',
    })
).run()
if results:
    message_dialog(
        title="Room service",
        text="You selected: %s\nGreat choice sir !" % ",".join(results)
    ).run()
else:
    message_dialog("*starves*").run()
开发者ID:jonathanslenders,项目名称:python-prompt-toolkit,代码行数:31,代码来源:checkbox_dialog.py

示例11: main

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
#!/usr/bin/env python
"""
A very simple progress bar which keep track of the progress as we consume an
iterator.
"""
from __future__ import unicode_literals
from prompt_toolkit.shortcuts import ProgressBar
from prompt_toolkit.styles import Style
import time

style = Style.from_dict({
    'title': '#4444ff underline',
    'label': '#ff4400 bold',
    'percentage': '#00ff00',
    'bar-a': 'bg:#00ff00 #004400',
    'bar-b': 'bg:#00ff00 #000000',
    'bar-c': '#000000 underline',
    'current': '#448844',
    'total': '#448844',
    'time-elapsed': '#444488',
    'time-left': 'bg:#88ff88 #000000',
})


def main():
    with ProgressBar(style=style, title='Progress bar example with custom styling.') as pb:
        for i in pb(range(1600), label='Downloading...'):
            time.sleep(.01)


if __name__ == '__main__':
    main()
开发者ID:tsvenson,项目名称:python-prompt-toolkit,代码行数:34,代码来源:styled-1.py

示例12:

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
terminal_style = None

dark_style = Style.from_dict({
    'dialog':             f"bg:{NAMED_COLORS['DimGrey']} {NAMED_COLORS['White']}",
    'dialog frame-label': 'bg:#ffffff #000000',
    'dialog.body':        f"bg:{NAMED_COLORS['DimGrey']} {NAMED_COLORS['White']}",
    'dialog shadow':      'bg:#444444',

    'status':     f"bg:{NAMED_COLORS['DimGrey']} {NAMED_COLORS['White']}",
    'details':    f"{NAMED_COLORS['Ivory']}",
    'status.position': '#aaaa00',
    'status.key': '#ffaa00',
    'not-searching': '#222222',
    'entry':      f"{NAMED_COLORS['LightGoldenRodYellow']}",
    'ask':        f"{NAMED_COLORS['Lime']} bold",
    'reply':      f"{NAMED_COLORS['DeepSkyBlue']}",

    'window.border': '#888888',
    'shadow':        'bg:#222222',

    'menu-bar': f"bg:{NAMED_COLORS['DimGrey']} {NAMED_COLORS['White']}",
    'menu-bar.selected-item': 'bg:#ffffff #000000',
    'menu': f"bg:{NAMED_COLORS['DimGrey']} {NAMED_COLORS['White']}",
    'menu.border': '#aaaaaa',
    'window.border shadow': '#444444',

    'focused  button': 'bg:#880000 #ffffff noinherit',
    })

light_style = Style.from_dict({
    'dialog':             f"bg:{NAMED_COLORS['DimGrey']} {NAMED_COLORS['White']}",
开发者ID:dagraham,项目名称:etm-mv,代码行数:33,代码来源:view.py

示例13: KeyBindings

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
# Global key bindings.
bindings = KeyBindings()
bindings.add('tab')(focus_next)
bindings.add('s-tab')(focus_previous)


style = Style.from_dict({
    'window.border': '#888888',
    'shadow': 'bg:#222222',

    'menu-bar': 'bg:#aaaaaa #888888',
    'menu-bar.selected-item': 'bg:#ffffff #000000',
    'menu': 'bg:#888888 #ffffff',
    'menu.border': '#aaaaaa',
    'window.border shadow': '#444444',

    'focused  button': 'bg:#880000 #ffffff noinherit',

    # Styling for Dialog widgets.

    'radiolist focused': 'noreverse',
    'radiolist focused radio.selected': 'reverse',

    'button-bar': 'bg:#aaaaff'
})


application = Application(
    layout=Layout(
        root_container,
        focused_element=yes_button,
开发者ID:jonathanslenders,项目名称:python-prompt-toolkit,代码行数:33,代码来源:full-screen-demo.py

示例14: __init__

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
    def __init__(self, player, enemy, song='worry 2.wav'):
        self.song = Sound( player,fileName = song, loop=-1)
        self.player = player
        self.playerClans = ' '.join(self.player.clantags)
        if len(self.player.clantags) > 0 : 
            self.playerName = FormattedText([
                ('#ffffff', str(player.aspect['name'])),
                ('', ' '),
                ('#cc00cc', str(self.playerClans)),
            ]) 
        else: 
            self.playerClans =  self.playerName = FormattedText([
                ('#ffffff', str(player.aspect['name'])),
            ]) 
        self.enemy = enemy

        self.playerGoesNext = True # by default, enemy always gets first strike
        self.playerJustDodged = False
        self.escapeTries = 0
        self.escapeChance = .3

        self.battleLog = '\n\n\n\n\n\n'
        self.maxHeightOfBattleLogWindow = 7
        self.totalWidth = 90
        self.actionsWidth = 30
        self.statsWidth = 20 

        self.selectedIndexText = ''
        self.result = None

        self.playerHPBar = ProgressBar()
        self.setHealthProgressBar(self.playerHPBar, self.toPercent(self.player.hp, self.player.maxhp)) 
        self.enemyHPBar = ProgressBar()
        self.setHealthProgressBar(self.enemyHPBar, 100) 

        self.radios = RadioList(
            values=[ #value, lable
                ('Attack', 'Attack'), # use eqipped weapon
                ('Dodge', 'Dodge'), # icrease miss chance for enemy
                ('Item', 'Item'),
                ('Run', 'Run') # try to escape
                # more options could be:
                # check - returns text about enemy potentially indicating weaknessess
            ],
            player = self.player,
            width = self.actionsWidth)
        
        self.bindings = KeyBindings()
        self.bindings.add('right' )(focus_next)
        self.bindings.add('tab' )(focus_next)
        self.bindings.add('s-tab')(focus_previous)
        self.bindings.add('left')(focus_previous)
        self.bindings.add('c-m')(self.handleEnter)
        self.bindings.add('escape')(self.tryToEscape)
        # self.bindings.add('up')(self.setSelectedIndexTextUp)
        # TODO: make secret easter egg key bindings # self.bindings.add('a', 'a')(self.test)  
        self.style = Style.from_dict({
            'dialog.body':        'bg:#000000 #ffcccc', #background color, text color
        })

        self.application = Application(
            layout=Layout(
                self.getRootContainer(),
                focused_element=self.radios,
            ),
            key_bindings=self.bindings,
            style=self.style,
            mouse_support=True,
            full_screen=True,
            )
开发者ID:DreamTeamXtreme,项目名称:Adventure,代码行数:72,代码来源:combatUI.py

示例15:

# 需要导入模块: from prompt_toolkit.styles import Style [as 别名]
# 或者: from prompt_toolkit.styles.Style import from_dict [as 别名]
ui_style = Style.from_dict({
    'border':                         '#888888',
    'terminal.focused border':      'ansigreen bold',

    #'terminal titleba':            'bg:#aaaaaa #dddddd ',
    'terminal titlebar':            'bg:#888888 #ffffff',
#    'terminal titlebar paneindex':  'bg:#888888 #000000',

    'terminal.focused titlebar':   'bg:#448844 #ffffff',
    'terminal.focused titlebar name':   'bg:#88aa44 #ffffff',
    'terminal.focused titlebar paneindex':         'bg:#ff0000',

#    'titlebar title':               '',
#    'titlebar name':                '#ffffff noitalic',
#    'focused-terminal titlebar name':       'bg:#88aa44',
#    'titlebar.line':                '#444444',
#    'titlebar.line focused':       '#448844 noinherit',
#    'titlebar focused':            'bg:#5f875f #ffffff bold',
#    'titlebar.title focused':      '',
#    'titlebar.zoom':                'bg:#884400 #ffffff',
#    'titlebar paneindex':           '',
#    'titlebar.copymode':            'bg:#88aa88 #444444',
#    'titlebar.copymode.position':   '',

#    'focused-terminal titlebar.copymode':          'bg:#aaff44 #000000',
#    'titlebar.copymode.position': '#888888',

    'commandline':                  'bg:#4e4e4e #ffffff',
    'commandline.command':          'bold',
    'commandline.prompt':           'bold',
    #'statusbar':                    'noreverse bg:#448844 #000000',
    'statusbar':                    'noreverse bg:ansigreen #000000',
    'statusbar window':             '#ffffff',
    'statusbar window.current':     'bg:#44ff44 #000000',
    'auto-suggestion':               'bg:#4e5e4e #88aa88',
    'message':                      'bg:#bbee88 #222222',
    'background':                   '#888888',
    'clock':                        'bg:#88aa00',
    'panenumber':                   'bg:#888888',
    'panenumber focused':          'bg:#aa8800',
    'terminated':                   'bg:#aa0000 #ffffff',

    'confirmationtoolbar':          'bg:#880000 #ffffff',
    'confirmationtoolbar question': '',
    'confirmationtoolbar yesno':    'bg:#440000',

    'copy-mode-cursor-position':   'bg:ansiyellow ansiblack',

#    'search-toolbar':                       'bg:#88ff44 #444444',
    'search-toolbar.prompt':                'bg:#88ff44 #444444',
    'search-toolbar.text':                  'bg:#88ff44 #000000',
#    'search-toolbar focused':              'bg:#aaff44 #444444',
#    'search-toolbar.text focused':         'bold #000000',

    'search-match':                  '#000000 bg:#88aa88',
    'search-match.current':          '#000000 bg:#aaffaa underline',

    # Pop-up dialog. Ignore built-in style.
    'dialog':                        'noinherit',
    'dialog.body':                   'noinherit',
    'dialog frame':                  'noinherit',
    'dialog.body text-area':         'noinherit',
    'dialog.body text-area last-line': 'noinherit',

}, priority=Priority.MOST_PRECISE)
开发者ID:jonathanslenders,项目名称:pymux,代码行数:67,代码来源:style.py


注:本文中的prompt_toolkit.styles.Style.from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。