eric6/CondaInterface/CondaExportDialog.py

Mon, 12 Oct 2020 19:28:42 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 12 Oct 2020 19:28:42 +0200
changeset 7781
607a6098cb44
parent 7780
41420f82c0ac
child 7785
9978016560ec
permissions
-rw-r--r--

Performed some more code cleanup.

6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7250
diff changeset
3 # Copyright (c) 2019 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to generate a requirements file for conda.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt5.QtCore import pyqtSlot, Qt
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
13 from PyQt5.QtWidgets import (
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 QDialog, QDialogButtonBox, QAbstractButton, QApplication
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
15 )
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui import E5MessageBox, E5FileDialog
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from E5Gui.E5PathPicker import E5PathPickerModes
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from E5Gui.E5Application import e5App
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
20 from E5Gui.E5OverrideCursor import E5OverrideCursor
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 from .Ui_CondaExportDialog import Ui_CondaExportDialog
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 class CondaExportDialog(QDialog, Ui_CondaExportDialog):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Class implementing a dialog to generate a requirements file for conda.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 def __init__(self, conda, envName, envPrefix, parent=None):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param conda reference to the master object
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @type Conda
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param envName name of the environment to create the requirements
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 file from
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @type str
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param envPrefix prefix of the environment to create the requirements
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 file from
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @type str
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @param parent reference to the parent widget
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 @type QWidget
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 super(CondaExportDialog, self).__init__(parent)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.setupUi(self)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.setWindowFlags(Qt.Window)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__refreshButton = self.buttonBox.addButton(
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.tr("&Refresh"), QDialogButtonBox.ActionRole)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.requirementsFilePicker.setMode(E5PathPickerModes.SaveFileMode)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.requirementsFilePicker.setFilters(
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.tr("Text Files (*.txt);;All Files (*)"))
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__conda = conda
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__prefix = envPrefix
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.environmentLabel.setText("<b>{0}</b>".format(envName))
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__requirementsEdited = False
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.__requirementsAvailable = False
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.__updateButtons()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 def closeEvent(self, e):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Protected slot implementing a close event handler.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param e close event
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @type QCloseEvent
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 e.accept()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 @pyqtSlot(str)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 def on_requirementsFilePicker_textChanged(self, txt):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 Private slot handling a change of the requirements file name.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 @param txt name of the requirements file
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 @type str
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.__updateButtons()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @pyqtSlot()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 def on_requirementsEdit_textChanged(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 Private slot handling changes of the requirements text.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.__requirementsEdited = True
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 @pyqtSlot(QAbstractButton)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 def on_buttonBox_clicked(self, button):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 Private slot called by a button of the button box clicked.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 @param button button that was clicked
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @type QAbstractButton
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 if button == self.buttonBox.button(QDialogButtonBox.Close):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.close()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 elif button == self.__refreshButton:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.__refresh()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 def __refresh(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 Private slot to refresh the displayed list.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if self.__requirementsEdited:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 ok = E5MessageBox.yesNo(
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self,
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.tr("Generate Requirements"),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 self.tr("""The requirements were changed. Do you want"""
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 """ to overwrite these changes?"""))
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 else:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 ok = True
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 if ok:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.start()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 def start(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 Public method to start the command.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 self.requirementsEdit.clear()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__requirementsAvailable = False
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 args = [
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 "list",
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 "--export",
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 "--prefix",
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 self.__prefix,
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 ]
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
133 with E5OverrideCursor():
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
134 success, output = self.__conda.runProcess(args)
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
135
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
136 if success:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
137 self.requirementsEdit.setPlainText(output)
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
138 self.__requirementsAvailable = True
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
139 else:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
140 self.requirementsEdit.setPlainText(
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
141 self.tr("No output generated by conda."))
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 self.__updateButtons()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 self.__requirementsEdited = False
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 def __updateButtons(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 Private method to set the state of the various buttons.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.saveButton.setEnabled(
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 self.__requirementsAvailable and
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 bool(self.requirementsFilePicker.text())
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 )
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 self.saveToButton.setEnabled(self.__requirementsAvailable)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.copyButton.setEnabled(self.__requirementsAvailable)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 aw = e5App().getObject("ViewManager").activeWindow()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 if aw and self.__requirementsAvailable:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.insertButton.setEnabled(True)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.replaceAllButton.setEnabled(True)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.replaceSelectionButton.setEnabled(
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 aw.hasSelectedText())
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 else:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.insertButton.setEnabled(False)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.replaceAllButton.setEnabled(False)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 self.replaceSelectionButton.setEnabled(False)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 def __writeToFile(self, fileName):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 Private method to write the requirements text to a file.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 @param fileName name of the file to write to
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 @type str
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 if os.path.exists(fileName):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 ok = E5MessageBox.warning(
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 self,
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 self.tr("Generate Requirements"),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 self.tr("""The file <b>{0}</b> already exists. Do you want"""
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 """ to overwrite it?""").format(fileName))
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if not ok:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 return
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 try:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 f = open(fileName, "w")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 f.write(self.requirementsEdit.toPlainText())
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 f.close()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 except (OSError, IOError) as err:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 E5MessageBox.critical(
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self,
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 self.tr("Generate Requirements"),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 self.tr("""<p>The requirements could not be written"""
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 """ to <b>{0}</b>.</p><p>Reason: {1}</p>""")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 .format(fileName, str(err)))
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 @pyqtSlot()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 def on_saveButton_clicked(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 Private slot to save the requirements text to the requirements file.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 fileName = self.requirementsFilePicker.text()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 self.__writeToFile(fileName)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 @pyqtSlot()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 def on_saveToButton_clicked(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 Private slot to write the requirements text to a new file.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 self,
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 self.tr("Generate Requirements"),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 os.path.expanduser("~"),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.tr("Text Files (*.txt);;All Files (*)"),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 None,
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 )
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 if fileName:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 ext = os.path.splitext(fileName)[1]
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 if not ext:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 ex = selectedFilter.split("(*")[1].split(")")[0]
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 if ex:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 fileName += ex
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 self.__writeToFile(fileName)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 @pyqtSlot()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 def on_copyButton_clicked(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 Private slot to copy the requirements text to the clipboard.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 txt = self.requirementsEdit.toPlainText()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 cb = QApplication.clipboard()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 cb.setText(txt)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 @pyqtSlot()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 def on_insertButton_clicked(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 Private slot to insert the requirements text at the cursor position
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 of the current editor.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 aw = e5App().getObject("ViewManager").activeWindow()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 if aw:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 aw.beginUndoAction()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 cline, cindex = aw.getCursorPosition()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 aw.insertAt(self.requirementsEdit.toPlainText(), cline, cindex)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 aw.endUndoAction()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 @pyqtSlot()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 def on_replaceSelectionButton_clicked(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 Private slot to replace the selected text of the current editor
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 with the requirements text.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 aw = e5App().getObject("ViewManager").activeWindow()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 if aw:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 aw.beginUndoAction()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 aw.replaceSelectedText(self.requirementsEdit.toPlainText())
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 aw.endUndoAction()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 @pyqtSlot()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 def on_replaceAllButton_clicked(self):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 Private slot to replace the text of the current editor with the
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 requirements text.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 aw = e5App().getObject("ViewManager").activeWindow()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 if aw:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 aw.setText(self.requirementsEdit.toPlainText())

eric ide

mercurial