5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog for the configuration of eric. |
7 Module implementing a dialog for the configuration of eric. |
8 """ |
8 """ |
9 |
9 |
|
10 import contextlib |
|
11 import enum |
10 import os |
12 import os |
11 import types |
13 import types |
12 import contextlib |
|
13 |
14 |
14 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QMetaObject, QRect |
15 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QMetaObject, QRect |
15 from PyQt5.QtGui import QPixmap |
16 from PyQt5.QtGui import QPixmap |
16 from PyQt5.QtWidgets import ( |
17 from PyQt5.QtWidgets import ( |
17 QSizePolicy, QSpacerItem, QWidget, QTreeWidget, QStackedWidget, QDialog, |
18 QSizePolicy, QSpacerItem, QWidget, QTreeWidget, QStackedWidget, QDialog, |
57 Public method to get the name of the associated configuration page. |
58 Public method to get the name of the associated configuration page. |
58 |
59 |
59 @return name of the configuration page (string) |
60 @return name of the configuration page (string) |
60 """ |
61 """ |
61 return self.__pageName |
62 return self.__pageName |
|
63 |
|
64 |
|
65 class ConfigurationMode(enum.Enum): |
|
66 """ |
|
67 Class defining the various modes of the configuration widget. |
|
68 """ |
|
69 DEFAULTMODE = 0 |
|
70 TRAYSTARTERMODE = 1 |
|
71 HEXEDITORMODE = 2 |
|
72 WEBBROWSERMODE = 3 |
62 |
73 |
63 |
74 |
64 class ConfigurationWidget(QWidget): |
75 class ConfigurationWidget(QWidget): |
65 """ |
76 """ |
66 Class implementing a dialog for the configuration of eric. |
77 Class implementing a dialog for the configuration of eric. |
74 preferencesChanged = pyqtSignal() |
85 preferencesChanged = pyqtSignal() |
75 masterPasswordChanged = pyqtSignal(str, str) |
86 masterPasswordChanged = pyqtSignal(str, str) |
76 accepted = pyqtSignal() |
87 accepted = pyqtSignal() |
77 rejected = pyqtSignal() |
88 rejected = pyqtSignal() |
78 |
89 |
79 # TODO: convert this to 'enum' |
90 def __init__(self, parent=None, fromEric=True, |
80 DefaultMode = 0 |
91 displayMode=ConfigurationMode.DEFAULTMODE, |
81 TrayStarterMode = 1 |
|
82 HexEditorMode = 2 |
|
83 WebBrowserMode = 3 |
|
84 |
|
85 def __init__(self, parent=None, fromEric=True, displayMode=DefaultMode, |
|
86 expandedEntries=None): |
92 expandedEntries=None): |
87 """ |
93 """ |
88 Constructor |
94 Constructor |
89 |
95 |
90 @param parent The parent widget of this dialog. (QWidget) |
96 @param parent reference to the parent widget |
|
97 @type QWidget |
91 @param fromEric flag indicating a dialog generation from within the |
98 @param fromEric flag indicating a dialog generation from within the |
92 eric ide (boolean) |
99 eric IDE |
|
100 @type bool |
93 @param displayMode mode of the configuration dialog |
101 @param displayMode mode of the configuration dialog |
94 (DefaultMode, TrayStarterMode, HexEditorMode, WebBrowserMode) |
102 @type ConfigurationMode |
95 @exception RuntimeError raised to indicate an invalid dialog mode |
|
96 @param expandedEntries list of entries to be shown expanded |
103 @param expandedEntries list of entries to be shown expanded |
97 (list of strings) |
104 @type list of str |
98 """ |
105 """ |
99 super().__init__(parent) |
106 super().__init__(parent) |
100 |
|
101 if displayMode not in ( |
|
102 ConfigurationWidget.DefaultMode, |
|
103 ConfigurationWidget.WebBrowserMode, |
|
104 ConfigurationWidget.TrayStarterMode, |
|
105 ConfigurationWidget.HexEditorMode, |
|
106 ): |
|
107 raise RuntimeError("Illegal mode value: {0}".format(displayMode)) |
|
108 |
107 |
109 self.fromEric = fromEric |
108 self.fromEric = fromEric |
110 self.displayMode = displayMode |
109 self.displayMode = displayMode |
111 self.__webEngine = getWebBrowserSupport() == "QtWebEngine" |
110 self.__webEngine = getWebBrowserSupport() == "QtWebEngine" |
112 expandedEntries = [] if expandedEntries is None else expandedEntries[:] |
111 expandedEntries = [] if expandedEntries is None else expandedEntries[:] |
129 except KeyError: |
128 except KeyError: |
130 self.virtualenvManager = VirtualenvManager(self) |
129 self.virtualenvManager = VirtualenvManager(self) |
131 e5App().registerObject("VirtualEnvManager", |
130 e5App().registerObject("VirtualEnvManager", |
132 self.virtualenvManager) |
131 self.virtualenvManager) |
133 |
132 |
134 if displayMode == ConfigurationWidget.DefaultMode: |
133 if displayMode == ConfigurationMode.DEFAULTMODE: |
135 self.configItems = { |
134 self.configItems = { |
136 # key : [display string, pixmap name, dialog module name or |
135 # key : [display string, pixmap name, dialog module name or |
137 # page creation function, parent key, |
136 # page creation function, parent key, |
138 # reference to configuration page (must always be last)] |
137 # reference to configuration page (must always be last)] |
139 # The dialog module must have the module function 'create' to |
138 # The dialog module must have the module function 'create' to |
366 }) |
365 }) |
367 |
366 |
368 self.configItems.update( |
367 self.configItems.update( |
369 e5App().getObject("PluginManager").getPluginConfigData()) |
368 e5App().getObject("PluginManager").getPluginConfigData()) |
370 |
369 |
371 elif displayMode == ConfigurationWidget.WebBrowserMode: |
370 elif displayMode == ConfigurationMode.WEBBROWSERMODE: |
372 self.configItems = { |
371 self.configItems = { |
373 # key : [display string, pixmap name, dialog module name or |
372 # key : [display string, pixmap name, dialog module name or |
374 # page creation function, parent key, |
373 # page creation function, parent key, |
375 # reference to configuration page (must always be last)] |
374 # reference to configuration page (must always be last)] |
376 # The dialog module must have the module function 'create' to |
375 # The dialog module must have the module function 'create' to |
409 [self.tr("Spell checking"), |
408 [self.tr("Spell checking"), |
410 "preferences-spellchecking", |
409 "preferences-spellchecking", |
411 "WebBrowserSpellCheckingPage", None, None], |
410 "WebBrowserSpellCheckingPage", None, None], |
412 } |
411 } |
413 |
412 |
414 elif displayMode == ConfigurationWidget.TrayStarterMode: |
413 elif displayMode == ConfigurationMode.TRAYSTARTERMODE: |
415 self.configItems = { |
414 self.configItems = { |
416 # key : [display string, pixmap name, dialog module name or |
415 # key : [display string, pixmap name, dialog module name or |
417 # page creation function, parent key, |
416 # page creation function, parent key, |
418 # reference to configuration page (must always be last)] |
417 # reference to configuration page (must always be last)] |
419 # The dialog module must have the module function 'create' to |
418 # The dialog module must have the module function 'create' to |
422 "trayStarterPage": |
421 "trayStarterPage": |
423 [self.tr("Tray Starter"), "erict", |
422 [self.tr("Tray Starter"), "erict", |
424 "TrayStarterPage", None, None], |
423 "TrayStarterPage", None, None], |
425 } |
424 } |
426 |
425 |
427 elif displayMode == ConfigurationWidget.HexEditorMode: |
426 elif displayMode == ConfigurationMode.HEXEDITORMODE: |
428 self.configItems = { |
427 self.configItems = { |
429 # key : [display string, pixmap name, dialog module name or |
428 # key : [display string, pixmap name, dialog module name or |
430 # page creation function, parent key, |
429 # page creation function, parent key, |
431 # reference to configuration page (must always be last)] |
430 # reference to configuration page (must always be last)] |
432 # The dialog module must have the module function 'create' to |
431 # The dialog module must have the module function 'create' to |
449 else: |
448 else: |
450 pitm = self.configList |
449 pitm = self.configList |
451 self.itmDict[key] = ConfigurationPageItem(pitm, pageData[0], key, |
450 self.itmDict[key] = ConfigurationPageItem(pitm, pageData[0], key, |
452 pageData[1]) |
451 pageData[1]) |
453 self.itmDict[key].setData(0, Qt.ItemDataRole.UserRole, key) |
452 self.itmDict[key].setData(0, Qt.ItemDataRole.UserRole, key) |
454 if (not self.fromEric or |
453 if ( |
455 displayMode != ConfigurationWidget.DefaultMode or |
454 not self.fromEric or |
456 key in expandedEntries): |
455 displayMode != ConfigurationMode.DEFAULTMODE or |
|
456 key in expandedEntries |
|
457 ): |
457 self.itmDict[key].setExpanded(True) |
458 self.itmDict[key].setExpanded(True) |
458 self.configList.sortByColumn(0, Qt.SortOrder.AscendingOrder) |
459 self.configList.sortByColumn(0, Qt.SortOrder.AscendingOrder) |
459 |
460 |
460 # set the initial size of the splitter |
461 # set the initial size of the splitter |
461 self.configSplitter.setSizes([200, 600]) |
462 self.configSplitter.setSizes([200, 600]) |
464 self.configList.itemActivated.connect(self.__showConfigurationPage) |
465 self.configList.itemActivated.connect(self.__showConfigurationPage) |
465 self.configList.itemClicked.connect(self.__showConfigurationPage) |
466 self.configList.itemClicked.connect(self.__showConfigurationPage) |
466 self.buttonBox.accepted.connect(self.accept) |
467 self.buttonBox.accepted.connect(self.accept) |
467 self.buttonBox.rejected.connect(self.rejected) |
468 self.buttonBox.rejected.connect(self.rejected) |
468 |
469 |
469 if displayMode in [ConfigurationWidget.TrayStarterMode, |
470 if displayMode in [ConfigurationMode.TRAYSTARTERMODE, |
470 ConfigurationWidget.HexEditorMode, |
471 ConfigurationMode.HEXEDITORMODE, |
471 ConfigurationWidget.WebBrowserMode]: |
472 ConfigurationMode.WEBBROWSERMODE]: |
472 self.configListSearch.hide() |
473 self.configListSearch.hide() |
473 |
474 |
474 if displayMode not in [ConfigurationWidget.TrayStarterMode, |
475 if displayMode not in [ConfigurationMode.TRAYSTARTERMODE, |
475 ConfigurationWidget.HexEditorMode]: |
476 ConfigurationMode.HEXEDITORMODE]: |
476 self.__initLexers() |
477 self.__initLexers() |
477 |
478 |
478 def accept(self): |
479 def accept(self): |
479 """ |
480 """ |
480 Public slot to accept the buttonBox accept signal. |
481 Public slot to accept the buttonBox accept signal. |
569 QDialogButtonBox.StandardButton.Reset |
570 QDialogButtonBox.StandardButton.Reset |
570 ) |
571 ) |
571 self.buttonBox.setObjectName("buttonBox") |
572 self.buttonBox.setObjectName("buttonBox") |
572 if ( |
573 if ( |
573 not self.fromEric and |
574 not self.fromEric and |
574 self.displayMode == ConfigurationWidget.DefaultMode |
575 self.displayMode == ConfigurationMode.DEFAULTMODE |
575 ): |
576 ): |
576 self.buttonBox.button(QDialogButtonBox.StandardButton.Apply).hide() |
577 self.buttonBox.button(QDialogButtonBox.StandardButton.Apply).hide() |
577 self.buttonBox.button( |
578 self.buttonBox.button( |
578 QDialogButtonBox.StandardButton.Apply).setEnabled(False) |
579 QDialogButtonBox.StandardButton.Apply).setEnabled(False) |
579 self.buttonBox.button( |
580 self.buttonBox.button( |
917 password has been changed with the old and the new password |
918 password has been changed with the old and the new password |
918 """ |
919 """ |
919 preferencesChanged = pyqtSignal() |
920 preferencesChanged = pyqtSignal() |
920 masterPasswordChanged = pyqtSignal(str, str) |
921 masterPasswordChanged = pyqtSignal(str, str) |
921 |
922 |
922 DefaultMode = ConfigurationWidget.DefaultMode |
|
923 TrayStarterMode = ConfigurationWidget.TrayStarterMode |
|
924 HexEditorMode = ConfigurationWidget.HexEditorMode |
|
925 WebBrowserMode = ConfigurationWidget.WebBrowserMode |
|
926 |
|
927 def __init__(self, parent=None, name=None, modal=False, |
923 def __init__(self, parent=None, name=None, modal=False, |
928 fromEric=True, displayMode=ConfigurationWidget.DefaultMode, |
924 fromEric=True, |
|
925 displayMode=ConfigurationMode.DEFAULTMODE, |
929 expandedEntries=None): |
926 expandedEntries=None): |
930 """ |
927 """ |
931 Constructor |
928 Constructor |
932 |
929 |
933 @param parent The parent widget of this dialog. (QWidget) |
930 @param parent reference to the parent widget |
934 @param name The name of this dialog. string |
931 @type QWidget |
935 @param modal Flag indicating a modal dialog. (boolean) |
932 @param name name of the dialog |
|
933 @type str |
|
934 @param modal flag indicating a modal dialog |
|
935 @type bool |
936 @param fromEric flag indicating a dialog generation from within the |
936 @param fromEric flag indicating a dialog generation from within the |
937 eric ide (boolean) |
937 eric IDE |
|
938 @type bool |
938 @param displayMode mode of the configuration dialog |
939 @param displayMode mode of the configuration dialog |
939 (DefaultMode, TrayStarterMode, HexEditorMode, WebBrowserMode) |
940 @type ConfigurationMode |
940 @param expandedEntries list of entries to be shown expanded |
941 @param expandedEntries list of entries to be shown expanded |
941 (list of strings) |
942 @type list of str |
942 """ |
943 """ |
943 super().__init__(parent) |
944 super().__init__(parent) |
944 if name: |
945 if name: |
945 self.setObjectName(name) |
946 self.setObjectName(name) |
946 self.setModal(modal) |
947 self.setModal(modal) |