Sun, 27 Jan 2019 19:52:37 +0100
Continued implementing environment creation with conda.
6677
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

1  # * coding: utf8 * 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

2  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

3  # Copyright (c) 2019 Detlev Offenbach <detlev@dieoffenbachs.de> 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

4  # 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

5  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

6  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

7  Module implementing a dialog to enter the logical name for a new virtual 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

8  environment. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

9  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

10  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

11  from PyQt5.QtCore import pyqtSlot, Qt 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

12  from PyQt5.QtWidgets import QDialog, QDialogButtonBox 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

13  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

14  from .Ui_VirtualenvNameDialog import Ui_VirtualenvNameDialog 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

15  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

16  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

17  class VirtualenvNameDialog(QDialog, Ui_VirtualenvNameDialog): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

18  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

19  Class implementing a dialog to enter the logical name for a new virtual 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

20  environment. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

21  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

22  def __init__(self, environments, currentName, parent=None): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

23  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

24  Constructor 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

25  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

26  @param environments list of environment names to be shown 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

27  @type list of str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

28  @param currentName name to be shown in the name edit 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

29  @type str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

30  @param parent reference to the parent widget 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

31  @type QWidget 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

32  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

33  super(VirtualenvNameDialog, self).__init__(parent) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

34  self.setupUi(self) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

35  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

36  self.envsList.addItems(environments) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

37  self.nameEdit.setText(currentName) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

38  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

39  self.nameEdit.setFocus(Qt.OtherFocusReason) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

40  self.nameEdit.selectAll() 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

41  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

42  @pyqtSlot(str) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

43  def on_nameEdit_textChanged(self, txt): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

44  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

45  Slot documentation goes here. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

46  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

47  @param txt contens of the name edit 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

48  @type str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

49  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

50  items = self.envsList.findItems(txt, Qt.MatchExactly) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

51  self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

52  bool(txt) and len(items) == 0) 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

53  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

54  def getName(self): 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

55  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

56  Public method to get the entered name. 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

57  
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

58  @return name for the environment 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

59  @rtype str 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

60  """ 
6299d69a218a
Continued implementing environment creation with conda.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

61  return self.nameEdit.text() 