20 from PyQt6.QtCore import ( |
20 from PyQt6.QtCore import ( |
21 pyqtSlot, QTimer, QFile, QFileInfo, pyqtSignal, PYQT_VERSION_STR, QDate, |
21 pyqtSlot, QTimer, QFile, QFileInfo, pyqtSignal, PYQT_VERSION_STR, QDate, |
22 QIODevice, qVersion, QProcess, QSize, QUrl, QObject, Qt, QUuid, QThread, |
22 QIODevice, qVersion, QProcess, QSize, QUrl, QObject, Qt, QUuid, QThread, |
23 QUrlQuery |
23 QUrlQuery |
24 ) |
24 ) |
25 from PyQt6.QtGui import QAction, QKeySequence, QDesktopServices |
25 from PyQt6.QtGui import ( |
|
26 QAction, QKeySequence, QDesktopServices, QSessionManager |
|
27 ) |
26 from PyQt6.QtWidgets import ( |
28 from PyQt6.QtWidgets import ( |
27 QSizePolicy, QWidget, QWhatsThis, QToolBar, QDialog, QSplitter, |
29 QSizePolicy, QWidget, QWhatsThis, QToolBar, QDialog, QSplitter, |
28 QApplication, QMenu, QVBoxLayout, QDockWidget, QLabel |
30 QApplication, QMenu, QVBoxLayout, QDockWidget, QLabel |
29 ) |
31 ) |
30 from PyQt6.Qsci import QSCINTILLA_VERSION_STR |
32 from PyQt6.Qsci import QSCINTILLA_VERSION_STR |
130 """ |
132 """ |
131 self.buffer += str(s) |
133 self.buffer += str(s) |
132 self.__nWrite(self.__bufferedWrite()) |
134 self.__nWrite(self.__bufferedWrite()) |
133 |
135 |
134 |
136 |
135 # TODO: add support for QSessionManager to save changed files |
|
136 class UserInterface(EricMainWindow): |
137 class UserInterface(EricMainWindow): |
137 """ |
138 """ |
138 Class implementing the main user interface. |
139 Class implementing the main user interface. |
139 |
140 |
140 @signal appendStderr(str) emitted to write data to stderr logger |
141 @signal appendStderr(str) emitted to write data to stderr logger |
747 |
748 |
748 # set the keyboard input interval |
749 # set the keyboard input interval |
749 interval = Preferences.getUI("KeyboardInputInterval") |
750 interval = Preferences.getUI("KeyboardInputInterval") |
750 if interval > 0: |
751 if interval > 0: |
751 QApplication.setKeyboardInputInterval(interval) |
752 QApplication.setKeyboardInputInterval(interval) |
|
753 |
|
754 # connect to the desktop environment session manager |
|
755 app.commitDataRequest.connect(self.__commitData, |
|
756 Qt.ConnectionType.DirectConnection) |
|
757 app.saveStateRequest.connect(self.__saveState) |
752 |
758 |
753 def networkAccessManager(self): |
759 def networkAccessManager(self): |
754 """ |
760 """ |
755 Public method to get a reference to the network access manager object. |
761 Public method to get a reference to the network access manager object. |
756 |
762 |
7485 """ |
7491 """ |
7486 Private slot handling the automatic connection of the IRC client. |
7492 Private slot handling the automatic connection of the IRC client. |
7487 """ |
7493 """ |
7488 self.__activateIRC() |
7494 self.__activateIRC() |
7489 |
7495 |
7490 ############################################### |
7496 ############################################## |
7491 ## Support for Code Documentation Viewer below |
7497 ## Support for Code Documentation Viewer below |
7492 ############################################### |
7498 ############################################## |
7493 |
7499 |
7494 def documentationViewer(self): |
7500 def documentationViewer(self): |
7495 """ |
7501 """ |
7496 Public method to provide a reference to the code documentation viewer. |
7502 Public method to provide a reference to the code documentation viewer. |
7497 |
7503 |
7498 @return reference to the code documentation viewer |
7504 @return reference to the code documentation viewer |
7499 @rtype CodeDocumentationViewer |
7505 @rtype CodeDocumentationViewer |
7500 """ |
7506 """ |
7501 return self.codeDocumentationViewer |
7507 return self.codeDocumentationViewer |
|
7508 |
|
7509 ############################################### |
|
7510 ## Support for Desktop session management below |
|
7511 ############################################### |
|
7512 |
|
7513 def __commitData(self, manager: QSessionManager): |
|
7514 """ |
|
7515 Private slot to commit unsaved data when instructed by the desktop |
|
7516 session manager. |
|
7517 |
|
7518 @param manager reference to the desktop session manager |
|
7519 @type QSessionManager |
|
7520 """ |
|
7521 if self.viewmanager.hasDirtyEditor(): |
|
7522 if manager.allowsInteraction(): |
|
7523 res = EricMessageBox.warning( |
|
7524 self, |
|
7525 self.tr("Unsaved Data Detected"), |
|
7526 self.tr("Some editors contain unsaved data. Shall these" |
|
7527 " be saved?"), |
|
7528 EricMessageBox.Abort | |
|
7529 EricMessageBox.Discard | |
|
7530 EricMessageBox.Save | |
|
7531 EricMessageBox.SaveAll, |
|
7532 EricMessageBox.SaveAll) |
|
7533 if res == EricMessageBox.SaveAll: |
|
7534 manager.release() |
|
7535 self.viewmanager.saveAllEditors() |
|
7536 elif res == EricMessageBox.Save: |
|
7537 manager.release() |
|
7538 ok = self.viewmanager.checkAllDirty() |
|
7539 if not ok: |
|
7540 manager.cancel() |
|
7541 elif res == EricMessageBox.Discard: |
|
7542 # nothing to do |
|
7543 pass |
|
7544 else: |
|
7545 # default action is to abort shutdown |
|
7546 manager.cancel() |
|
7547 else: |
|
7548 # We did not get permission to interact, play it safe and |
|
7549 # save all data. |
|
7550 self.viewmanager.saveAllEditors() |
|
7551 |
|
7552 def __saveState(self, manager: QSessionManager): |
|
7553 """ |
|
7554 Private slot to save the state when instructed by the desktop session |
|
7555 manager. |
|
7556 |
|
7557 @param manager reference to the desktop session manager |
|
7558 @type QSessionManager |
|
7559 """ |
|
7560 # TODO: implement saving the state |
|
7561 print("__saveState() call by session manager") |