[syntax_highlight] Fix deprecation warnings, fix pylint errors

This fixes some deprecation warnings related to Gtk.Color and restructures
code and formatting according to pylint suggestions
This commit is contained in:
Daniel Brötzmann
2019-05-08 11:53:13 +02:00
parent 845faff240
commit c60deaea19
8 changed files with 511 additions and 509 deletions

View File

@@ -1,29 +1,33 @@
import logging
import sys
from gajim.plugins import GajimPlugin
from syntax_highlight.types import LineBreakOptions
from syntax_highlight.types import CodeMarkerOptions
from syntax_highlight.types import PLUGIN_INTERNAL_NONE_LEXER_ID
if sys.version_info >= (3, 4):
from importlib.util import find_spec as find_module
else:
from importlib import find_loader as find_module
from gajim.plugins.helpers import log_calls, log
from gajim.plugins import GajimPlugin
from .types import MatchType, LineBreakOptions, CodeMarkerOptions, \
PLUGIN_INTERNAL_NONE_LEXER_ID
PYGMENTS_MISSING = 'You are missing Python-Pygments.'
log = logging.getLogger('gajim.p.syntax_highlight')
def try_loading_pygments():
success = find_module('pygments') is not None
if success:
try:
from .chat_syntax_highlighter import ChatSyntaxHighlighter
from .plugin_config_dialog import SyntaxHighlighterPluginConfiguration
from .plugin_config import SyntaxHighlighterConfig
global SyntaxHighlighterPluginConfiguration, ChatSyntaxHighlighter, \
SyntaxHighlighterConfig
from syntax_highlight.chat_syntax_highlighter import \
ChatSyntaxHighlighter
from syntax_highlight.plugin_config_dialog import \
SyntaxHighlighterPluginConfiguration
from syntax_highlight.plugin_config import SyntaxHighlighterConfig
global SyntaxHighlighterPluginConfiguration
global ChatSyntaxHighlighter
global SyntaxHighlighterConfig
success = True
log.debug("pygments loaded.")
except Exception as exception:
@@ -32,27 +36,21 @@ def try_loading_pygments():
return success
PYGMENTS_MISSING = 'You are missing Python-Pygments.'
class SyntaxHighlighterPlugin(GajimPlugin):
@log_calls('SyntaxHighlighterPlugin')
def on_connect_with_chat_control(self, chat_control):
account = chat_control.contact.account.name
jid = chat_control.contact.jid
jid = chat_control.contact.jid
if account not in self.ccontrol:
self.ccontrol[account] = {}
self.ccontrol[account][jid] = ChatSyntaxHighlighter(
self.conf, chat_control.conv_textview)
self.conf, chat_control.conv_textview)
@log_calls('SyntaxHighlighterPlugin')
def on_disconnect_from_chat_control(self, chat_control):
account = chat_control.contact.account.name
jid = chat_control.contact.jid
del self.ccontrol[account][jid]
@log_calls('SyntaxHighlighterPlugin')
def on_print_real_text(self, text_view, real_text, other_tags, graphics,
iterator, additional):
account = text_view.account
@@ -78,36 +76,32 @@ class SyntaxHighlighterPlugin(GajimPlugin):
self.available_text = None
self.config_dialog = SyntaxHighlighterPluginConfiguration(self)
self.conf = SyntaxHighlighterConfig(self.config)
self.conf = SyntaxHighlighterConfig(self.config)
# The following initialization requires pygments to be available.
self.conf.init_pygments()
self.config_dialog = SyntaxHighlighterPluginConfiguration(self)
self.config_dialog = SyntaxHighlighterPluginConfiguration(self)
self.config_dialog.set_config(self.conf)
self.gui_extension_points = {
'chat_control_base': (
self.on_connect_with_chat_control,
self.on_disconnect_from_chat_control
),
'print_real_text': (self.on_print_real_text, None),
}
'chat_control_base': (
self.on_connect_with_chat_control,
self.on_disconnect_from_chat_control),
'print_real_text': (self.on_print_real_text, None), }
return True
@log_calls('SyntaxHighlighterPlugin')
def init(self):
self.ccontrol = {}
self.ccontrol = {}
self.config_default_values = {
'default_lexer' : (PLUGIN_INTERNAL_NONE_LEXER_ID, ''),
'line_break' : (LineBreakOptions.MULTILINE, ''),
'style' : ('default', ''),
'font' : ('Monospace 10', ''),
'bgcolor' : ('#ccc', ''),
'bgcolor_override' : (True, ''),
'code_marker' : (CodeMarkerOptions.AS_COMMENT, ''),
'pygments_path' : (None, ''),
}
'default_lexer': (PLUGIN_INTERNAL_NONE_LEXER_ID, ''),
'line_break': (LineBreakOptions.MULTILINE, ''),
'style': ('default', ''),
'font': ('Monospace 10', ''),
'bgcolor': ('#ccc', ''),
'bgcolor_override': (True, ''),
'code_marker': (CodeMarkerOptions.AS_COMMENT, ''),
'pygments_path': (None, ''), }
is_initialized = self.try_init()