def make_ui(self): """make_ui - build up UI""" ui = type('CSVEditUI', (), {}) self.setLayout(QtWidgets.QVBoxLayout()) buttons = QtWidgets.QHBoxLayout() self.layout().addLayout(buttons) def mkbuttons(what, function): list_ = [ ('go-first', "%s column left", QtWidgets.QStyle.SP_ArrowLeft), ('go-last', "%s column right", QtWidgets.QStyle.SP_ArrowRight), ('go-top', "%s row above", QtWidgets.QStyle.SP_ArrowUp), ('go-bottom', "%s row below", QtWidgets.QStyle.SP_ArrowDown), ] buttons.addWidget(QtWidgets.QLabel(what+": ")) for name, tip, fallback in list_: button = QtWidgets.QPushButton() button.setIcon(QtGui.QIcon.fromTheme(name, QtWidgets.QApplication.style().standardIcon(fallback))) button.setToolTip(tip % what) button.clicked.connect(lambda checked, name=name: function(name)) buttons.addWidget(button) mkbuttons("Move", self.move) mkbuttons("Insert", self.insert) for text, function in [ ("Del row", lambda clicked: self.delete_col(row=True)), ("Del col.", lambda clicked: self.delete_col()), ("Prev", lambda clicked: self.prev_tbl()), ("Next", lambda clicked: self.prev_tbl(next=True)), ]: btn = QtWidgets.QPushButton(text) buttons.addWidget(btn) btn.clicked.connect(function) ui.min_rows = QtWidgets.QSpinBox() buttons.addWidget(ui.min_rows) ui.min_rows.setMinimum(1) ui.min_rows.setPrefix("tbl with ") ui.min_rows.setSuffix(" rows") ui.min_rows.setValue(4) buttons.addStretch(1) ui.table = QtWidgets.QTableView() self.layout().addWidget(ui.table) return ui
def make_ui(self): """make_ui - build up UI""" ui = type('CSVEditUI', (), {}) # a QVBox containing two QHBoxes self.setLayout(QtWidgets.QVBoxLayout()) buttons = QtWidgets.QHBoxLayout() self.layout().addLayout(buttons) buttons2 = QtWidgets.QHBoxLayout() self.layout().addLayout(buttons2) # make 4 directional buttons def mkbuttons(what, function): list_ = [ ('go-first', "%s column left", QtWidgets.QStyle.SP_ArrowLeft), ('go-last', "%s column right", QtWidgets.QStyle.SP_ArrowRight), ('go-top', "%s row above", QtWidgets.QStyle.SP_ArrowUp), ('go-bottom', "%s row below", QtWidgets.QStyle.SP_ArrowDown), ] buttons.addWidget(QtWidgets.QLabel(what + ": ")) for name, tip, fallback in list_: button = QtWidgets.QPushButton() button.setIcon( QtGui.QIcon.fromTheme( name, QtWidgets.QApplication.style().standardIcon(fallback))) button.setToolTip(tip % what) button.clicked.connect( lambda checked, name=name: function(name)) buttons.addWidget(button) # add buttons to move rows / columns mkbuttons("Move", self.move) # add buttons to insert rows / columns mkbuttons("Insert", self.insert) for text, function, layout in [ ("Del row", lambda clicked: self.delete_col(row=True), buttons), ("Del col.", lambda clicked: self.delete_col(), buttons), ("Prev", lambda clicked: self.prev_tbl(), buttons2), ("Next", lambda clicked: self.prev_tbl(next=True), buttons2), ]: btn = QtWidgets.QPushButton(text) layout.addWidget(btn) btn.clicked.connect(function) # input for minimum rows to count as a table ui.min_rows = QtWidgets.QSpinBox() buttons2.addWidget(ui.min_rows) ui.min_rows.setMinimum(1) ui.min_rows.setPrefix("tbl with ") ui.min_rows.setSuffix(" rows") ui.min_rows.setValue(self.state['rows']) # separator text and line start / end text for attr in 'sep', 'start', 'end': buttons2.addWidget(QtWidgets.QLabel(attr.title() + ':')) w = QtWidgets.QLineEdit() w.setText(self.state[attr]) setattr(ui, attr + '_txt', w) # w.textEdited.connect(self.delim_changed) buttons2.addWidget(w) ui.sep_txt.setToolTip("Use Prev/Next to rescan table with new sep") w = QtWidgets.QPushButton('Change') w.setToolTip("Change separator in text") w.clicked.connect(lambda checked: self.delim_changed()) buttons2.addWidget(w) buttons.addStretch(1) buttons2.addStretch(1) ui.table = QtWidgets.QTableView() self.layout().addWidget(ui.table) return ui