| 1 | import re |
|---|
| 2 | from PyQt4.QtCore import * |
|---|
| 3 | from PyQt4.QtGui import * |
|---|
| 4 | import PyQt4.QtCore as QtCore |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | import os |
|---|
| 8 | from PyQt4.QtCore import * |
|---|
| 9 | from PyQt4.QtGui import * |
|---|
| 10 | |
|---|
| 11 | from Messaging import stdMsg, dbgMsg, errMsg, setDebugging |
|---|
| 12 | |
|---|
| 13 | MAC = "qt_mac_set_native_menubar" in dir() |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | class CycleTabsPopup(QLabel): |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | def __init__(self, parent=None): |
|---|
| 31 | super(CycleTabsPopup, self).__init__(parent) |
|---|
| 32 | self.editorWindow=parent |
|---|
| 33 | self.setText("THIS IS CYCLE WINDOWS TAB") |
|---|
| 34 | |
|---|
| 35 | self.setWindowFlags(Qt.Popup|Qt.FramelessWindowHint) |
|---|
| 36 | |
|---|
| 37 | palette=self.palette() |
|---|
| 38 | palette.setColor(self.backgroundRole(),QColor('#F5F6CE')) |
|---|
| 39 | self.setPalette(palette) |
|---|
| 40 | font=self.font() |
|---|
| 41 | font.setPointSize(9) |
|---|
| 42 | self.setFont(font) |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | self.setTextFormat(Qt.RichText) |
|---|
| 46 | |
|---|
| 47 | self.ctrlTabShortcut=QShortcut(QKeySequence("Ctrl+Tab") ,self) |
|---|
| 48 | self.connect( self.ctrlTabShortcut, SIGNAL("activated()"), self.cycleTabs ) |
|---|
| 49 | self.highlightedItem='' |
|---|
| 50 | self.openFileNames=None |
|---|
| 51 | self.cycleTabFilesList=None |
|---|
| 52 | |
|---|
| 53 | dbgMsg("self.editorWindow.pos()=",str(self.editorWindow.pos())+"\n\n\n\n") |
|---|
| 54 | |
|---|
| 55 | def initializeContent(self,_cycleTabFilesList): |
|---|
| 56 | labelContent='' |
|---|
| 57 | i=0 |
|---|
| 58 | self.cycleTabFilesList=_cycleTabFilesList |
|---|
| 59 | self.openFileNames=_cycleTabFilesList.tabList |
|---|
| 60 | |
|---|
| 61 | if len(self.openFileNames)==1: |
|---|
| 62 | labelContent+="<b>"+self.openFileNames[0][0]+"</b><br>" |
|---|
| 63 | self.highlightedItem=self.openFileNames[0] |
|---|
| 64 | self.setText(labelContent) |
|---|
| 65 | return |
|---|
| 66 | |
|---|
| 67 | for fileName in self.openFileNames: |
|---|
| 68 | |
|---|
| 69 | if i == 1: |
|---|
| 70 | |
|---|
| 71 | labelContent+="<b>"+fileName[0]+"</b><br>" |
|---|
| 72 | self.highlightedItem=fileName |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | else: |
|---|
| 76 | labelContent+=fileName[0]+"<br>" |
|---|
| 77 | |
|---|
| 78 | i+=1 |
|---|
| 79 | |
|---|
| 80 | self.setText(labelContent) |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | def cycleTabs(self): |
|---|
| 85 | dbgMsg("QLabel cycleTabs") |
|---|
| 86 | |
|---|
| 87 | highlightTextFlag=False |
|---|
| 88 | if self.highlightedItem==self.openFileNames[-1]: |
|---|
| 89 | highlightTextFlag=True |
|---|
| 90 | highlightingChanged=False |
|---|
| 91 | |
|---|
| 92 | if self.openFileNames: |
|---|
| 93 | labelContent='' |
|---|
| 94 | for fileName in self.openFileNames: |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | if highlightTextFlag: |
|---|
| 98 | dbgMsg("GOT HIGHLIGHT TEXT FLAG") |
|---|
| 99 | labelContent+="<b>"+fileName[0]+"</b><br>" |
|---|
| 100 | highlightTextFlag=False |
|---|
| 101 | self.highlightedItem=fileName |
|---|
| 102 | highlightingChanged=True |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | else: |
|---|
| 106 | labelContent+=fileName[0]+"<br>" |
|---|
| 107 | |
|---|
| 108 | if self.highlightedItem[0]==fileName[0] and not highlightingChanged: |
|---|
| 109 | highlightTextFlag=True |
|---|
| 110 | |
|---|
| 111 | self.setText(labelContent) |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | def keyPressEvent(self, event): |
|---|
| 115 | if event.key()==Qt.Key_Control: |
|---|
| 116 | dbgMsg("CTRL key pressed") |
|---|
| 117 | self.ctrlPressed=True |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | self.ctrlPressed=True |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | def keyReleaseEvent(self, event): |
|---|
| 124 | if event.key()==Qt.Key_Control: |
|---|
| 125 | dbgMsg("CTRL RELEASED in QTextEdit") |
|---|
| 126 | self.ctrlPressed=False |
|---|
| 127 | self.close() |
|---|
| 128 | |
|---|
| 129 | self.cycleTabFilesList.makeItemCurrent(self.highlightedItem) |
|---|
| 130 | self.openFileNames=None |
|---|
| 131 | self.cycleTabFilesList=None |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | class CycleTabFileList: |
|---|
| 140 | |
|---|
| 141 | def __init__(self,_editorWindow): |
|---|
| 142 | self.editorWindow=_editorWindow |
|---|
| 143 | self.tabList=[] |
|---|
| 144 | self.tabDict={} |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | def initializeTabFileList(self): |
|---|
| 148 | |
|---|
| 149 | if not len(self.tabList): |
|---|
| 150 | dbgMsg("INITIALIZE FILE TAB LIST\n\n\n\n") |
|---|
| 151 | openFileDict={} |
|---|
| 152 | for i in range(self.editorWindow.editTab.count()): |
|---|
| 153 | editor=self.editorWindow.editTab.widget(i) |
|---|
| 154 | if editor==self.editorWindow.editTab.currentWidget(): |
|---|
| 155 | if self.editorWindow.getEditorFileName(editor)!="": |
|---|
| 156 | self.tabList.insert(0,[self.editorWindow.getEditorFileName(editor),editor]) |
|---|
| 157 | else: |
|---|
| 158 | documentName=self.editorWindow.editTab.tabText(self.editorWindow.editTab.indexOf(editor)) |
|---|
| 159 | self.tabList.insert(0,[documentName,editor]) |
|---|
| 160 | self.tabDict[editor]=self.tabList[0][0] |
|---|
| 161 | else: |
|---|
| 162 | if self.editorWindow.getEditorFileName(editor)!="": |
|---|
| 163 | self.tabList.append([self.editorWindow.getEditorFileName(editor),editor]) |
|---|
| 164 | else: |
|---|
| 165 | documentName=self.editorWindow.editTab.tabText(self.editorWindow.editTab.indexOf(editor)) |
|---|
| 166 | self.tabList.append([documentName,editor]) |
|---|
| 167 | |
|---|
| 168 | self.tabDict[editor]=self.tabList[-1][0] |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | else: |
|---|
| 174 | self.refresh() |
|---|
| 175 | |
|---|
| 176 | def refresh(self): |
|---|
| 177 | dbgMsg("REFRESH FILE TAB LIST\n\n\n\n") |
|---|
| 178 | for i in range(self.editorWindow.editTab.count()): |
|---|
| 179 | editor=self.editorWindow.editTab.widget(i) |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | try: |
|---|
| 183 | self.tabDict[editor] |
|---|
| 184 | |
|---|
| 185 | documentName=self.editorWindow.getEditorFileName(editor) |
|---|
| 186 | if documentName=="": |
|---|
| 187 | documentName=self.editorWindow.editTab.tabText(self.editorWindow.editTab.indexOf(editor)) |
|---|
| 188 | if documentName!=self.tabDict[editor]: |
|---|
| 189 | dbgMsg("fileName has changed in the open tab") |
|---|
| 190 | |
|---|
| 191 | for i in range(len(self.tabList)): |
|---|
| 192 | if self.tabList[i][1]==editor: |
|---|
| 193 | self.tabList[i][0]=documentName |
|---|
| 194 | self.tabDict[editor]=self.tabList[i][0] |
|---|
| 195 | break |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | except KeyError,e: |
|---|
| 199 | |
|---|
| 200 | dbgMsg("# found new editor window") |
|---|
| 201 | if self.editorWindow.getEditorFileName(editor)!="": |
|---|
| 202 | self.insertNewItem([self.editorWindow.getEditorFileName(editor),editor]) |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | else: |
|---|
| 206 | documentName=self.editorWindow.editTab.tabText(self.editorWindow.editTab.indexOf(editor)) |
|---|
| 207 | self.insertNewItem([documentName,editor]) |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | editorItemsToBeDeleted=[] |
|---|
| 213 | for editor in self.tabDict.keys(): |
|---|
| 214 | if not self.editorWindow.checkIfEditorExists(editor): |
|---|
| 215 | |
|---|
| 216 | editorItemsToBeDeleted.append(editor) |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | for editorItem in editorItemsToBeDeleted: |
|---|
| 225 | del self.tabDict[editor] |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | for i in range(len(self.tabList)): |
|---|
| 229 | if self.tabList[i][1]==editor: |
|---|
| 230 | del self.tabList[i] |
|---|
| 231 | break |
|---|
| 232 | |
|---|
| 233 | currentEditor=self.editorWindow.editTab.currentWidget() |
|---|
| 234 | currentItem=[self.tabDict[currentEditor],currentEditor] |
|---|
| 235 | self.makeItemCurrent(currentItem) |
|---|
| 236 | |
|---|
| 237 | def insertNewItem(self,_item): |
|---|
| 238 | if(len(self.tabList)>=1): |
|---|
| 239 | self.tabList.insert(1,_item) |
|---|
| 240 | self.tabDict[_item[1]]=_item[0] |
|---|
| 241 | |
|---|
| 242 | def makeItemCurrent(self,_item): |
|---|
| 243 | self.editorWindow.editTab.setCurrentWidget(_item[1]) |
|---|
| 244 | |
|---|
| 245 | index=0 |
|---|
| 246 | for i in range(len(self.tabList)): |
|---|
| 247 | if self.tabList[i]==_item: |
|---|
| 248 | index=i |
|---|
| 249 | break |
|---|
| 250 | |
|---|
| 251 | del self.tabList[index] |
|---|
| 252 | self.tabList.insert(0,_item) |
|---|