|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Pyramid configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot |
|
11 |
|
12 from E5Gui.E5Completers import E5DirCompleter |
|
13 from E5Gui import E5FileDialog |
|
14 |
|
15 from Preferences.ConfigurationPages.ConfigurationPageBase import ConfigurationPageBase |
|
16 from .Ui_PyramidPage import Ui_PyramidPage |
|
17 |
|
18 import Utilities |
|
19 |
|
20 from Globals import isWindowsPlatform, isMacPlatform |
|
21 |
|
22 |
|
23 class PyramidPage(ConfigurationPageBase, Ui_PyramidPage): |
|
24 """ |
|
25 Class implementing the Pyramid configuration page. |
|
26 """ |
|
27 def __init__(self, plugin): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param plugin reference to the plugin object |
|
32 """ |
|
33 super().__init__() |
|
34 self.setupUi(self) |
|
35 self.setObjectName("PyramidPage") |
|
36 |
|
37 self.__plugin = plugin |
|
38 |
|
39 consoleList = [] |
|
40 if isWindowsPlatform(): |
|
41 consoleList.append("cmd.exe /c") |
|
42 elif isMacPlatform(): |
|
43 consoleList.append("xterm -e") |
|
44 else: |
|
45 consoleList.append("konsole -e") |
|
46 consoleList.append("@konsole --workdir . -e") |
|
47 # KDE4 konsole spawns |
|
48 consoleList.append("gnome-terminal -x") |
|
49 consoleList.append("xterm -e") |
|
50 |
|
51 consoleNoCloseList = [] |
|
52 if isWindowsPlatform(): |
|
53 consoleNoCloseList.append("cmd.exe /k") |
|
54 elif isMacPlatform(): |
|
55 consoleNoCloseList.append("xterm -hold -e") |
|
56 else: |
|
57 consoleNoCloseList.append("konsole --noclose -e") |
|
58 consoleNoCloseList.append("@konsole --noclose --workdir . -e") |
|
59 # KDE4 konsole spawns |
|
60 consoleNoCloseList.append("xterm -hold -e") |
|
61 |
|
62 self.consoleCommandCombo.addItems(consoleList) |
|
63 self.consoleCommandNoCloseCombo.addItems(consoleNoCloseList) |
|
64 |
|
65 self.virtualEnvPy2Completer = E5DirCompleter(self.virtualEnvPy2Edit) |
|
66 self.virtualEnvPy3Completer = E5DirCompleter(self.virtualEnvPy3Edit) |
|
67 |
|
68 self.py2ShellCombo.addItem(self.trUtf8("Plain Python"), "python") |
|
69 self.py2ShellCombo.addItem(self.trUtf8("IPython"), "ipython") |
|
70 self.py2ShellCombo.addItem(self.trUtf8("bpython"), "bpython") |
|
71 |
|
72 self.py3ShellCombo.addItem(self.trUtf8("Plain Python"), "python") |
|
73 self.py3ShellCombo.addItem(self.trUtf8("IPython"), "ipython") |
|
74 self.py3ShellCombo.addItem(self.trUtf8("bpython"), "bpython") |
|
75 |
|
76 # set initial values |
|
77 self.consoleCommandCombo.setEditText( |
|
78 self.__plugin.getPreferences("ConsoleCommand")) |
|
79 self.consoleCommandNoCloseCombo.setEditText( |
|
80 self.__plugin.getPreferences("ConsoleCommandNoClose")) |
|
81 |
|
82 self.virtualEnvPy2Edit.setText( |
|
83 self.__plugin.getPreferences("VirtualEnvironmentPy2")) |
|
84 self.virtualEnvPy3Edit.setText( |
|
85 self.__plugin.getPreferences("VirtualEnvironmentPy3")) |
|
86 |
|
87 self.portSpinBox.setValue( |
|
88 self.__plugin.getPreferences("ServerPort")) |
|
89 |
|
90 self.py2ShellCombo.setCurrentIndex(self.py2ShellCombo.findData( |
|
91 self.__plugin.getPreferences("Python2ConsoleType"))) |
|
92 self.py3ShellCombo.setCurrentIndex(self.py3ShellCombo.findData( |
|
93 self.__plugin.getPreferences("Python3ConsoleType"))) |
|
94 |
|
95 self.urlEdit.setText( |
|
96 self.__plugin.getPreferences("PyramidDocUrl")) |
|
97 |
|
98 def save(self): |
|
99 """ |
|
100 Public slot to save the Pyramid configuration. |
|
101 """ |
|
102 self.__plugin.setPreferences("ConsoleCommand", |
|
103 self.consoleCommandCombo.currentText()) |
|
104 self.__plugin.setPreferences("ConsoleCommandNoClose", |
|
105 self.consoleCommandNoCloseCombo.currentText()) |
|
106 |
|
107 self.__plugin.setPreferences("VirtualEnvironmentPy2", |
|
108 self.virtualEnvPy2Edit.text()) |
|
109 self.__plugin.setPreferences("VirtualEnvironmentPy3", |
|
110 self.virtualEnvPy3Edit.text()) |
|
111 |
|
112 self.__plugin.setPreferences("ServerPort", |
|
113 self.portSpinBox.value()) |
|
114 |
|
115 self.__plugin.setPreferences("Python2ConsoleType", |
|
116 self.py2ShellCombo.itemData(self.py2ShellCombo.currentIndex())) |
|
117 self.__plugin.setPreferences("Python3ConsoleType", |
|
118 self.py3ShellCombo.itemData(self.py3ShellCombo.currentIndex())) |
|
119 |
|
120 self.__plugin.setPreferences("PyramidDocUrl", |
|
121 self.urlEdit.text()) |
|
122 |
|
123 @pyqtSlot() |
|
124 def on_virtualEnvPy3Button_clicked(self): |
|
125 """ |
|
126 Private slot to select the virtual environment for Python 3 via a |
|
127 directory selection dialog. |
|
128 """ |
|
129 vDir = self.virtualEnvPy3Edit.text() |
|
130 if not vDir: |
|
131 vDir = Utilities.getHomeDir() |
|
132 virtualEnv = E5FileDialog.getExistingDirectory( |
|
133 self, |
|
134 self.trUtf8("Select Virtual Environment for Python 3"), |
|
135 vDir, |
|
136 E5FileDialog.Options(E5FileDialog.Option(0))) |
|
137 |
|
138 if virtualEnv: |
|
139 self.virtualEnvPy3Edit.setText(Utilities.toNativeSeparators(virtualEnv)) |
|
140 |
|
141 @pyqtSlot() |
|
142 def on_virtualEnvPy2Button_clicked(self): |
|
143 """ |
|
144 Private slot to select the virtual environment for Python 2 via a |
|
145 directory selection dialog. |
|
146 """ |
|
147 vDir = self.virtualEnvPy2Edit.text() |
|
148 if not vDir: |
|
149 vDir = Utilities.getHomeDir() |
|
150 virtualEnv = E5FileDialog.getExistingDirectory( |
|
151 self, |
|
152 self.trUtf8("Select Virtual Environment for Python 2"), |
|
153 vDir, |
|
154 E5FileDialog.Options(E5FileDialog.Option(0))) |
|
155 |
|
156 if virtualEnv: |
|
157 self.virtualEnvPy2Edit.setText(Utilities.toNativeSeparators(virtualEnv)) |