Preferences/ConfigurationDialog.py

changeset 4216
bca19a75be32
parent 4214
b8fd47f8b707
child 4278
ccd1e13cb9bd
equal deleted inserted replaced
4214:b8fd47f8b707 4216:bca19a75be32
77 77
78 DefaultMode = 0 78 DefaultMode = 0
79 HelpBrowserMode = 1 79 HelpBrowserMode = 1
80 TrayStarterMode = 2 80 TrayStarterMode = 2
81 81
82 def __init__(self, parent=None, fromEric=True, displayMode=DefaultMode): 82 def __init__(self, parent=None, fromEric=True, displayMode=DefaultMode,
83 expandedEntries=[]):
83 """ 84 """
84 Constructor 85 Constructor
85 86
86 @param parent The parent widget of this dialog. (QWidget) 87 @param parent The parent widget of this dialog. (QWidget)
87 @keyparam fromEric flag indicating a dialog generation from within the 88 @keyparam fromEric flag indicating a dialog generation from within the
88 eric6 ide (boolean) 89 eric6 ide (boolean)
89 @keyparam displayMode mode of the configuration dialog 90 @keyparam displayMode mode of the configuration dialog
90 (DefaultMode, HelpBrowserMode, TrayStarterMode) 91 (DefaultMode, HelpBrowserMode, TrayStarterMode)
91 @exception RuntimeError raised to indicate an invalid dialog mode 92 @exception RuntimeError raised to indicate an invalid dialog mode
93 @keyparam expandedEntries list of entries to be shown expanded
94 (list of strings)
92 """ 95 """
93 assert displayMode in ( 96 assert displayMode in (
94 ConfigurationWidget.DefaultMode, 97 ConfigurationWidget.DefaultMode,
95 ConfigurationWidget.HelpBrowserMode, 98 ConfigurationWidget.HelpBrowserMode,
96 ConfigurationWidget.TrayStarterMode 99 ConfigurationWidget.TrayStarterMode
115 if displayMode == ConfigurationWidget.DefaultMode: 118 if displayMode == ConfigurationWidget.DefaultMode:
116 self.configItems = { 119 self.configItems = {
117 # key : [display string, pixmap name, dialog module name or 120 # key : [display string, pixmap name, dialog module name or
118 # page creation function, parent key, 121 # page creation function, parent key,
119 # reference to configuration page (must always be last)] 122 # reference to configuration page (must always be last)]
120 # The dialog module must have the module function create to 123 # The dialog module must have the module function 'create' to
121 # create the configuration page. This must have the method 124 # create the configuration page. This must have the method
122 # save to save the settings. 125 # 'save' to save the settings.
123 "applicationPage": 126 "applicationPage":
124 [self.tr("Application"), "preferences-application.png", 127 [self.tr("Application"), "preferences-application.png",
125 "ApplicationPage", None, None], 128 "ApplicationPage", None, None],
126 "cooperationPage": 129 "cooperationPage":
127 [self.tr("Cooperation"), "preferences-cooperation.png", 130 [self.tr("Cooperation"), "preferences-cooperation.png",
315 "ViewmanagerPage", "0interfacePage", None], 318 "ViewmanagerPage", "0interfacePage", None],
316 } 319 }
317 320
318 self.configItems.update( 321 self.configItems.update(
319 e5App().getObject("PluginManager").getPluginConfigData()) 322 e5App().getObject("PluginManager").getPluginConfigData())
323
320 elif displayMode == ConfigurationWidget.HelpBrowserMode: 324 elif displayMode == ConfigurationWidget.HelpBrowserMode:
321 self.configItems = { 325 self.configItems = {
322 # key : [display string, pixmap name, dialog module name or 326 # key : [display string, pixmap name, dialog module name or
323 # page creation function, parent key, 327 # page creation function, parent key,
324 # reference to configuration page (must always be last)] 328 # reference to configuration page (must always be last)]
325 # The dialog module must have the module function create to 329 # The dialog module must have the module function 'create' to
326 # create the configuration page. This must have the method 330 # create the configuration page. This must have the method
327 # save to save the settings. 331 # 'save' to save the settings.
328 "interfacePage": 332 "interfacePage":
329 [self.tr("Interface"), "preferences-interface.png", 333 [self.tr("Interface"), "preferences-interface.png",
330 "HelpInterfacePage", None, None], 334 "HelpInterfacePage", None, None],
331 "networkPage": 335 "networkPage":
332 [self.tr("Network"), "preferences-network.png", 336 [self.tr("Network"), "preferences-network.png",
353 "HelpVirusTotalPage", "0helpPage", None], 357 "HelpVirusTotalPage", "0helpPage", None],
354 "helpWebBrowserPage": 358 "helpWebBrowserPage":
355 [self.tr("eric6 Web Browser"), "ericWeb.png", 359 [self.tr("eric6 Web Browser"), "ericWeb.png",
356 "HelpWebBrowserPage", "0helpPage", None], 360 "HelpWebBrowserPage", "0helpPage", None],
357 } 361 }
362
358 elif displayMode == ConfigurationWidget.TrayStarterMode: 363 elif displayMode == ConfigurationWidget.TrayStarterMode:
359 self.configItems = { 364 self.configItems = {
360 # key : [display string, pixmap name, dialog module name or 365 # key : [display string, pixmap name, dialog module name or
361 # page creation function, parent key, 366 # page creation function, parent key,
362 # reference to configuration page (must always be last)] 367 # reference to configuration page (must always be last)]
363 # The dialog module must have the module function create to 368 # The dialog module must have the module function 'create' to
364 # create the configuration page. This must have the method 369 # create the configuration page. This must have the method
365 # save to save the settings. 370 # 'save' to save the settings.
366 "trayStarterPage": 371 "trayStarterPage":
367 [self.tr("Tray Starter"), "erict.png", 372 [self.tr("Tray Starter"), "erict.png",
368 "TrayStarterPage", None, None], 373 "TrayStarterPage", None, None],
369 } 374 }
375
370 else: 376 else:
371 raise RuntimeError("Illegal mode value: {0}".format(displayMode)) 377 raise RuntimeError("Illegal mode value: {0}".format(displayMode))
372 378
373 # generate the list entries 379 # generate the list entries
380 self.__expandedEntries = []
374 for key in sorted(self.configItems.keys()): 381 for key in sorted(self.configItems.keys()):
375 pageData = self.configItems[key] 382 pageData = self.configItems[key]
376 if pageData[3]: 383 if pageData[3]:
377 pitm = self.itmDict[pageData[3]] # get the parent item 384 pitm = self.itmDict[pageData[3]] # get the parent item
378 else: 385 else:
379 pitm = self.configList 386 pitm = self.configList
380 self.itmDict[key] = ConfigurationPageItem(pitm, pageData[0], key, 387 self.itmDict[key] = ConfigurationPageItem(pitm, pageData[0], key,
381 pageData[1]) 388 pageData[1])
382 self.itmDict[key].setData(0, Qt.UserRole, key) 389 self.itmDict[key].setData(0, Qt.UserRole, key)
383 self.itmDict[key].setExpanded(True) 390 if (not self.fromEric or
391 displayMode != ConfigurationWidget.DefaultMode or
392 key in expandedEntries):
393 self.itmDict[key].setExpanded(True)
384 self.configList.sortByColumn(0, Qt.AscendingOrder) 394 self.configList.sortByColumn(0, Qt.AscendingOrder)
385 395
386 # set the initial size of the splitter 396 # set the initial size of the splitter
387 self.configSplitter.setSizes([200, 600]) 397 self.configSplitter.setSizes([200, 600])
388 398
745 self.configItems[pageName][-1] = None 755 self.configItems[pageName][-1] = None
746 756
747 self.showConfigurationPageByName(pageName) 757 self.showConfigurationPageByName(pageName)
748 if savedState is not None: 758 if savedState is not None:
749 self.configStack.currentWidget().setState(savedState) 759 self.configStack.currentWidget().setState(savedState)
760
761 def getExpandedEntries(self):
762 """
763 Public method to get a list of expanded entries.
764
765 @return list of expanded entries (list of string)
766 """
767 return self.__expandedEntries
768
769 @pyqtSlot(QTreeWidgetItem)
770 def on_configList_itemCollapsed(self, item):
771 """
772 Private slot handling a list entry being collapsed.
773
774 @param item reference to the collapsed item (QTreeWidgetItem)
775 """
776 pageName = item.data(0, Qt.UserRole)
777 if pageName in self.__expandedEntries:
778 self.__expandedEntries.remove(pageName)
779
780 @pyqtSlot(QTreeWidgetItem)
781 def on_configList_itemExpanded(self, item):
782 """
783 Private slot handling a list entry being expanded.
784
785 @param item reference to the expanded item (QTreeWidgetItem)
786 """
787 pageName = item.data(0, Qt.UserRole)
788 if pageName not in self.__expandedEntries:
789 self.__expandedEntries.append(pageName)
750 790
751 791
752 class ConfigurationDialog(QDialog): 792 class ConfigurationDialog(QDialog):
753 """ 793 """
754 Class for the dialog variant. 794 Class for the dialog variant.
763 DefaultMode = ConfigurationWidget.DefaultMode 803 DefaultMode = ConfigurationWidget.DefaultMode
764 HelpBrowserMode = ConfigurationWidget.HelpBrowserMode 804 HelpBrowserMode = ConfigurationWidget.HelpBrowserMode
765 TrayStarterMode = ConfigurationWidget.TrayStarterMode 805 TrayStarterMode = ConfigurationWidget.TrayStarterMode
766 806
767 def __init__(self, parent=None, name=None, modal=False, 807 def __init__(self, parent=None, name=None, modal=False,
768 fromEric=True, displayMode=ConfigurationWidget.DefaultMode): 808 fromEric=True, displayMode=ConfigurationWidget.DefaultMode,
809 expandedEntries=[]):
769 """ 810 """
770 Constructor 811 Constructor
771 812
772 @param parent The parent widget of this dialog. (QWidget) 813 @param parent The parent widget of this dialog. (QWidget)
773 @param name The name of this dialog. string 814 @param name The name of this dialog. string
774 @param modal Flag indicating a modal dialog. (boolean) 815 @param modal Flag indicating a modal dialog. (boolean)
775 @keyparam fromEric flag indicating a dialog generation from within the 816 @keyparam fromEric flag indicating a dialog generation from within the
776 eric6 ide (boolean) 817 eric6 ide (boolean)
777 @keyparam displayMode mode of the configuration dialog 818 @keyparam displayMode mode of the configuration dialog
778 (DefaultMode, HelpBrowserMode, TrayStarterMode) 819 (DefaultMode, HelpBrowserMode, TrayStarterMode)
820 @keyparam expandedEntries list of entries to be shown expanded
821 (list of strings)
779 """ 822 """
780 super(ConfigurationDialog, self).__init__(parent) 823 super(ConfigurationDialog, self).__init__(parent)
781 if name: 824 if name:
782 self.setObjectName(name) 825 self.setObjectName(name)
783 self.setModal(modal) 826 self.setModal(modal)
784 self.layout = QVBoxLayout(self) 827 self.layout = QVBoxLayout(self)
785 self.layout.setContentsMargins(0, 0, 0, 0) 828 self.layout.setContentsMargins(0, 0, 0, 0)
786 self.layout.setSpacing(0) 829 self.layout.setSpacing(0)
787 830
788 self.cw = ConfigurationWidget(self, fromEric=fromEric, 831 self.cw = ConfigurationWidget(self, fromEric=fromEric,
789 displayMode=displayMode) 832 displayMode=displayMode,
833 expandedEntries=expandedEntries)
790 size = self.cw.size() 834 size = self.cw.size()
791 self.layout.addWidget(self.cw) 835 self.layout.addWidget(self.cw)
792 self.resize(size) 836 self.resize(size)
793 self.setWindowTitle(self.cw.windowTitle()) 837 self.setWindowTitle(self.cw.windowTitle())
794 838
825 Public method to get the page name of the current page. 869 Public method to get the page name of the current page.
826 870
827 @return page name of the current page (string) 871 @return page name of the current page (string)
828 """ 872 """
829 return self.cw.getConfigurationPageName() 873 return self.cw.getConfigurationPageName()
874
875 def getExpandedEntries(self):
876 """
877 Public method to get a list of expanded entries.
878
879 @return list of expanded entries (list of string)
880 """
881 return self.cw.getExpandedEntries()
830 882
831 def setPreferences(self): 883 def setPreferences(self):
832 """ 884 """
833 Public method called to store the selected values into the preferences 885 Public method called to store the selected values into the preferences
834 storage. 886 storage.

eric ide

mercurial