1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#!/usr/bin/env python
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Form(QDialog):
def __init__(self,parent=None):
self.e = 1.60217646e-19
super(Form, self).__init__(parent)
# femto coulomb charge
self.chargefc = QDoubleSpinBox()
self.chargefc.setSingleStep(0.01)
self.chargefc.setRange(1e-4, 1e10)
self.chargefc.setValue(1)
self.chargefclabel = QLabel("Charge [fC]")
self.chargefc.setSuffix(" fC")
# electron charge
self.chargeelectron = QDoubleSpinBox()
self.chargeelectronlabel = QLabel("Charge [e]")
self.chargeelectron.setSuffix(" e")
self.chargeelectron.setRange(1e-4, 1e10)
self.chargeelectron.setValue(float(1e-15/self.e))
# yield
self.work = QDoubleSpinBox()
self.work.setSingleStep(0.1)
self.worklabel = QLabel("Yield")
self.work.setValue(15.6)
# electron charge
self.chargeelectronvolt = QDoubleSpinBox()
self.chargeelectronvoltlabel = QLabel("Charge [eV]")
self.chargeelectronvolt.setRange(1e-4, 1e10)
self.chargeelectronvolt.setSuffix(" eV")
self.chargeelectronvolt.setValue(float(1e-15/self.e)*15.6)
# layout
layout = QGridLayout()
layout.addWidget(self.chargefc, 0, 1)
layout.addWidget(self.chargefclabel, 0, 0)
layout.addWidget(self.chargeelectron, 1, 1)
layout.addWidget(self.chargeelectronlabel,1, 0)
layout.addWidget(self.work,2, 1)
layout.addWidget(self.worklabel, 2, 0)
layout.addWidget(self.chargeelectronvolt, 3, 1)
layout.addWidget(self.chargeelectronvoltlabel, 3, 0)
self.setLayout(layout)
self.chargefc.setFocus()
self.setWindowTitle("fc to eV")
# Connections
self.connect(self.chargefc,SIGNAL("valueChanged(double)"), self.updateUi_fc)
self.connect(self.chargeelectron,SIGNAL("valueChanged(double)"), self.updateUi_el)
self.connect(self.chargeelectronvolt,SIGNAL("valueChanged(double)"), self.updateUi_ev)
self.connect(self.work,SIGNAL("valueChanged(double)"), self.updateUi_w)
def updateUi_fc(self):
"update user interface"
# get values
fc = self.chargefc.value()
# derivation
electron = fc*1e-15/self.e
ev = electron*self.work.value()
# block signals
self.chargeelectron.blockSignals(True)
self.chargeelectronvolt.blockSignals(True)
# change values
self.chargeelectron.setValue(electron)
self.chargeelectronvolt.setValue(ev)
# unBlock signals
self.chargeelectron.blockSignals(False)
self.chargeelectronvolt.blockSignals(False)
def updateUi_el(self):
"update user interface"
# get values
el = self.chargeelectron.value()
# derivation
fc = (el/1e-15)*self.e
ev = el*self.work.value()
# block signals
self.chargefc.blockSignals(True)
self.chargeelectronvolt.blockSignals(True)
# change values
self.chargefc.setValue(fc)
self.chargeelectronvolt.setValue(ev)
# unBlock signals
self.chargefc.blockSignals(False)
self.chargeelectronvolt.blockSignals(False)
def updateUi_ev(self):
"update user interface"
# get values
ev = self.chargeelectronvolt.value()
# derivation
el = ev/self.work.value()
fc = (el/1e-15)*self.e
# block signals
self.chargefc.blockSignals(True)
self.chargeelectron.blockSignals(True)
# change values
self.chargefc.setValue(fc)
self.chargeelectron.setValue(el)
# unBlock signals
self.chargefc.blockSignals(False)
self.chargeelectron.blockSignals(False)
def updateUi_w(self):
"update user interface"
# derivation
ev = self.chargeelectron.value() * self.work.value()
# block signals
self.chargeelectronvolt.blockSignals(True)
# change values
self.chargeelectronvolt.setValue(ev)
# unBlock signals
self.chargeelectronvolt.blockSignals(False)
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_() |
Partager