eric6/Preferences/ConfigurationDialog.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8265
0090cfa83159
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
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 14
13 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QMetaObject, QRect 15 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QMetaObject, QRect
14 from PyQt5.QtGui import QPixmap 16 from PyQt5.QtGui import QPixmap
44 QTreeWidgetItem) 46 QTreeWidgetItem)
45 @param text text to be displayed (string) 47 @param text text to be displayed (string)
46 @param pageName name of the configuration page (string) 48 @param pageName name of the configuration page (string)
47 @param iconFile file name of the icon to be shown (string) 49 @param iconFile file name of the icon to be shown (string)
48 """ 50 """
49 super(ConfigurationPageItem, self).__init__(parent, [text]) 51 super().__init__(parent, [text])
50 self.setIcon(0, UI.PixmapCache.getIcon(iconFile)) 52 self.setIcon(0, UI.PixmapCache.getIcon(iconFile))
51 53
52 self.__pageName = pageName 54 self.__pageName = pageName
53 55
54 def getPageName(self): 56 def getPageName(self):
56 Public method to get the name of the associated configuration page. 58 Public method to get the name of the associated configuration page.
57 59
58 @return name of the configuration page (string) 60 @return name of the configuration page (string)
59 """ 61 """
60 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
61 73
62 74
63 class ConfigurationWidget(QWidget): 75 class ConfigurationWidget(QWidget):
64 """ 76 """
65 Class implementing a dialog for the configuration of eric. 77 Class implementing a dialog for the configuration of eric.
73 preferencesChanged = pyqtSignal() 85 preferencesChanged = pyqtSignal()
74 masterPasswordChanged = pyqtSignal(str, str) 86 masterPasswordChanged = pyqtSignal(str, str)
75 accepted = pyqtSignal() 87 accepted = pyqtSignal()
76 rejected = pyqtSignal() 88 rejected = pyqtSignal()
77 89
78 DefaultMode = 0 90 def __init__(self, parent=None, fromEric=True,
79 HelpBrowserMode = 1 91 displayMode=ConfigurationMode.DEFAULTMODE,
80 TrayStarterMode = 2
81 HexEditorMode = 3
82 WebBrowserMode = 4
83
84 def __init__(self, parent=None, fromEric=True, displayMode=DefaultMode,
85 expandedEntries=None): 92 expandedEntries=None):
86 """ 93 """
87 Constructor 94 Constructor
88 95
89 @param parent The parent widget of this dialog. (QWidget) 96 @param parent reference to the parent widget
97 @type QWidget
90 @param fromEric flag indicating a dialog generation from within the 98 @param fromEric flag indicating a dialog generation from within the
91 eric ide (boolean) 99 eric IDE
100 @type bool
92 @param displayMode mode of the configuration dialog 101 @param displayMode mode of the configuration dialog
93 (DefaultMode, HelpBrowserMode, TrayStarterMode, HexEditorMode, 102 @type ConfigurationMode
94 WebBrowserMode)
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(ConfigurationWidget, self).__init__(parent) 106 super().__init__(parent)
107
100 self.fromEric = fromEric 108 self.fromEric = fromEric
101 self.displayMode = displayMode 109 self.displayMode = displayMode
102 self.__webEngine = getWebBrowserSupport() == "QtWebEngine" 110 self.__webEngine = getWebBrowserSupport() == "QtWebEngine"
103 expandedEntries = [] if expandedEntries is None else expandedEntries[:] 111 expandedEntries = [] if expandedEntries is None else expandedEntries[:]
104 112
120 except KeyError: 128 except KeyError:
121 self.virtualenvManager = VirtualenvManager(self) 129 self.virtualenvManager = VirtualenvManager(self)
122 e5App().registerObject("VirtualEnvManager", 130 e5App().registerObject("VirtualEnvManager",
123 self.virtualenvManager) 131 self.virtualenvManager)
124 132
125 if displayMode == ConfigurationWidget.DefaultMode: 133 if displayMode == ConfigurationMode.DEFAULTMODE:
126 self.configItems = { 134 self.configItems = {
127 # key : [display string, pixmap name, dialog module name or 135 # key : [display string, pixmap name, dialog module name or
128 # page creation function, parent key, 136 # page creation function, parent key,
129 # reference to configuration page (must always be last)] 137 # reference to configuration page (must always be last)]
130 # The dialog module must have the module function 'create' to 138 # The dialog module must have the module function 'create' to
357 }) 365 })
358 366
359 self.configItems.update( 367 self.configItems.update(
360 e5App().getObject("PluginManager").getPluginConfigData()) 368 e5App().getObject("PluginManager").getPluginConfigData())
361 369
362 elif displayMode == ConfigurationWidget.WebBrowserMode: 370 elif displayMode == ConfigurationMode.WEBBROWSERMODE:
363 self.configItems = { 371 self.configItems = {
364 # key : [display string, pixmap name, dialog module name or 372 # key : [display string, pixmap name, dialog module name or
365 # page creation function, parent key, 373 # page creation function, parent key,
366 # reference to configuration page (must always be last)] 374 # reference to configuration page (must always be last)]
367 # The dialog module must have the module function 'create' to 375 # The dialog module must have the module function 'create' to
400 [self.tr("Spell checking"), 408 [self.tr("Spell checking"),
401 "preferences-spellchecking", 409 "preferences-spellchecking",
402 "WebBrowserSpellCheckingPage", None, None], 410 "WebBrowserSpellCheckingPage", None, None],
403 } 411 }
404 412
405 elif displayMode == ConfigurationWidget.TrayStarterMode: 413 elif displayMode == ConfigurationMode.TRAYSTARTERMODE:
406 self.configItems = { 414 self.configItems = {
407 # key : [display string, pixmap name, dialog module name or 415 # key : [display string, pixmap name, dialog module name or
408 # page creation function, parent key, 416 # page creation function, parent key,
409 # reference to configuration page (must always be last)] 417 # reference to configuration page (must always be last)]
410 # The dialog module must have the module function 'create' to 418 # The dialog module must have the module function 'create' to
413 "trayStarterPage": 421 "trayStarterPage":
414 [self.tr("Tray Starter"), "erict", 422 [self.tr("Tray Starter"), "erict",
415 "TrayStarterPage", None, None], 423 "TrayStarterPage", None, None],
416 } 424 }
417 425
418 elif displayMode == ConfigurationWidget.HexEditorMode: 426 elif displayMode == ConfigurationMode.HEXEDITORMODE:
419 self.configItems = { 427 self.configItems = {
420 # key : [display string, pixmap name, dialog module name or 428 # key : [display string, pixmap name, dialog module name or
421 # page creation function, parent key, 429 # page creation function, parent key,
422 # reference to configuration page (must always be last)] 430 # reference to configuration page (must always be last)]
423 # The dialog module must have the module function 'create' to 431 # The dialog module must have the module function 'create' to
425 # 'save' to save the settings. 433 # 'save' to save the settings.
426 "hexEditorPage": 434 "hexEditorPage":
427 [self.tr("Hex Editor"), "hexEditor", 435 [self.tr("Hex Editor"), "hexEditor",
428 "HexEditorPage", None, None], 436 "HexEditorPage", None, None],
429 } 437 }
430
431 else:
432 raise RuntimeError("Illegal mode value: {0}".format(displayMode))
433 438
434 # generate the list entries 439 # generate the list entries
435 self.__expandedEntries = [] 440 self.__expandedEntries = []
436 for key in sorted(self.configItems.keys()): 441 for key in sorted(self.configItems.keys()):
437 pageData = self.configItems[key] 442 pageData = self.configItems[key]
443 else: 448 else:
444 pitm = self.configList 449 pitm = self.configList
445 self.itmDict[key] = ConfigurationPageItem(pitm, pageData[0], key, 450 self.itmDict[key] = ConfigurationPageItem(pitm, pageData[0], key,
446 pageData[1]) 451 pageData[1])
447 self.itmDict[key].setData(0, Qt.ItemDataRole.UserRole, key) 452 self.itmDict[key].setData(0, Qt.ItemDataRole.UserRole, key)
448 if (not self.fromEric or 453 if (
449 displayMode != ConfigurationWidget.DefaultMode or 454 not self.fromEric or
450 key in expandedEntries): 455 displayMode != ConfigurationMode.DEFAULTMODE or
456 key in expandedEntries
457 ):
451 self.itmDict[key].setExpanded(True) 458 self.itmDict[key].setExpanded(True)
452 self.configList.sortByColumn(0, Qt.SortOrder.AscendingOrder) 459 self.configList.sortByColumn(0, Qt.SortOrder.AscendingOrder)
453 460
454 # set the initial size of the splitter 461 # set the initial size of the splitter
455 self.configSplitter.setSizes([200, 600]) 462 self.configSplitter.setSizes([200, 600])
458 self.configList.itemActivated.connect(self.__showConfigurationPage) 465 self.configList.itemActivated.connect(self.__showConfigurationPage)
459 self.configList.itemClicked.connect(self.__showConfigurationPage) 466 self.configList.itemClicked.connect(self.__showConfigurationPage)
460 self.buttonBox.accepted.connect(self.accept) 467 self.buttonBox.accepted.connect(self.accept)
461 self.buttonBox.rejected.connect(self.rejected) 468 self.buttonBox.rejected.connect(self.rejected)
462 469
463 if displayMode in [ConfigurationWidget.HelpBrowserMode, 470 if displayMode in [ConfigurationMode.TRAYSTARTERMODE,
464 ConfigurationWidget.TrayStarterMode, 471 ConfigurationMode.HEXEDITORMODE,
465 ConfigurationWidget.HexEditorMode, 472 ConfigurationMode.WEBBROWSERMODE]:
466 ConfigurationWidget.WebBrowserMode]:
467 self.configListSearch.hide() 473 self.configListSearch.hide()
468 474
469 if displayMode not in [ConfigurationWidget.TrayStarterMode, 475 if displayMode not in [ConfigurationMode.TRAYSTARTERMODE,
470 ConfigurationWidget.HexEditorMode]: 476 ConfigurationMode.HEXEDITORMODE]:
471 self.__initLexers() 477 self.__initLexers()
472 478
473 def accept(self): 479 def accept(self):
474 """ 480 """
475 Public slot to accept the buttonBox accept signal. 481 Public slot to accept the buttonBox accept signal.
564 QDialogButtonBox.StandardButton.Reset 570 QDialogButtonBox.StandardButton.Reset
565 ) 571 )
566 self.buttonBox.setObjectName("buttonBox") 572 self.buttonBox.setObjectName("buttonBox")
567 if ( 573 if (
568 not self.fromEric and 574 not self.fromEric and
569 self.displayMode == ConfigurationWidget.DefaultMode 575 self.displayMode == ConfigurationMode.DEFAULTMODE
570 ): 576 ):
571 self.buttonBox.button(QDialogButtonBox.StandardButton.Apply).hide() 577 self.buttonBox.button(QDialogButtonBox.StandardButton.Apply).hide()
572 self.buttonBox.button( 578 self.buttonBox.button(
573 QDialogButtonBox.StandardButton.Apply).setEnabled(False) 579 QDialogButtonBox.StandardButton.Apply).setEnabled(False)
574 self.buttonBox.button( 580 self.buttonBox.button(
610 """ 616 """
611 childEnabled = False 617 childEnabled = False
612 text = text.lower() 618 text = text.lower()
613 for index in range(parent.childCount()): 619 for index in range(parent.childCount()):
614 itm = parent.child(index) 620 itm = parent.child(index)
615 if itm.childCount() > 0: 621 enable = (
616 enable = ( 622 (self.__searchChildItems(itm, text) or
617 self.__searchChildItems(itm, text) or 623 text == "" or
618 text == "" or 624 text in itm.text(0).lower())
619 text in itm.text(0).lower() 625 if itm.childCount() > 0 else
620 ) 626 (text == "" or text in itm.text(0).lower())
621 else: 627 )
622 enable = text == "" or text in itm.text(0).lower()
623 if enable: 628 if enable:
624 childEnabled = True 629 childEnabled = True
625 itm.setDisabled(not enable) 630 itm.setDisabled(not enable)
626 631
627 return childEnabled 632 return childEnabled
636 ) 641 )
637 642
638 self.lexers = {} 643 self.lexers = {}
639 for language in QScintilla.Lexers.getSupportedLanguages(): 644 for language in QScintilla.Lexers.getSupportedLanguages():
640 if language not in self.lexers: 645 if language not in self.lexers:
641 try: 646 with contextlib.suppress(PreferencesLexerLanguageError):
642 self.lexers[language] = PreferencesLexer(language, self) 647 self.lexers[language] = PreferencesLexer(language, self)
643 except PreferencesLexerLanguageError:
644 pass
645 648
646 def __importConfigurationPage(self, name): 649 def __importConfigurationPage(self, name):
647 """ 650 """
648 Private method to import a configuration page module. 651 Private method to import a configuration page module.
649 652
690 if mod: 693 if mod:
691 page = mod.create(self) 694 page = mod.create(self)
692 if page is not None: 695 if page is not None:
693 self.configStack.addWidget(page) 696 self.configStack.addWidget(page)
694 pageData[-1] = page 697 pageData[-1] = page
695 try: 698 with contextlib.suppress(AttributeError):
696 page.setMode(self.displayMode) 699 page.setMode(self.displayMode)
697 except AttributeError:
698 pass
699 return page 700 return page
700 701
701 def showConfigurationPageByName(self, pageName, setCurrent=True): 702 def showConfigurationPageByName(self, pageName, setCurrent=True):
702 """ 703 """
703 Public slot to show a named configuration page. 704 Public slot to show a named configuration page.
902 @return flag indicating the use of QtWebEngine 903 @return flag indicating the use of QtWebEngine
903 @rtype bool 904 @rtype bool
904 """ 905 """
905 return ( 906 return (
906 self.__webEngine or 907 self.__webEngine or
907 self.displayMode == ConfigurationWidget.WebBrowserMode 908 self.displayMode == ConfigurationMode.WEBBROWSERMODE
908 ) 909 )
909 910
910 911
911 class ConfigurationDialog(QDialog): 912 class ConfigurationDialog(QDialog):
912 """ 913 """
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 HelpBrowserMode = ConfigurationWidget.HelpBrowserMode
924 TrayStarterMode = ConfigurationWidget.TrayStarterMode
925 HexEditorMode = ConfigurationWidget.HexEditorMode
926 WebBrowserMode = ConfigurationWidget.WebBrowserMode
927
928 def __init__(self, parent=None, name=None, modal=False, 923 def __init__(self, parent=None, name=None, modal=False,
929 fromEric=True, displayMode=ConfigurationWidget.DefaultMode, 924 fromEric=True,
925 displayMode=ConfigurationMode.DEFAULTMODE,
930 expandedEntries=None): 926 expandedEntries=None):
931 """ 927 """
932 Constructor 928 Constructor
933 929
934 @param parent The parent widget of this dialog. (QWidget) 930 @param parent reference to the parent widget
935 @param name The name of this dialog. string 931 @type QWidget
936 @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
937 @param fromEric flag indicating a dialog generation from within the 936 @param fromEric flag indicating a dialog generation from within the
938 eric ide (boolean) 937 eric IDE
938 @type bool
939 @param displayMode mode of the configuration dialog 939 @param displayMode mode of the configuration dialog
940 (DefaultMode, HelpBrowserMode, TrayStarterMode, HexEditorMode, 940 @type ConfigurationMode
941 WebBrowserMode)
942 @param expandedEntries list of entries to be shown expanded 941 @param expandedEntries list of entries to be shown expanded
943 (list of strings) 942 @type list of str
944 """ 943 """
945 super(ConfigurationDialog, self).__init__(parent) 944 super().__init__(parent)
946 if name: 945 if name:
947 self.setObjectName(name) 946 self.setObjectName(name)
948 self.setModal(modal) 947 self.setModal(modal)
949 self.setWindowFlags(Qt.WindowType.Window) 948 self.setWindowFlags(Qt.WindowType.Window)
950 949
1013 1012
1014 def accept(self): 1013 def accept(self):
1015 """ 1014 """
1016 Public method to accept the dialog. 1015 Public method to accept the dialog.
1017 """ 1016 """
1018 super(ConfigurationDialog, self).accept() 1017 super().accept()
1019 1018
1020 1019
1021 class ConfigurationWindow(E5MainWindow): 1020 class ConfigurationWindow(E5MainWindow):
1022 """ 1021 """
1023 Main window class for the standalone dialog. 1022 Main window class for the standalone dialog.
1026 """ 1025 """
1027 Constructor 1026 Constructor
1028 1027
1029 @param parent reference to the parent widget (QWidget) 1028 @param parent reference to the parent widget (QWidget)
1030 """ 1029 """
1031 super(ConfigurationWindow, self).__init__(parent) 1030 super().__init__(parent)
1032 1031
1033 self.cw = ConfigurationWidget(self, fromEric=False) 1032 self.cw = ConfigurationWidget(self, fromEric=False)
1034 size = self.cw.size() 1033 size = self.cw.size()
1035 self.setCentralWidget(self.cw) 1034 self.setCentralWidget(self.cw)
1036 self.resize(size) 1035 self.resize(size)

eric ide

mercurial