Plugins/ViewManagerPlugins/Listspace/Listspace.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2791
a9577f248f04
parent 3005
3953ddfb991d
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
10 from __future__ import unicode_literals # __IGNORE_WARNING__ 10 from __future__ import unicode_literals # __IGNORE_WARNING__
11 11
12 import os 12 import os
13 13
14 from PyQt4.QtCore import pyqtSignal, QFileInfo, QEvent, Qt 14 from PyQt4.QtCore import pyqtSignal, QFileInfo, QEvent, Qt
15 from PyQt4.QtGui import QStackedWidget, QSplitter, QListWidget, QListWidgetItem, \ 15 from PyQt4.QtGui import QStackedWidget, QSplitter, QListWidget, \
16 QSizePolicy, QMenu, QApplication 16 QListWidgetItem, QSizePolicy, QMenu, QApplication
17 17
18 from ViewManager.ViewManager import ViewManager 18 from ViewManager.ViewManager import ViewManager
19 19
20 import QScintilla.Editor 20 import QScintilla.Editor
21 from QScintilla.Editor import Editor 21 from QScintilla.Editor import Editor
126 """ 126 """
127 return editor in self.editors 127 return editor in self.editors
128 128
129 def firstEditor(self): 129 def firstEditor(self):
130 """ 130 """
131 Public method to retrieve the first editor in the list of managed editors. 131 Public method to retrieve the first editor in the list of managed
132 editors.
132 133
133 @return first editor in list (QScintilla.Editor.Editor) 134 @return first editor in list (QScintilla.Editor.Editor)
134 """ 135 """
135 return len(self.editors) and self.editors[0] or None 136 return len(self.editors) and self.editors[0] or None
136 137
144 @signal editorChangedEd(Editor) emitted when the current editor has changed 145 @signal editorChangedEd(Editor) emitted when the current editor has changed
145 @signal lastEditorClosed() emitted after the last editor window was closed 146 @signal lastEditorClosed() emitted after the last editor window was closed
146 @signal editorOpened(str) emitted after an editor window was opened 147 @signal editorOpened(str) emitted after an editor window was opened
147 @signal editorOpenedEd(Editor) emitted after an editor window was opened 148 @signal editorOpenedEd(Editor) emitted after an editor window was opened
148 @signal editorClosed(str) emitted just before an editor window gets closed 149 @signal editorClosed(str) emitted just before an editor window gets closed
149 @signal editorClosedEd(Editor) emitted just before an editor window gets closed 150 @signal editorClosedEd(Editor) emitted just before an editor window gets
151 closed
150 @signal editorSaved(str) emitted after an editor window was saved 152 @signal editorSaved(str) emitted after an editor window was saved
151 @signal checkActions(Editor) emitted when some actions should be checked 153 @signal checkActions(Editor) emitted when some actions should be checked
152 for their status 154 for their status
153 @signal cursorChanged(Editor) emitted after the cursor position of the active 155 @signal cursorChanged(Editor) emitted after the cursor position of the
154 window has changed 156 active window has changed
155 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled. 157 @signal breakpointToggled(Editor) emitted when a breakpoint is toggled.
156 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled. 158 @signal bookmarkToggled(Editor) emitted when a bookmark is toggled.
157 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled. 159 @signal syntaxerrorToggled(Editor) emitted when a syntax error is toggled.
158 @signal previewStateChanged(bool) emitted to signal a change in the preview state 160 @signal previewStateChanged(bool) emitted to signal a change in the
161 preview state
159 @signal editorLanguageChanged(Editor) emitted to signal a change of an 162 @signal editorLanguageChanged(Editor) emitted to signal a change of an
160 editors language 163 editors language
161 @signal editorTextChanged(Editor) emitted to signal a change of an editor's text 164 @signal editorTextChanged(Editor) emitted to signal a change of an
162 @signal editorLineChanged(str,int) emitted to signal a change of an editor's 165 editor's text
163 current line (line is given one based) 166 @signal editorLineChanged(str,int) emitted to signal a change of an
167 editor's current line (line is given one based)
164 """ 168 """
165 changeCaption = pyqtSignal(str) 169 changeCaption = pyqtSignal(str)
166 editorChanged = pyqtSignal(str) 170 editorChanged = pyqtSignal(str)
167 editorChangedEd = pyqtSignal(Editor) 171 editorChangedEd = pyqtSignal(Editor)
168 lastEditorClosed = pyqtSignal() 172 lastEditorClosed = pyqtSignal()
184 def __init__(self, parent): 188 def __init__(self, parent):
185 """ 189 """
186 Constructor 190 Constructor
187 191
188 @param parent parent widget (QWidget) 192 @param parent parent widget (QWidget)
189 @param ui reference to the main user interface
190 @param dbs reference to the debug server object
191 """ 193 """
192 self.stacks = [] 194 self.stacks = []
193 195
194 QSplitter.__init__(self, parent) 196 QSplitter.__init__(self, parent)
195 ViewManager.__init__(self) 197 ViewManager.__init__(self)
226 """ 228 """
227 self.__menu = QMenu(self) 229 self.__menu = QMenu(self)
228 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"), 230 self.__menu.addAction(UI.PixmapCache.getIcon("tabClose.png"),
229 self.trUtf8('Close'), self.__contextMenuClose) 231 self.trUtf8('Close'), self.__contextMenuClose)
230 self.closeOthersMenuAct = self.__menu.addAction( 232 self.closeOthersMenuAct = self.__menu.addAction(
231 UI.PixmapCache.getIcon("tabCloseOther.png"), self.trUtf8("Close Others"), 233 UI.PixmapCache.getIcon("tabCloseOther.png"),
234 self.trUtf8("Close Others"),
232 self.__contextMenuCloseOthers) 235 self.__contextMenuCloseOthers)
233 self.__menu.addAction(self.trUtf8('Close All'), self.__contextMenuCloseAll) 236 self.__menu.addAction(
237 self.trUtf8('Close All'), self.__contextMenuCloseAll)
234 self.__menu.addSeparator() 238 self.__menu.addSeparator()
235 self.saveMenuAct = \ 239 self.saveMenuAct = \
236 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"), 240 self.__menu.addAction(UI.PixmapCache.getIcon("fileSave.png"),
237 self.trUtf8('Save'), self.__contextMenuSave) 241 self.trUtf8('Save'), self.__contextMenuSave)
238 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"), 242 self.__menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"),
245 self.__contextMenuOpenRejections) 249 self.__contextMenuOpenRejections)
246 self.__menu.addSeparator() 250 self.__menu.addSeparator()
247 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"), 251 self.__menu.addAction(UI.PixmapCache.getIcon("print.png"),
248 self.trUtf8('Print'), self.__contextMenuPrintFile) 252 self.trUtf8('Print'), self.__contextMenuPrintFile)
249 self.__menu.addSeparator() 253 self.__menu.addSeparator()
250 self.copyPathAct = self.__menu.addAction(self.trUtf8("Copy Path to Clipboard"), 254 self.copyPathAct = self.__menu.addAction(
255 self.trUtf8("Copy Path to Clipboard"),
251 self.__contextMenuCopyPathToClipboard) 256 self.__contextMenuCopyPathToClipboard)
252 257
253 def __showMenu(self, point): 258 def __showMenu(self, point):
254 """ 259 """
255 Private slot to handle the customContextMenuRequested signal of the viewlist. 260 Private slot to handle the customContextMenuRequested signal of
261 the viewlist.
262
263 @param point position to open the menu at (QPoint)
256 """ 264 """
257 if self.editors: 265 if self.editors:
258 itm = self.viewlist.itemAt(point) 266 itm = self.viewlist.itemAt(point)
259 if itm is not None: 267 if itm is not None:
260 row = self.viewlist.row(itm) 268 row = self.viewlist.row(itm)
261 self.contextMenuEditor = self.editors[row] 269 self.contextMenuEditor = self.editors[row]
262 self.contextMenuIndex = row 270 self.contextMenuIndex = row
263 if self.contextMenuEditor: 271 if self.contextMenuEditor:
264 self.saveMenuAct.setEnabled(self.contextMenuEditor.isModified()) 272 self.saveMenuAct.setEnabled(
273 self.contextMenuEditor.isModified())
265 fileName = self.contextMenuEditor.getFileName() 274 fileName = self.contextMenuEditor.getFileName()
266 self.copyPathAct.setEnabled(bool(fileName)) 275 self.copyPathAct.setEnabled(bool(fileName))
267 if fileName: 276 if fileName:
268 rej = "{0}.rej".format(fileName) 277 rej = "{0}.rej".format(fileName)
269 self.openRejectionsMenuAct.setEnabled(os.path.exists(rej)) 278 self.openRejectionsMenuAct.setEnabled(
279 os.path.exists(rej))
270 else: 280 else:
271 self.openRejectionsMenuAct.setEnabled(False) 281 self.openRejectionsMenuAct.setEnabled(False)
272 282
273 self.closeOthersMenuAct.setEnabled(self.viewlist.count() > 1) 283 self.closeOthersMenuAct.setEnabled(
284 self.viewlist.count() > 1)
274 285
275 self.__menu.popup(self.viewlist.mapToGlobal(point)) 286 self.__menu.popup(self.viewlist.mapToGlobal(point))
276 287
277 def canCascade(self): 288 def canCascade(self):
278 """ 289 """
310 """ 321 """
311 pass 322 pass
312 323
313 def _removeAllViews(self): 324 def _removeAllViews(self):
314 """ 325 """
315 Protected method to remove all views (i.e. windows) 326 Protected method to remove all views (i.e. windows).
316 """ 327 """
317 self.viewlist.clear() 328 self.viewlist.clear()
318 for win in self.editors: 329 for win in self.editors:
319 for stack in self.stacks: 330 for stack in self.stacks:
320 if stack.hasEditor(win): 331 if stack.hasEditor(win):
322 break 333 break
323 win.closeIt() 334 win.closeIt()
324 335
325 def _removeView(self, win): 336 def _removeView(self, win):
326 """ 337 """
327 Protected method to remove a view (i.e. window) 338 Protected method to remove a view (i.e. window).
328 339
329 @param win editor window to be removed 340 @param win editor window to be removed
330 """ 341 """
331 self.__inRemoveView = True 342 self.__inRemoveView = True
332 ind = self.editors.index(win) 343 ind = self.editors.index(win)
359 self.changeCaption.emit("") 370 self.changeCaption.emit("")
360 self.editorChangedEd.emit(aw) 371 self.editorChangedEd.emit(aw)
361 372
362 def _addView(self, win, fn=None, noName=""): 373 def _addView(self, win, fn=None, noName=""):
363 """ 374 """
364 Protected method to add a view (i.e. window) 375 Protected method to add a view (i.e. window).
365 376
366 @param win editor assembly to be added 377 @param win editor assembly to be added
367 @param fn filename of this editor (string) 378 @param fn filename of this editor (string)
368 @param noName name to be used for an unnamed editor (string) 379 @param noName name to be used for an unnamed editor (string)
369 """ 380 """
422 if fn: 433 if fn:
423 self.editorLineChanged.emit(fn, lineno + 1) 434 self.editorLineChanged.emit(fn, lineno + 1)
424 435
425 def _showView(self, win, fn=None): 436 def _showView(self, win, fn=None):
426 """ 437 """
427 Protected method to show a view (i.e. window) 438 Protected method to show a view (i.e. window).
428 439
429 @param win editor assembly to be shown 440 @param win editor assembly to be shown
430 @param fn filename of this editor (string) 441 @param fn filename of this editor (string)
431 """ 442 """
432 editor = win.getEditor() 443 editor = win.getEditor()
473 """ 484 """
474 pass 485 pass
475 486
476 def _initWindowActions(self): 487 def _initWindowActions(self):
477 """ 488 """
478 Protected method to define the user interface actions for window handling. 489 Protected method to define the user interface actions for window
490 handling.
479 """ 491 """
480 pass 492 pass
481 493
482 def setEditorName(self, editor, newName): 494 def setEditorName(self, editor, newName):
483 """ 495 """
506 @param editor editor window changed 518 @param editor editor window changed
507 """ 519 """
508 currentRow = self.viewlist.currentRow() 520 currentRow = self.viewlist.currentRow()
509 index = self.editors.index(editor) 521 index = self.editors.index(editor)
510 if m: 522 if m:
511 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("fileModified.png")) 523 self.viewlist.item(index).setIcon(
524 UI.PixmapCache.getIcon("fileModified.png"))
512 elif editor.hasSyntaxErrors(): 525 elif editor.hasSyntaxErrors():
513 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("syntaxError.png")) 526 self.viewlist.item(index).setIcon(
527 UI.PixmapCache.getIcon("syntaxError.png"))
514 elif editor.hasFlakesWarnings(): 528 elif editor.hasFlakesWarnings():
515 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("warning.png")) 529 self.viewlist.item(index).setIcon(
530 UI.PixmapCache.getIcon("warning.png"))
516 else: 531 else:
517 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("empty.png")) 532 self.viewlist.item(index).setIcon(
533 UI.PixmapCache.getIcon("empty.png"))
518 self.viewlist.setCurrentRow(currentRow) 534 self.viewlist.setCurrentRow(currentRow)
519 self._checkActions(editor) 535 self._checkActions(editor)
520 536
521 def _syntaxErrorToggled(self, editor): 537 def _syntaxErrorToggled(self, editor):
522 """ 538 """
525 @param editor editor that sent the signal 541 @param editor editor that sent the signal
526 """ 542 """
527 currentRow = self.viewlist.currentRow() 543 currentRow = self.viewlist.currentRow()
528 index = self.editors.index(editor) 544 index = self.editors.index(editor)
529 if editor.hasSyntaxErrors(): 545 if editor.hasSyntaxErrors():
530 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("syntaxError.png")) 546 self.viewlist.item(index).setIcon(
547 UI.PixmapCache.getIcon("syntaxError.png"))
531 elif editor.hasFlakesWarnings(): 548 elif editor.hasFlakesWarnings():
532 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("warning.png")) 549 self.viewlist.item(index).setIcon(
550 UI.PixmapCache.getIcon("warning.png"))
533 elif editor.isModified(): 551 elif editor.isModified():
534 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("fileModified.png")) 552 self.viewlist.item(index).setIcon(
553 UI.PixmapCache.getIcon("fileModified.png"))
535 else: 554 else:
536 self.viewlist.item(index).setIcon(UI.PixmapCache.getIcon("empty.png")) 555 self.viewlist.item(index).setIcon(
556 UI.PixmapCache.getIcon("empty.png"))
537 self.viewlist.setCurrentRow(currentRow) 557 self.viewlist.setCurrentRow(currentRow)
538 558
539 ViewManager._syntaxErrorToggled(self, editor) 559 ViewManager._syntaxErrorToggled(self, editor)
540 560
541 def addSplit(self): 561 def addSplit(self):
551 stack.installEventFilter(self) 571 stack.installEventFilter(self)
552 if self.stackArea.orientation() == Qt.Horizontal: 572 if self.stackArea.orientation() == Qt.Horizontal:
553 size = self.stackArea.width() 573 size = self.stackArea.width()
554 else: 574 else:
555 size = self.stackArea.height() 575 size = self.stackArea.height()
556 self.stackArea.setSizes([int(size / len(self.stacks))] * len(self.stacks)) 576 self.stackArea.setSizes(
577 [int(size / len(self.stacks))] * len(self.stacks))
557 self.splitRemoveAct.setEnabled(True) 578 self.splitRemoveAct.setEnabled(True)
558 self.nextSplitAct.setEnabled(True) 579 self.nextSplitAct.setEnabled(True)
559 self.prevSplitAct.setEnabled(True) 580 self.prevSplitAct.setEnabled(True)
560 581
561 def removeSplit(self): 582 def removeSplit(self):
679 """ 700 """
680 self.saveEditorsList(self.editors) 701 self.saveEditorsList(self.editors)
681 702
682 def __contextMenuOpenRejections(self): 703 def __contextMenuOpenRejections(self):
683 """ 704 """
684 Private slot to open a rejections file associated with the selected editor. 705 Private slot to open a rejections file associated with the selected
706 editor.
685 """ 707 """
686 if self.contextMenuEditor: 708 if self.contextMenuEditor:
687 fileName = self.contextMenuEditor.getFileName() 709 fileName = self.contextMenuEditor.getFileName()
688 if fileName: 710 if fileName:
689 rej = "{0}.rej".format(fileName) 711 rej = "{0}.rej".format(fileName)
697 if self.contextMenuEditor: 719 if self.contextMenuEditor:
698 self.printEditor(self.contextMenuEditor) 720 self.printEditor(self.contextMenuEditor)
699 721
700 def __contextMenuCopyPathToClipboard(self): 722 def __contextMenuCopyPathToClipboard(self):
701 """ 723 """
702 Private method to copy the file name of the selected editor to the clipboard. 724 Private method to copy the file name of the selected editor to the
725 clipboard.
703 """ 726 """
704 if self.contextMenuEditor: 727 if self.contextMenuEditor:
705 fn = self.contextMenuEditor.getFileName() 728 fn = self.contextMenuEditor.getFileName()
706 if fn: 729 if fn:
707 cb = QApplication.clipboard() 730 cb = QApplication.clipboard()
725 fn = editor.getFileName() 748 fn = editor.getFileName()
726 if fn: 749 if fn:
727 self.changeCaption.emit(fn) 750 self.changeCaption.emit(fn)
728 if not self.__inRemoveView: 751 if not self.__inRemoveView:
729 self.editorChanged.emit(fn) 752 self.editorChanged.emit(fn)
730 self.editorLineChanged.emit(fn, editor.getCursorPosition()[0] + 1) 753 self.editorLineChanged.emit(
754 fn, editor.getCursorPosition()[0] + 1)
731 else: 755 else:
732 self.changeCaption.emit("") 756 self.changeCaption.emit("")
733 self.editorChangedEd.emit(editor) 757 self.editorChangedEd.emit(editor)
734 758
735 cindex = self.editors.index(editor) 759 cindex = self.editors.index(editor)
766 fn = aw.getFileName() 790 fn = aw.getFileName()
767 if fn: 791 if fn:
768 self.changeCaption.emit(fn) 792 self.changeCaption.emit(fn)
769 if switched: 793 if switched:
770 self.editorChanged.emit(fn) 794 self.editorChanged.emit(fn)
771 self.editorLineChanged.emit(fn, aw.getCursorPosition()[0] + 1) 795 self.editorLineChanged.emit(
796 fn, aw.getCursorPosition()[0] + 1)
772 else: 797 else:
773 self.changeCaption.emit("") 798 self.changeCaption.emit("")
774 self.editorChangedEd.emit(aw) 799 self.editorChangedEd.emit(aw)
775 800
776 return False 801 return False

eric ide

mercurial