| 1 | """ |
|---|
| 2 | Need to add more languages |
|---|
| 3 | """ |
|---|
| 4 | from PyQt4.QtCore import * |
|---|
| 5 | from PyQt4.QtGui import * |
|---|
| 6 | from PyQt4.Qsci import * |
|---|
| 7 | import PyQt4.Qsci |
|---|
| 8 | |
|---|
| 9 | from PyQt4 import QtCore, QtGui |
|---|
| 10 | from Messaging import stdMsg, dbgMsg, errMsg, dbgMsg |
|---|
| 11 | |
|---|
| 12 | class LanguageManager: |
|---|
| 13 | |
|---|
| 14 | def __init__(self,_editorWindow): |
|---|
| 15 | self.editorWindow=_editorWindow |
|---|
| 16 | self.actionDict={} |
|---|
| 17 | self.languageMapper = QSignalMapper(self.editorWindow) |
|---|
| 18 | self.editorWindow.connect(self.languageMapper,SIGNAL("mapped(const QString&)"), self.selectLexer) |
|---|
| 19 | |
|---|
| 20 | self.actionChecked=None |
|---|
| 21 | |
|---|
| 22 | self.languageLexerDictionary={ |
|---|
| 23 | "Bash":[QsciLexerBash(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 24 | "Batch":[QsciLexerBash(),"REM ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 25 | "C":[QsciLexerCPP(),"// ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 26 | "C#":[QsciLexerCSharp(),"// ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 27 | "CSS":[QsciLexerCSS(),"/* "," */",1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 28 | "D":[QsciLexerD(),"// ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 29 | "Diff":[QsciLexerDiff(),None,None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 30 | "Python":[QsciLexerPython(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 31 | "CMake":[QsciLexerCMake(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 32 | "Fortran":[QsciLexerFortran(),"! ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 33 | "Fortran77":[QsciLexerFortran77(),"c ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 34 | "HTML":[QsciLexerHTML(),"<!-- "," -->",1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 35 | "Java":[QsciLexerJava(),"// ", None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 36 | "JavaScript":[QsciLexerJavaScript(),"// ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 37 | "Lua":[QsciLexerLua(),"-- ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 38 | "Makefile":[QsciLexerMakefile(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 39 | "Pascal":[QsciLexerPascal(),"{ "," }",1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 40 | "Perl":[QsciLexerPerl(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 41 | "PostScript":[QsciLexerPostScript(),"% ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 42 | "Properties":[QsciLexerProperties(),"; ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 43 | "POV":[QsciLexerPOV(),"// ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 44 | "Spice":[QsciLexerSpice(),"* ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 45 | "SQL":[QsciLexerSQL(),"/* "," */",1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 46 | "Ruby":[QsciLexerRuby(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 47 | "TCL":[QsciLexerTCL(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 48 | "Verilog":[QsciLexerVerilog(),"// ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 49 | "VHDL":[QsciLexerVHDL(),"-- ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 50 | "TeX":[QsciLexerTeX(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 51 | "XML":[QsciLexerXML(),"<!-- "," -->",1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 52 | "YML":[QsciLexerYAML(),"# ",None,1,5,QsciScintilla.SCWS_INVISIBLE], |
|---|
| 53 | } |
|---|
| 54 | self.lDict={"XML":QsciLexerXML()} |
|---|
| 55 | |
|---|
| 56 | def createActions(self): |
|---|
| 57 | keys=self.languageLexerDictionary.keys() |
|---|
| 58 | keys.sort() |
|---|
| 59 | for key in keys: |
|---|
| 60 | action=self.editorWindow.languageMenu.addAction(key) |
|---|
| 61 | self.actionDict[key]=action |
|---|
| 62 | action.setCheckable(True) |
|---|
| 63 | self.editorWindow.connect(action,SIGNAL("triggered()"),self.languageMapper,SLOT("map()")) |
|---|
| 64 | self.languageMapper.setMapping(action, key) |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | def selectLexer(self,_language): |
|---|
| 68 | print "selecting language ", _language |
|---|
| 69 | if self.actionChecked: |
|---|
| 70 | self.actionChecked.setChecked(False) |
|---|
| 71 | self.actionDict[str(_language)].setChecked(True) |
|---|
| 72 | self.actionChecked=self.actionDict[str(_language)] |
|---|
| 73 | else: |
|---|
| 74 | self.actionDict[str(_language)].setChecked(True) |
|---|
| 75 | self.actionChecked=self.actionDict[str(_language)] |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | editor=self.editorWindow.editTab.currentWidget() |
|---|
| 79 | editor.setLexer(self.languageLexerDictionary[str(_language)][0]) |
|---|
| 80 | |
|---|
| 81 | self.editorWindow.commentStyleDict[editor]= self.languageLexerDictionary[str(_language)][1:3] |
|---|
| 82 | |
|---|