ProjectFlask/ConfigurationPage/FlaskPage.py

branch
eric7
changeset 70
22e1d0f69668
parent 66
0d3168d0e310
child 72
4557829a4acf
equal deleted inserted replaced
69:c31a4f756a04 70:22e1d0f69668
10 from PyQt6.QtCore import pyqtSlot 10 from PyQt6.QtCore import pyqtSlot
11 11
12 from EricWidgets.EricApplication import ericApp 12 from EricWidgets.EricApplication import ericApp
13 from EricWidgets.EricPathPicker import EricPathPickerModes 13 from EricWidgets.EricPathPicker import EricPathPickerModes
14 14
15 from Preferences.ConfigurationPages.ConfigurationPageBase import ( 15 from Preferences.ConfigurationPages.ConfigurationPageBase import ConfigurationPageBase
16 ConfigurationPageBase
17 )
18 from .Ui_FlaskPage import Ui_FlaskPage 16 from .Ui_FlaskPage import Ui_FlaskPage
19 17
20 import UI.PixmapCache 18 import UI.PixmapCache
21 19
22 from Globals import isWindowsPlatform, isMacPlatform 20 from Globals import isWindowsPlatform, isMacPlatform
26 24
27 class FlaskPage(ConfigurationPageBase, Ui_FlaskPage): 25 class FlaskPage(ConfigurationPageBase, Ui_FlaskPage):
28 """ 26 """
29 Class implementing the Flask configuration page. 27 Class implementing the Flask configuration page.
30 """ 28 """
29
31 def __init__(self, plugin): 30 def __init__(self, plugin):
32 """ 31 """
33 Constructor 32 Constructor
34 33
35 @param plugin reference to the plugin object 34 @param plugin reference to the plugin object
36 @type ProjectFlaskPlugin 35 @type ProjectFlaskPlugin
37 """ 36 """
38 super().__init__() 37 super().__init__()
39 self.setupUi(self) 38 self.setupUi(self)
40 self.setObjectName("FlaskPage") 39 self.setObjectName("FlaskPage")
41 40
42 self.__plugin = plugin 41 self.__plugin = plugin
43 42
44 consoleList = [] 43 consoleList = []
45 if isWindowsPlatform(): 44 if isWindowsPlatform():
46 consoleList.append("cmd.exe /c") 45 consoleList.append("cmd.exe /c")
47 elif isMacPlatform(): 46 elif isMacPlatform():
48 consoleList.append("xterm -e") 47 consoleList.append("xterm -e")
52 consoleList.append("gnome-terminal -e") 51 consoleList.append("gnome-terminal -e")
53 consoleList.append("mate-terminal -e") 52 consoleList.append("mate-terminal -e")
54 consoleList.append("xfce4-terminal -e") 53 consoleList.append("xfce4-terminal -e")
55 consoleList.append("xterm -e") 54 consoleList.append("xterm -e")
56 self.consoleCommandCombo.addItems(consoleList) 55 self.consoleCommandCombo.addItems(consoleList)
57 56
58 self.colorSchemeComboBox.addItems( 57 self.colorSchemeComboBox.addItems(sorted(AnsiTools.getAvailableColorSchemes()))
59 sorted(AnsiTools.getAvailableColorSchemes())) 58
60 59 self.urlResetButton.setIcon(UI.PixmapCache.getIcon("editUndo"))
61 self.urlResetButton.setIcon( 60 self.py3VenvNamesReloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
62 UI.PixmapCache.getIcon("editUndo")) 61
63 self.py3VenvNamesReloadButton.setIcon(
64 UI.PixmapCache.getIcon("reload"))
65
66 venvManager = ericApp().getObject("VirtualEnvManager") 62 venvManager = ericApp().getObject("VirtualEnvManager")
67 self.py3VenvNameComboBox.addItems( 63 self.py3VenvNameComboBox.addItems(
68 [""] + sorted(venvManager.getVirtualenvNames())) 64 [""] + sorted(venvManager.getVirtualenvNames())
69 65 )
70 self.translationsEditorPicker.setMode( 66
71 EricPathPickerModes.OPEN_FILE_MODE) 67 self.translationsEditorPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
72 self.translationsEditorPicker.setFilters(self.tr("All Files (*)")) 68 self.translationsEditorPicker.setFilters(self.tr("All Files (*)"))
73 69
74 # set initial values 70 # set initial values
75 self.consoleCommandCombo.setEditText( 71 self.consoleCommandCombo.setEditText(
76 self.__plugin.getPreferences("ConsoleCommand")) 72 self.__plugin.getPreferences("ConsoleCommand")
77 73 )
74
78 self.externalBrowserCheckBox.setChecked( 75 self.externalBrowserCheckBox.setChecked(
79 self.__plugin.getPreferences("UseExternalBrowser")) 76 self.__plugin.getPreferences("UseExternalBrowser")
80 77 )
81 venvName = self.__plugin.getPreferences( 78
82 "VirtualEnvironmentNamePy3") 79 venvName = self.__plugin.getPreferences("VirtualEnvironmentNamePy3")
83 if venvName: 80 if venvName:
84 index = self.py3VenvNameComboBox.findText(venvName) 81 index = self.py3VenvNameComboBox.findText(venvName)
85 if index < 0: 82 if index < 0:
86 index = 0 83 index = 0
87 self.py3VenvNameComboBox.setCurrentIndex(index) 84 self.py3VenvNameComboBox.setCurrentIndex(index)
88 85
89 self.colorSchemeComboBox.setCurrentText( 86 self.colorSchemeComboBox.setCurrentText(
90 self.__plugin.getPreferences("AnsiColorScheme")) 87 self.__plugin.getPreferences("AnsiColorScheme")
91 88 )
92 self.urlEdit.setText( 89
93 self.__plugin.getPreferences("FlaskDocUrl")) 90 self.urlEdit.setText(self.__plugin.getPreferences("FlaskDocUrl"))
94 91
95 self.translationsEditorPicker.setText( 92 self.translationsEditorPicker.setText(
96 self.__plugin.getPreferences("TranslationsEditor")) 93 self.__plugin.getPreferences("TranslationsEditor")
97 94 )
95
98 def save(self): 96 def save(self):
99 """ 97 """
100 Public slot to save the Flask configuration. 98 Public slot to save the Flask configuration.
101 """ 99 """
102 self.__plugin.setPreferences( 100 self.__plugin.setPreferences(
103 "ConsoleCommand", self.consoleCommandCombo.currentText()) 101 "ConsoleCommand", self.consoleCommandCombo.currentText()
104 102 )
103
105 self.__plugin.setPreferences( 104 self.__plugin.setPreferences(
106 "UseExternalBrowser", self.externalBrowserCheckBox.isChecked()) 105 "UseExternalBrowser", self.externalBrowserCheckBox.isChecked()
107 106 )
107
108 self.__plugin.setPreferences( 108 self.__plugin.setPreferences(
109 "VirtualEnvironmentNamePy3", 109 "VirtualEnvironmentNamePy3", self.py3VenvNameComboBox.currentText()
110 self.py3VenvNameComboBox.currentText()) 110 )
111 111
112 self.__plugin.setPreferences( 112 self.__plugin.setPreferences(
113 "AnsiColorScheme", 113 "AnsiColorScheme", self.colorSchemeComboBox.currentText()
114 self.colorSchemeComboBox.currentText()) 114 )
115 115
116 self.__plugin.setPreferences("FlaskDocUrl", self.urlEdit.text())
117
116 self.__plugin.setPreferences( 118 self.__plugin.setPreferences(
117 "FlaskDocUrl", self.urlEdit.text()) 119 "TranslationsEditor", self.translationsEditorPicker.text()
118 120 )
119 self.__plugin.setPreferences( 121
120 "TranslationsEditor", self.translationsEditorPicker.text())
121
122 @pyqtSlot() 122 @pyqtSlot()
123 def on_py3VenvNamesReloadButton_clicked(self): 123 def on_py3VenvNamesReloadButton_clicked(self):
124 """ 124 """
125 Private slot to reload the virtual environment names. 125 Private slot to reload the virtual environment names.
126 """ 126 """
127 currentVenvName = self.py3VenvNameComboBox.currentText() 127 currentVenvName = self.py3VenvNameComboBox.currentText()
128 self.py3VenvNameComboBox.clear() 128 self.py3VenvNameComboBox.clear()
129 venvManager = ericApp().getObject("VirtualEnvManager") 129 venvManager = ericApp().getObject("VirtualEnvManager")
130 self.py3VenvNameComboBox.addItems( 130 self.py3VenvNameComboBox.addItems(
131 [""] + sorted(venvManager.getVirtualenvNames())) 131 [""] + sorted(venvManager.getVirtualenvNames())
132 )
132 if currentVenvName: 133 if currentVenvName:
133 index = self.py3VenvNameComboBox.findText(currentVenvName) 134 index = self.py3VenvNameComboBox.findText(currentVenvName)
134 if index < 0: 135 if index < 0:
135 index = 0 136 index = 0
136 self.py3VenvNameComboBox.setCurrentIndex(index) 137 self.py3VenvNameComboBox.setCurrentIndex(index)
137 138
138 @pyqtSlot() 139 @pyqtSlot()
139 def on_urlResetButton_clicked(self): 140 def on_urlResetButton_clicked(self):
140 """ 141 """
141 Private slot to reset the Flask documentation URL. 142 Private slot to reset the Flask documentation URL.
142 """ 143 """
143 self.urlEdit.setText( 144 self.urlEdit.setText(self.__plugin.getDefaultPreference("FlaskDocUrl"))
144 self.__plugin.getDefaultPreference("FlaskDocUrl"))

eric ide

mercurial