Package empro :: Package toolkit :: Package gui
[frames] | no frames]

Source Code for Package empro.toolkit.gui

  1  # Copyright 1983-2012 Keysight Technologies, Inc  
  2  # some handy ui functionality 
  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   
10 -class AddDefaultMaterialDialog:
11 - def __init__(self):
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 # calculating first column margin to fix the issue of not properly sized column width 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
63 - def onLayoutChanged(self):
64 self.selectedMaterialNames = [self.table.data(x,0) for x in self.table.selectedRows()] 65 # ugly workaround: the table doesn't repaint itself properly when changing the selection. 66 # to work around it, we wiggle the window's size a bit. 67 w, h = self.dialog.size() 68 self.dialog.resize(w + 2, h) 69 self.dialog.resize(w, h)
70
71 - def onSelectionChanged(self):
72 self.selectedMaterialNames = [self.table.data(x,0) for x in self.table.selectedRows()] 73 # ugly workaround: the table doesn't repaint itself properly when changing the selection. 74 # to work around it, we wiggle the window's size a bit. 75 w, h = self.dialog.size() 76 self.dialog.resize(w + 2, h) 77 self.dialog.resize(w, h)
78
79 - def onFinished(self, result):
80 if result != 1: 81 return 82 import empro.toolkit 83 empro.core.ApplicationPreferences.setPreference("EXPAND_MATERIAL_LIST_ON_EVERY_ADD",True) 84 for name in self.selectedMaterialNames: 85 materialToAdd = empro.toolkit.defaultMaterial(name) 86 empro.activeProject.materials().append(materialToAdd) 87 projectUpdated = True 88 if projectUpdated and hasattr(empro.gui, "activeProjectView"): 89 empro.gui._projectUpdatedNoUndo() 90 empro.core.ApplicationPreferences.setPreference("EXPAND_MATERIAL_LIST_ON_EVERY_ADD",False)
91
92 -def showAddDefaultMaterial():
93 #availableMaterials() 94 d = AddDefaultMaterialDialog()
95
96 -class InfoDialog:
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
104 -class YesNoDialog:
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
113 - def show(self):
114 """ 115 Returns True when 'Yes' was selected, False when 'No' was selected. 116 """ 117 self.dialog.show(True) 118 return self.rvalue
119 - def storeReturn(self,iValue):
120 self.rvalue = iValue
121