|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Flask configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 |
|
12 from E5Gui.E5Application import e5App |
|
13 |
|
14 from Preferences.ConfigurationPages.ConfigurationPageBase import ( |
|
15 ConfigurationPageBase |
|
16 ) |
|
17 from .Ui_FlaskPage import Ui_FlaskPage |
|
18 |
|
19 import UI.PixmapCache |
|
20 |
|
21 |
|
22 class FlaskPage(ConfigurationPageBase, Ui_FlaskPage): |
|
23 """ |
|
24 Class implementing the Flask configuration page. |
|
25 """ |
|
26 def __init__(self, plugin): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param plugin reference to the plugin object |
|
31 """ |
|
32 super(FlaskPage, self).__init__() |
|
33 self.setupUi(self) |
|
34 self.setObjectName("FlaskPage") |
|
35 |
|
36 self.__plugin = plugin |
|
37 |
|
38 self.urlResetButton.setIcon( |
|
39 UI.PixmapCache.getIcon("editUndo")) |
|
40 self.py3VenvNamesReloadButton.setIcon( |
|
41 UI.PixmapCache.getIcon("reload")) |
|
42 |
|
43 venvManager = e5App().getObject("VirtualEnvManager") |
|
44 self.py3VenvNameComboBox.addItems( |
|
45 [""] + sorted(venvManager.getVirtualenvNames())) |
|
46 |
|
47 # set initial values |
|
48 self.externalBrowserCheckBox.setChecked( |
|
49 self.__plugin.getPreferences("UseExternalBrowser")) |
|
50 |
|
51 venvName = self.__plugin.getPreferences( |
|
52 "VirtualEnvironmentNamePy3") |
|
53 if venvName: |
|
54 index = self.py3VenvNameComboBox.findText(venvName) |
|
55 if index < 0: |
|
56 index = 0 |
|
57 self.py3VenvNameComboBox.setCurrentIndex(index) |
|
58 |
|
59 self.urlEdit.setText( |
|
60 self.__plugin.getPreferences("FlaskDocUrl")) |
|
61 |
|
62 def save(self): |
|
63 """ |
|
64 Public slot to save the Flask configuration. |
|
65 """ |
|
66 self.__plugin.setPreferences( |
|
67 "UseExternalBrowser", self.externalBrowserCheckBox.isChecked()) |
|
68 |
|
69 self.__plugin.setPreferences( |
|
70 "VirtualEnvironmentNamePy3", |
|
71 self.py3VenvNameComboBox.currentText()) |
|
72 |
|
73 self.__plugin.setPreferences( |
|
74 "FlaskDocUrl", self.urlEdit.text()) |
|
75 |
|
76 @pyqtSlot() |
|
77 def on_py3VenvNamesReloadButton_clicked(self): |
|
78 """ |
|
79 Private slot to reload the virtual environment names. |
|
80 """ |
|
81 currentVenvName = self.py3VenvNameComboBox.currentText() |
|
82 self.py3VenvNameComboBox.clear() |
|
83 venvManager = e5App().getObject("VirtualEnvManager") |
|
84 self.py3VenvNameComboBox.addItems( |
|
85 [""] + sorted(venvManager.getVirtualenvNames())) |
|
86 if currentVenvName: |
|
87 index = self.py3VenvNameComboBox.findText(currentVenvName) |
|
88 if index < 0: |
|
89 index = 0 |
|
90 self.py3VenvNameComboBox.setCurrentIndex(index) |
|
91 |
|
92 @pyqtSlot() |
|
93 def on_urlResetButton_clicked(self): |
|
94 """ |
|
95 Private slot to reset the Flask documentation URL. |
|
96 """ |
|
97 self.urlEdit.setText( |
|
98 self.__plugin.getDefaultPreference("FlaskDocUrl")) |