class PointSeriesController(QtGui.QWidget): def __init__(self, line_names, callback, io_config_layout): super(PointSeriesController, self).__init__() self.layout = QtGui.QHBoxLayout() self.setLayout(self.layout) self.io_grid = IOGrid() # def add_line_controllers(self, line_names): for n in line_names: io_config_layout["groups"][0]["items"].append({ "class": "button", "qtype": "check", "label": str(n), "name": "check_" + str(n), "clicked": callback, "args": [n] }) self.params, self.io_config = self.io_grid.load_config( io_config_layout) self.layout.addWidget(self.io_grid) def onChange(self, param, changes): pass
def __init__(self, line_names, callback, io_config_layout): super(PointSeriesController, self).__init__() self.layout = QtGui.QHBoxLayout() self.setLayout(self.layout) self.io_grid = IOGrid() # def add_line_controllers(self, line_names): for n in line_names: io_config_layout["groups"][0]["items"].append({ "class": "button", "qtype": "check", "label": str(n), "name": "check_" + str(n), "clicked": callback, "args": [n] }) self.params, self.io_config = self.io_grid.load_config(io_config_layout) self.layout.addWidget(self.io_grid)
class Line(QtGui.QWidget): def __init__(self, legend=False, controller=False, update_controller=False, size=(1, 0), title=None, range=None): super(Line, self).__init__() self.artists = dict() self.layout = QtGui.QHBoxLayout() self.setup_graph(legend=legend, range=range) self.layout.addWidget(self.graph) self.controller_enabled = controller # self.setSizePolicy( # QtGui.QSizePolicy( # QtGui.QSizePolicy.MinimumExpanding, # QtGui.QSizePolicy.MinimumExpanding # ) # ) self.setLayout(self.layout) # self.setMaximumWidth(1200) if self.controller_enabled: # self.setup_controller() self.layout.addWidget(self.controller) def setup_graph(self, legend=False, range=None): self.graph = pg.PlotWidget() if range is not None: if range['y_range'] != "auto": self.graph.setYRange(*range['y_range']) if range['x_range'] != "auto": self.graph.setYRange(*range['x_range']) # self.graph.setSizePolicy( # QtGui.QSizePolicy( # QtGui.QSizePolicy.MinimumExpanding, # QtGui.QSizePolicy.MinimumExpanding # ) # ) # self.graph.setMaximumWidth(1000) self.legend_enabled = False self.graph.showGrid(x=True, y=True) if legend: self.legend = self.graph.addLegend() self.legend_enabled = True def setup_controller(self): self.controller = IOGrid() self.controller.load_config() # self.controller_config = self.controller.config_init(1, [0]) # self.controller_config["groups"][0]["box_enabled"] = True # self.controller_config["groups"][0]["box_name"] = "plot control" # self.controller_config["groups"][0]["checkable"] = False # self.controller_config["groups"][0]["layout"] = ["v", "t"] # self.controller.config_widget(self.controller_config) # print self.controller_config def link_xaxis(self, graph): self.graph.getViewBox().setXLink(graph.getViewBox()) def controller_callback(self, args): button = args[0] name = args[1] if not button.isChecked(): # print "diable:", name self.hide_line(name) else: self.show_line(name) def add_plot(self, name, plot_args): if plot_args is None: plot_args = { "pen": 'r', "downsample": None, "fillLevel": 0, "brush": (0, 0, 255, 80) } self.artists[name] = self.graph.plot(**plot_args) if self.legend_enabled: self.legend.addItem(self.artists[name], name) if self.controller_enabled: self.controller_config["groups"][0]["items"].append({ "class": "button", "added": False, "name": str(name), "qtype": "check", "label": str(name), "clicked": self.controller_callback, "enabled": True, "args": [name] }) self.controller.config_update(self.controller_config) def remove_plot(self, name): self.graph.removeItem(self.artists[name]) if self.legend_enabled: self.legend.removeItem(name) def hide_line(self, name): self.legend.removeItem(name) self.graph.removeItem(self.artists[name]) def show_line(self, name): self.graph.addItem(self.artists[name]) self.legend.addItem(self.artists[name], name) def update(self, data, config): """ @summary: Updates @param data: @param config: @result: """ # Cycle through the plot config and add the data to the artist for idx, plot in enumerate(config['plots'], start=1): # If the plot does not exsist add it if plot["name"] not in self.artists.keys(): self.add_plot(plot["name"], plot["plot kwargs"]) # Update the line artist with the new data self.artists[plot["name"]].setData( x=np.squeeze(np.asarray(data[:, 0])), y=np.squeeze(np.asarray(data[:, idx])))
def setup_controller(self): self.controller = IOGrid() self.controller.load_config()