def get_plot_average_y_section(obj, apply_lut=False): """ Return cross section along y-axis, averaged on ROI defined by 'obj' 'obj' is an AbstractShape object supporting the 'get_rect' method (RectangleShape, AnnotatedRectangle, etc.) """ x0, y0, x1, y1 = obj.get_rect() xc0, yc0 = axes_to_canvas(obj, x0, y0) xc1, yc1 = axes_to_canvas(obj, x1, y1) invert = False ydir = obj.plot().get_axis_direction("left") if (ydir and yc0 > yc1) or (not ydir and yc0 < yc1): invert = True yc1, yc0 = yc0, yc1 if xc0 > xc1: xc1, xc0 = xc0, xc1 try: data = get_image_from_qrect(obj.plot(), QPoint(xc0, yc0), QPoint(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=1) x = np.linspace(y0, y1, len(y)) if invert: x = x[::-1] return x, y
def get_plot_y_section(obj, apply_lut=False): """ Return plot cross section along y-axis, at the x value defined by 'obj', a Marker/AnnotatedPoint object """ x0, _y0 = get_object_coordinates(obj) plot = obj.plot() ymap = plot.canvasMap(plot.Y_LEFT) yc0, yc1 = ymap.p1(), ymap.p2() if plot.get_axis_direction("left"): yc1, yc0 = yc0, yc1 xc0, _yc0 = axes_to_canvas(obj, x0, 0) xc1 = xc0 + 1 try: data = get_image_from_qrect(plot, QPoint(xc0, yc0), QPoint(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=1) _x0, y0 = canvas_to_axes(obj, QPoint(xc0, yc0)) _x1, y1 = canvas_to_axes(obj, QPoint(xc1, yc1)) x = np.linspace(y0, y1, len(y)) return x, y
def get_plot_x_section(obj, apply_lut=False): """ Return plot cross section along x-axis, at the y value defined by 'obj', a Marker/AnnotatedPoint object """ _x0, y0 = get_object_coordinates(obj) plot = obj.plot() xmap = plot.canvasMap(plot.X_BOTTOM) xc0, xc1 = xmap.p1(), xmap.p2() _xc0, yc0 = axes_to_canvas(obj, 0, y0) if plot.get_axis_direction("left"): yc1 = yc0 + 1 else: yc1 = yc0 - 1 try: #TODO: eventually add an option to apply interpolation algorithm data = get_image_from_qrect(plot, QPoint(xc0, yc0), QPoint(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=0) x0, _y0 = canvas_to_axes(obj, QPoint(xc0, yc0)) x1, _y1 = canvas_to_axes(obj, QPoint(xc1, yc1)) x = np.linspace(x0, x1, len(y)) return x, y
def __init__(self): QMainWindow.__init__(self) self.setWindowIcon(get_icon(os.path.join(APP_RESOURCES, 'icons', 'python.png'))) self.setupUi(self) # Redirect output to GUI's QTextEdit sys.stdout = OutLog(self.outputTextEdit, sys.stdout) sys.stderr = OutLog(self.outputTextEdit, sys.stderr, QColor(255,0,0) ) settings = QSettings() size = settings.value("MainWindow/Size", QVariant(QSize(600, 500))).toSize() self.resize(size) position = settings.value("MainWindow/Position", QVariant(QPoint(0, 0))).toPoint() self.move(position) self.restoreState( settings.value("MainWindow/State").toByteArray()) self.logger = Logger('Zupport.GUIloader') self.logger.debugging = settings.value("Logging/debugging").toBool() # Set up a ZupportManager to deal with the plugins self.manager = Manager(self) self.plugins = {} # Set up the extents menu self.extent = ExtentContainer() self.menuExtent = QMenu("Extent") resolutions = self.extent.resolutions self.extenactiongroup = QActionGroup(self.menuExtent) noneaction = QAction("None", self.menuExtent) self.extenactiongroup.addAction(noneaction) self.menuExtent.addAction(noneaction) for resolution in resolutions: resolution_text = str(resolution) submenu = self.menuExtent.addMenu(resolution_text) self.menuExtent.addMenu(submenu) for area in self.extent.get_names(resolution): subaction = QAction(str(area) + ": %s" % resolution_text, submenu) subaction.setCheckable(True) self.extenactiongroup.addAction(subaction) submenu.addAction(subaction) noneaction.isChecked() self.menuSettings.addMenu(self.menuExtent) self.actionDebugging_messages.setChecked(self.logger.debugging) self.setWindowTitle("Zupport GUI") self.load_tools() self.toolTreeWidget.itemSelectionChanged.connect(self.update_ui) self.actionDebugging_messages.toggled.connect(self._set_debugging) self.menuExtent.triggered.connect(self.update_ui) self.actionLoad_tool.triggered.connect(self.show_tool_gui) self.toolTreeWidget.doubleClicked.connect(self.show_tool_gui)
def start_moving(self, filter, event): self.shape.attach(filter.plot) self.shape.setZ(filter.plot.get_max_z() + 1) if self.avoid_null_shape: self.start -= QPoint(1, 1) self.shape.move_local_point_to(self.shape_h0, self.start) self.shape.move_local_point_to(self.shape_h1, event.pos()) self.start_moving_action(filter, event) if self.setup_shape_cb is not None: self.setup_shape_cb(self.shape) self.shape.show() filter.plot.replot()
def __init__(self, parent=None): QSplitter.__init__(self, parent) self.setWindowTitle(MAIN_WINDOW_TITLE) self.setWindowIcon(get_icon("agent.svg")) self.sysTray = SystemTray(self) self.connect(self.sysTray, SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.__icon_activated) checks = get_checks() datadog_conf = DatadogConf(get_config_path(), description="Agent settings file: datadog.conf") self.log_file = LogFile() listwidget = QListWidget(self) listwidget.addItems([osp.basename(check.module_name).replace("_", " ").title() for check in checks]) self.properties = PropertiesWidget(self) self.addWidget(listwidget) self.addWidget(self.properties) self.connect(self.properties.enable_button, SIGNAL("clicked()"), lambda: enable_check(self.properties)) self.connect(self.properties.disable_button, SIGNAL("clicked()"), lambda: disable_check(self.properties)) self.connect(self.properties.save_button, SIGNAL("clicked()"), lambda: save_file(self.properties)) self.connect(listwidget, SIGNAL('currentRowChanged(int)'), lambda row: self.properties.set_item(checks[row])) self.connect(self.properties.edit_datadog_conf_button, SIGNAL('clicked()'), lambda: self.properties.set_datadog_conf(datadog_conf)) self.connect(self.properties.view_log_button, SIGNAL('clicked()'), lambda: self.properties.set_log_file(self.log_file)) self.manager_menu = Menu(self) self.connect(self.properties.menu_button, SIGNAL("clicked()"), lambda: self.manager_menu.popup(self.properties.menu_button.mapToGlobal(QPoint(0,0)))) listwidget.setCurrentRow(0) self.setSizes([150, 1]) self.setStretchFactor(1, 1) self.resize(QSize(950, 600)) self.properties.set_datadog_conf(datadog_conf) self.do_refresh()
def move(self, filter, event): if self.active is None: return self.unselection_pending = False if self.inside: self.active.move_local_shape(self.last_pos, event.pos()) self.undo_action = UndoMoveObject(self.active, event.pos(), self.first_pos) else: ctrl = event.modifiers() & Qt.ControlModifier == Qt.ControlModifier self.active.move_local_point_to(self.handle, event.pos(), ctrl) self.undo_action = UndoMovePoint(self.active, self.first_pos, event.pos(), self.handle, ctrl) self.last_pos = QPoint(event.pos()) filter.plot.replot()
def start_tracking(self, filter, event): self.start = self.last = QPoint(event.pos())
def start_tracking(self, filter, event): plot = filter.plot self.inside = False self.active = None self.handle = None self.first_pos = pos = event.pos() self.last_pos = QPoint(pos) selected = plot.get_active_item() distance = CONF.get("plot", "selection/distance", 6) (nearest, nearest_dist, nearest_handle, nearest_inside) = plot.get_nearest_object(pos, distance) if nearest is not None: # Is the nearest object the real deal? if not nearest.can_select() or nearest_dist >= distance: # Looking for the nearest object in z containing cursor position (nearest, nearest_dist, nearest_handle, nearest_inside) = plot.get_nearest_object_in_z(pos) # This will unselect active item only if it's not moved afterwards: self.unselection_pending = selected is nearest if selected and not self.multiselection: # An item is selected self.active = selected (dist, self.handle, self.inside, other_object) = self.active.hit_test(pos) if other_object is not None: # e.g. LegendBoxItem: 'other_object' is the selected curve plot.set_active_item(other_object) return if dist >= distance and not self.inside: # The following allows to move together selected items by # clicking inside any of them (instead of active item only) other_selitems = [ _it for _it in plot.get_selected_items() if _it is not self.active and _it.can_move() ] for selitem in other_selitems: dist, handle, inside, _other = selitem.hit_test(pos) if dist < distance or inside: self.inside = inside break else: self.__unselect_objects(filter) filter.set_state(self.start_state, event) return else: # No item is selected self.active = nearest self.handle = nearest_handle self.inside = nearest_inside dist = nearest_dist if nearest is not None: plot.set_active_item(nearest) if not nearest.selected: if not self.multiselection: plot.unselect_all() plot.select_item(nearest) # Eventually move or resize selected object: self.__move_or_resize_object(dist, distance, event, filter) plot.replot()
def compute_positions(self): from guiqwt.baseplot import axes_to_canvas pos1 = QPoint(*axes_to_canvas(self.obj, *self.coords1)) pos2 = QPoint(*axes_to_canvas(self.obj, *self.coords2)) return pos1, pos2
def get_move_state(self, filter, pos): rct = filter.plot.contentsRect() dx = (pos.x(), self.last.x(), self.start.x(), rct.width()) dy = (pos.y(), self.last.y(), self.start.y(), rct.height()) self.last = QPoint(pos) return dx, dy
def __init__(self, parent=None): log_conf = get_logging_config() QSplitter.__init__(self, parent) self.setWindowTitle(MAIN_WINDOW_TITLE) self.setWindowIcon(get_icon("agent.svg")) self.sysTray = SystemTray(self) self.connect(self.sysTray, SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.__icon_activated) checks = get_checks() datadog_conf = DatadogConf(get_config_path()) self.create_logs_files_windows(log_conf) listwidget = QListWidget(self) listwidget.addItems([ osp.basename(check.module_name).replace("_", " ").title() for check in checks ]) self.properties = PropertiesWidget(self) self.setting_button = QPushButton(get_icon("info.png"), "Logs and Status", self) self.menu_button = QPushButton(get_icon("settings.png"), "Actions", self) self.settings = [ ("Forwarder Logs", lambda: [ self.properties.set_log_file(self.forwarder_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ("Collector Logs", lambda: [ self.properties.set_log_file(self.collector_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ("Dogstatsd Logs", lambda: [ self.properties.set_log_file(self.dogstatsd_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ("JMX Fetch Logs", lambda: [ self.properties.set_log_file(self.jmxfetch_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ] if Platform.is_windows(): self.settings.extend([ ("Service Logs", lambda: [ self.properties.set_log_file(self.service_log_file), self.show_html(self.properties.group_code, self.properties. html_window, False) ]), ]) self.settings.extend([ ("Agent Status", lambda: [ self.properties.html_window.setHtml(self.properties.html_window .latest_status()), self.show_html(self.properties.group_code, self.properties. html_window, True), self.properties.set_status() ]), ]) self.agent_settings = QPushButton(get_icon("edit.png"), "Settings", self) self.connect( self.agent_settings, SIGNAL("clicked()"), lambda: [ self.properties.set_datadog_conf(datadog_conf), self.show_html(self.properties.group_code, self.properties. html_window, False) ]) self.setting_menu = SettingMenu(self.settings) self.connect( self.setting_button, SIGNAL("clicked()"), lambda: self.setting_menu.popup( self.setting_button.mapToGlobal(QPoint(0, 0)))) self.manager_menu = Menu(self) self.connect( self.menu_button, SIGNAL("clicked()"), lambda: self.manager_menu.popup( self.menu_button.mapToGlobal(QPoint(0, 0)))) holdingBox = QGroupBox("", self) Box = QVBoxLayout(self) Box.addWidget(self.agent_settings) Box.addWidget(self.setting_button) Box.addWidget(self.menu_button) Box.addWidget(listwidget) holdingBox.setLayout(Box) self.addWidget(holdingBox) self.addWidget(self.properties) self.connect(self.properties.enable_button, SIGNAL("clicked()"), lambda: enable_check(self.properties)) self.connect(self.properties.disable_button, SIGNAL("clicked()"), lambda: disable_check(self.properties)) self.connect(self.properties.save_button, SIGNAL("clicked()"), lambda: save_file(self.properties)) self.connect( self.properties.refresh_button, SIGNAL("clicked()"), lambda: [ self.properties.set_log_file(self.properties.current_file), self.properties.html_window.setHtml(self.properties.html_window .latest_status()) ]) self.connect( listwidget, SIGNAL('currentRowChanged(int)'), lambda row: [ self.properties.set_item(checks[row]), self.show_html(self.properties.group_code, self.properties. html_window, False) ]) listwidget.setCurrentRow(0) self.setSizes([150, 1]) self.setStretchFactor(1, 1) self.resize(QSize(950, 600)) self.properties.set_datadog_conf(datadog_conf) self.do_refresh()