15 from PyQt4.QtCore import * |
15 from PyQt4.QtCore import * |
16 from PyQt4.QtGui import * |
16 from PyQt4.QtGui import * |
17 |
17 |
18 from E4Gui.E4Application import e4App |
18 from E4Gui.E4Application import e4App |
19 |
19 |
20 import Exporters |
20 from . import Exporters |
21 import Lexers |
21 from . import Lexers |
22 import TypingCompleters |
22 from . import TypingCompleters |
23 from QsciScintillaCompat import QsciScintillaCompat, QSCINTILLA_VERSION |
23 from .QsciScintillaCompat import QsciScintillaCompat, QSCINTILLA_VERSION |
24 from SpellChecker import SpellChecker |
24 from .SpellChecker import SpellChecker |
25 from SpellCheckingDialog import SpellCheckingDialog |
25 from .SpellCheckingDialog import SpellCheckingDialog |
26 |
26 |
27 from Debugger.EditBreakpointDialog import EditBreakpointDialog |
27 from Debugger.EditBreakpointDialog import EditBreakpointDialog |
28 |
28 |
29 from DebugClients.Python.coverage import coverage |
29 from DebugClients.Python3.coverage import coverage |
30 |
30 |
31 from DataViews.CodeMetricsDialog import CodeMetricsDialog |
31 from DataViews.CodeMetricsDialog import CodeMetricsDialog |
32 from DataViews.PyCoverageDialog import PyCoverageDialog |
32 from DataViews.PyCoverageDialog import PyCoverageDialog |
33 from DataViews.PyProfileDialog import PyProfileDialog |
33 from DataViews.PyProfileDialog import PyProfileDialog |
34 |
34 |
35 from Printer import Printer |
35 from .Printer import Printer |
36 |
36 |
37 import Preferences |
37 import Preferences |
38 import Utilities |
38 import Utilities |
39 |
39 |
40 import UI.PixmapCache |
40 import UI.PixmapCache |
235 self.__setEolMode() |
235 self.__setEolMode() |
236 |
236 |
237 self.isResourcesFile = False |
237 self.isResourcesFile = False |
238 if editor is None: |
238 if editor is None: |
239 if self.fileName is not None: |
239 if self.fileName is not None: |
240 if (QFileInfo(self.fileName).size() / 1024) > \ |
240 if (QFileInfo(self.fileName).size() // 1024) > \ |
241 Preferences.getEditor("WarnFilesize"): |
241 Preferences.getEditor("WarnFilesize"): |
242 res = QMessageBox.warning(None, |
242 res = QMessageBox.warning(None, |
243 self.trUtf8("Open File"), |
243 self.trUtf8("Open File"), |
244 self.trUtf8("""<p>The size of the file <b>{0}</b>""" |
244 self.trUtf8("""<p>The size of the file <b>{0}</b>""" |
245 """ is <b>{1} KB</b>.""" |
245 """ is <b>{1} KB</b>.""" |
246 """ Do you really want to load it?</p>""")\ |
246 """ Do you really want to load it?</p>""")\ |
247 .format(self.fileName, |
247 .format(self.fileName, |
248 QFileInfo(self.fileName).size() / 1024), |
248 QFileInfo(self.fileName).size() // 1024), |
249 QMessageBox.StandardButtons(\ |
249 QMessageBox.StandardButtons(\ |
250 QMessageBox.No | \ |
250 QMessageBox.No | \ |
251 QMessageBox.Yes), |
251 QMessageBox.Yes), |
252 QMessageBox.No) |
252 QMessageBox.No) |
253 if res == QMessageBox.No or res == QMessageBox.Cancel: |
253 if res == QMessageBox.No or res == QMessageBox.Cancel: |
738 self.languagesActGrp.addAction(self.noLanguageAct) |
738 self.languagesActGrp.addAction(self.noLanguageAct) |
739 menu.addSeparator() |
739 menu.addSeparator() |
740 |
740 |
741 self.supportedLanguages = {} |
741 self.supportedLanguages = {} |
742 supportedLanguages = Lexers.getSupportedLanguages() |
742 supportedLanguages = Lexers.getSupportedLanguages() |
743 languages = supportedLanguages.keys() |
743 languages = sorted(list(supportedLanguages.keys())) |
744 languages.sort() |
|
745 for language in languages: |
744 for language in languages: |
746 if language != "Guessed": |
745 if language != "Guessed": |
747 self.supportedLanguages[language] = supportedLanguages[language][:] |
746 self.supportedLanguages[language] = supportedLanguages[language][:] |
748 act = menu.addAction(self.supportedLanguages[language][0]) |
747 act = menu.addAction(self.supportedLanguages[language][0]) |
749 act.setCheckable(True) |
748 act.setCheckable(True) |
824 Private method used to setup the Exporters context sub menu. |
823 Private method used to setup the Exporters context sub menu. |
825 """ |
824 """ |
826 menu = QMenu(self.trUtf8("Export as")) |
825 menu = QMenu(self.trUtf8("Export as")) |
827 |
826 |
828 supportedExporters = Exporters.getSupportedFormats() |
827 supportedExporters = Exporters.getSupportedFormats() |
829 exporters = supportedExporters.keys() |
828 exporters = sorted(list(supportedExporters.keys())) |
830 exporters.sort() |
|
831 for exporter in exporters: |
829 for exporter in exporters: |
832 act = menu.addAction(supportedExporters[exporter]) |
830 act = menu.addAction(supportedExporters[exporter]) |
833 act.setData(exporter) |
831 act.setData(exporter) |
834 |
832 |
835 self.connect(menu, SIGNAL('triggered(QAction *)'), self.__exportMenuTriggered) |
833 self.connect(menu, SIGNAL('triggered(QAction *)'), self.__exportMenuTriggered) |
1585 This method checks, if lines have been inserted or removed in order to |
1583 This method checks, if lines have been inserted or removed in order to |
1586 update the breakpoints. |
1584 update the breakpoints. |
1587 """ |
1585 """ |
1588 if self.breaks: |
1586 if self.breaks: |
1589 bps = [] # list of breakpoints |
1587 bps = [] # list of breakpoints |
1590 for handle, (ln, cond, temp, enabled, ignorecount) in self.breaks.items(): |
1588 for handle, (ln, cond, temp, enabled, ignorecount) in list(self.breaks.items()): |
1591 line = self.markerLine(handle) + 1 |
1589 line = self.markerLine(handle) + 1 |
1592 bps.append((ln, line, (cond, temp, enabled, ignorecount))) |
1590 bps.append((ln, line, (cond, temp, enabled, ignorecount))) |
1593 self.markerDeleteHandle(handle) |
1591 self.markerDeleteHandle(handle) |
1594 self.breaks = {} |
1592 self.breaks = {} |
1595 for bp in bps: |
1593 for bp in bps: |
1599 |
1597 |
1600 def __restoreBreakpoints(self): |
1598 def __restoreBreakpoints(self): |
1601 """ |
1599 """ |
1602 Private method to restore the breakpoints. |
1600 Private method to restore the breakpoints. |
1603 """ |
1601 """ |
1604 for handle in self.breaks.keys(): |
1602 for handle in list(self.breaks.keys()): |
1605 self.markerDeleteHandle(handle) |
1603 self.markerDeleteHandle(handle) |
1606 self.__addBreakPoints(QModelIndex(), 0, self.breakpointModel.rowCount() - 1) |
1604 self.__addBreakPoints(QModelIndex(), 0, self.breakpointModel.rowCount() - 1) |
1607 |
1605 |
1608 def __deleteBreakPoints(self, parentIndex, start, end): |
1606 def __deleteBreakPoints(self, parentIndex, start, end): |
1609 """ |
1607 """ |
1658 Note: This doesn't clear the breakpoint in the debugger, |
1656 Note: This doesn't clear the breakpoint in the debugger, |
1659 it just deletes it from the editor internal list of breakpoints. |
1657 it just deletes it from the editor internal list of breakpoints. |
1660 |
1658 |
1661 @param line linenumber of the breakpoint (integer) |
1659 @param line linenumber of the breakpoint (integer) |
1662 """ |
1660 """ |
1663 for handle, (ln, _, _, _, _) in self.breaks.items(): |
1661 for handle, (ln, _, _, _, _) in list(self.breaks.items()): |
1664 if self.markerLine(handle) == line-1: |
1662 if self.markerLine(handle) == line-1: |
1665 break |
1663 break |
1666 else: |
1664 else: |
1667 # not found, simply ignore it |
1665 # not found, simply ignore it |
1668 return |
1666 return |
1694 Private method to toggle a breakpoint. |
1692 Private method to toggle a breakpoint. |
1695 |
1693 |
1696 @param line line number of the breakpoint (integer) |
1694 @param line line number of the breakpoint (integer) |
1697 @param temporary flag indicating a temporary breakpoint (boolean) |
1695 @param temporary flag indicating a temporary breakpoint (boolean) |
1698 """ |
1696 """ |
1699 for handle, (ln, _, _, _, _) in self.breaks.items(): |
1697 for handle, (ln, _, _, _, _) in list(self.breaks.items()): |
1700 if self.markerLine(handle) == line - 1: |
1698 if self.markerLine(handle) == line - 1: |
1701 # delete breakpoint or toggle it to the next state |
1699 # delete breakpoint or toggle it to the next state |
1702 index = self.breakpointModel.getBreakPointIndex(self.fileName, line) |
1700 index = self.breakpointModel.getBreakPointIndex(self.fileName, line) |
1703 if Preferences.getDebugger("ThreeStateBreakPoints") and \ |
1701 if Preferences.getDebugger("ThreeStateBreakPoints") and \ |
1704 not self.breakpointModel.isBreakPointTemporaryByIndex(index): |
1702 not self.breakpointModel.isBreakPointTemporaryByIndex(index): |
1728 """ |
1726 """ |
1729 Private method to toggle a breakpoints enabled status. |
1727 Private method to toggle a breakpoints enabled status. |
1730 |
1728 |
1731 @param line line number of the breakpoint (integer) |
1729 @param line line number of the breakpoint (integer) |
1732 """ |
1730 """ |
1733 for handle, (ln, cond, temp, enabled, ignorecount) in self.breaks.items(): |
1731 for handle, (ln, cond, temp, enabled, ignorecount) in list(self.breaks.items()): |
1734 if self.markerLine(handle) == line - 1: |
1732 if self.markerLine(handle) == line - 1: |
1735 break |
1733 break |
1736 else: |
1734 else: |
1737 # no breakpoint found on that line |
1735 # no breakpoint found on that line |
1738 return |
1736 return |
1796 if line is not None: |
1794 if line is not None: |
1797 self.line = line - 1 |
1795 self.line = line - 1 |
1798 if self.line < 0: |
1796 if self.line < 0: |
1799 self.line, index = self.getCursorPosition() |
1797 self.line, index = self.getCursorPosition() |
1800 found = False |
1798 found = False |
1801 for handle, (ln, cond, temp, enabled, ignorecount) in self.breaks.items(): |
1799 for handle, (ln, cond, temp, enabled, ignorecount) in list(self.breaks.items()): |
1802 if self.markerLine(handle) == self.line: |
1800 if self.markerLine(handle) == self.line: |
1803 found = True |
1801 found = True |
1804 break |
1802 break |
1805 |
1803 |
1806 if found: |
1804 if found: |
1861 def __clearBreakpoints(self, fileName): |
1859 def __clearBreakpoints(self, fileName): |
1862 """ |
1860 """ |
1863 Private slot to clear all breakpoints. |
1861 Private slot to clear all breakpoints. |
1864 """ |
1862 """ |
1865 idxList = [] |
1863 idxList = [] |
1866 for handle, (ln, _, _, _, _) in self.breaks.items(): |
1864 for handle, (ln, _, _, _, _) in list(self.breaks.items()): |
1867 index = self.breakpointModel.getBreakPointIndex(fileName, ln) |
1865 index = self.breakpointModel.getBreakPointIndex(fileName, ln) |
1868 if index.isValid(): |
1866 if index.isValid(): |
1869 idxList.append(index) |
1867 idxList.append(index) |
1870 if idxList: |
1868 if idxList: |
1871 self.breakpointModel.deleteBreakPoints(idxList) |
1869 self.breakpointModel.deleteBreakPoints(idxList) |
2182 one doesn't exist (boolean) |
2180 one doesn't exist (boolean) |
2183 @return first line of the file (string) |
2181 @return first line of the file (string) |
2184 """ |
2182 """ |
2185 try: |
2183 try: |
2186 if createIt and not os.path.exists(fn): |
2184 if createIt and not os.path.exists(fn): |
2187 f = open(fn, "wb") |
2185 f = open(fn, "w") |
2188 f.close() |
2186 f.close() |
2189 f = open(fn, 'rb') |
2187 f = open(fn, 'r') |
2190 except IOError: |
2188 except IOError as why: |
2191 QMessageBox.critical(self.vm, self.trUtf8('Open File'), |
2189 QMessageBox.critical(self.vm, self.trUtf8('Open File'), |
2192 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>') |
2190 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>' |
2193 .format(fn)) |
2191 '<p>Reason: {1}</p>') |
|
2192 .format(fn, str(why))) |
2194 raise |
2193 raise |
2195 |
2194 |
2196 txt = f.readline() |
2195 try: |
|
2196 txt = f.readline() |
|
2197 except UnicodeDecodeError as why: |
|
2198 QMessageBox.critical(self.vm, self.trUtf8('Open File'), |
|
2199 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>' |
|
2200 '<p>Reason: {1}</p>') |
|
2201 .format(fn, str(why))) |
|
2202 raise |
2197 f.close() |
2203 f.close() |
2198 return txt |
2204 return txt |
2199 |
2205 |
2200 def readFile(self, fn, createIt = False): |
2206 def readFile(self, fn, createIt = False): |
2201 """ |
2207 """ |
2205 @param createIt flag indicating the creation of a new file, if the given |
2211 @param createIt flag indicating the creation of a new file, if the given |
2206 one doesn't exist (boolean) |
2212 one doesn't exist (boolean) |
2207 """ |
2213 """ |
2208 try: |
2214 try: |
2209 if createIt and not os.path.exists(fn): |
2215 if createIt and not os.path.exists(fn): |
2210 f = open(fn, "wb") |
2216 f = open(fn, "w") |
2211 f.close() |
2217 f.close() |
2212 f = open(fn, 'rb') |
2218 f = open(fn, 'r') |
2213 except IOError: |
2219 except IOError as why: |
2214 QMessageBox.critical(self.vm, self.trUtf8('Open File'), |
2220 QMessageBox.critical(self.vm, self.trUtf8('Open File'), |
2215 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>') |
2221 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>' |
2216 .format(fn)) |
2222 '<p>Reason: {1}</p>') |
|
2223 .format(fn, str(why))) |
2217 raise |
2224 raise |
2218 |
2225 |
2219 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
2226 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
2220 |
2227 |
2221 if fn.endswith('.ts') or fn.endswith('.ui'): |
2228 ## if fn.endswith('.ts') or fn.endswith('.ui'): |
2222 # special treatment for Qt-Linguist and Qt-Designer files |
2229 ## # special treatment for Qt-Linguist and Qt-Designer files |
|
2230 ## txt = f.read() |
|
2231 ## self.encoding = 'latin-1' |
|
2232 ## else: |
|
2233 ## txt, self.encoding = f.read(), "utf-8" #Utilities.decode(f.read()) |
|
2234 try: |
2223 txt = f.read() |
2235 txt = f.read() |
2224 self.encoding = 'latin-1' |
2236 except UnicodeDecodeError as why: |
2225 else: |
2237 QApplication.restoreOverrideCursor() |
2226 txt, self.encoding = Utilities.decode(f.read()) |
2238 QMessageBox.critical(self.vm, self.trUtf8('Open File'), |
|
2239 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>' |
|
2240 '<p>Reason: {1}</p>') |
|
2241 .format(fn, str(why))) |
|
2242 QApplication.restoreOverrideCursor() |
|
2243 raise |
|
2244 self.encoding = f.encoding.lower() |
2227 f.close() |
2245 f.close() |
2228 fileEol = self.detectEolString(txt) |
2246 fileEol = self.detectEolString(txt) |
2229 |
2247 |
2230 modified = False |
2248 modified = False |
2231 if (not Preferences.getEditor("TabForIndentation")) and \ |
2249 if (not Preferences.getEditor("TabForIndentation")) and \ |
2298 if len(txt) >= len(eol): |
2316 if len(txt) >= len(eol): |
2299 if txt[-len(eol):] != eol: |
2317 if txt[-len(eol):] != eol: |
2300 txt += eol |
2318 txt += eol |
2301 else: |
2319 else: |
2302 txt += eol |
2320 txt += eol |
2303 try: |
2321 ## try: |
2304 txt, self.encoding = Utilities.encode(txt, self.encoding) |
2322 ## txt, self.encoding = Utilities.encode(txt, self.encoding) |
2305 except Utilities.CodingError, e: |
2323 ## except Utilities.CodingError as e: |
2306 QMessageBox.critical(self, self.trUtf8('Save File'), |
2324 ## QMessageBox.critical(self, self.trUtf8('Save File'), |
2307 self.trUtf8('<p>The file <b>{0}</b> could not be saved.<br/>' |
2325 ## self.trUtf8('<p>The file <b>{0}</b> could not be saved.<br/>' |
2308 'Reason: {1}</p>') |
2326 ## 'Reason: {1}</p>') |
2309 .format(fn, unicode(e))) |
2327 ## .format(fn, str(e))) |
2310 return False |
2328 ## return False |
2311 |
2329 ## |
2312 # create a backup file, if the option is set |
2330 # create a backup file, if the option is set |
2313 createBackup = Preferences.getEditor("CreateBackupFile") |
2331 createBackup = Preferences.getEditor("CreateBackupFile") |
2314 if createBackup: |
2332 if createBackup: |
2315 if os.path.islink(fn): |
2333 if os.path.islink(fn): |
2316 fn = os.path.realpath(fn) |
2334 fn = os.path.realpath(fn) |
2332 # if there was an error, ignore it |
2350 # if there was an error, ignore it |
2333 pass |
2351 pass |
2334 |
2352 |
2335 # now write text to the file fn |
2353 # now write text to the file fn |
2336 try: |
2354 try: |
2337 f = open(fn, 'wb') |
2355 f = open(fn, 'w', encoding = self.encoding) |
2338 f.write(txt) |
2356 f.write(txt) |
2339 f.close() |
2357 f.close() |
2340 if createBackup and perms_valid: |
2358 if createBackup and perms_valid: |
2341 os.chmod(fn, permissions) |
2359 os.chmod(fn, permissions) |
2342 return True |
2360 return True |
2343 except IOError, why: |
2361 except IOError as why: |
2344 QMessageBox.critical(self, self.trUtf8('Save File'), |
2362 QMessageBox.critical(self, self.trUtf8('Save File'), |
2345 self.trUtf8('<p>The file <b>{0}</b> could not be saved.<br/>' |
2363 self.trUtf8('<p>The file <b>{0}</b> could not be saved.<br/>' |
2346 'Reason: {1}</p>') |
2364 'Reason: {1}</p>') |
2347 .format(fn, unicode(why))) |
2365 .format(fn, str(why))) |
2348 return False |
2366 return False |
2349 |
2367 |
2350 def saveFile(self, saveas = False, path = None): |
2368 def saveFile(self, saveas = False, path = None): |
2351 """ |
2369 """ |
2352 Public slot to save the text to a file. |
2370 Public slot to save the text to a file. |
3467 Public slot called to handle the user entering a character. |
3485 Public slot called to handle the user entering a character. |
3468 |
3486 |
3469 @param charNumber value of the character entered (integer) |
3487 @param charNumber value of the character entered (integer) |
3470 """ |
3488 """ |
3471 if self.isListActive(): |
3489 if self.isListActive(): |
3472 char = unichr(charNumber) |
3490 char = chr(charNumber) |
3473 if self.__isStartChar(char): |
3491 if self.__isStartChar(char): |
3474 self.cancelList() |
3492 self.cancelList() |
3475 self.autoComplete(auto = True, context = True) |
3493 self.autoComplete(auto = True, context = True) |
3476 return |
3494 return |
3477 elif char == '(': |
3495 elif char == '(': |
3478 self.cancelList() |
3496 self.cancelList() |
3479 |
3497 |
3480 if self.callTipsStyle() != QsciScintilla.CallTipsNone and \ |
3498 if self.callTipsStyle() != QsciScintilla.CallTipsNone and \ |
3481 self.lexer_ is not None and unichr(charNumber) in '()': |
3499 self.lexer_ is not None and chr(charNumber) in '()': |
3482 self.callTip() |
3500 self.callTip() |
3483 |
3501 |
3484 if not self.isCallTipActive(): |
3502 if not self.isCallTipActive(): |
3485 char = unichr(charNumber) |
3503 char = chr(charNumber) |
3486 if self.__isStartChar(char): |
3504 if self.__isStartChar(char): |
3487 self.autoComplete(auto = True, context = True) |
3505 self.autoComplete(auto = True, context = True) |
3488 return |
3506 return |
3489 |
3507 |
3490 line, col = self.getCursorPosition() |
3508 line, col = self.getCursorPosition() |
4033 """ |
4051 """ |
4034 Private method to perform an automatic syntax check of the file. |
4052 Private method to perform an automatic syntax check of the file. |
4035 """ |
4053 """ |
4036 if Preferences.getEditor("AutoCheckSyntax"): |
4054 if Preferences.getEditor("AutoCheckSyntax"): |
4037 self.clearSyntaxError() |
4055 self.clearSyntaxError() |
4038 if self.isPyFile(): |
4056 if self.isPy3File(): |
4039 syntaxError, _fn, errorline, _code, _error = \ |
4057 syntaxError, _fn, errorline, _code, _error = \ |
4040 Utilities.compile(self.fileName, self.text()) |
4058 Utilities.compile(self.fileName, self.text()) |
4041 if syntaxError: |
4059 if syntaxError: |
4042 self.toggleSyntaxError(int(errorline), 1, _error) |
4060 self.toggleSyntaxError(int(errorline), 1, _error) |
4043 |
4061 |
4285 if not (markers & (1 << self.syntaxerror)): |
4303 if not (markers & (1 << self.syntaxerror)): |
4286 handle = self.markerAdd(line - 1, self.syntaxerror) |
4304 handle = self.markerAdd(line - 1, self.syntaxerror) |
4287 self.syntaxerrors[handle] = msg |
4305 self.syntaxerrors[handle] = msg |
4288 self.emit(SIGNAL('syntaxerrorToggled'), self) |
4306 self.emit(SIGNAL('syntaxerrorToggled'), self) |
4289 else: |
4307 else: |
4290 for handle in self.syntaxerrors.keys(): |
4308 for handle in list(self.syntaxerrors.keys()): |
4291 if self.markerLine(handle) == line - 1: |
4309 if self.markerLine(handle) == line - 1: |
4292 del self.syntaxerrors[handle] |
4310 del self.syntaxerrors[handle] |
4293 self.markerDeleteHandle(handle) |
4311 self.markerDeleteHandle(handle) |
4294 self.emit(SIGNAL('syntaxerrorToggled'), self) |
4312 self.emit(SIGNAL('syntaxerrorToggled'), self) |
4295 |
4313 |
4326 |
4344 |
4327 def clearSyntaxError(self): |
4345 def clearSyntaxError(self): |
4328 """ |
4346 """ |
4329 Public slot to handle the 'Clear all syntax error' context menu action. |
4347 Public slot to handle the 'Clear all syntax error' context menu action. |
4330 """ |
4348 """ |
4331 for handle in self.syntaxerrors.keys(): |
4349 for handle in list(self.syntaxerrors.keys()): |
4332 line = self.markerLine(handle) + 1 |
4350 line = self.markerLine(handle) + 1 |
4333 self.toggleSyntaxError(line, False) |
4351 self.toggleSyntaxError(line, False) |
4334 |
4352 |
4335 def __showSyntaxError(self, line = -1): |
4353 def __showSyntaxError(self, line = -1): |
4336 """ |
4354 """ |
4339 @param line line number to show the syntax error for (integer) |
4357 @param line line number to show the syntax error for (integer) |
4340 """ |
4358 """ |
4341 if line == -1: |
4359 if line == -1: |
4342 line = self.line |
4360 line = self.line |
4343 |
4361 |
4344 for handle in self.syntaxerrors.keys(): |
4362 for handle in list(self.syntaxerrors.keys()): |
4345 if self.markerLine(handle) == line: |
4363 if self.markerLine(handle) == line: |
4346 QMessageBox.critical(None, |
4364 QMessageBox.critical(None, |
4347 self.trUtf8("Syntax Error"), |
4365 self.trUtf8("Syntax Error"), |
4348 self.syntaxerrors[handle]) |
4366 self.syntaxerrors[handle]) |
4349 break |
4367 break |
4362 |
4380 |
4363 @return Tuple of macro name and a flag, indicating, if the user pressed ok or |
4381 @return Tuple of macro name and a flag, indicating, if the user pressed ok or |
4364 canceled the operation. (string, boolean) |
4382 canceled the operation. (string, boolean) |
4365 """ |
4383 """ |
4366 qs = [] |
4384 qs = [] |
4367 for s in self.macros.keys(): |
4385 for s in list(self.macros.keys()): |
4368 qs.append(s) |
4386 qs.append(s) |
4369 qs.sort() |
4387 qs.sort() |
4370 return QInputDialog.getItem(\ |
4388 return QInputDialog.getItem(\ |
4371 self, |
4389 self, |
4372 self.trUtf8("Macro Name"), |
4390 self.trUtf8("Macro Name"), |
4403 |
4421 |
4404 if not fname: |
4422 if not fname: |
4405 return # user aborted |
4423 return # user aborted |
4406 |
4424 |
4407 try: |
4425 try: |
4408 f = open(fname, "rb") |
4426 f = open(fname, "r") |
4409 lines = f.readlines() |
4427 lines = f.readlines() |
4410 f.close() |
4428 f.close() |
4411 except IOError: |
4429 except IOError: |
4412 QMessageBox.critical(self, |
4430 QMessageBox.critical(self, |
4413 self.trUtf8("Error loading macro"), |
4431 self.trUtf8("Error loading macro"), |
4463 if res == QMessageBox.Abort or res == QMessageBox.Cancel: |
4481 if res == QMessageBox.Abort or res == QMessageBox.Cancel: |
4464 return |
4482 return |
4465 fname = Utilities.toNativeSeparators(fname) |
4483 fname = Utilities.toNativeSeparators(fname) |
4466 |
4484 |
4467 try: |
4485 try: |
4468 f = open(fname, "wb") |
4486 f = open(fname, "w") |
4469 f.write("%s%s" % (name, os.linesep)) |
4487 f.write("%s%s" % (name, os.linesep)) |
4470 f.write(self.macros[name].save()) |
4488 f.write(self.macros[name].save()) |
4471 f.close() |
4489 f.close() |
4472 except IOError: |
4490 except IOError: |
4473 QMessageBox.critical(self, |
4491 QMessageBox.critical(self, |
5194 Public slot called to handle the user entering a character. |
5212 Public slot called to handle the user entering a character. |
5195 |
5213 |
5196 @param charNumber value of the character entered (integer) |
5214 @param charNumber value of the character entered (integer) |
5197 """ |
5215 """ |
5198 if self.spell: |
5216 if self.spell: |
5199 if not unichr(charNumber).isalnum(): |
5217 if not chr(charNumber).isalnum(): |
5200 self.spell.checkWord(self.positionBefore(self.currentPosition()), True) |
5218 self.spell.checkWord(self.positionBefore(self.currentPosition()), True) |
5201 elif self.hasIndicator(self.spellingIndicator, self.currentPosition()): |
5219 elif self.hasIndicator(self.spellingIndicator, self.currentPosition()): |
5202 self.spell.checkWord(self.currentPosition()) |
5220 self.spell.checkWord(self.currentPosition()) |
5203 |
5221 |
5204 def checkSpelling(self): |
5222 def checkSpelling(self): |