PluginToolGenerateHash.py

changeset 11
75b2e663fe71
parent 10
4e1e5853c0c7
child 12
62102ad23820
equal deleted inserted replaced
10:4e1e5853c0c7 11:75b2e663fe71
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the 'Generate Hash' tool plug-in. 7 Module implementing the 'Generate Hash' tool plug-in.
8 """ 8 """
9
10 from __future__ import unicode_literals
9 11
10 import os 12 import os
11 import hashlib 13 import hashlib
12 14
13 from PyQt4.QtCore import QObject, QTranslator 15 from PyQt4.QtCore import QObject, QTranslator
273 self.trUtf8("""<p>The hash for some files could not""" 275 self.trUtf8("""<p>The hash for some files could not"""
274 """ be generated.</p>""") 276 """ be generated.</p>""")
275 ) 277 )
276 else: 278 else:
277 editor = e5App().getObject("ViewManager").activeWindow() 279 editor = e5App().getObject("ViewManager").activeWindow()
280 if (editor.getLanguage() in ['Python', 'Python2'] and
281 "from __future__ import unicode_literals"
282 not in editor.text()):
283 prefix = 'u'
284 else:
285 prefix = ''
286
278 line, index = editor.getCursorPosition() 287 line, index = editor.getCursorPosition()
279 indLevel = (editor.indentation(line) // 288 indLevel = (editor.indentation(line) //
280 editor.indentationWidth()) 289 editor.indentationWidth())
281 if editor.indentationsUseTabs(): 290 if editor.indentationsUseTabs():
282 indString = '\t' 291 indString = '\t'
283 else: 292 else:
284 indString = editor.indentationWidth() * ' ' 293 indString = editor.indentationWidth() * ' '
285 indent = (indLevel + 1) * indString 294 indent = (indLevel + 1) * indString
286 code = ["["] 295 code = ["["]
287 for hash in hashes: 296 for name, hash in hashes:
288 code.append("{0}{1},".format(indent, str(hash))) 297 code.append("{0}({1}'{2}', '{3}'),".format(
298 indent, prefix, name, hash))
289 code.append("{0}]".format(indLevel * indString)) 299 code.append("{0}]".format(indLevel * indString))
290 300
291 self.__insertHash(os.linesep.join(code)) 301 self.__insertHash(os.linesep.join(code))

eric ide

mercurial