Package chianti :: Package Gui :: Package gui_qt :: Module gui
[hide private]
[frames] | no frames]

Source Code for Module chianti.Gui.gui_qt.gui

  1  ''' 
  2  PyQt4 widget selection dialogs 
  3  ''' 
  4  import sys,  os 
  5  from PyQt4 import QtGui 
  6  import chianti 
  7  from chianti.Gui.gui_qt.ui import * 
  8  ' qt4 selection dialogs' 
  9   
10 -def chpicker(dir, filter='*.*', label='ChiantiPy'):
11 '''Select a filename using a Qt gui dialog.''' 12 app=QtGui.QApplication(sys.argv) 13 a=QtGui.QFileDialog() 14 a.setDirectory(dir) 15 a.setFilter(filter) 16 # mylabel=QtCore.QString('some label') 17 # a.setLabelText(mylabel) 18 a.setWindowTitle(label) 19 a.setModal(True) 20 a.exec_() 21 qfilename=a.selectedFiles() 22 return str(qfilename[0])
23 # 24 #
25 -class selectorDialog(QtGui.QDialog):
26 '''Make a single or multiple selection from a list of items. 27 28 expects the input of an array of items, will select one or more'''
29 - def __init__(self, items, label=None , parent=None):
30 # if using the Qt4Agg backend for matplotlib, the following line needs to be comment out 31 # app=QtGui.QApplication(sys.argv) 32 QtGui.QDialog.__init__(self) 33 self.ui = Ui_selectorDialogForm() 34 self.ui.setupUi(self) 35 self.ui.listWidget.setSelectionMode(QtGui.QListWidget.MultiSelection) 36 if label == None: 37 self.setWindowTitle('ChiantiPy') 38 else: 39 self.setWindowTitle('ChiantiPy - '+label) 40 imagefile = os.path.join(chianti.__path__[0], "images/chianti2.png") 41 self.setWindowIcon(QtGui.QIcon(imagefile)) 42 for anitem in items: 43 # print ' item = ', anitem, QtCore.QString(anitem) 44 self.ui.listWidget.addItem(str(anitem)) 45 self.exec_()
46
47 - def accept(self):
48 # print ' selector button pushed' 49 nitems = self.ui.listWidget.count() 50 # print ' nitems = ', nitems 51 self.selectedIndex=[] 52 self.selectedText=[] 53 for i in range(nitems): 54 anitem = self.ui.listWidget.item(i) 55 # print 'selected? = ', anitem.isSelected() 56 if anitem.isSelected(): 57 # print ' item = ' , str(anitem.text()) 58 self.selectedText.append(str(anitem.text())) 59 self.selectedIndex.append(i) 60 self.done(1)
61
62 - def reject(self):
63 # print ' cancel button pushed' 64 self.selectedIndex = None 65 self.selectedText = None 66 self.done(1)
67 # 68 #from choice2DialogForm import * 69 #
70 -class choice2Dialog(QtGui.QDialog):
71 '''Make a single or multiple selection from a list of items and another 72 single or multiple selection from the same list. 73 74 Useful for picking numerators and denominators. 75 76 expects the input of an array of items, will select one or more from both widgets.'''
77 - def __init__(self, items, label=None , parent=None):
78 # if using the Qt4Agg backend for matplotlib, the following line needs to be comment out 79 # app=QtGui.QApplication(sys.argv) 80 QtGui.QDialog.__init__(self) 81 # app=QtGui.QApplication(sys.argv) 82 self.ui = Ui_choice2DialogForm() 83 self.ui.setupUi(self) 84 if label == None: 85 self.setWindowTitle('ChiantiPy') 86 else: 87 self.setWindowTitle('ChiantiPy - '+label) 88 self.setWindowIcon(QtGui.QIcon('images/chianti2.png')) 89 for anitem in items: 90 # print ' item = ', anitem, QtCore.QString(anitem) 91 self.ui.numListWidget.addItem(str(anitem)) 92 self.ui.denListWidget.addItem(str(anitem)) 93 self.exec_()
94 #
95 - def accept(self):
96 nitems = self.ui.numListWidget.count() 97 self.numIndex=[] 98 self.numText=[] 99 for i in range(nitems): 100 anitem = self.ui.numListWidget.item(i) 101 # print 'selected? = ', anitem.isSelected() 102 if anitem.isSelected(): 103 # print ' item = ' , str(anitem.text()) 104 self.numText.append(str(anitem.text())) 105 self.numIndex.append(i) 106 self.denIndex=[] 107 self.denText=[] 108 for i in range(nitems): 109 anitem = self.ui.denListWidget.item(i) 110 # print 'selected? = ', anitem.isSelected() 111 if anitem.isSelected(): 112 # print ' item = ' , str(anitem.text()) 113 self.denText.append(str(anitem.text())) 114 self.denIndex.append(i) 115 self.done(1)
116
117 - def reject(self):
118 print(' cancel button pushed') 119 self.done(1)
120