def __init__(self, controller, config, parent=None): super(LeadDefinitionWidget, self).__init__(parent) self.config = config self.controller = controller # Subwidgets self.label_edit = QtGui.QLineEdit() self.x_size_edit = QtGui.QLineEdit() self.y_size_edit = QtGui.QLineEdit() self.type_box = QtGui.QComboBox() for label, electrode_type in config['lead_types'].items(): if 'u' not in label: self.type_box.addItem("{}: {name}".format(label, **electrode_type)) self.micro_box = QtGui.QComboBox() for micro_lead_type in sorted(config['micros'].keys()): self.micro_box.addItem(micro_lead_type) self.submit_button = QtGui.QPushButton("Submit") self.delete_button = QtGui.QPushButton("Delete") self.close_button = QtGui.QPushButton("Confirm") self.leads_list = QtGui.QListWidget() self.add_callbacks() self.set_layout() self.set_tab_order() self.set_shortcuts() self._leads = OrderedDict()
def create_control(self, parent): """ Creates the initial editor control. """ self.control = QtGui.QComboBox() QtCore.QObject.connect(self.control, QtCore.SIGNAL('activated(QString)'), self.update_object)
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = QtGui.QWidget() layout = QtGui.QVBoxLayout(self.control) layout.setContentsMargins(0, 0, 0, 0) # Add the standard font control: self._font = font = QtGui.QLineEdit(self.str_value) font.editingFinished.connect(self.update_object) layout.addWidget(font) # Add all of the font choice controls: layout2 = QtGui.QHBoxLayout() self._facename = control = QtGui.QFontComboBox() control.setEditable(False) control.currentFontChanged.connect(self.update_object_parts) layout2.addWidget(control) self._point_size = control = QtGui.QComboBox() control.addItems(PointSizes) control.currentIndexChanged.connect(self.update_object_parts) layout2.addWidget(control) # These don't have explicit controls. self._bold = self._italic = False layout.addLayout(layout2)
def create_combo_box(self): """ Returns the QComboBox used for the editor control. """ control = QtGui.QComboBox() control.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) control.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed) return control
def __init__(self, settings): QtGui.QMainWindow.__init__(self) self.frame = QtGui.QFrame() layout = QtGui.QVBoxLayout(self.frame) # tabs tabs = QtGui.QTabWidget() layout.addWidget(tabs) self.settings = settings self.copied_settings = copy.deepcopy(self.settings) self.fields = {} # settings for title, dic in self.copied_settings.iteritems(): self.fields[title] = {} tabFrame = QtGui.QFrame() tabLayout = QtGui.QFormLayout(tabFrame) tabs.addTab(tabFrame, "%s" % title) for k, v in dic.iteritems(): if type(v) == int: field = QtGui.QSpinBox() field.setValue(v) field.setMaximum(1000) field.setMinimum(1) field.valueChanged.connect(self.updateSettings) elif type(v) == float: field = QtGui.QLineEdit() field.setText(str(v)) field.editingFinished.connect(self.updateSettings) elif type(v) == list: field = QtGui.QComboBox() activeItem = v[0] l = v[1] assert type(l) == list for item in l: field.addItem(str(item)) field.setCurrentIndex(activeItem) field.currentIndexChanged.connect(self.updateSettings) else: raise Exception("BUG ??") self.fields[title][k] = field tabLayout.addRow(QtGui.QLabel("%s:" % k), field) # "OK" and "Cancel" buttons buttonFrame = QtGui.QFrame() layout.addWidget(buttonFrame) buttonLayout = QtGui.QHBoxLayout(buttonFrame) okButton = QtGui.QPushButton("Apply") okButton.clicked.connect(self.ok) buttonLayout.addWidget(okButton) closeButton = QtGui.QPushButton("Close") closeButton.clicked.connect(self.cancel) buttonLayout.addWidget(closeButton) self.setCentralWidget(self.frame) self.setWindowTitle("Settings") self.show()
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = control = QtGui.QComboBox() control.setEditable(True) control.setInsertPolicy(QtGui.QComboBox.InsertAtTop) if self.factory.entries > 0: control.model().rowsInserted.connect(self._truncate) if self.factory.auto_set: control.editTextChanged.connect(self.update_object) else: control.activated[str].connect(self.update_object) self.set_tooltip()
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self.control = control = QtGui.QComboBox() control.setEditable(True) control.setInsertPolicy(QtGui.QComboBox.InsertAtTop) if self.factory.entries > 0: signal = QtCore.SIGNAL( 'rowsInserted(const QModelIndex&, int, int)') QtCore.QObject.connect(control.model(), signal, self._truncate) if self.factory.auto_set: signal = QtCore.SIGNAL('editTextChanged(QString)') else: signal = QtCore.SIGNAL('activated(QString)') QtCore.QObject.connect(control, signal, self.update_object) self.set_tooltip()
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ factory = self.factory if factory.name != '': self._object, self._name, self._value = \ self.parse_extended_name( factory.name ) # Create a panel to hold the object trait's view: if factory.editable: self.control = self._panel = parent = QtGui.QWidget() # Build the instance selector if needed: selectable = factory.selectable droppable = factory.droppable items = self.items for item in items: droppable |= item.is_droppable() selectable |= item.is_selectable() if selectable: self._object_cache = {} item = self.item_for(self.value) if item is not None: self._object_cache[id(item)] = self.value self._choice = QtGui.QComboBox() QtCore.QObject.connect(self._choice, QtCore.SIGNAL('activated(QString)'), self.update_object) self.set_tooltip(self._choice) if factory.name != '': self._object.on_trait_change(self.rebuild_items, self._name, dispatch='ui') self._object.on_trait_change(self.rebuild_items, self._name + '_items', dispatch='ui') factory.on_trait_change(self.rebuild_items, 'values', dispatch='ui') factory.on_trait_change(self.rebuild_items, 'values_items', dispatch='ui') self.rebuild_items() elif droppable: self._choice = QtGui.QLineEdit() self._choice.setReadOnly(True) self.set_tooltip(self._choice) if droppable: self._choice.SetDropTarget(PythonDropTarget(self)) orientation = OrientationMap[factory.orientation] if orientation is None: orientation = self.orientation if (selectable or droppable) and factory.editable: layout = QtGui.QBoxLayout(orientation, parent) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._choice) if orientation == QtGui.QBoxLayout.TopToBottom: hline = QtGui.QFrame() hline.setFrameShape(QtGui.QFrame.HLine) hline.setFrameShadow(QtGui.QFrame.Sunken) layout.addWidget(hline) self.create_editor(parent, layout) elif self.control is None: if self._choice is None: self._choice = QtGui.QComboBox() QtCore.QObject.connect(self._choice, QtCore.SIGNAL('activated(QString)'), self.update_object) self.control = self._choice else: layout = QtGui.QBoxLayout(orientation, parent) layout.setContentsMargins(0, 0, 0, 0) self.create_editor(parent, layout) # Synchronize the 'view' to use: # fixme: A normal assignment can cause a crash (for unknown reasons) in # some cases, so we make sure that no notifications are generated: self.trait_setq(view=factory.view) self.sync_value(factory.view_name, 'view', 'from')
def create_control(self, parent): """ Creates the initial editor control. """ self.control = QtGui.QComboBox() self.control.activated[int].connect(self.update_object)
def __init__(self, tddftb, parent=None): self.tddftb = tddftb QtGui.QWidget.__init__(self, parent) layout = QtGui.QVBoxLayout(self) # upperFrame = QtGui.QFrame() layout.addWidget(upperFrame) upperLayout = QtGui.QHBoxLayout(upperFrame) # table with MOs and Kohn-Sham energies tableFrame = QtGui.QFrame() upperLayout.addWidget(tableFrame) tableLayout = QtGui.QVBoxLayout(tableFrame) tableLayout.addWidget(QtGui.QLabel("Molecular Orbitals:")) self.tableMOs = QtGui.QTableWidget() self.tableMOs.setToolTip( "Select a row to highlight the respective orbital in the density of states" ) self.tableMOs.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.tableMOs.itemSelectionChanged.connect(self.plotDOS) tableLayout.addWidget(self.tableMOs) cubeFrame = QtGui.QFrame() tableLayout.addWidget(cubeFrame) cubeLayout = QtGui.QHBoxLayout(cubeFrame) self.ppbGrid = QtGui.QComboBox() self.ppbGrid.addItems( ["crude: 1.0", "coarse: 2.0", "medium: 3.0", "fine: 4.0"]) self.ppbGrid.setCurrentIndex(1) self.ppbGrid.setToolTip( "The number of points per bohr determines the resolution of the grid on which the cubes are calculated" ) self.ppbGrid.currentIndexChanged.connect(self.recalculateCubes) cubeLayout.addWidget(self.ppbGrid) calcCubesButton = QtGui.QPushButton("Calc. cubes") calcCubesButton.setToolTip("Calculate cubes for the selected orbitals") calcCubesButton.clicked.connect(self.calculateCubes) cubeLayout.addWidget(calcCubesButton) # MOs moFrame = QtGui.QFrame() upperLayout.addWidget(moFrame) moLayout = QtGui.QVBoxLayout(moFrame) self.moLabel = QtGui.QLabel("Ground State:") moLayout.addWidget(self.moLabel) moTab = QtGui.QTabWidget() moLayout.addWidget(moTab) # 3D cubes - MOs self.bs = AtomicBasisSet(self.tddftb.dftb2.atomlist) self.molecularOrbitalViewer = QCubeViewerWidget() self.molecularOrbitalViewer.setIsoValue(0.02) moTab.addTab(self.molecularOrbitalViewer, "3D Molecular Orbital") # 3D cubes - MOs # Mulliken Charges self.chargesViewer = QCubeViewerWidget() moTab.addTab(self.chargesViewer, "Mulliken Charges") atomlist = self.tddftb.dftb2.getGeometry() partial_charges = -self.tddftb.dftb2.getPartialCharges() self.chargesViewer.setGeometriesAndCharges([atomlist], [partial_charges]) self.chargesViewer.selectShowOptions(options=["charges"]) # figure with DOS dosFrame = QtGui.QFrame() layout.addWidget(dosFrame) dosLayout = QtGui.QVBoxLayout(dosFrame) self.figDOS = Figure() self.canvasDOS = FigureCanvas(self.figDOS) dosLayout.addWidget(self.canvasDOS) NavigationToolbar(self.canvasDOS, dosFrame, coordinates=True) # controls controlFrame = QtGui.QFrame() dosLayout.addWidget(controlFrame) controlLayout = QtGui.QHBoxLayout(controlFrame) self.energyUnits = QtGui.QComboBox() self.energyUnits.addItems(["Hartree", "eV", "cm-1"]) self.energyUnits.currentIndexChanged.connect(self.plotDOS) controlLayout.addWidget(QtGui.QLabel("units:")) controlLayout.addWidget(self.energyUnits) controlLayout.addWidget(QtGui.QLabel("broadening:")) self.broadening = QtGui.QLineEdit() self.broadening.setText("0.01") self.broadening.editingFinished.connect(self.plotDOS) self.broadening.setToolTip( "The sticks are convolved with a Gaussian to simulated a temperature broadened DOS" ) controlLayout.addWidget(self.broadening) # load KS orbitals tab = self.tableMOs dftb = self.tddftb.dftb2 orbe = dftb.getKSEnergies() f = dftb.getOccupation() self.H**O, self.LUMO = dftb.getFrontierOrbitals() tab.setRowCount(len(orbe)) headers = [ "N", "name", "occ.", "orb. en. / hartree", "orb. en. / eV", "Cube" ] tab.setColumnCount(len(headers)) tab.setHorizontalHeaderLabels(headers) self.mo_names = [] for i in range(0, len(orbe)): if i == self.H**O: name = "H**O" elif i == self.LUMO: name = "LUMO" else: name = "" self.mo_names.append(name) row = [str.rjust(str(i+1),5), \ str.rjust(name,5), str.rjust(str(f[i]),5), str.rjust("%.7f" % orbe[i],20), \ str.rjust("%.7f" % (orbe[i]*AtomicData.hartree_to_eV), 17) ] for j, r in enumerate(row): tab.setItem(i, j, QtGui.QTableWidgetItem("%s" % r)) tab.resizeColumnsToContents() self.plotDOS() # cubes with MOs self.mo_cubes = {} # select H**O self.tableMOs.setCurrentCell(self.H**O, 0)
def __init__(self, tddftb, parent=None): self.tddftb = tddftb QtGui.QWidget.__init__(self, parent) layout = QtGui.QVBoxLayout(self) # upperFrame = QtGui.QFrame() layout.addWidget(upperFrame) upperLayout = QtGui.QHBoxLayout(upperFrame) # table with excitation energies and states tableFrame = QtGui.QFrame() upperLayout.addWidget(tableFrame) tableLayout = QtGui.QVBoxLayout(tableFrame) tableLayout.addWidget(QtGui.QLabel("Excited States:")) self.tableStates = QtGui.QTableWidget() self.tableStates.setToolTip( "Select a row to highlight the respective state in the absorption spectrum" ) self.tableStates.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows) self.tableStates.itemSelectionChanged.connect(self.plotSpectrum) tableLayout.addWidget(self.tableStates) cubeFrame = QtGui.QFrame() tableLayout.addWidget(cubeFrame) cubeLayout = QtGui.QHBoxLayout(cubeFrame) self.ppbGrid = QtGui.QComboBox() self.ppbGrid.addItems( ["crude: 1.0", "coarse: 2.0", "medium: 3.0", "fine: 4.0"]) self.ppbGrid.setCurrentIndex(1) self.ppbGrid.setToolTip( "The number of points per bohr determines the resolution of the grid on which the cubes are calculated" ) self.ppbGrid.currentIndexChanged.connect(self.recalculateCubes) cubeLayout.addWidget(self.ppbGrid) calcCubesButton = QtGui.QPushButton("Calc. cubes") calcCubesButton.setToolTip( "Calculate cubes with the transition densities for the selected states" ) calcCubesButton.clicked.connect(self.calculateCubes) cubeLayout.addWidget(calcCubesButton) # transition densities tdenseFrame = QtGui.QFrame() upperLayout.addWidget(tdenseFrame) tdenseLayout = QtGui.QVBoxLayout(tdenseFrame) self.tdenseLabel = QtGui.QLabel("Excitated State:") tdenseLayout.addWidget(self.tdenseLabel) tdenseTab = QtGui.QTabWidget() tdenseLayout.addWidget(tdenseTab) # 3D cubes - transition density self.bs = AtomicBasisSet(self.tddftb.dftb2.atomlist) self.transitionDensityViewer = QCubeViewerWidget() tdenseTab.addTab(self.transitionDensityViewer, "3D Transition Density") # 3D cubes - density difference self.bs_aux = AuxiliaryBasisSet(self.tddftb.dftb2.atomlist, self.tddftb.dftb2.hubbard_U) self.differenceDensityViewer = QCubeViewerWidget() tdenseTab.addTab(self.differenceDensityViewer, "3D Difference Density") # 2D occ-virt plane exvec2dFrame = QtGui.QFrame() exvec2dLayout = QtGui.QVBoxLayout(exvec2dFrame) self.figExvec = Figure() self.canvasExvec = FigureCanvas(self.figExvec) exvec2dLayout.addWidget(self.canvasExvec) tdenseTab.addTab(exvec2dFrame, "2D Excitation Vector") NavigationToolbar(self.canvasExvec, exvec2dFrame, coordinates=True) # atomic charges in the excited state self.chargesViewer = QCubeViewerWidget() tdenseTab.addTab(self.chargesViewer, "Partial Charges") atomlist = self.tddftb.dftb2.getGeometry() # partial_charges = -self.tddftb.dftb2.getPartialCharges() # self.chargesViewer.setGeometriesAndCharges([atomlist], [partial_charges]) self.chargesViewer.selectShowOptions(options=["charges"]) # transition charges between ground and excited state self.trans_chargesViewer = QCubeViewerWidget() tdenseTab.addTab(self.trans_chargesViewer, "Transition Charges") atomlist = self.tddftb.dftb2.getGeometry() # # for S0->S0 transition, the transition charges are equal to the partial charges # transition_charges = -self.tddftb.dftb2.getPartialCharges() # self.trans_chargesViewer.setGeometriesAndCharges([atomlist], [transition_charges]) self.trans_chargesViewer.selectShowOptions( options=["charges", "transition charges"]) # figure with spectrum spectrumFrame = QtGui.QFrame() layout.addWidget(spectrumFrame) spectrumLayout = QtGui.QVBoxLayout(spectrumFrame) self.figSpectrum = Figure() self.canvasSpectrum = FigureCanvas(self.figSpectrum) spectrumLayout.addWidget(self.canvasSpectrum) NavigationToolbar(self.canvasSpectrum, spectrumFrame, coordinates=True) # controls controlFrame = QtGui.QFrame() spectrumLayout.addWidget(controlFrame) controlLayout = QtGui.QHBoxLayout(controlFrame) self.energyUnits = QtGui.QComboBox() self.energyUnits.addItems(["Hartree", "eV", "nm", "cm-1"]) self.energyUnits.currentIndexChanged.connect(self.plotSpectrum) controlLayout.addWidget(QtGui.QLabel("units:")) controlLayout.addWidget(self.energyUnits) controlLayout.addWidget(QtGui.QLabel("broadening:")) self.broadening = QtGui.QLineEdit() self.broadening.setText("0.0") self.broadening.editingFinished.connect(self.plotSpectrum) self.broadening.setToolTip( "The stick spectrum is convolved with a Gaussian to simulated a temperature broadened spectrum" ) controlLayout.addWidget(self.broadening) # load spectrum nr_dominant_ex = 2 tab = self.tableStates tab.setRowCount(len(tddftb.Omega)) headers = [ "N", "Spin", "Sym", "exc. en. / hartree", "exc. en. / eV", "exc. en. / nm", "osc. strength", "Lambda diagn.", "Cube" ] tab.setColumnCount(len(headers)) tab.setHorizontalHeaderLabels(headers) for I in range(0, len(tddftb.Omega)): row = [str.rjust(str(I+1),5), \ tddftb.multiplicity, \ str.rjust(tddftb.Irreps[I], 3), \ str.rjust("%.7f" % tddftb.Omega[I],20), \ str.rjust("%.7f" % (tddftb.Omega[I]*AtomicData.hartree_to_eV), 17), \ str.rjust("%.7f" % (AtomicData.hartree_to_nm / tddftb.Omega[I]), 17), \ str.rjust("%.7f" % tddftb.oscillator_strength[I], 12), \ str.rjust("%.4f" % tddftb.Lambda2[I], 7)] for j, r in enumerate(row): tab.setItem(I, j, QtGui.QTableWidgetItem("%s" % r)) tab.resizeColumnsToContents() self.plotSpectrum() # cubes with transition densities and difference densities for each state if calculated self.tdense_cubes = {} self.difdense_cubes = {} self.partial_charges = {} # partial charges on excited states
def __init__(self, ): super(Main, self).__init__() self.ui = loadUiWidget( os.path.join(os.path.dirname(os.path.abspath(__file__)), "window2.ui")) self.setCentralWidget(self.ui) self.canvases = [] self.trajdirs = [] self.dt = 0.0 self.geometries = [] self.particle_hole_charges = [] self.ui.trajSelection.itemSelectionChanged.connect( self.changeTrajectory) # load Trajectories dyndir = "./" if len(sys.argv) > 1: dyndir = sys.argv[1] self.ui.dirBrowser.setText(dyndir) self.ui.dirBrowser.returnPressed.connect(self.fetchURL) self.ui.openButton.clicked.connect(self.openDirectory) # save movie self.ui.movieButton.clicked.connect(self.renderMovie) self.stop = False # plots import matplotlib.pyplot as plt cmap = plt.get_cmap('gnuplot') self.colors = ['black', 'red', 'green', 'blue', 'orange', 'm' ] + [cmap(f) for f in np.linspace(0.4, 1.0, 10)] self.energiesAxis = self.addTab(self.ui.energiesLayout) self.coefficientsAxis = self.addTab(self.ui.coefficientsLayout) self.couplingsAxis = self.addTab(self.ui.couplingsLayout) self.currEnergyAxis = self.addTab(self.ui.currEnergyLayout) self.currStateAxis = self.addTab(self.ui.currStateLayout) self.populationsAxis = self.addTab(self.ui.populationsLayout) self.axes = [ self.energiesAxis, self.coefficientsAxis, self.couplingsAxis, self.currEnergyAxis, self.currStateAxis ] self.objects = [] # Window with geometries self.geometryViewer = QCubeViewerWidget() self.geometryViewer.setAnimation(True) #self.geometryViewer.hideIsoControls() self.geometryViewer.selectShowOptions(options=["charges"]) self.ui.viewerWidgetLayout.addWidget(self.geometryViewer) """ self.glWidget = self.newGLWidget() self.mol = Avogadro.molecules.addMolecule() self.objects.append( self.mol ) self.glWidget.molecule = self.mol self.ui.viewerWidgetLayout.addWidget(Avogadro.toPyQt(self.glWidget)) """ # self.ui.animationSlider.valueChanged.connect(self.showMolecules) self.loadTrajectories(dyndir) # self.pictureAorDiab = QtGui.QComboBox() self.pictureAorDiab.addItems(["adiabatic", "local diabatic"]) self.pictureAorDiab.setToolTip( "Choose whether energies and couplings should be shown in the adiabatic or the local diabatic picture." ) self.pictureAorDiab.currentIndexChanged.connect(self.switchPicture) self.picture = self.pictureAorDiab.currentText() self.ui.gridLayout.addWidget(self.pictureAorDiab, 1, 0)
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ factory = self.factory if factory.name != "": self._object, self._name, self._value = self.parse_extended_name( factory.name ) # Create a panel to hold the object trait's view: if factory.editable: self.control = self._panel = parent = QtGui.QWidget() # Build the instance selector if needed: selectable = factory.selectable droppable = factory.droppable items = self.items for item in items: droppable |= item.is_droppable() selectable |= item.is_selectable() if selectable: self._object_cache = {} item = self.item_for(self.value) if item is not None: self._object_cache[id(item)] = self.value self._choice = QtGui.QComboBox() self._choice.activated.connect(self.update_object) self.set_tooltip(self._choice) if factory.name != "": self._object.observe( self.rebuild_items, self._name + ".items", dispatch="ui" ) factory.observe( self.rebuild_items, "values.items", dispatch="ui" ) self.rebuild_items() elif droppable: self._choice = QtGui.QLineEdit() self._choice.setReadOnly(True) self.set_tooltip(self._choice) if droppable: # Install EventFilter on control to handle DND events. drop_event_filter = _DropEventFilter(self.control) self.control.installEventFilter(drop_event_filter) orientation = OrientationMap[factory.orientation] if orientation is None: orientation = self.orientation if (selectable or droppable) and factory.editable: layout = QtGui.QBoxLayout(orientation, parent) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._choice) if orientation == QtGui.QBoxLayout.TopToBottom: hline = QtGui.QFrame() hline.setFrameShape(QtGui.QFrame.HLine) hline.setFrameShadow(QtGui.QFrame.Sunken) layout.addWidget(hline) self.create_editor(parent, layout) elif self.control is None: if self._choice is None: self._choice = QtGui.QComboBox() self._choice.activated[int].connect(self.update_object) self.control = self._choice else: layout = QtGui.QBoxLayout(orientation, parent) layout.setContentsMargins(0, 0, 0, 0) self.create_editor(parent, layout) # Synchronize the 'view' to use: # fixme: A normal assignment can cause a crash (for unknown reasons) in # some cases, so we make sure that no notifications are generated: self.trait_setq(view=factory.view) self.sync_value(factory.view_name, "view", "from")