def copy(self): ''' Copy the table selection to the clipboard At this point, works only for single line selection ''' selection = self.selectionModel() indexes = selection.selectedIndexes() indexes.sort() previous = indexes.pop(0) data = self.model().data(previous) text = data.toString() selected_text = QString(text) for current in indexes: if current.row() != previous.row(): selected_text.append('\n') else: selected_text.append('\t') data = self.model().data(current) text = data.toString() selected_text.append(text) previous = current selected_text.append('\n') QApplication.clipboard().setText(selected_text)
def copy(self): ''' Copy the table selection to the clipboard ''' selection = self.selectionModel() indexes = selection.selectedIndexes() indexes.sort() previous = indexes.pop(0) data = self.model().data(previous) try: text = data.toString() except: text = str(data) selected_text = QString(text) for current in indexes: if current.row() != previous.row(): selected_text.append('\n') else: selected_text.append('\t') data = self.model().data(current) try: text = data.toString() except: text = str(data) selected_text.append(text) previous = current selected_text.append('\n') QApplication.clipboard().setText(selected_text)
def data(self, index, role = Qt.DisplayRole): row = index.row() col = index.column() colname = self.colnames[col] if role == Qt.DisplayRole: val = self.dataframe.get_value(row, colname) if isinstance(val, str) or isinstance(val, unicode): return unicode(QString(val)) else: if isnan(val): return QString("NaN") elif isinf(val): return QString("Inf") else: if abs(val) <= 1: return to_qvariant(('%.3g' % val)) else: return to_qvariant(int(round(val))) elif role == Qt.TextAlignmentRole: return to_qvariant(Qt.AlignRight | Qt.AlignVCenter)
def _qfiledialog_wrapper(attr, parent=None, caption='', basedir='', filters='', selectedfilter='', options=None): if options is None: options = QFileDialog.Options(0) try: # PyQt <v4.6 (API #1) from src.gui.qt.QtCore import QString except ImportError: # PySide or PyQt >=v4.6 QString = None # analysis:ignore tuple_returned = True try: # PyQt >=v4.6 func = getattr(QFileDialog, attr+'AndFilter') except AttributeError: # PySide or PyQt <v4.6 func = getattr(QFileDialog, attr) if QString is not None: selectedfilter = QString() tuple_returned = False # Calling QFileDialog static method if sys.platform == "win32": # On Windows platforms: redirect standard outputs _temp1, _temp2 = sys.stdout, sys.stderr sys.stdout, sys.stderr = None, None try: result = func(parent, caption, basedir, filters, selectedfilter, options) except TypeError: # The selectedfilter option (`initialFilter` in Qt) has only been # introduced in Jan. 2010 for PyQt v4.7, that's why we handle here # the TypeError exception which will be raised with PyQt v4.6 # (see Issue 960 for more details) result = func(parent, caption, basedir, filters, options) finally: if sys.platform == "win32": # On Windows platforms: restore standard outputs sys.stdout, sys.stderr = _temp1, _temp2 # Processing output if tuple_returned: # PySide or PyQt >=v4.6 output, selectedfilter = result else: # PyQt <v4.6 (API #1) output = result if QString is not None: # PyQt API #1: conversions needed from QString/QStringList selectedfilter = unicode(selectedfilter) if isinstance(output, QString): # Single filename output = unicode(output) else: # List of filenames output = [unicode(fname) for fname in output] # Always returns the tuple (output, selectedfilter) print "in compat " print selectedfilter return output, selectedfilter