def convert(self, settings): # generate odmltables objects table1 = odml_table.OdmlTable() table2 = odml_table.OdmlTable() # loading input files table1.load_from_file(settings.get_object('inputfilename1')) table2.load_from_file(settings.get_object('inputfilename2')) # extracting merge mode from selections overwrite = settings.get_object('rboverwrite').isChecked() # merging inputfiles try: table1.merge(table2, overwrite_values=overwrite) except ValueError as e: message = e.message if hasattr(e, 'message') else (str(e)) Qtw.QMessageBox.warning(self, 'Error while merging files', 'Value error: %s.' % (message)) return False except: Qtw.QMessageBox.warning(self, 'Unexpected error:', sys.exc_info()[0]) return False # saving file table1.write2odml(settings.get_object('outputfilename')) return True
def initializePage(self): # Set up layout vbox = Qtw.QVBoxLayout() clearLayout(self.layout()) self.layout().addLayout(vbox) # Adding input part topLabel = Qtw.QLabel( self.tr("Provide the column types used in the " "input table")) topLabel.setWordWrap(True) vbox.addSpacing(20) vbox.addWidget(topLabel) vbox.addSpacing(20) self.grid = Qtw.QGridLayout() vbox.addLayout(self.grid) # self.setLayout(vbox) # get header names from input file load_from = str(self.settings.get_object('inputfilename')) if load_from.endswith('.xls'): inputxlsheaders = odml_table.OdmlTable.get_xls_header(load_from) elif load_from.endswith('.csv'): inputxlsheaders = odml_table.OdmlTable.get_csv_header(load_from) else: raise TypeError('Header can be only read for xls or csv files.') odtables = odml_table.OdmlTable() header_names = list(odtables._header_titles.values()) self.headerlabels = [] self.customheaders = [] for h, header in enumerate(inputxlsheaders): # set up individual row for header association h_label = Qtw.QLabel(header) dd_list = Qtw.QComboBox() dd_list.addItems(header_names) # Preselect fitting header name if possible if header in header_names: ind = header_names.index(header) dd_list.setCurrentIndex(ind) self.grid.addWidget(h_label, h, 0) self.grid.addWidget(dd_list, h, 1) self.headerlabels.append(h_label) self.customheaders.append(dd_list) self.settings.register('headerlabels', self.headerlabels) self.settings.register('customheaders', self.customheaders) self.update()
def load_odml(self): # loading odml file self.table = odml_table.OdmlTable() self.settings.get_object('inputfilename') # setting xls_table or csv_table headers if necessary title_translator = { v: k for k, v in iteritems(self.table._header_titles) } if ((os.path.splitext(self.settings.get_object('inputfilename'))[1] in ['.xls', '.csv']) and (self.settings.get_object('CBcustominput').isChecked())): inputheaderlabels = [ str(l.text()) for l in self.settings.get_object('headerlabels') ] inputcustomheaders = [ str(cb.currentText()) for cb in self.settings.get_object('customheaders') ] inputcolumnnames = [ title_translator[label] for label in inputcustomheaders ] self.table.change_header_titles( **dict(zip(inputcolumnnames, inputheaderlabels))) # loading input file if os.path.splitext( self.settings.get_object('inputfilename'))[1] == '.xls': self.table.load_from_xls_table( self.settings.get_object('inputfilename')) elif os.path.splitext( self.settings.get_object('inputfilename'))[1] == '.csv': self.table.load_from_csv_table( self.settings.get_object('inputfilename')) elif os.path.splitext( self.settings.get_object('inputfilename'))[1] in [ '.odml', '.xml' ]: self.table.load_from_file( self.settings.get_object('inputfilename')) else: raise ValueError( 'Unknown input file extension "%s"' '' % os.path.splitext(self.settings.get_object('inputfilename'))[1]) self.update_tree(self.table) self.filtered_table = copy.deepcopy(self.table) self.settings.register('filtered_table', self.filtered_table, useconfig=False)
def __init__(self, parent=None): super(HeaderOrderPage, self).__init__(parent) self.setTitle("Customize the output table") self.setSubTitle( "Select the columns for the output table by putting them in " "the " "list of selected columns and arranging the order using the " "buttons to the right") # Set up layout vbox = Qtw.QVBoxLayout() self.setLayout(vbox) hbox0 = Qtw.QHBoxLayout() hbox0.addStretch() hbox0.addWidget(Qtw.QLabel('available columns')) hbox0.addStretch() hbox0.addSpacing(90) hbox0.addWidget(Qtw.QLabel('selected columns')) hbox0.addStretch() hbox0.addSpacing(30) vbox.addLayout(hbox0) # Adding input part odtables = odml_table.OdmlTable() self.header_names = list(odtables._header_titles.values()) # generating selection lists self.header_list = Qtw.QListWidget() self.header_list.setSelectionMode(3) self.header_list.itemDoubleClicked.connect(self.itemdoubleclicked) self.selection_list = Qtw.QListWidget() self.selection_list.setSelectionMode(3) self.selection_list.itemDoubleClicked.connect(self.itemdoubleclicked) toright = Qtw.QToolButton() toright.setArrowType(Qt.RightArrow) toright.clicked.connect(self.toright) toleft = Qtw.QToolButton() toleft.setArrowType(Qt.LeftArrow) toleft.clicked.connect(self.toleft) hbox = Qtw.QHBoxLayout() hbox.addWidget(self.header_list) vboxbuttons = Qtw.QVBoxLayout() vboxbuttons.addStretch() vboxbuttons.addWidget(toright) vboxbuttons.addSpacing(30) vboxbuttons.addWidget(toleft) vboxbuttons.addStretch() hbox.addLayout(vboxbuttons) vbox.addLayout(hbox) default_selection_list = ['Path to Section', 'Property Name', 'Value', 'Data Uncertainty', 'Data Unit', 'odML Data Type', 'Property Definition', 'Section Definition'] self.mandatory_headers = mandatory_headers for i, h in enumerate(self.header_names): if h not in default_selection_list: item = Qtw.QListWidgetItem() item.setText(h) self.header_list.addItem(item) for i, h in enumerate(default_selection_list): item = Qtw.QListWidgetItem() item.setText(h) self.selection_list.addItem(item) if h in self.mandatory_headers: item.setForeground(Qtg.QColor('red')) hbox.addWidget(self.selection_list) # adding up and down buttons up = Qtw.QToolButton() up.setArrowType(Qt.UpArrow) up.clicked.connect(self.up) down = Qtw.QToolButton() down.setArrowType(Qt.DownArrow) down.clicked.connect(self.down) vboxbuttons2 = Qtw.QVBoxLayout() vboxbuttons2.addStretch() vboxbuttons2.addWidget(up) vboxbuttons2.addSpacing(30) vboxbuttons2.addWidget(down) vboxbuttons2.addStretch() hbox.addLayout(vboxbuttons2) vbox.addSpacing(20)