def __delitem__(self, key): """ Delete the setting for key. If key is a group remove the whole group. .. note:: defaults cannot be deleted they are instead reverted to their original state. """ if key not in self: raise KeyError(key) if self.isgroup(key): group = self.group(key) for key in group: del group[key] else: fullkey = self.__key(key) oldValue = self.get(key) if self.__store.contains(fullkey): self.__store.remove(fullkey) newValue = None if fullkey in self.__defaults: newValue = self.__defaults[fullkey].default_value etype = SettingChangedEvent.SettingChanged else: etype = SettingChangedEvent.SettingRemoved QCoreApplication.sendEvent( self, SettingChangedEvent(etype, key, newValue, oldValue) )
def __on_activate_parent(self): """ Activate parent shortcut was pressed. """ event = events.WorkflowEvent( events.WorkflowEvent.ActivateParentRequest) QCoreApplication.sendEvent(self.scheme(), event)
def __setitem__(self, key, value): """ Set the setting for key. """ if not isinstance(key, basestring): raise TypeError(key) fullkey = self.__key(key) value_type = None if fullkey in self.__defaults: value_type = self.__defaults[fullkey].value_type if not isinstance(value, value_type): value = qt_to_mapped_type(value) if not isinstance(value, value_type): raise TypeError("Expected {0!r} got {1!r}".format( value_type.__name__, type(value).__name__)) if key in self: oldValue = self.get(key) etype = SettingChangedEvent.SettingChanged else: oldValue = None etype = SettingChangedEvent.SettingAdded self.__setValue(fullkey, value, value_type) QCoreApplication.sendEvent( self, SettingChangedEvent(etype, key, value, oldValue))
def __delitem__(self, key): """ Delete the setting for key. If key is a group remove the whole group. .. note:: defaults cannot be deleted they are instead reverted to their original state. """ if key not in self: raise KeyError(key) if self.isgroup(key): group = self.group(key) for key in group: del group[key] else: fullkey = self.__key(key) oldValue = self.get(key) if self.__store.contains(fullkey): self.__store.remove(fullkey) newValue = None if fullkey in self.__defaults: newValue = self.__defaults[fullkey].default_value etype = SettingChangedEvent.SettingChanged else: etype = SettingChangedEvent.SettingRemoved QCoreApplication.sendEvent( self, SettingChangedEvent(etype, key, newValue, oldValue))
def add_link(self, link): """ Add a `link` to the scheme. Parameters ---------- link : :class:`.SchemeLink` An initialized link instance to add to the scheme. """ check_type(link, SchemeLink) self.check_connect(link) self.__links.append(link) ev = events.LinkEvent(events.LinkEvent.LinkAdded, link) QCoreApplication.sendEvent(self, ev) log.info("Added link %r (%r) -> %r (%r) to scheme %r." % \ (link.source_node.title, link.source_channel.name, link.sink_node.title, link.sink_channel.name, self.title) ) self.link_added.emit(link)
def __setitem__(self, key, value): """ Set the setting for key. """ if not isinstance(key, basestring): raise TypeError(key) fullkey = self.__key(key) value_type = None if fullkey in self.__defaults: value_type = self.__defaults[fullkey].value_type if not isinstance(value, value_type): value = qt_to_mapped_type(value) if not isinstance(value, value_type): raise TypeError("Expected {0!r} got {1!r}".format( value_type.__name__, type(value).__name__) ) if key in self: oldValue = self.get(key) etype = SettingChangedEvent.SettingChanged else: oldValue = None etype = SettingChangedEvent.SettingAdded self.__setValue(fullkey, value, value_type) QCoreApplication.sendEvent( self, SettingChangedEvent(etype, key, value, oldValue) )
def _stateChanged(self, future, state): """ The `future` state has changed (called by :class:`Future`). """ ev = StateChangedEvent(state) if self.thread() is QThread.currentThread(): QCoreApplication.sendEvent(self, ev) else: QCoreApplication.postEvent(self, ev)
def _stateChanged(self, future, state): """ The `future` state has changed (called by :class:`Future`). """ ev = StateChangedEvent(state) if self.thread() is QThread.currentThread(): QCoreApplication.sendEvent(self, ev) else: QCoreApplication.postEvent(self, ev)
def move(x, y): event = QMouseEvent( QEvent.MouseMove, QPoint(x, y), QPoint(x, y), Qt.NoButton, Qt.NoButton, Qt.NoModifier ) QCoreApplication.sendEvent(desktop, event) QCoreApplication.processEvents()
def remove_annotation(self, annotation): """ Remove the `annotation` instance from the scheme. """ check_arg(annotation in self.__annotations, "Annotation is not in the scheme.") self.__annotations.remove(annotation) ev = events.AnnotationEvent(events.AnnotationEvent.AnnotationRemoved, annotation) QCoreApplication.sendEvent(self, ev) self.annotation_removed.emit(annotation)
def __on_help_request(self): """ Help shortcut was pressed. We send a `QWhatsThisClickedEvent` and hope someone responds to it. """ # Sender is the QShortcut, and parent the OWBaseWidget widget = self.sender().parent() node = self.node_for_widget.get(widget) if node: url = "help://search?id={0}".format(node.description.id) event = QWhatsThisClickedEvent(url) QCoreApplication.sendEvent(self, event)
def __on_help_request(self): """ Help shortcut was pressed. We send a `QWhatsThisClickedEvent` and hope someone responds to it. """ # Sender is the QShortcut, and parent the OWBaseWidget widget = self.sender().parent() node = self.node_for_widget.get(widget) if node: url = "help://search?id={0}".format(node.description.id) event = QWhatsThisClickedEvent(url) QCoreApplication.sendEvent(self, event)
def add_annotation(self, annotation): """ Add an annotation (:class:`BaseSchemeAnnotation` subclass) instance to the scheme. """ check_arg(annotation not in self.__annotations, "Cannot add the same annotation multiple times.") check_type(annotation, BaseSchemeAnnotation) self.__annotations.append(annotation) ev = events.AnnotationEvent(events.AnnotationEvent.AnnotationAdded, annotation) QCoreApplication.sendEvent(self, ev) self.annotation_added.emit(annotation)
def add_widget_for_node(self, node): """ Create a new OWWidget instance for the corresponding scheme node. """ future = concurrent.futures.Future() state = WidgetManager.Delayed(node, future) self.__initstate_for_node[node] = state event = WidgetManager.WidgetInitEvent(state) if self.__delayed_init: def schedule_later(): QCoreApplication.postEvent( self, event, Qt.LowEventPriority - 10) QTimer.singleShot(int(1000 / 30) + 10, schedule_later) else: QCoreApplication.sendEvent(self, event)
def add_widget_for_node(self, node): """ Create a new OWWidget instance for the corresponding scheme node. """ future = concurrent.futures.Future() state = WidgetManager.Delayed(node, future) self.__initstate_for_node[node] = state event = WidgetManager.WidgetInitEvent(state) if self.__delayed_init: def schedule_later(): QCoreApplication.postEvent( self, event, Qt.LowEventPriority - 10) QTimer.singleShot(int(1000 / 30) + 10, schedule_later) else: QCoreApplication.sendEvent(self, event)
def __on_help_request(self): """ Help shortcut was pressed. We send a `QWhatsThisClickedEvent` to the scheme and hope someone responds to it. """ # Sender is the QShortcut, and parent the OWBaseWidget widget = self.sender().parent() try: node = self.node_for_widget(widget) except KeyError: pass else: qualified_name = node.description.qualified_name help_url = "help://search?" + urlencode({"id": qualified_name}) event = QWhatsThisClickedEvent(help_url) QCoreApplication.sendEvent(self.scheme(), event)
def __on_help_request(self): """ Help shortcut was pressed. We send a `QWhatsThisClickedEvent` to the scheme and hope someone responds to it. """ # Sender is the QShortcut, and parent the OWBaseWidget widget = self.sender().parent() try: node = self.node_for_widget(widget) except KeyError: pass else: qualified_name = node.description.qualified_name help_url = "help://search?" + urlencode({"id": qualified_name}) event = QWhatsThisClickedEvent(help_url) QCoreApplication.sendEvent(self.scheme(), event)
def add_node(self, node): """ Add a node to the scheme. An error is raised if the node is already in the scheme. Parameters ---------- node : :class:`.SchemeNode` Node instance to add to the scheme. """ check_arg(node not in self.__nodes, "Node already in scheme.") check_type(node, SchemeNode) self.__nodes.append(node) ev = events.NodeEvent(events.NodeEvent.NodeAdded, node) QCoreApplication.sendEvent(self, ev) log.info("Added node %r to scheme %r." % (node.title, self.title)) self.node_added.emit(node)
def add_default_slot(self, default): """ Add a default slot to the settings This also replaces any previously set value for the key. """ value = default.default_value oldValue = None etype = SettingChangedEvent.SettingAdded key = default.key if key in self: oldValue = self.get(key) etype = SettingChangedEvent.SettingChanged if not self.isdefault(key): # Replacing a default value. self.__store.remove(self.__key(key)) self.__defaults[key] = default event = SettingChangedEvent(etype, key, value, oldValue) QCoreApplication.sendEvent(self, event)
def add_default_slot(self, default): """ Add a default slot to the settings This also replaces any previously set value for the key. """ value = default.default_value oldValue = None etype = SettingChangedEvent.SettingAdded key = default.key if key in self: oldValue = self.get(key) etype = SettingChangedEvent.SettingChanged if not self.isdefault(key): # Replacing a default value. self.__store.remove(self.__key(key)) self.__defaults[key] = default event = SettingChangedEvent(etype, key, value, oldValue) QCoreApplication.sendEvent(self, event)
def remove_node(self, node): """ Remove a `node` from the scheme. All links into and out of the `node` are also removed. If the node in not in the scheme an error is raised. Parameters ---------- node : :class:`.SchemeNode` Node instance to remove. """ check_arg(node in self.__nodes, "Node is not in the scheme.") self.__remove_node_links(node) self.__nodes.remove(node) ev = events.NodeEvent(events.NodeEvent.NodeRemoved, node) QCoreApplication.sendEvent(self, ev) log.info("Removed node %r from scheme %r." % (node.title, self.title)) self.node_removed.emit(node) return node
def remove_link(self, link): """ Remove a link from the scheme. Parameters ---------- link : :class:`.SchemeLink` Link instance to remove. """ check_arg(link in self.__links, "Link is not in the scheme.") self.__links.remove(link) ev = events.LinkEvent(events.LinkEvent.LinkRemoved, link) QCoreApplication.sendEvent(self, ev) log.info("Removed link %r (%r) -> %r (%r) from scheme %r." % \ (link.source_node.title, link.source_channel.name, link.sink_node.title, link.sink_channel.name, self.title) ) self.link_removed.emit(link)
def eventFilter(self, obj, event): if event.type() == QEvent.StatusTip and \ not isinstance(event, QuickHelpTipEvent) and \ hasattr(obj, "whatsThis") and \ isinstance(obj.whatsThis, Callable): tip = event.tip() try: text = obj.whatsThis() except Exception: text = None if text: ev = QuickHelpTipEvent(tip, text if tip else "") return QCoreApplication.sendEvent(obj, ev) return QObject.eventFilter(self, obj, event)
def eventFilter(self, obj, event): if event.type() == QEvent.StatusTip and \ not isinstance(event, QuickHelpTipEvent) and \ hasattr(obj, "whatsThis") and \ isinstance(obj.whatsThis, Callable): tip = event.tip() try: text = obj.whatsThis() except Exception: text = None if text: ev = QuickHelpTipEvent(tip, text if tip else "") return QCoreApplication.sendEvent(obj, ev) return QObject.eventFilter(self, obj, event)
def __on_activate_parent(self): """ Activate parent shortcut was pressed. """ event = ActivateParentEvent() QCoreApplication.sendEvent(self.scheme(), event)
def __on_activate_parent(self): """ Activate parent shortcut was pressed. """ event = WorkflowEvent(WorkflowEvent.ActivateParentRequest) QCoreApplication.sendEvent(self.scheme(), event)
def __on_activate_parent(self): """ Activate parent shortcut was pressed. """ event = ActivateParentEvent() QCoreApplication.sendEvent(self.scheme(), event)
def draw_spatial_unit(self, model, clear_existing=True): """ Draw geometry of the given model in the respective local and web views. :param model: Source model whose geometry will be drawn. :type model: object :param clear_existing: Clears any existing features prior to adding the new features. :type clear_existing: bool """ if model is None: msg = QApplication.translate("SpatialPreview", "Data model is empty, the spatial " "unit cannot be rendered.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return table_name = model.__class__.__name__.replace(' ', '_').lower() if not pg_table_exists(table_name): msg = QApplication.translate("SpatialPreview", "The spatial unit data source could " "not be retrieved, the feature cannot " "be rendered.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return spatial_cols = table_column_names(table_name, True) geom, geom_col = None, "" for sc in spatial_cols: geom = getattr(model, sc) #Use the first non-empty geometry value in the collection if not geom is None: geom_col = sc if geom is None: msg = QApplication.translate("SpatialPreview", "The selected spatial unit does not " "contain a valid geometry.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return geom_type, epsg_code = geometryType(table_name, geom_col) if self._overlay_layer is None: self._create_vector_layer(geom_type, epsg_code) #Add layer to map QgsMapLayerRegistry.instance().addMapLayer(self._overlay_layer, False) #Ensure it is always added on top QgsProject.instance().layerTreeRoot().insertLayer(0, self._overlay_layer) if clear_existing: self.delete_local_features() feat, extent = self._add_geom_to_map(geom) #Add spatial unit to web viewer self._web_spatial_loader.add_overlay(model, geom_col) #Increase bounding box by 50%, so that layer slightly zoomed out extent.scale(1.5) #Select feature. Hack for forcing a selection by using inversion self._overlay_layer.invertSelection() self._iface.mapCanvas().setExtent(extent) self._iface.mapCanvas().refresh() self.refresh_canvas_layers() #Need to force event so that layer is shown QCoreApplication.sendEvent(self.local_map, QShowEvent())
def onTab(self): if not self._tela: return evento = EventoTecladoConsole(EventoTecladoConsole.TabType, EngineConsole.TAB) QCoreApplication.sendEvent(self._tela, evento)
def forward_char(self): QCoreApplication.sendEvent(self, QKeyEvent(QEvent.KeyPress, Qt.Key_Right, Qt.NoModifier))
def onFuncional(self, func): if not self._tela: return evento = EventoTecladoConsole(EventoTecladoConsole.FuncionalType, func) QCoreApplication.sendEvent(self._tela, evento)
def onEspecial(self, esp): if not self._tela: return evento = EventoTecladoConsole(EventoTecladoConsole.EspecialType, esp) QCoreApplication.sendEvent(self._tela, evento)
def onEscape(self): if not self._tela: return evento = EventoTecladoConsole(EventoTecladoConsole.EscapeType, EngineConsole.ESC) QCoreApplication.sendEvent(self._tela, evento)
def onDirecional(self, direc): if not self._tela: return evento = EventoTecladoConsole(EventoTecladoConsole.DirecionalType, direc) QCoreApplication.sendEvent(self._tela, evento)
def onEnter(self): if not self._tela: return evento = EventoTecladoConsole(EventoTecladoConsole.EnterType, EngineConsole.ENTER) QCoreApplication.sendEvent(self._tela, evento)
def onKey(self, key): if not self._tela: return evento = EventoTecladoConsole(EventoTecladoConsole.KeyType, key) QCoreApplication.sendEvent(self._tela, evento)
def backward_char(self): QCoreApplication.sendEvent(self, QKeyEvent(QEvent.KeyPress, Qt.Key_Left, Qt.NoModifier))
def previous_line(self): QCoreApplication.sendEvent(self, QKeyEvent(QEvent.KeyPress, Qt.Key_Up, Qt.NoModifier))
def next_line(self): QCoreApplication.sendEvent(self, QKeyEvent(QEvent.KeyPress, Qt.Key_Down, Qt.NoModifier))