9 |
9 |
10 import sys |
10 import sys |
11 import os |
11 import os |
12 |
12 |
13 from PyQt4.QtCore import QProcess, QSettings, QFileInfo |
13 from PyQt4.QtCore import QProcess, QSettings, QFileInfo |
14 from PyQt4.QtGui import QSystemTrayIcon, QMenu, qApp, QCursor, QApplication, QDialog |
14 from PyQt4.QtGui import QSystemTrayIcon, QMenu, qApp, QCursor, \ |
|
15 QApplication, QDialog |
15 |
16 |
16 from E5Gui import E5MessageBox |
17 from E5Gui import E5MessageBox |
17 |
18 |
18 import Globals |
19 import Globals |
19 import UI.PixmapCache |
20 import UI.PixmapCache |
51 |
53 |
52 self.activated.connect(self.__activated) |
54 self.activated.connect(self.__activated) |
53 |
55 |
54 self.__menu = QMenu(self.trUtf8("Eric5 tray starter")) |
56 self.__menu = QMenu(self.trUtf8("Eric5 tray starter")) |
55 |
57 |
56 self.recentProjectsMenu = QMenu(self.trUtf8('Recent Projects'), self.__menu) |
58 self.recentProjectsMenu = QMenu( |
57 self.recentProjectsMenu.aboutToShow.connect(self.__showRecentProjectsMenu) |
59 self.trUtf8('Recent Projects'), self.__menu) |
|
60 self.recentProjectsMenu.aboutToShow.connect( |
|
61 self.__showRecentProjectsMenu) |
58 self.recentProjectsMenu.triggered.connect(self.__openRecent) |
62 self.recentProjectsMenu.triggered.connect(self.__openRecent) |
59 |
63 |
60 self.recentMultiProjectsMenu = \ |
64 self.recentMultiProjectsMenu = \ |
61 QMenu(self.trUtf8('Recent Multiprojects'), self.__menu) |
65 QMenu(self.trUtf8('Recent Multiprojects'), self.__menu) |
62 self.recentMultiProjectsMenu.aboutToShow.connect( |
66 self.recentMultiProjectsMenu.aboutToShow.connect( |
72 font = act.font() |
76 font = act.font() |
73 font.setBold(True) |
77 font.setBold(True) |
74 act.setFont(font) |
78 act.setFont(font) |
75 self.__menu.addSeparator() |
79 self.__menu.addSeparator() |
76 |
80 |
77 self.__menu.addAction(self.trUtf8("QRegExp editor"), self.__startQRegExp) |
81 self.__menu.addAction( |
78 self.__menu.addAction(self.trUtf8("Python re editor"), self.__startPyRe) |
82 self.trUtf8("QRegExp editor"), self.__startQRegExp) |
|
83 self.__menu.addAction( |
|
84 self.trUtf8("Python re editor"), self.__startPyRe) |
79 self.__menu.addSeparator() |
85 self.__menu.addSeparator() |
80 |
86 |
81 self.__menu.addAction(UI.PixmapCache.getIcon("uiPreviewer.png"), |
87 self.__menu.addAction(UI.PixmapCache.getIcon("uiPreviewer.png"), |
82 self.trUtf8("UI Previewer"), self.__startUIPreviewer) |
88 self.trUtf8("UI Previewer"), self.__startUIPreviewer) |
83 self.__menu.addAction(UI.PixmapCache.getIcon("trPreviewer.png"), |
89 self.__menu.addAction(UI.PixmapCache.getIcon("trPreviewer.png"), |
128 self.menuRecentFilesAct = self.__menu.addMenu(self.recentFilesMenu) |
134 self.menuRecentFilesAct = self.__menu.addMenu(self.recentFilesMenu) |
129 # recent multi projects |
135 # recent multi projects |
130 self.menuRecentMultiProjectsAct = \ |
136 self.menuRecentMultiProjectsAct = \ |
131 self.__menu.addMenu(self.recentMultiProjectsMenu) |
137 self.__menu.addMenu(self.recentMultiProjectsMenu) |
132 # recent projects |
138 # recent projects |
133 self.menuRecentProjectsAct = self.__menu.addMenu(self.recentProjectsMenu) |
139 self.menuRecentProjectsAct = self.__menu.addMenu( |
|
140 self.recentProjectsMenu) |
134 self.__menu.addSeparator() |
141 self.__menu.addSeparator() |
135 |
142 |
136 self.__menu.addAction(UI.PixmapCache.getIcon("exit.png"), |
143 self.__menu.addAction(UI.PixmapCache.getIcon("exit.png"), |
137 self.trUtf8('Quit'), qApp.quit) |
144 self.trUtf8('Quit'), qApp.quit) |
138 |
145 |
168 |
175 |
169 def __activated(self, reason): |
176 def __activated(self, reason): |
170 """ |
177 """ |
171 Private slot to handle the activated signal. |
178 Private slot to handle the activated signal. |
172 |
179 |
173 @param reason reason code of the signal (QSystemTrayIcon.ActivationReason) |
180 @param reason reason code of the signal |
|
181 (QSystemTrayIcon.ActivationReason) |
174 """ |
182 """ |
175 if reason == QSystemTrayIcon.Context or \ |
183 if reason == QSystemTrayIcon.Context or \ |
176 reason == QSystemTrayIcon.MiddleClick: |
184 reason == QSystemTrayIcon.MiddleClick: |
177 self.__showContextMenu() |
185 self.__showContextMenu() |
178 elif reason == QSystemTrayIcon.DoubleClick: |
186 elif reason == QSystemTrayIcon.DoubleClick: |
181 def __showContextMenu(self): |
189 def __showContextMenu(self): |
182 """ |
190 """ |
183 Private slot to show the context menu. |
191 Private slot to show the context menu. |
184 """ |
192 """ |
185 self.menuRecentProjectsAct.setEnabled(len(self.recentProjects) > 0) |
193 self.menuRecentProjectsAct.setEnabled(len(self.recentProjects) > 0) |
186 self.menuRecentMultiProjectsAct.setEnabled(len(self.recentMultiProjects) > 0) |
194 self.menuRecentMultiProjectsAct.setEnabled( |
|
195 len(self.recentMultiProjects) > 0) |
187 self.menuRecentFilesAct.setEnabled(len(self.recentFiles) > 0) |
196 self.menuRecentFilesAct.setEnabled(len(self.recentFiles) > 0) |
188 |
197 |
189 pos = QCursor.pos() |
198 pos = QCursor.pos() |
190 x = pos.x() - self.__menu.sizeHint().width() |
199 x = pos.x() - self.__menu.sizeHint().width() |
191 pos.setX(x > 0 and x or 0) |
200 pos.setX(x > 0 and x or 0) |
206 args = [] |
215 args = [] |
207 args.append(applPath) |
216 args.append(applPath) |
208 for arg in applArgs: |
217 for arg in applArgs: |
209 args.append(arg) |
218 args.append(arg) |
210 |
219 |
211 if not os.path.isfile(applPath) or not proc.startDetached(sys.executable, args): |
220 if not os.path.isfile(applPath) or \ |
|
221 not proc.startDetached(sys.executable, args): |
212 E5MessageBox.critical(self, |
222 E5MessageBox.critical(self, |
213 self.trUtf8('Process Generation Error'), |
223 self.trUtf8('Process Generation Error'), |
214 self.trUtf8( |
224 self.trUtf8( |
215 '<p>Could not start the process.<br>' |
225 '<p>Could not start the process.<br>' |
216 'Ensure that it is available as <b>{0}</b>.</p>' |
226 'Ensure that it is available as <b>{0}</b>.</p>' |
402 act.setData(rf) |
412 act.setData(rf) |
403 idx += 1 |
413 idx += 1 |
404 |
414 |
405 def __openRecent(self, act): |
415 def __openRecent(self, act): |
406 """ |
416 """ |
407 Private method to open a project or file from the list of rencently opened |
417 Private method to open a project or file from the list of recently |
408 projects or files. |
418 opened projects or files. |
409 |
419 |
410 @param act reference to the action that triggered (QAction) |
420 @param act reference to the action that triggered (QAction) |
411 """ |
421 """ |
412 filename = act.data() |
422 filename = act.data() |
413 if filename: |
423 if filename: |
416 def __showPreferences(self): |
426 def __showPreferences(self): |
417 """ |
427 """ |
418 Private slot to set the preferences. |
428 Private slot to set the preferences. |
419 """ |
429 """ |
420 from Preferences.ConfigurationDialog import ConfigurationDialog |
430 from Preferences.ConfigurationDialog import ConfigurationDialog |
421 dlg = ConfigurationDialog(None, 'Configuration', True, |
431 dlg = ConfigurationDialog( |
422 fromEric=True, |
432 None, 'Configuration', True, fromEric=True, |
423 displayMode=ConfigurationDialog.TrayStarterMode) |
433 displayMode=ConfigurationDialog.TrayStarterMode) |
424 dlg.preferencesChanged.connect(self.preferencesChanged) |
434 dlg.preferencesChanged.connect(self.preferencesChanged) |
425 dlg.show() |
435 dlg.show() |
426 dlg.showConfigurationPageByName("trayStarterPage") |
436 dlg.showConfigurationPageByName("trayStarterPage") |
427 dlg.exec_() |
437 dlg.exec_() |
428 QApplication.processEvents() |
438 QApplication.processEvents() |