def loadRecords(self, records): """ Loads the inputed records as children to this item. :param records | [<orb.Table>, ..] || {<str> sub: <variant>, .. } """ self.setChildIndicatorPolicy(self.DontShowIndicatorWhenChildless) self._loaded = True if records is None: return # load sub-groups if desired if self._nextLevels and RecordSet.typecheck(records): level = self._nextLevels[0] sublevels = self._nextLevels[1:] records = records.grouped(level) elif RecordSet.typecheck(records): sublevels = None records = records.all() else: sublevels = None # load a child set of groups if type(records) == dict: try: generator = self.treeWidget().createGroupItem cls = None except AttributeError: generator = None cls = type(self) for subgroup, subrecords in records.items(): if generator: generator(subgroup, subrecords, sublevels, self) elif cls: cls(self, subgroup, subrecords, sublevels) # load records else: try: generator = self.treeWidget().createRecordItem cls = None except AttributeError: generator = None cls = XOrbRecordItem cls = self.treeWidget().createRecordItem for record in records: if generator: generator(record, self) elif cls: cls(self, record)
def loadRecords(self, records): """ Loads the inputed records as children to this item. :param records | [<orb.Table>, ..] || {<str> sub: <variant>, .. } """ self.setChildIndicatorPolicy(self.DontShowIndicatorWhenChildless) self._loaded = True if records is None: return # load sub-groups if desired if self._nextLevels and RecordSet.typecheck(records): level = self._nextLevels[0] sublevels = self._nextLevels[1:] records = records.grouped(level) elif RecordSet.typecheck(records): sublevels = None records = records.all() else: sublevels = None # load a child set of groups if type(records) == dict: try: generator = self.treeWidget().createGroupItem cls = None except AttributeError: generator = None cls = type(self) for subgroup, subrecords in records.items(): if generator: generator(subgroup, subrecords, sublevels, self) elif cls: cls(self, subgroup, subrecords, sublevels) # load records else: try: generator = self.treeWidget().createRecordItem cls = None except AttributeError: generator = None cls = XOrbRecordItem cls = self.treeWidget().createRecordItem for record in records: if generator: generator(record, self) elif cls: cls(self, record)
def refresh(self, records): """ Refreshs the current user interface to match the latest settings. """ self._loaded = True if self.isLoading(): return # load the information if RecordSet.typecheck(records): table = records.table() self.setTableType(table) if self.order(): records.setOrder(self.order()) # load specific data for this record box if self.specifiedColumnsOnly(): records.setColumns(map(lambda x: x.name(), self.specifiedColumns())) # load the records asynchronously if self.isThreadEnabled() and \ table and \ table.getDatabase().isThreadEnabled(): # assign ordering based on tree table if self.showTreePopup(): tree = self.treePopupWidget() if tree.isSortingEnabled(): col = tree.sortColumn() colname = tree.headerItem().text(col) column = table.schema().column(colname) if column: if tree.sortOrder() == Qt.AscendingOrder: sort_order = 'asc' else: sort_order = 'desc' records.setOrder([(column.name(), sort_order)]) self.loadRequested.emit(records) return # load the records synchronously self.loadingStarted.emit() curr_record = self.currentRecord() self.blockSignals(True) self.setUpdatesEnabled(False) self.clear() use_dummy = not self.isRequired() or self.isCheckable() if use_dummy: self.addItem('') self.addRecords(records) self.setUpdatesEnabled(True) self.blockSignals(False) self.setCurrentRecord(curr_record) self.loadingFinished.emit()
def refresh(self, records): """ Refreshs the current user interface to match the latest settings. """ self._loaded = True if self.isLoading(): return # load the information if RecordSet.typecheck(records): table = records.table() self.setTableType(table) if self.order(): records.setOrder(self.order()) # load specific data for this record box if self.specifiedColumnsOnly(): records.setColumns( map(lambda x: x.name(), self.specifiedColumns())) # load the records asynchronously if self.isThreadEnabled() and \ table and \ table.getDatabase().isThreadEnabled(): # assign ordering based on tree table if self.showTreePopup(): tree = self.treePopupWidget() if tree.isSortingEnabled(): col = tree.sortColumn() colname = tree.headerItem().text(col) column = table.schema().column(colname) if column: if tree.sortOrder() == Qt.AscendingOrder: sort_order = 'asc' else: sort_order = 'desc' records.setOrder([(column.name(), sort_order)]) self.loadRequested.emit(records) return # load the records synchronously self.loadingStarted.emit() curr_record = self.currentRecord() self.blockSignals(True) self.setUpdatesEnabled(False) self.clear() use_dummy = not self.isRequired() or self.isCheckable() if use_dummy: self.addItem('') self.addRecords(records) self.setUpdatesEnabled(True) self.blockSignals(False) self.setCurrentRecord(curr_record) self.loadingFinished.emit()
def loadRecords(self, records): """ Loads the record set for this instance. :param records | <orb.RecordSet> || <list> """ try: if self._running: return self._cancelled = False self._running = True try: self.setDatabase(records.database()) except AttributeError: pass self.startLoading() # make sure the orb module is loaded, or there is really no point if RecordSet is None: logger.error('Orb was not loaded.') # lookup a group of results if RecordSet.typecheck(records) and records.groupBy(): levels = records.groupBy() next_levels = levels[1:] for key, records in records.grouped(levels[0]).items(): if self._cancelled: break # PySide Hack! Emitting None across threads will crash Qt # when in PySide mode. if key == None: key = 'None' self.loadedGroup.emit(key, records, next_levels) # lookup a list of results, in batched mode elif self.isBatched(): self.loadBatch(records) # lookup a list of results, not in batched mode else: records = list(records) if self._preloadColumns: for record in curr_records: record.recordValues(self._preloadColumns) self.loadedRecords[object].emit(records) self._running = False self.finishLoading() except ConnectionLostError: self.finishLoading() self.connectionLost.emit() except Interruption: self.finishLoading() finally: self.finishLoading()
def loadRecords(self, records): """ Loads the record set for this instance. :param records | <orb.RecordSet> || <list> """ try: if self._running: return self._cancelled = False self._running = True try: self.setDatabase(records.database()) except AttributeError: pass self.startLoading() # make sure the orb module is loaded, or there is really no point if RecordSet is None: logger.error('Orb was not loaded.') # lookup a group of results if RecordSet.typecheck(records) and records.groupBy(): levels = records.groupBy() next_levels = levels[1:] for key, records in records.grouped(levels[0]).items(): if self._cancelled: break # PySide Hack! Emitting None across threads will crash Qt # when in PySide mode. if key == None: key = 'None' self.loadedGroup.emit(key, records, next_levels) # lookup a list of results, in batched mode elif self.isBatched(): self.loadBatch(records) # lookup a list of results, not in batched mode else: records = list(records) if self._preloadColumns: for record in curr_records: record.recordValues(self._preloadColumns) self.loadedRecords[object].emit(records) self._running = False self.finishLoading() except ConnectionLostError: self.finishLoading() self.connectionLost.emit() except Interruption: self.finishLoading() finally: self.finishLoading()