root/branch/twedit/LanguageManager.py

Revision 1591, 4.5 kB (checked in by mswat, 16 months ago)

converted print statements into dbgMsg with switchable debug output option

Line 
1"""
2 Need to add more languages
3"""
4from PyQt4.QtCore import *
5from PyQt4.QtGui import *
6from PyQt4.Qsci import *
7import PyQt4.Qsci
8               
9from PyQt4 import QtCore, QtGui
10from Messaging import stdMsg, dbgMsg, errMsg, dbgMsg
11
12class 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        # format [lexer,begin comment, end comment, brace matching (0- nor matching, 1 matching), codeFolding]
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            # self.actionDict[key]=QtGui.QAction(key, self, shortcut="",
66                # statusTip=key, triggered=self.increaseIndent)
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        #setting Lexer
78        editor=self.editorWindow.editTab.currentWidget()
79        editor.setLexer(self.languageLexerDictionary[str(_language)][0])
80        # print "commentStyle=",self.languageLexerDictionary[str(_language)][1:3]
81        self.editorWindow.commentStyleDict[editor]= self.languageLexerDictionary[str(_language)][1:3]       
82
Note: See TracBrowser for help on using the browser.