QScintilla/MiniEditor.py

changeset 500
c3abc7895a01
parent 461
34528aaedf1c
child 537
72b32daeb8d6
equal deleted inserted replaced
499:622ab17a68d5 500:c3abc7895a01
85 85
86 class MiniEditor(QMainWindow): 86 class MiniEditor(QMainWindow):
87 """ 87 """
88 Class implementing a minimalistic editor for simple editing tasks. 88 Class implementing a minimalistic editor for simple editing tasks.
89 89
90 @signal editorSaved emitted after the file has been saved 90 @signal editorSaved() emitted after the file has been saved
91 """ 91 """
92 editorSaved = pyqtSignal()
93
92 def __init__(self, filename = "", filetype = "", parent = None, name = None): 94 def __init__(self, filename = "", filetype = "", parent = None, name = None):
93 """ 95 """
94 Constructor 96 Constructor
95 97
96 @param filename name of the file to open (string) 98 @param filename name of the file to open (string)
151 # initialise the mark occurrences timer 153 # initialise the mark occurrences timer
152 self.__markOccurrencesTimer = QTimer(self) 154 self.__markOccurrencesTimer = QTimer(self)
153 self.__markOccurrencesTimer.setSingleShot(True) 155 self.__markOccurrencesTimer.setSingleShot(True)
154 self.__markOccurrencesTimer.setInterval( 156 self.__markOccurrencesTimer.setInterval(
155 Preferences.getEditor("MarkOccurrencesTimeout")) 157 Preferences.getEditor("MarkOccurrencesTimeout"))
156 self.connect(self.__markOccurrencesTimer, SIGNAL("timeout()"), 158 self.__markOccurrencesTimer.timeout.connect(self.__markOccurrences)
157 self.__markOccurrences)
158 self.__markedText = "" 159 self.__markedText = ""
159 160
160 self.connect(self.__textEdit, SIGNAL("textChanged()"), self.__documentWasModified) 161 self.__textEdit.textChanged.connect(self.__documentWasModified)
161 self.connect(self.__textEdit, SIGNAL('modificationChanged(bool)'), 162 self.__textEdit.modificationChanged.connect(self.__modificationChanged)
162 self.__modificationChanged) 163 self.__textEdit.cursorPositionChanged.connect(self.__cursorPositionChanged)
163 self.connect(self.__textEdit, SIGNAL('cursorPositionChanged(int, int)'),
164 self.__cursorPositionChanged)
165 164
166 self.__textEdit.setContextMenuPolicy(Qt.CustomContextMenu) 165 self.__textEdit.setContextMenuPolicy(Qt.CustomContextMenu)
167 self.__textEdit.customContextMenuRequested.connect(self.__contextMenuRequested) 166 self.__textEdit.customContextMenuRequested.connect(self.__contextMenuRequested)
168 167
169 self.connect(self.__textEdit, 168 self.__textEdit.selectionChanged.connect(self.searchDlg.selectionChanged)
170 SIGNAL("selectionChanged()"), 169 self.__textEdit.selectionChanged.connect(self.replaceDlg.selectionChanged)
171 self.searchDlg.selectionChanged)
172 self.connect(self.__textEdit,
173 SIGNAL("selectionChanged()"),
174 self.replaceDlg.selectionChanged)
175 170
176 self.__setCurrentFile("") 171 self.__setCurrentFile("")
177 if filename: 172 if filename:
178 self.__loadFile(filename, filetype) 173 self.__loadFile(filename, filetype)
179 174
527 self.deleteAct.triggered[()].connect(self.__textEdit.clear) 522 self.deleteAct.triggered[()].connect(self.__textEdit.clear)
528 self.editActions.append(self.deleteAct) 523 self.editActions.append(self.deleteAct)
529 524
530 self.cutAct.setEnabled(False); 525 self.cutAct.setEnabled(False);
531 self.copyAct.setEnabled(False); 526 self.copyAct.setEnabled(False);
532 self.connect(self.__textEdit, SIGNAL("copyAvailable(bool)"), 527 self.__textEdit.copyAvailable.connect(self.cutAct.setEnabled)
533 self.cutAct, SLOT("setEnabled(bool)")) 528 self.__textEdit.copyAvailable.connect(self.copyAct.setEnabled)
534 self.connect(self.__textEdit, SIGNAL("copyAvailable(bool)"),
535 self.copyAct, SLOT("setEnabled(bool)"))
536 529
537 #################################################################### 530 ####################################################################
538 ## Below follow the actions for qscintilla standard commands. 531 ## Below follow the actions for qscintilla standard commands.
539 #################################################################### 532 ####################################################################
540 533
541 self.esm = QSignalMapper(self) 534 self.esm = QSignalMapper(self)
542 self.connect(self.esm, SIGNAL('mapped(int)'), self.__textEdit.editorCommand) 535 self.esm.mapped[int].connect(self.__textEdit.editorCommand)
543 536
544 self.editorActGrp = createActionGroup(self) 537 self.editorActGrp = createActionGroup(self)
545 538
546 act = E5Action(QApplication.translate('ViewManager', 'Move left one character'), 539 act = E5Action(QApplication.translate('ViewManager', 'Move left one character'),
547 QApplication.translate('ViewManager', 'Move left one character'), 540 QApplication.translate('ViewManager', 'Move left one character'),
1552 self.__checkActions() 1545 self.__checkActions()
1553 1546
1554 return False 1547 return False
1555 1548
1556 QApplication.restoreOverrideCursor() 1549 QApplication.restoreOverrideCursor()
1557 self.emit(SIGNAL("editorSaved")) 1550 self.editorSaved.emit()
1558 1551
1559 self.__setCurrentFile(fileName) 1552 self.__setCurrentFile(fileName)
1560 self.__statusBar.showMessage(self.trUtf8("File saved"), 2000) 1553 self.__statusBar.showMessage(self.trUtf8("File saved"), 2000)
1561 1554
1562 self.__checkActions() 1555 self.__checkActions()
1837 if self.__curFile: 1830 if self.__curFile:
1838 printer.setDocName(QFileInfo(self.__curFile).fileName()) 1831 printer.setDocName(QFileInfo(self.__curFile).fileName())
1839 else: 1832 else:
1840 printer.setDocName(self.trUtf8("Untitled")) 1833 printer.setDocName(self.trUtf8("Untitled"))
1841 preview = QPrintPreviewDialog(printer, self) 1834 preview = QPrintPreviewDialog(printer, self)
1842 self.connect(preview, SIGNAL("paintRequested(QPrinter*)"), self.__printPreview) 1835 preview.paintRequested.connect(self.__printPreview)
1843 preview.exec_() 1836 preview.exec_()
1844 1837
1845 def __printPreview(self, printer): 1838 def __printPreview(self, printer):
1846 """ 1839 """
1847 Private slot to generate a print preview. 1840 Private slot to generate a print preview.
1916 self.pygmentsAct.setData("Guessed") 1909 self.pygmentsAct.setData("Guessed")
1917 self.languagesActGrp.addAction(self.pygmentsAct) 1910 self.languagesActGrp.addAction(self.pygmentsAct)
1918 self.pygmentsSelAct = menu.addAction(self.trUtf8("Alternatives")) 1911 self.pygmentsSelAct = menu.addAction(self.trUtf8("Alternatives"))
1919 self.pygmentsSelAct.setData("Alternatives") 1912 self.pygmentsSelAct.setData("Alternatives")
1920 1913
1921 self.connect(menu, SIGNAL('triggered(QAction *)'), self.__languageMenuTriggered) 1914 menu.triggered.connect(self.__languageMenuTriggered)
1922 menu.aboutToShow.connect(self.__showContextMenuLanguages) 1915 menu.aboutToShow.connect(self.__showContextMenuLanguages)
1923 1916
1924 return menu 1917 return menu
1925 1918
1926 def __showContextMenuLanguages(self): 1919 def __showContextMenuLanguages(self):
1980 """ 1973 """
1981 Private method used to reset the language selection. 1974 Private method used to reset the language selection.
1982 """ 1975 """
1983 if self.lexer_ is not None and \ 1976 if self.lexer_ is not None and \
1984 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None): 1977 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None):
1985 self.disconnect(self.__textEdit, SIGNAL("SCN_STYLENEEDED(int)"), 1978 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
1986 self.__styleNeeded)
1987 1979
1988 self.apiLanguage = "" 1980 self.apiLanguage = ""
1989 self.lexer_ = None 1981 self.lexer_ = None
1990 self.__textEdit.setLexer() 1982 self.__textEdit.setLexer()
1991 self.__setMonospaced(self.useMonospaced) 1983 self.__setMonospaced(self.useMonospaced)
2041 @param filename filename used to determine the associated lexer language (string) 2033 @param filename filename used to determine the associated lexer language (string)
2042 @keyparam pyname name of the pygments lexer to use (string) 2034 @keyparam pyname name of the pygments lexer to use (string)
2043 """ 2035 """
2044 if self.lexer_ is not None and \ 2036 if self.lexer_ is not None and \
2045 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None): 2037 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None):
2046 self.disconnect(self.__textEdit, SIGNAL("SCN_STYLENEEDED(int)"), 2038 self.__textEdit.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
2047 self.__styleNeeded)
2048 2039
2049 filename = os.path.basename(filename) 2040 filename = os.path.basename(filename)
2050 language = Preferences.getEditorLexerAssoc(filename) 2041 language = Preferences.getEditorLexerAssoc(filename)
2051 if language.startswith("Pygments|"): 2042 if language.startswith("Pygments|"):
2052 pyname = language.split("|", 1)[1] 2043 pyname = language.split("|", 1)[1]
2063 else: 2054 else:
2064 self.apiLanguage = self.lexer_.language() 2055 self.apiLanguage = self.lexer_.language()
2065 self.__textEdit.setLexer(self.lexer_) 2056 self.__textEdit.setLexer(self.lexer_)
2066 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None: 2057 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None:
2067 self.__textEdit.setStyleBits(self.lexer_.styleBitsNeeded()) 2058 self.__textEdit.setStyleBits(self.lexer_.styleBitsNeeded())
2068 self.connect(self.__textEdit, SIGNAL("SCN_STYLENEEDED(int)"), 2059 self.__textEdit.SCN_STYLENEEDED.connect(self.__styleNeeded)
2069 self.__styleNeeded)
2070 2060
2071 # get the font for style 0 and set it as the default font 2061 # get the font for style 0 and set it as the default font
2072 key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) 2062 key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
2073 fdesc = Preferences.Prefs.settings.value(key) 2063 fdesc = Preferences.Prefs.settings.value(key)
2074 if fdesc is not None: 2064 if fdesc is not None:

eric ide

mercurial