def data(self, index, role=Qt.DisplayRole): if not index.isValid(): return None if (index.column() == 2): value = '' elif (index.column() == 1): g = self._data[index.row()][index.column()] value = str(g[0]) + ',' + str(g[1]) + ',' + str(g[2]) else: value = QtCore.QVariant(self._data[index.row()][index.column()]) if role == QtCore.Qt.EditRole: return value elif role == QtCore.Qt.DisplayRole: return value elif role == Qt.DecorationRole: if index.column() == 1: g = self._data[index.row()][index.column()] return QtGui.QColor(g[0], g[1], g[2]) elif role == QtCore.Qt.CheckStateRole: if index.column() == 2: if self.test[index.row()]: return QtCore.Qt.Checked else: return QtCore.Qt.Unchecked elif role == Qt.TextAlignmentRole: return Qt.AlignCenter return QtCore.QVariant()
def data(self, index, role=QtCore.Qt.DisplayRole): if role != QtCore.Qt.DisplayRole: return QtCore.QVariant() if not index.isValid(): return QtCore.QVariant() return QtCore.QVariant(str(self._df.ix[index.row(), index.column()]))
def SetProxy(): self.use_proxy = bool(self.checkUseProxy.isChecked()) self.proxy_config = self.textProxyConfig.text() if os.environ['QT_API'] == 'pyqt': self.settings.setValue("use_proxy", self.use_proxy) self.settings.setValue("proxy_config", str(self.proxy_config)) elif os.environ['QT_API'] == 'pyqt5': self.settings.setValue("use_proxy", QtCore.QVariant(self.use_proxy)) self.settings.setValue("proxy_config", QtCore.QVariant(str(self.proxy_config))) d.done(0)
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole): if role != QtCore.Qt.DisplayRole: return QtCore.QVariant() if orientation == QtCore.Qt.Horizontal: try: return self._df.columns.tolist()[section] except (IndexError, ): return QtCore.QVariant() elif orientation == QtCore.Qt.Vertical: try: # return self.df.index.tolist() return self._df.index.tolist()[section] except (IndexError, ): return QtCore.QVariant()
def data(self, index, role=QtCore.Qt.DisplayRole): if not index.isValid(): return QtCore.QVariant() if index.row() >= self.rowCount(): return QtCore.QVariant() if index.column() >= self.columnCount(): return QtCore.QVariant() if role == QtCore.Qt.DisplayRole: try: item = str(self._list[index.row()][index.column()]) except IndexError: item = "" return item else: return QtCore.QVariant()
def data(self, index, role=QtCore.Qt.DisplayRole): if not index.isValid(): # does > 0 bounds check return QtCore.QVariant() if index.column() >= self.columnCount() or index.row( ) >= self.rowCount(): return QtCore.QVariant() if role == QtCore.Qt.DisplayRole: if index in self._data: return self._data[index] else: self._data[index] = LOADING_PLACEHOLDER self._work_queue.append(index) return LOADING_PLACEHOLDER else: return QtCore.QVariant()
def headerData(self, index, orientation, role): if orientation == Qt.Horizontal and role == Qt.DecorationRole: if index == 2: return QtCore.QVariant( QtGui.QPixmap(self.header_icon).scaled( 100, 100, Qt.KeepAspectRatio, Qt.SmoothTransformation)) if orientation == Qt.Horizontal and role == Qt.DisplayRole: if index == 0: return QtCore.QVariant('Nombre') elif index == 1: return QtCore.QVariant('Color') else: return QtCore.QVariant('Habilitado') return QtCore.QVariant()
def headerData(self, section, orientation, role): if role == Qt.DisplayRole: if orientation == Qt.Horizontal: return self._data.columns[section] else: return self._data.index[section] else: return QtCore.QVariant()
def data(self, index, role=QtCore.Qt.DisplayRole): if index.isValid() and role == Qt.DisplayRole: if index.column() == 0: return index.internalPointer().key else: return index.internalPointer().value elif not index.isValid(): return "root" return QtCore.QVariant()
def PlotSpecificArea(): # Save coordinates for the next time if os.environ['QT_API'] == 'pyqt': self.settings.setValue("last_point_coord_lat", self.spinboxLatDec.value()) self.settings.setValue("last_point_coord_lon", self.spinboxLonDec.value()) elif os.environ['QT_API'] == 'pyqt5': self.settings.setValue( "last_point_coord_lat", QtCore.QVariant(self.spinboxLatDec.value())) self.settings.setValue( "last_point_coord_lon", QtCore.QVariant(self.spinboxLonDec.value())) # Select the 3D Map tab self.tab.setCurrentIndex(2) # Plot if self.check3DMapSelection.isChecked(): tile_selection = 'auto' else: tile_selection = self.text3DMapName.text() terrain, track, warnings = bombo.Generate3DMap( [self.spinboxLatDec.value()], [self.spinboxLonDec.value()], tile_selection=tile_selection, margin=self.spinbox3DMargin.value(), elevation_scale=self.spinbox3DElevationScale.value(), mapping='coords', use_osm_texture=True, texture_type='osm', texture_zoom=self.spinbox3DOSMZoom.value(), texture_invert=self.check3DOSMInvert.isChecked(), use_proxy=self.use_proxy, proxy_data=self.proxy_config, verbose=False) self.textWarningConsole.append(warnings) if terrain is not None: self.map3d.update_plot(terrain, track) d.done(0)
def data(self, index, role=QtCore.Qt.DisplayRole): col = index.column() if role == QtCore.Qt.TextAlignmentRole: return QtCore.Qt.AlignCenter if role == QtCore.Qt.DisplayRole: if col < 4: format_str = '{0:g}' else: format_str = '{0:.4f}' return format_str.format(self.reflection_data[index.row(), index.column()]) else: return QtCore.QVariant()
def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole): if role != QtCore.Qt.DisplayRole: # if '' is returned, the headers won't show up... return QtCore.QVariant() if orientation == QtCore.Qt.Horizontal: try: return self._headers[section] except (TypeError, IndexError): return '' else: return section + 1
def headerData(self, section, orientation, role): # If role is not DisplayRole, return empty QVariant if (role != QC.Qt.DisplayRole): return (QC.QVariant()) # If the horizontal header information is requested if (orientation == QC.Qt.Horizontal): # Return the corresponding column name return (self._data.columns[section]) # If the vertical header information is requested else: # Return the corresponding row name return (self._data.index[section])
def data(self, index, role): # If this index is valid if index.isValid() and role in (QC.Qt.DisplayRole, QC.Qt.EditRole): # Obtain the requested value value = self._data.iat[index.row(), index.column()] # Convert value to a Python scalar if isinstance(value, np.generic): value = value.item() # If value is None, always use an empty QVariant if pd.isna(value): data_point = QC.QVariant() # Else, create proper QVariant else: data_point = QC.QVariant(value) # Else, use an empty QVariant else: data_point = QC.QVariant() # Return created data_point return (data_point)
def nonDestructiveBasicTest(self): """ nonDestructiveBasicTest tries to call a number of the basic functions (not all) to make sure the model doesn't outright segfault, testing the functions that makes sense. """ assert (self.model.buddy(QtCore.QModelIndex()) == QtCore.QModelIndex()) self.model.canFetchMore(QtCore.QModelIndex()) assert (self.model.columnCount(QtCore.QModelIndex()) >= 0) assert (self.model.data(QtCore.QModelIndex(), QtCore.Qt.DisplayRole) == QtCore.QVariant()) self.fetchingMore = True self.model.fetchMore(QtCore.QModelIndex()) self.fetchingMore = False flags = self.model.flags(QtCore.QModelIndex()) assert (int(flags & constants.IS_ENABLED) == constants.IS_ENABLED or int(flags & constants.IS_ENABLED) == 0) self.model.hasChildren(QtCore.QModelIndex()) self.model.hasIndex(0, 0) self.model.headerData(0, constants.HORIZONTAL, QtCore.Qt.DisplayRole) self.model.index(0, 0, QtCore.QModelIndex()) self.model.itemData(QtCore.QModelIndex()) cache = QtCore.QVariant() self.model.match(QtCore.QModelIndex(), -1, cache) self.model.mimeTypes() assert (self.model.parent( QtCore.QModelIndex()) == QtCore.QModelIndex()) assert (self.model.rowCount(QtCore.QModelIndex()) >= 0) variant = QtCore.QVariant() self.model.setData(QtCore.QModelIndex(), variant, -1) self.model.setHeaderData(-1, constants.HORIZONTAL, QtCore.QVariant()) self.model.setHeaderData(0, constants.HORIZONTAL, QtCore.QVariant()) self.model.setHeaderData(999999, constants.HORIZONTAL, QtCore.QVariant()) self.model.sibling(0, 0, QtCore.QModelIndex()) self.model.span(QtCore.QModelIndex()) self.model.supportedDropActions()
def selectFileToOpen(self): def getPreProcessingChoice(self, filename, filestructure): items = ("Choose the longest", "Merge all") item, okPressed = QInputDialog.getItem( self, "Multiple tracks/segments", "File '" + filename + "' contains more than one track/segment\n\n" + infos + "\nWhat to do?", items, 0, False) if okPressed and item: return items.index(item) else: return 0 # Try to recover the last used directory old_directory = self.settings.value("lastdirectory", str) # Check if the setting exists if old_directory is not None: # Check if it's not empty if old_directory: old_directory = old_directory else: old_directory = bombo.TRACKS_FOLDER else: old_directory = bombo.TRACKS_FOLDER # Open the dialog box fullfilename_list = QFileDialog.getOpenFileNames( self, 'Open .gpx', old_directory, "GPX files (*.gpx)") if os.environ['QT_API'] == 'pyqt': pass elif os.environ['QT_API'] == 'pyqt5': fullfilename_list = fullfilename_list[0] # Process every selected file for i, fullfilename in enumerate(fullfilename_list): # Process filename directory, filename = os.path.split(str(fullfilename)) filename, fileextension = os.path.splitext(filename) # Save the new directory in the application settings (it only # needs to be done once) if i == 0: # print "New directory to be saved: {}\n".format(directory) if os.environ['QT_API'] == 'pyqt': self.settings.setValue("lastdirectory", str(directory)) elif os.environ['QT_API'] == 'pyqt5': self.settings.setValue("lastdirectory", QtCore.QVariant(str(directory))) # Open file and inspect what's inside gpxraw, longest_traseg, Ntracks, Nsegments, infos = bombo.LoadGPX( fullfilename) # If there's more than one track or segment, ask how to proceed if (Ntracks > 1) or (Nsegments > 1): preprocessingchoice = getPreProcessingChoice( self, filename, infos) if preprocessingchoice == 0: preprocessedgpx = bombo.SelectOneTrackAndSegmentFromGPX( gpxraw, longest_traseg[0], longest_traseg[1]) listname = filename + " (longest)" elif preprocessingchoice == 1: preprocessedgpx = bombo.MergeAllTracksAndSegmentsFromGPX( gpxraw) listname = filename + " (merged)" else: preprocessedgpx = gpxraw listname = filename # Append the list of open GPX files using the next available color (that's the size of the list -1) self.gpxlist.append(preprocessedgpx) self.gpxnamelist.append(listname) newitem = QListWidgetItem(listname) newitem.setBackground( QtGui.QColor(self.palette[len(self.gpxlist) - 1])) self.tracklist.addItem(newitem) return
def data(self): """ Tests self.model's implementation of QtCore.QAbstractItemModel::data() """ # Invalid index should return an invalid qvariant qvar = self.model.data(QtCore.QModelIndex(), QtCore.Qt.DisplayRole) assert (qvar is None) if self.model.rowCount(QtCore.QModelIndex()) == 0: return # A valid index should have a valid QtCore.QVariant data assert (self.model.index(0, 0, QtCore.QModelIndex()).isValid()) # shouldn't be able to set data on an invalid index assert (self.model.setData(QtCore.QModelIndex(), QtCore.QVariant("foo"), QtCore.Qt.DisplayRole) is False) # General Purpose roles that should return a QString data = self.model.data(self.model.index(0, 0, QtCore.QModelIndex()), constants.TOOLTIP_ROLE) assert data is None or isinstance(data, str) data = self.model.data(self.model.index(0, 0, QtCore.QModelIndex()), QtCore.Qt.StatusTipRole) assert data is None or isinstance(data, str) data = self.model.data(self.model.index(0, 0, QtCore.QModelIndex()), QtCore.Qt.WhatsThisRole) assert data is None or isinstance(data, str) # General Purpose roles that should return a QSize data = self.model.data(self.model.index(0, 0, QtCore.QModelIndex()), QtCore.Qt.SizeHintRole) assert data is None or isinstance(data, QtCore.QSize) # General Purpose roles that should return a QFont data = self.model.data(self.model.index(0, 0, QtCore.QModelIndex()), QtCore.Qt.FontRole) assert data is None or isinstance(data, QtGui.QFont) # Check that the alignment is one we know about alignment = self.model.data( self.model.index(0, 0, QtCore.QModelIndex()), constants.ALIGNMENT_ROLE) if alignment is not None: flag = QtCore.Qt.AlignHorizontal_Mask | QtCore.Qt.AlignVertical_Mask assert (alignment == (alignment & int(flag))) # General Purpose roles that should return a QColor data = self.model.data(self.model.index(0, 0, QtCore.QModelIndex()), constants.BACKGROUND_ROLE) assert data is None or isinstance(data, QtGui.QColor) data = self.model.data(self.model.index(0, 0, QtCore.QModelIndex()), QtCore.Qt.TextColorRole) assert data is None or isinstance(data, QtGui.QColor) # Check that the "check state" is one we know about. state = self.model.data(self.model.index(0, 0, QtCore.QModelIndex()), QtCore.Qt.CheckStateRole) assert state in [ None, QtCore.Qt.Unchecked, QtCore.Qt.PartiallyChecked, QtCore.Qt.Checked ]
def _display_name(self) -> str: return self.key.replace("__", "\n").replace("_", " ").title() display_name: str = attr.Factory(_display_name, takes_self=True) always_show: bool = False def plus_minus_one(value: str) -> int: if int(value) >= 0: # Raises ValueError return 1 else: return -1 nope = qc.QVariant() def parse_bool_maybe(s: str) -> Optional[bool]: """Does not throw. But could legally throw ValueError.""" if not s: return None # len(s) >= 1 try: return bool(int(s)) except ValueError: pass s = s.lower()
def loadResource(self, typ: int, name: QtCore.QUrl): if name.scheme() == 'qthelp': return QtCore.QVariant(self.help_engine.fileData(name)) else: return super().loadResource(typ, name)