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