Skip to content

Instantly share code, notes, and snippets.



Last active Apr 22, 2019
What would you like to do?
dispatcher cutevariant
class QueryPluginWidget(PluginWidget):
""" Base class for all query plugin """
query_changed = Signal() # Signal to emit if UI change the query
def query(self):
return self._query
def query(self, query: Query):
self._query = query
def on_query_changed(self):
""" Only this method should be implemented by children """
raise NotImplemented()
class ChildPlugin(QueryPluginWidget):
def on_query_changed(self):
""" Overrided """
self.populate(self.query) # Example : Populate ui on query changed
def button_pressed(self): # Example : Action from the UI which change query
self.query.columns = .... # Update query
self.query_changed.emit() # Tell Other to update query
class QueryDispatcher(object):
def __init__(self, query: Query):
self.query = query
def add_widget(self, widget: QueryPluginWidget) :
widget.query = self.query # Link as reference ? Really ? All will point to the same query ?
def dispatch(self):
# Notify All widget except the sender that query has changed
for widget in self.widgets:
if widget is not self.sender():
# Usage
query = Query()
dispatcher = QueryDispacher(query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.