src/eric7/Templates/TemplateMultipleVariablesDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
7 Module implementing a dialog for entering multiple template variables. 7 Module implementing a dialog for entering multiple template variables.
8 """ 8 """
9 9
10 from PyQt6.QtCore import QSize, Qt 10 from PyQt6.QtCore import QSize, Qt
11 from PyQt6.QtWidgets import ( 11 from PyQt6.QtWidgets import (
12 QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, QLineEdit, QPushButton, 12 QSizePolicy,
13 QTextEdit, QDialog, QScrollArea, QFrame, QGridLayout, QVBoxLayout, QLabel 13 QSpacerItem,
14 QWidget,
15 QHBoxLayout,
16 QLineEdit,
17 QPushButton,
18 QTextEdit,
19 QDialog,
20 QScrollArea,
21 QFrame,
22 QGridLayout,
23 QVBoxLayout,
24 QLabel,
14 ) 25 )
15 26
16 27
17 class TemplateMultipleVariablesDialog(QDialog): 28 class TemplateMultipleVariablesDialog(QDialog):
18 """ 29 """
19 Class implementing a dialog for entering multiple template variables. 30 Class implementing a dialog for entering multiple template variables.
20 """ 31 """
32
21 def __init__(self, variables, parent=None): 33 def __init__(self, variables, parent=None):
22 """ 34 """
23 Constructor 35 Constructor
24 36
25 @param variables list of template variable names (list of strings) 37 @param variables list of template variable names (list of strings)
26 @param parent parent widget of this dialog (QWidget) 38 @param parent parent widget of this dialog (QWidget)
27 """ 39 """
28 super().__init__(parent) 40 super().__init__(parent)
29 41
30 self.TemplateMultipleVariablesDialogLayout = QVBoxLayout(self) 42 self.TemplateMultipleVariablesDialogLayout = QVBoxLayout(self)
31 self.TemplateMultipleVariablesDialogLayout.setContentsMargins( 43 self.TemplateMultipleVariablesDialogLayout.setContentsMargins(6, 6, 6, 6)
32 6, 6, 6, 6)
33 self.TemplateMultipleVariablesDialogLayout.setSpacing(6) 44 self.TemplateMultipleVariablesDialogLayout.setSpacing(6)
34 self.TemplateMultipleVariablesDialogLayout.setObjectName( 45 self.TemplateMultipleVariablesDialogLayout.setObjectName(
35 "TemplateMultipleVariablesDialogLayout") 46 "TemplateMultipleVariablesDialogLayout"
47 )
36 self.setLayout(self.TemplateMultipleVariablesDialogLayout) 48 self.setLayout(self.TemplateMultipleVariablesDialogLayout)
37 49
38 # generate the scrollarea 50 # generate the scrollarea
39 self.variablesView = QScrollArea(self) 51 self.variablesView = QScrollArea(self)
40 self.variablesView.setObjectName("variablesView") 52 self.variablesView.setObjectName("variablesView")
41 self.TemplateMultipleVariablesDialogLayout.addWidget( 53 self.TemplateMultipleVariablesDialogLayout.addWidget(self.variablesView)
42 self.variablesView) 54
43
44 self.variablesView.setWidgetResizable(True) 55 self.variablesView.setWidgetResizable(True)
45 self.variablesView.setFrameStyle(QFrame.Shape.NoFrame) 56 self.variablesView.setFrameStyle(QFrame.Shape.NoFrame)
46 57
47 self.top = QWidget(self) 58 self.top = QWidget(self)
48 self.variablesView.setWidget(self.top) 59 self.variablesView.setWidget(self.top)
49 self.grid = QGridLayout(self.top) 60 self.grid = QGridLayout(self.top)
50 self.grid.setContentsMargins(0, 0, 0, 0) 61 self.grid.setContentsMargins(0, 0, 0, 0)
51 self.grid.setSpacing(6) 62 self.grid.setSpacing(6)
67 t = QLineEdit(self.top) 78 t = QLineEdit(self.top)
68 self.grid.addWidget(t, row, 1) 79 self.grid.addWidget(t, row, 1)
69 self.variablesEntries[var] = t 80 self.variablesEntries[var] = t
70 # add a spacer to make the entries aligned at the top 81 # add a spacer to make the entries aligned at the top
71 spacer = QSpacerItem( 82 spacer = QSpacerItem(
72 20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding) 83 20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding
84 )
73 self.grid.addItem(spacer, self.grid.rowCount(), 1) 85 self.grid.addItem(spacer, self.grid.rowCount(), 1)
74 self.variablesEntries[variables[0]].setFocus() 86 self.variablesEntries[variables[0]].setFocus()
75 self.top.adjustSize() 87 self.top.adjustSize()
76 88
77 # generate the buttons 89 # generate the buttons
78 layout1 = QHBoxLayout() 90 layout1 = QHBoxLayout()
79 layout1.setContentsMargins(0, 0, 0, 0) 91 layout1.setContentsMargins(0, 0, 0, 0)
80 layout1.setSpacing(6) 92 layout1.setSpacing(6)
81 layout1.setObjectName("layout1") 93 layout1.setObjectName("layout1")
82 94
83 spacer1 = QSpacerItem( 95 spacer1 = QSpacerItem(
84 40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum) 96 40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum
97 )
85 layout1.addItem(spacer1) 98 layout1.addItem(spacer1)
86 99
87 self.okButton = QPushButton(self) 100 self.okButton = QPushButton(self)
88 self.okButton.setObjectName("okButton") 101 self.okButton.setObjectName("okButton")
89 self.okButton.setDefault(True) 102 self.okButton.setDefault(True)
90 layout1.addWidget(self.okButton) 103 layout1.addWidget(self.okButton)
91 104
92 self.cancelButton = QPushButton(self) 105 self.cancelButton = QPushButton(self)
93 self.cancelButton.setObjectName("cancelButton") 106 self.cancelButton.setObjectName("cancelButton")
94 layout1.addWidget(self.cancelButton) 107 layout1.addWidget(self.cancelButton)
95 108
96 spacer2 = QSpacerItem( 109 spacer2 = QSpacerItem(
97 40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum) 110 40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum
111 )
98 layout1.addItem(spacer2) 112 layout1.addItem(spacer2)
99 113
100 self.TemplateMultipleVariablesDialogLayout.addLayout(layout1) 114 self.TemplateMultipleVariablesDialogLayout.addLayout(layout1)
101 115
102 # set the texts of the standard widgets 116 # set the texts of the standard widgets
103 self.setWindowTitle(self.tr("Enter Template Variables")) 117 self.setWindowTitle(self.tr("Enter Template Variables"))
104 self.okButton.setText(self.tr("&OK")) 118 self.okButton.setText(self.tr("&OK"))
111 self.cancelButton.clicked.connect(self.reject) 125 self.cancelButton.clicked.connect(self.reject)
112 126
113 def getVariables(self): 127 def getVariables(self):
114 """ 128 """
115 Public method to get the values for all variables. 129 Public method to get the values for all variables.
116 130
117 @return dictionary with the variable as a key and its value (string) 131 @return dictionary with the variable as a key and its value (string)
118 """ 132 """
119 values = {} 133 values = {}
120 for var, textEdit in list(self.variablesEntries.items()): 134 for var, textEdit in list(self.variablesEntries.items()):
121 try: 135 try:

eric ide

mercurial