diff options
author | Onderwaater <onderwaa@esrf.fr> | 2015-10-08 11:44:39 +0200 |
---|---|---|
committer | Onderwaater <onderwaa@esrf.fr> | 2015-10-08 11:44:39 +0200 |
commit | 753f1cbb2482ff75a183a53b7bbd3892ee3dd3d7 (patch) | |
tree | f955bc46b00835e6ab8d13ff29ef9174d60e072b | |
parent | 6c2085e33407a859c8d30fcd8e3b2e46d1214b9f (diff) | |
parent | 1287cace9b52364be4147ace5367ae0826267726 (diff) |
Merge pull request #8 from RNencib/patch-1
Update processgui.py
-rwxr-xr-x | processgui.py | 294 |
1 files changed, 190 insertions, 104 deletions
diff --git a/processgui.py b/processgui.py index 34402b2..e6d831e 100755 --- a/processgui.py +++ b/processgui.py @@ -1,5 +1,5 @@ """ -BINoculars gui for data processing +BINoculars gui for data processing Created on 2015-06-04 author: Remy Nencib (remy.nencib@esrf.r) """ @@ -7,8 +7,9 @@ author: Remy Nencib (remy.nencib@esrf.r) import sys import os import glob +import traceback from PyQt4 import QtGui, QtCore, Qt -import sys, os +import sys,os import itertools import inspect import glob @@ -16,6 +17,9 @@ import BINoculars.util, BINoculars.main import time + + +#--------------------------------------------CREATE MAIN WINDOW---------------------------------------- class Window(QtGui.QMainWindow): def __init__(self): @@ -23,13 +27,16 @@ class Window(QtGui.QMainWindow): self.initUI() self.tab_widget = QtGui.QTabWidget(self) self.setCentralWidget(self.tab_widget) + #add the close button for tabs close = self.tab_widget.setTabsClosable(True) self.tab_widget.tabCloseRequested.connect(self.close_tab) + #method for close tabs def close_tab(self, tab): self.tab_widget.removeTab(tab) def initUI(self): + #we create the menu bar openFile = QtGui.QAction('Open', self) openFile.setShortcut('Ctrl+O') openFile.setStatusTip('Open new File') @@ -43,41 +50,129 @@ class Window(QtGui.QMainWindow): Create = QtGui.QAction('Create', self) Create.setStatusTip('Create Configfile') Create.triggered.connect(self.New_Config) - + + menubar = self.menuBar() fileMenu = menubar.addMenu('&File') fileMenu.addAction(openFile) fileMenu.addAction(saveFile) fileMenu = menubar.addMenu('&New Configfile') fileMenu.addAction(Create) - fileMenu = menubar.addMenu('&HELP') + #we configue the main windows palette = QtGui.QPalette() palette.setColor(QtGui.QPalette.Background,QtCore.Qt.gray) self.setPalette(palette) - self.setGeometry(250, 100,500,500) + self.setGeometry(50, 100,700,700) self.setWindowTitle('Binoculars processgui') - self.setWindowIcon(QtGui.QIcon('binoculars.png')) self.show() + self.ListCommand = QtGui.QTableWidget(1, 2, self) + self.ListCommand.verticalHeader().setVisible(True) + self.ListCommand.horizontalHeader().setVisible(False) + self.ListCommand.horizontalHeader().stretchSectionCount() + self.ListCommand.setColumnWidth(0, 80) + self.ListCommand.setColumnWidth(1, 80) + self.ListCommand.setRowCount(0) + self.buttonDelete = QtGui.QPushButton('Delete',self) + self.connect(self.buttonDelete, QtCore.SIGNAL("clicked()"), self.removeConf) + self.process = QtGui.QPushButton('run',self) + self.process.setStyleSheet("background-color: darkred") + self.connect(self.process, QtCore.SIGNAL("clicked()"),self.run) + + + self.wid = QtGui.QWidget() + self.CommandLayout = QtGui.QVBoxLayout() + self.CommandLayout.addWidget(self.ListCommand) + self.CommandLayout.addWidget(self.process) + self.CommandLayout.addWidget(self.buttonDelete) + self.wid.setLayout(self.CommandLayout) + + self.Dock = QtGui.QDockWidget() + self.Dock.setAllowedAreas( QtCore.Qt.LeftDockWidgetArea) + self.Dock.setFeatures(QtGui.QDockWidget.NoDockWidgetFeatures) + self.Dock.setWidget(self.wid) + self.Dock.setMaximumWidth(200) + self.Dock.setMinimumWidth(200) + self.addDockWidget(QtCore.Qt.DockWidgetArea(1),self.Dock) + + def removeConf(self): + self.ListCommand.removeRow(self.ListCommand.currentRow()) + + + def Add_To_Liste(self,(command, cfg)): + row = self.ListCommand.rowCount() + index = self.tab_widget.currentIndex() + filename = self.tab_widget.tabText(index) + self.ListCommand.insertRow(self.ListCommand.rowCount()) + dic = {filename:cfg} + self.item1 = QtGui.QTableWidgetItem(str(command)) + self.item1.command = command + self.item2 = QtGui.QTableWidgetItem(str(filename)) + self.item2.cfg = dic[filename] + self.ListCommand.setItem(row, 0, self.item1) + self.ListCommand.setItem(row, 1, self.item2) + + + + + + + #We run the script and create a hdf5 file + def run(self): + maximum = self.ListCommand.rowCount() + pd = QtGui.QProgressDialog('running', 'Cancel', 0, maximum, self) + pd.setWindowModality(QtCore.Qt.WindowModal) + pd.show() + def progress(cfg, command): + if pd.wasCanceled(): + raise KeyboardInterrupt + QtGui.QApplication.processEvents() + return BINoculars.main.Main.from_object(cfg, command) + try: + for index in range(self.ListCommand.rowCount()): + pd.setValue(index) + cfg = self.ListCommand.item(index,1).cfg + command = self.ListCommand.item(index,0).command + print cfg + progress(cfg, command) + self.ListCommand.clear() + self.ListCommand.setRowCount(0) + except BaseException, e: + #cfg = self.ListCommand.item(index,1).cfg + #print cfg + QtGui.QMessageBox.about(self,"Error","There was an error processing one of the scans: {0}".format(e)) + + finally: + pd.close() + + #we call the load function def ShowFile(self): filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '') for F in filename.split('/') : - NameFile = [] - NameFile.append(F) - NameFile.reverse() - self.tab_widget.addTab(Conf_Tab(self),NameFile[0]) + self.NameFile = [] + self.NameFile.append(F) + self.NameFile.reverse() + confwidget = Conf_Tab(self) + newIndex = self.tab_widget.addTab(confwidget,self.NameFile[0]) + QtCore.QObject.connect(confwidget, QtCore.SIGNAL("command"),self.Add_To_Liste) + self.tab_widget.setCurrentIndex(newIndex) widget = self.tab_widget.currentWidget() widget.read_data(filename) + #we call the save function def Save(self): filename = QtGui.QFileDialog().getSaveFileName(self, 'Save', '', '*.txt') widget = self.tab_widget.currentWidget() widget.save(filename) - + + #we call the new tab conf def New_Config(self): - self.tab_widget.addTab(Conf_Tab(self),'New configfile') + widget = Conf_Tab(self) + self.tab_widget.addTab(widget,'New configfile') + QtCore.QObject.connect(widget, QtCore.SIGNAL("command"),self.Add_To_Liste) + #---------------------------------------------------------------------------------------------------- #-----------------------------------------CREATE TABLE----------------------------------------------- @@ -86,7 +181,7 @@ class Table(QtGui.QWidget): super(Table, self).__init__() # create a QTableWidget - self.table = QtGui.QTableWidget(1, 3, self) + self.table = QtGui.QTableWidget(1, 2, self) self.table.setHorizontalHeaderLabels(['Parameter', 'Value','Comment']) self.table.horizontalHeader().setStretchLastSection(True) self.table.verticalHeader().setVisible(False) @@ -94,21 +189,21 @@ class Table(QtGui.QWidget): #create combobox self.combobox = QtGui.QComboBox() #add items - cell = QtGui.QTableWidgetItem(QtCore.QString("type")) - cell2 = QtGui.QTableWidgetItem(QtCore.QString("")) - self.table.setItem(0, 0, cell) + self.cell = QtGui.QTableWidgetItem(QtCore.QString("type")) + self.table.setItem(0, 0,self.cell) self.table.setCellWidget(0, 1, self.combobox) - self.table.setItem(0, 2,cell2) - + #we create pushbuttons and we call the method when we clic on self.btn_add_row = QtGui.QPushButton('+', self) self.connect(self.btn_add_row, QtCore.SIGNAL('clicked()'), self.add_row) self.buttonRemove = QtGui.QPushButton('-',self) - self.connect(self.buttonRemove, QtCore.SIGNAL("clicked()"), self.remove) - + self.connect(self.buttonRemove, QtCore.SIGNAL("clicked()"), self.remove) + self.btn_add_row.resize(10,10) + self.buttonRemove.resize(10,10) + #the dispositon of the table and the butttons layout = QtGui.QGridLayout() - layout.addWidget(self.table,0,0,3,10) - layout.addWidget(self.btn_add_row,0,11) - layout.addWidget(self.buttonRemove,1,11) + layout.addWidget(self.table,1,0,1,0) + layout.addWidget(self.btn_add_row,0,0) + layout.addWidget(self.buttonRemove,0,1) self.setLayout(layout) def add_row(self): @@ -120,11 +215,11 @@ class Table(QtGui.QWidget): def get_keys(self): return list(self.table.item(index,0).text() for index in range(self.table.rowCount())) - + #Here we take all values on tables def getParam(self): for index in range(self.table.rowCount()): - key = str(self.table.item(index,0).text()) - comment = str(self.table.item(index, 2).text()) + key = str(self.table.item(index,0).text()) + comment = str(self.table.item(index,0).toolTip()) if self.table.item(index,1): value = str(self.table.item(index, 1).text()) else: @@ -132,25 +227,38 @@ class Table(QtGui.QWidget): if self.table.item == None: value = str(self.table.item(index,1).text("")) yield key, value, comment - - def addData(self, data): - for item in data: - if item[0] == 'type': + + #Here we put all values on tables + def addData(self,cfg): + for item in cfg: + if item == 'type': box = self.table.cellWidget(0,1) - box.setCurrentIndex(box.findText(item[1], QtCore.Qt.MatchFixedString)) - newitem = QtGui.QTableWidgetItem(item[2]) - self.table.setItem(0, 2, newitem) + value = cfg[item].split(':') + if len(value)> 1 : + box.setCurrentIndex(box.findText(value[1], QtCore.Qt.MatchFixedString)) + + else: + box.setCurrentIndex(box.findText(cfg[item], QtCore.Qt.MatchFixedString)) else: self.add_row() row = self.table.rowCount() for col in range(self.table.columnCount()): - newitem = QtGui.QTableWidgetItem(item[col]) - self.table.setItem(row -1, col, newitem) + if col == 0: + newitem = QtGui.QTableWidgetItem(item) + self.table.setItem(row -1, col, newitem) + if col == 1: + newitem2 = QtGui.QTableWidgetItem(cfg[item]) + self.table.setItem(row -1, col, newitem2) + + + + def addDataConf(self, items): keys = self.get_keys() - newconfigs = list([item[0], '', item[1]] for item in items if item[0] not in keys) + newconfigs = dict((item[0], '') for item in items if item[0] not in keys) self.addData(newconfigs) + def add_to_combo(self, items): self.combobox.clear() @@ -163,34 +271,39 @@ class Conf_Tab(QtGui.QWidget): def __init__(self, parent = None): super(Conf_Tab,self).__init__() + #we create 3 tables self.Dis = Table() self.Inp = Table() self.Pro = Table() - label1 = QtGui.QLabel('<strong>Dispatcher</strong>') - label2 = QtGui.QLabel('<strong>Input</strong>') - label3 = QtGui.QLabel('<strong>Projection<strong>') + label1 = QtGui.QLabel('<strong>Dispatcher :</strong>') + label2 = QtGui.QLabel('<strong>Input :</strong>') + label3 = QtGui.QLabel('<strong>Projection :<strong>') self.select = QtGui.QComboBox() backends = list(backend.lower() for backend in BINoculars.util.get_backends()) + #we add the list of different backends on the select combobox self.select.addItems(QtCore.QStringList(backends)) - self.start = QtGui.QPushButton('run') - self.connect(self.start, QtCore.SIGNAL("clicked()"), self.run) + self.add = QtGui.QPushButton('add') + self.connect(self.add, QtCore.SIGNAL("clicked()"), self.AddCommand) self.scan = QtGui.QLineEdit() - self.start.setStyleSheet("background-color: darkred") + self.scan.setToolTip('scan selection example: 820 824') + + #the dispositon of all elements of the gui Layout = QtGui.QGridLayout() - Layout.addWidget(self.select,0,1) - Layout.addWidget(label1,1,1) + Layout.addWidget(label1,1,1,1,2) + Layout.addWidget(label2,1,0,1,2) + Layout.addWidget(label3,1,2,1,2) + Layout.addWidget(self.select,0,0) Layout.addWidget(self.Dis,2,1) - Layout.addWidget(label2,3,1) - Layout.addWidget(self.Inp,4,1) - Layout.addWidget(label3,5,1) - Layout.addWidget(self.Pro,6,1) - Layout.addWidget(self.start,7,0) - Layout.addWidget(self.scan,7,1) + Layout.addWidget(self.Inp,2,0) + Layout.addWidget(self.Pro,2,2) + Layout.addWidget(self.add,3,0) + Layout.addWidget(self.scan,3,1) self.setLayout(Layout) - + + #Here we call all methods for selected an ellement on differents combobox self.Dis.add_to_combo(QtCore.QStringList(BINoculars.util.get_dispatchers())) self.select.activated['QString'].connect(self.DataCombo) self.Inp.combobox.activated['QString'].connect(self.DataTableInp) @@ -203,25 +316,29 @@ class Conf_Tab(QtGui.QWidget): self.Pro.add_to_combo(QtCore.QStringList(BINoculars.util.get_projections(str(text)))) def DataTableInp (self,text): + #self.Inp.table.setRowCount(1) backend = str(self.select.currentText()) inp = BINoculars.util.get_input_configkeys(backend, str(self.Inp.combobox.currentText())) self.Inp.addDataConf(inp) def DataTableInpPro (self,text): + #self.Pro.table.setRowCount(1) backend = str(self.select.currentText()) proj = BINoculars.util.get_projection_configkeys(backend, str(self.Pro.combobox.currentText())) self.Pro.addDataConf(proj) def DataTableInpDis (self,text): + #self.Dis.table.setRowCount(1) backend = str(self.select.currentText()) disp = BINoculars.util.get_dispatcher_configkeys(str(self.Dis.combobox.currentText())) self.Dis.addDataConf(disp) - + #The save method we take all ellements on tables and we put them in this format {0} = {1} #{2} def save(self, filename): with open(filename, 'w') as fp: fp.write('[dispatcher]\n') - for key, value, comment in self.Dis.getParam():# cycles over the iterator object + # cycles over the iterator object + for key, value, comment in self.Dis.getParam(): fp.write('{0} = {1} #{2}\n'.format(key, value, comment)) fp.write('[input]\n') for key, value, comment in self.Inp.getParam(): @@ -234,16 +351,19 @@ class Conf_Tab(QtGui.QWidget): value = '{0}:{1}'.format(self.select.currentText(),value) fp.write('{0} = {1} #{2}\n'.format(key, value, comment)) + #This method take the name of objects and values for run the script def get_configobj(self): - inDis = dict((key, value) for key, value, comment in self.Dis.getParam()) inInp = {} + inDis = {} inPro = {} + inDis = dict((key, value) for key, value, comment in self.Dis.getParam()) + for key, value, comment in self.Inp.getParam(): if key == 'type': value = '{0}:{1}'.format(str(self.select.currentText()).strip(),value) - inInp[key] = value + inInp[key] = value for key, value, comment in self.Pro.getParam(): if key == 'type': @@ -254,58 +374,29 @@ class Conf_Tab(QtGui.QWidget): setattr(cfg, 'input', inInp) setattr(cfg, 'dispatcher', inDis) setattr(cfg, 'projection', inPro) - - print inInp - return cfg - + #This method take elements on a text file or the binocular script and put them on tables def read_data(self,filename): - with open(filename, 'r') as inf: - lines = inf.readlines() - - data = {'dispatcher': [], 'input': [], 'projection': []} - for line in lines: - line = line.strip('\n') - if '[dispatcher]' in line: - key = 'dispatcher' - elif '[input]' in line: - key = 'input' - elif '[projection]' in line: - key = 'projection' - else: - if '#' in line: - index = line.index('#') - caput = line[:index] - cauda = line[index:] - else: - caput = line - cauda = '' - if '=' in caput: - name, value = caput.split('=') - if name.strip(' ') == 'type' and ':' in value: - backend, value = value.strip(' ').split(':') - data[key].append([name.strip(' '), value.strip(' '), cauda.strip(' ')]) - + cfg = BINoculars.util.ConfigFile.fromtxtfile(str(filename)) + input_type = cfg.input['type'] + backend, value = input_type.strip(' ').split(':') self.select.setCurrentIndex(self.select.findText(backend, QtCore.Qt.MatchFixedString)) self.DataCombo(backend) + self.Dis.addData(cfg.dispatcher) + self.Inp.addData(cfg.input) + self.Pro.addData(cfg.projection) - for key in data: - if key == 'dispatcher': - self.Dis.addData(data[key]) - elif key == 'input': - self.Inp.addData(data[key]) - elif key == 'projection': - self.Pro.addData(data[key]) - - def run(self): - command = [str(self.scan.text())] + + #we add command on the DockWidget + def AddCommand(self): + scan = [str(self.scan.text())] cfg = self.get_configobj() + commandconfig = (scan , cfg) + self.emit(QtCore.SIGNAL('command'), commandconfig) + + - print 'Command: {0}'.format(command) - print cfg - - BINoculars.main.Main.from_object(cfg, command) if __name__ == '__main__': app = QtGui.QApplication(sys.argv) @@ -314,8 +405,3 @@ if __name__ == '__main__': main.show() sys.exit(app.exec_()) - - - - - |