fix coding standards
This commit is contained in:
parent
826e66ba81
commit
5951ea5d86
|
@ -61,8 +61,8 @@ class TextViewImage(gtk.Image):
|
||||||
self.anchor = anchor
|
self.anchor = anchor
|
||||||
self._selected = False
|
self._selected = False
|
||||||
self._disconnect_funcs = []
|
self._disconnect_funcs = []
|
||||||
self.connect("parent-set", self.on_parent_set)
|
self.connect('parent-set', self.on_parent_set)
|
||||||
self.connect("expose-event", self.on_expose)
|
self.connect('expose-event', self.on_expose)
|
||||||
|
|
||||||
def _get_selected(self):
|
def _get_selected(self):
|
||||||
parent = self.get_parent()
|
parent = self.get_parent()
|
||||||
|
@ -110,13 +110,13 @@ class TextViewImage(gtk.Image):
|
||||||
self._disconnect_signals()
|
self._disconnect_signals()
|
||||||
return
|
return
|
||||||
|
|
||||||
self._do_connect(parent, "style-set", self.do_queue_draw)
|
self._do_connect(parent, 'style-set', self.do_queue_draw)
|
||||||
self._do_connect(parent, "focus-in-event", self.do_queue_draw)
|
self._do_connect(parent, 'focus-in-event', self.do_queue_draw)
|
||||||
self._do_connect(parent, "focus-out-event", self.do_queue_draw)
|
self._do_connect(parent, 'focus-out-event', self.do_queue_draw)
|
||||||
|
|
||||||
textbuf = parent.get_buffer()
|
textbuf = parent.get_buffer()
|
||||||
self._do_connect(textbuf, "mark-set", self.on_mark_set)
|
self._do_connect(textbuf, 'mark-set', self.on_mark_set)
|
||||||
self._do_connect(textbuf, "mark-deleted", self.on_mark_deleted)
|
self._do_connect(textbuf, 'mark-deleted', self.on_mark_deleted)
|
||||||
|
|
||||||
def do_queue_draw(self, *args):
|
def do_queue_draw(self, *args):
|
||||||
self.queue_draw()
|
self.queue_draw()
|
||||||
|
@ -186,7 +186,7 @@ class ConversationTextview:
|
||||||
self.on_textview_button_press_event)
|
self.on_textview_button_press_event)
|
||||||
self.handlers[id] = self.tv
|
self.handlers[id] = self.tv
|
||||||
|
|
||||||
id = self.tv.connect("expose-event",
|
id = self.tv.connect('expose-event',
|
||||||
self.on_textview_expose_event)
|
self.on_textview_expose_event)
|
||||||
self.handlers[id] = self.tv
|
self.handlers[id] = self.tv
|
||||||
|
|
||||||
|
@ -422,7 +422,8 @@ class ConversationTextview:
|
||||||
|
|
||||||
end_iter = buffer.get_end_iter()
|
end_iter = buffer.get_end_iter()
|
||||||
before_img_iter = end_iter.copy()
|
before_img_iter = end_iter.copy()
|
||||||
before_img_iter.backward_char() # one char back (an image also takes one char)
|
# one char back (an image also takes one char)
|
||||||
|
before_img_iter.backward_char()
|
||||||
buffer.apply_tag_by_name('focus-out-line', before_img_iter, end_iter)
|
buffer.apply_tag_by_name('focus-out-line', before_img_iter, end_iter)
|
||||||
|
|
||||||
self.allow_focus_out_line = False
|
self.allow_focus_out_line = False
|
||||||
|
@ -451,7 +452,8 @@ class ConversationTextview:
|
||||||
# check if the current pointer is still over the line
|
# check if the current pointer is still over the line
|
||||||
position = self.tv.window.get_origin()
|
position = self.tv.window.get_origin()
|
||||||
self.line_tooltip.show_tooltip(_('Text below this line is what has '
|
self.line_tooltip.show_tooltip(_('Text below this line is what has '
|
||||||
'been said since the last time you paid attention to this group chat'), 8, position[1] + pointer[1])
|
'been said since the last time you paid attention to this group chat'),
|
||||||
|
8, position[1] + pointer[1])
|
||||||
|
|
||||||
def on_textview_expose_event(self, widget, event):
|
def on_textview_expose_event(self, widget, event):
|
||||||
expalloc = event.area
|
expalloc = event.area
|
||||||
|
@ -581,7 +583,8 @@ class ConversationTextview:
|
||||||
else:
|
else:
|
||||||
if dict_link.find('%s') == -1:
|
if dict_link.find('%s') == -1:
|
||||||
# we must have %s in the url if not WIKTIONARY
|
# we must have %s in the url if not WIKTIONARY
|
||||||
item = gtk.MenuItem(_('Dictionary URL is missing an "%s" and it is not WIKTIONARY'))
|
item = gtk.MenuItem(_(
|
||||||
|
'Dictionary URL is missing an "%s" and it is not WIKTIONARY'))
|
||||||
item.set_property('sensitive', False)
|
item.set_property('sensitive', False)
|
||||||
else:
|
else:
|
||||||
link = dict_link % self.selected_phrase
|
link = dict_link % self.selected_phrase
|
||||||
|
@ -638,7 +641,8 @@ class ConversationTextview:
|
||||||
if return_val: # if sth was selected when we right-clicked
|
if return_val: # if sth was selected when we right-clicked
|
||||||
# get the selected text
|
# get the selected text
|
||||||
start_sel, finish_sel = return_val[0], return_val[1]
|
start_sel, finish_sel = return_val[0], return_val[1]
|
||||||
self.selected_phrase = buffer.get_text(start_sel, finish_sel).decode('utf-8')
|
self.selected_phrase = buffer.get_text(start_sel, finish_sel).decode(
|
||||||
|
'utf-8')
|
||||||
|
|
||||||
def on_open_link_activate(self, widget, kind, text):
|
def on_open_link_activate(self, widget, kind, text):
|
||||||
helpers.launch_browser_mailer(kind, text)
|
helpers.launch_browser_mailer(kind, text)
|
||||||
|
@ -672,7 +676,8 @@ class ConversationTextview:
|
||||||
if kind == 'url':
|
if kind == 'url':
|
||||||
id = childs[0].connect('activate', self.on_copy_link_activate, text)
|
id = childs[0].connect('activate', self.on_copy_link_activate, text)
|
||||||
self.handlers[id] = childs[0]
|
self.handlers[id] = childs[0]
|
||||||
id = childs[1].connect('activate', self.on_open_link_activate, kind, text)
|
id = childs[1].connect('activate', self.on_open_link_activate, kind,
|
||||||
|
text)
|
||||||
self.handlers[id] = childs[1]
|
self.handlers[id] = childs[1]
|
||||||
childs[2].hide() # copy mail address
|
childs[2].hide() # copy mail address
|
||||||
childs[3].hide() # open mail composer
|
childs[3].hide() # open mail composer
|
||||||
|
@ -690,7 +695,8 @@ class ConversationTextview:
|
||||||
text = text.lower()
|
text = text.lower()
|
||||||
id = childs[2].connect('activate', self.on_copy_link_activate, text)
|
id = childs[2].connect('activate', self.on_copy_link_activate, text)
|
||||||
self.handlers[id] = childs[2]
|
self.handlers[id] = childs[2]
|
||||||
id = childs[3].connect('activate', self.on_open_link_activate, kind, text)
|
id = childs[3].connect('activate', self.on_open_link_activate, kind,
|
||||||
|
text)
|
||||||
self.handlers[id] = childs[3]
|
self.handlers[id] = childs[3]
|
||||||
id = childs[5].connect('activate', self.on_start_chat_activate, text)
|
id = childs[5].connect('activate', self.on_start_chat_activate, text)
|
||||||
self.handlers[id] = childs[5]
|
self.handlers[id] = childs[5]
|
||||||
|
@ -707,7 +713,8 @@ class ConversationTextview:
|
||||||
allow_add = True
|
allow_add = True
|
||||||
|
|
||||||
if allow_add:
|
if allow_add:
|
||||||
id = childs[7].connect('activate', self.on_add_to_roster_activate, text)
|
id = childs[7].connect('activate', self.on_add_to_roster_activate,
|
||||||
|
text)
|
||||||
self.handlers[id] = childs[7]
|
self.handlers[id] = childs[7]
|
||||||
childs[7].show() # show add to roster menuitem
|
childs[7].show() # show add to roster menuitem
|
||||||
else:
|
else:
|
||||||
|
@ -728,7 +735,8 @@ class ConversationTextview:
|
||||||
# we get the end of the tag
|
# we get the end of the tag
|
||||||
while not end_iter.ends_tag(texttag):
|
while not end_iter.ends_tag(texttag):
|
||||||
end_iter.forward_char()
|
end_iter.forward_char()
|
||||||
word = self.tv.get_buffer().get_text(begin_iter, end_iter).decode('utf-8')
|
word = self.tv.get_buffer().get_text(begin_iter, end_iter).decode(
|
||||||
|
'utf-8')
|
||||||
if event.button == 3: # right click
|
if event.button == 3: # right click
|
||||||
self.make_link_menu(event, kind, word)
|
self.make_link_menu(event, kind, word)
|
||||||
else:
|
else:
|
||||||
|
@ -785,16 +793,16 @@ class ConversationTextview:
|
||||||
exitcode = 0
|
exitcode = 0
|
||||||
|
|
||||||
# some latex commands are really bad
|
# some latex commands are really bad
|
||||||
blacklist = ["\\def", "\\let", "\\futurelet",
|
blacklist = ['\\def', '\\let', '\\futurelet',
|
||||||
"\\newcommand", "\\renewcomment", "\\else", "\\fi", "\\write",
|
'\\newcommand', '\\renewcomment', '\\else', '\\fi', '\\write',
|
||||||
"\\input", "\\include", "\\chardef", "\\catcode", "\\makeatletter",
|
'\\input', '\\include', '\\chardef', '\\catcode', '\\makeatletter',
|
||||||
"\\noexpand", "\\toksdef", "\\every", "\\errhelp", "\\errorstopmode",
|
'\\noexpand', '\\toksdef', '\\every', '\\errhelp', '\\errorstopmode',
|
||||||
"\\scrollmode", "\\nonstopmode", "\\batchmode", "\\read", "\\csname",
|
'\\scrollmode', '\\nonstopmode', '\\batchmode', '\\read', '\\csname',
|
||||||
"\\newhelp", "\\relax", "\\afterground", "\\afterassignment",
|
'\\newhelp', '\\relax', '\\afterground', '\\afterassignment',
|
||||||
"\\expandafter", "\\noexpand", "\\special", "\\command", "\\loop",
|
'\\expandafter', '\\noexpand', '\\special', '\\command', '\\loop',
|
||||||
"\\repeat", "\\toks", "\\output", "\\line", "\\mathcode", "\\name",
|
'\\repeat', '\\toks', '\\output', '\\line', '\\mathcode', '\\name',
|
||||||
"\\item", "\\section", "\\mbox", "\\DeclareRobustCommand", "\\[",
|
'\\item', '\\section', '\\mbox', '\\DeclareRobustCommand', '\\[',
|
||||||
"\\]"]
|
'\\]']
|
||||||
|
|
||||||
str = str[2:len(str)-2]
|
str = str[2:len(str)-2]
|
||||||
|
|
||||||
|
@ -806,16 +814,18 @@ class ConversationTextview:
|
||||||
|
|
||||||
if exitcode == 0:
|
if exitcode == 0:
|
||||||
random.seed()
|
random.seed()
|
||||||
tmpfile = os.path.join(gettempdir(), "gajimtex_" + random.randint(0,
|
tmpfile = os.path.join(gettempdir(), 'gajimtex_' + random.randint(0,
|
||||||
100).__str__())
|
100).__str__())
|
||||||
|
|
||||||
# build latex string
|
# build latex string
|
||||||
texstr = "\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}\\usepackage{amsmath}\\usepackage{amssymb}\\pagestyle{empty}"
|
texstr = '\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}'
|
||||||
texstr += "\\begin{document}\\begin{large}\\begin{gather*}"
|
texstr += '\\usepackage{amsmath}\\usepackage{amssymb}'
|
||||||
|
texstr += '\\pagestyle{empty}'
|
||||||
|
texstr += '\\begin{document}\\begin{large}\\begin{gather*}'
|
||||||
texstr += str
|
texstr += str
|
||||||
texstr += "\\end{gather*}\\end{large}\\end{document}"
|
texstr += '\\end{gather*}\\end{large}\\end{document}'
|
||||||
|
|
||||||
file = open(os.path.join(tmpfile + ".tex"), "w+")
|
file = open(os.path.join(tmpfile + '.tex'), 'w+')
|
||||||
file.write(texstr)
|
file.write(texstr)
|
||||||
file.flush()
|
file.flush()
|
||||||
file.close()
|
file.close()
|
||||||
|
@ -830,11 +840,11 @@ class ConversationTextview:
|
||||||
exitcode = p.wait()
|
exitcode = p.wait()
|
||||||
|
|
||||||
if exitcode == 0:
|
if exitcode == 0:
|
||||||
p = Popen(['convert', '-alpha', 'off', tmpfile + '.ps', tmpfile + '.png'],
|
p = Popen(['convert', '-alpha', 'off', tmpfile + '.ps',
|
||||||
cwd=gettempdir())
|
tmpfile + '.png'], cwd=gettempdir())
|
||||||
exitcode = p.wait()
|
exitcode = p.wait()
|
||||||
|
|
||||||
extensions = [".tex", ".log", ".aux", ".dvi", ".ps"]
|
extensions = ['.tex', '.log', '.aux', '.dvi', '.ps']
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
try:
|
try:
|
||||||
os.remove(tmpfile + ext)
|
os.remove(tmpfile + ext)
|
||||||
|
@ -894,11 +904,13 @@ class ConversationTextview:
|
||||||
use_other_tags = False
|
use_other_tags = False
|
||||||
elif special_text.startswith('*'): # it's a bold text
|
elif special_text.startswith('*'): # it's a bold text
|
||||||
tags.append('bold')
|
tags.append('bold')
|
||||||
if special_text[1] == '/' and special_text[-2] == '/' and len(special_text) > 4: # it's also italic
|
if special_text[1] == '/' and special_text[-2] == '/' and
|
||||||
|
len(special_text) > 4: # it's also italic
|
||||||
tags.append('italic')
|
tags.append('italic')
|
||||||
if not show_ascii_formatting_chars:
|
if not show_ascii_formatting_chars:
|
||||||
special_text = special_text[2:-2] # remove */ /*
|
special_text = special_text[2:-2] # remove */ /*
|
||||||
elif special_text[1] == '_' and special_text[-2] == '_' and len(special_text) > 4: # it's also underlined
|
elif special_text[1] == '_' and special_text[-2] == '_' and
|
||||||
|
len(special_text) > 4: # it's also underlined
|
||||||
tags.append('underline')
|
tags.append('underline')
|
||||||
if not show_ascii_formatting_chars:
|
if not show_ascii_formatting_chars:
|
||||||
special_text = special_text[2:-2] # remove *_ _*
|
special_text = special_text[2:-2] # remove *_ _*
|
||||||
|
@ -907,11 +919,13 @@ class ConversationTextview:
|
||||||
special_text = special_text[1:-1] # remove * *
|
special_text = special_text[1:-1] # remove * *
|
||||||
elif special_text.startswith('/'): # it's an italic text
|
elif special_text.startswith('/'): # it's an italic text
|
||||||
tags.append('italic')
|
tags.append('italic')
|
||||||
if special_text[1] == '*' and special_text[-2] == '*' and len(special_text) > 4: # it's also bold
|
if special_text[1] == '*' and special_text[-2] == '*' and
|
||||||
|
len(special_text) > 4: # it's also bold
|
||||||
tags.append('bold')
|
tags.append('bold')
|
||||||
if not show_ascii_formatting_chars:
|
if not show_ascii_formatting_chars:
|
||||||
special_text = special_text[2:-2] # remove /* */
|
special_text = special_text[2:-2] # remove /* */
|
||||||
elif special_text[1] == '_' and special_text[-2] == '_' and len(special_text) > 4: # it's also underlined
|
elif special_text[1] == '_' and special_text[-2] == '_' and
|
||||||
|
len(special_text) > 4: # it's also underlined
|
||||||
tags.append('underline')
|
tags.append('underline')
|
||||||
if not show_ascii_formatting_chars:
|
if not show_ascii_formatting_chars:
|
||||||
special_text = special_text[2:-2] # remove /_ _/
|
special_text = special_text[2:-2] # remove /_ _/
|
||||||
|
@ -920,11 +934,13 @@ class ConversationTextview:
|
||||||
special_text = special_text[1:-1] # remove / /
|
special_text = special_text[1:-1] # remove / /
|
||||||
elif special_text.startswith('_'): # it's an underlined text
|
elif special_text.startswith('_'): # it's an underlined text
|
||||||
tags.append('underline')
|
tags.append('underline')
|
||||||
if special_text[1] == '*' and special_text[-2] == '*' and len(special_text) > 4: # it's also bold
|
if special_text[1] == '*' and special_text[-2] == '*' and
|
||||||
|
len(special_text) > 4: # it's also bold
|
||||||
tags.append('bold')
|
tags.append('bold')
|
||||||
if not show_ascii_formatting_chars:
|
if not show_ascii_formatting_chars:
|
||||||
special_text = special_text[2:-2] # remove _* *_
|
special_text = special_text[2:-2] # remove _* *_
|
||||||
elif special_text[1] == '/' and special_text[-2] == '/' and len(special_text) > 4: # it's also italic
|
elif special_text[1] == '/' and special_text[-2] == '/' and
|
||||||
|
len(special_text) > 4: # it's also italic
|
||||||
tags.append('italic')
|
tags.append('italic')
|
||||||
if not show_ascii_formatting_chars:
|
if not show_ascii_formatting_chars:
|
||||||
special_text = special_text[2:-2] # remove _/ /_
|
special_text = special_text[2:-2] # remove _/ /_
|
||||||
|
@ -1122,8 +1138,8 @@ class ConversationTextview:
|
||||||
self.tv.display_html(xhtml.encode('utf-8'))
|
self.tv.display_html(xhtml.encode('utf-8'))
|
||||||
return
|
return
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
gajim.log.debug(str("Error processing xhtml")+str(e))
|
gajim.log.debug(str('Error processing xhtml')+str(e))
|
||||||
gajim.log.debug(str("with |"+xhtml+"|"))
|
gajim.log.debug(str('with |'+xhtml+'|'))
|
||||||
|
|
||||||
buffer = self.tv.get_buffer()
|
buffer = self.tv.get_buffer()
|
||||||
# /me is replaced by name if name is given
|
# /me is replaced by name if name is given
|
||||||
|
@ -1135,4 +1151,3 @@ class ConversationTextview:
|
||||||
# add the rest of text located in the index and after
|
# add the rest of text located in the index and after
|
||||||
end_iter = buffer.get_end_iter()
|
end_iter = buffer.get_end_iter()
|
||||||
buffer.insert_with_tags_by_name(end_iter, text[index:], *text_tags)
|
buffer.insert_with_tags_by_name(end_iter, text[index:], *text_tags)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue