Package muntjac :: Package addon :: Package codemirror :: Module code_mirror
[hide private]
[frames] | no frames]

Source Code for Module muntjac.addon.codemirror.code_mirror

 1  # Copyright (C) 2012 Vaadin Ltd.  
 2  # Copyright (C) 2012 Richard Lincoln 
 3  #  
 4  # Licensed under the Apache License, Version 2.0 (the "License");  
 5  # you may not use this file except in compliance with the License.  
 6  # You may obtain a copy of the License at  
 7  #  
 8  #     http://www.apache.org/licenses/LICENSE-2.0  
 9  #  
10  # Unless required by applicable law or agreed to in writing, software  
11  # distributed under the License is distributed on an "AS IS" BASIS,  
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13  # See the License for the specific language governing permissions and  
14  # limitations under the License. 
15   
16  from muntjac.ui.text_field import TextField 
17   
18  from muntjac.addon.codemirror.client.code_mode import CodeMode 
19  from muntjac.addon.codemirror.client.code_theme import CodeTheme 
20   
21   
22 -class CodeMirror(TextField):
23 """Server side component for the VCodeMirrorTextField2 widget.""" 24 25 CLIENT_WIDGET = None #ClientWidget(VCodeMirror) 26 27 TYPE_MAPPING = 'org.vaadin.codemirror2.CodeMirror' 28
29 - def __init__(self, caption, codeMode=None, codeTheme=None):
30 if codeMode is None: 31 codeMode = CodeMode.TEXT 32 33 if codeTheme is None: 34 codeTheme = CodeTheme.DEFAULT 35 36 self._codeStyle = None 37 self._showLineNumbers = False 38 self._codeTheme = None 39 40 super(CodeMirror, self).__init__(caption) 41 42 self.setCodeMode(codeMode) 43 self.setCodeTheme(codeTheme)
44 45
46 - def paintContent(self, target):
47 super(CodeMirror, self).paintContent(target) 48 49 if self.getCodeMode() is not None: 50 target.addAttribute('codeMode', self.getCodeMode().getId()) 51 52 target.addAttribute('showLineNumbers', self.isShowLineNumbers()) 53 54 if self.getCodeTheme() is not None: 55 target.addAttribute('codeTheme', self.getCodeTheme().getId())
56 57
58 - def setCodeMode(self, codeMode):
59 self._codeMode = codeMode 60 self.requestRepaint()
61 62
63 - def getCodeMode(self):
64 return self._codeMode
65 66
67 - def setShowLineNumbers(self, showLineNumbers):
68 self._showLineNumbers = showLineNumbers 69 self.requestRepaint()
70 71
72 - def isShowLineNumbers(self):
73 return self._showLineNumbers
74 75
76 - def setCodeTheme(self, codeTheme):
77 self._codeTheme = codeTheme 78 self.requestRepaint()
79 80
81 - def getCodeTheme(self):
82 return self._codeTheme
83