1
2
3 try:
4 from empro.gui import SimpleDialog,Label,Ok,TableView, PushButton,Cancel, Icon, WF_WindowStaysOnTopHint
5 except:
6 pass
7
8 import adfiImportDialog
9
12 from empro import toolkit
13 def toStr(x, format='%s'):
14 if x is None:
15 return ''
16 return format % x
17 self.materialNames = toolkit.availableMaterials()
18 self.dialog = SimpleDialog(Ok | Cancel)
19 self.dialog.windowFlags &= ~WF_WindowStaysOnTopHint
20 self.dialog.setButtonText(Ok,'Add')
21 self.dialog.title = "Add a default material"
22 self.dialog.resize(800, 400)
23 self.dialog.onFinished = self.onFinished
24 self.dialog.layout.add(Label("Select one or more materials and press Add."))
25 self.table = TableView(self.dialog)
26 self.table.selectionBehavior = TableView.SelectRows
27 self.table.selectionMode = TableView.ExtendedSelection
28 self.table.onSelectionChanged = self.onSelectionChanged
29 self.table.onLayoutChanged = self.onLayoutChanged
30 materialDescriptions = [toolkit.defaultMaterialDescriptions[name] for name in self.materialNames]
31 materialDescriptionsMaxLen = max([len(name) for name in self.materialNames])
32
33 firstColumnTitleMargin = ' ' * (int(materialDescriptionsMaxLen*0.5)+4)
34 columnSpecs = [
35 ('name', '%sMaterial Name%s' % (firstColumnTitleMargin, firstColumnTitleMargin), '%s'),
36 ('permittivity', 'Relative Permittivity', '%g'),
37 ('lossTangent', 'Loss Tangent', '%g'),
38 ('conductivity', 'Conductivity [S/m]', '%g'),
39 ('nominalTemperature', 'Nominal Temperature [K]', '%g'),
40 ('linearTemperatureCoefficient', 'Linear Temperature Coefficient', '%g'),
41 ('quadraticTemperatureCoefficient', 'Quadratic Temperature Coefficient', '%g'),
42 ('density', 'Density [kg/m**3]', '%g'),
43 ('heatCapacity', 'Heat Capacity [J/kg/K]', '%g'),
44 ('thermalConductivity', 'Thermal Conductivity [W/m/K]', '%g'),
45 ('thermalConductivityThroughPlane', 'Through Plane Thermal Conductivity [W/m/K]', '%g')
46 ]
47 for k, (attr, title, format) in enumerate(columnSpecs):
48 self.table.setColumn(k, [toStr(desc.__dict__.get(attr), format) for desc in materialDescriptions])
49 try:
50 from empro.gui import _recolorIcon
51 except ImportError:
52 pass
53 else:
54 materialIcon = Icon( ":selectable/MaterialDefinition.ico" )
55 for row, desc in enumerate(materialDescriptions):
56 self.table.setDecoration(row, 0, _recolorIcon( materialIcon, desc.color ) )
57 self.table.headers = zip(*columnSpecs)[1]
58 self.table.resizeRowsToContents()
59 self.table.resizeColumnsToContents()
60 self.dialog.layout.add(self.table)
61 self.dialog.show(False)
62
64 self.selectedMaterialNames = [self.table.data(x,0) for x in self.table.selectedRows()]
65
66
67 w, h = self.dialog.size()
68 self.dialog.resize(w + 2, h)
69 self.dialog.resize(w, h)
70
72 self.selectedMaterialNames = [self.table.data(x,0) for x in self.table.selectedRows()]
73
74
75 w, h = self.dialog.size()
76 self.dialog.resize(w + 2, h)
77 self.dialog.resize(w, h)
78
91
95
97 - def __init__(self,iText,iTitle = "Message",iModal=False):
98 self.dialog = SimpleDialog(Ok)
99 self.dialog.title = iTitle
100 self.label = Label(iText)
101 self.dialog.layout.add(self.label)
102 self.dialog.show(iModal)
103
105 - def __init__(self,iText,iTitle = "Message"):
106 self.dialog = SimpleDialog(Ok+Cancel)
107 self.dialog.title = iTitle
108 self.label = Label(iText)
109 self.dialog.layout.add(self.label)
110 self.dialog.setButtonText(Ok,'Yes')
111 self.dialog.setButtonText(Cancel,'No')
112 self.dialog.onFinished = self.storeReturn
114 """
115 Returns True when 'Yes' was selected, False when 'No' was selected.
116 """
117 self.dialog.show(True)
118 return self.rvalue
121