我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用pygments.styles()。
def _on_config_changed(self, junk=None): # when the font family or size changes, self.textwidget['font'] # also changes because it's a porcupine.textwiddet.ThemedText widget fontobject = tkfont.Font(name=self.textwidget['font'], exists=True) font_updates = fontobject.actual() del font_updates['weight'] # ignore boldness del font_updates['slant'] # ignore italicness for (bold, italic), font in self._fonts.items(): # fonts don't have an update() method for key, value in font_updates.items(): font[key] = value # http://pygments.org/docs/formatterdevelopment/#styles # all styles seem to yield all token types when iterated over, # so we should always end up with the same tags configured style = pygments.styles.get_style_by_name(config['pygments_style']) for tokentype, infodict in style: # this doesn't use underline and border # i don't like random underlines in my code and i don't know # how to implement the border with tkinter key = (infodict['bold'], infodict['italic']) # pep8 line length kwargs = {'font': self._fonts[key]} if infodict['color'] is None: kwargs['foreground'] = '' # reset it else: kwargs['foreground'] = '#' + infodict['color'] if infodict['bgcolor'] is None: kwargs['background'] = '' else: kwargs['background'] = '#' + infodict['bgcolor'] self.textwidget.tag_config(str(tokentype), **kwargs) # make sure that the selection tag takes precedence over our # token tag self.textwidget.tag_lower(str(tokentype), 'sel') # handle things from the highlighting process