Example #1
0
 def mousePressEvent(self, event: Qt.QMouseEvent) -> None:
     super().mousePressEvent(event)
     pos = Qt.QPoint(event.pos())
     if self.scroll_rect.contains(pos):
         self.cursor_x = pos.x()
         self.clicked.emit(self.x_to_f(self.cursor_x), self.x_to_t(self.cursor_x))
         self.update()
Example #2
0
 def mousePressEvent(self, event: Qt.QMouseEvent) -> None:
     super().mousePressEvent(event)
     pos = Qt.QPoint(event.pos())
     if self.scroll_rect.contains(pos):
         self.set_position(pos.x())
         self.clicked.emit(self.x_to_f(self.cursor_x, Frame),
                           self.x_to_t(self.cursor_x, Time))
Example #3
0
 def mousePressEvent(self, event):
     if event.button() == Qt.RightButton:
         # Rewrite the mouse event to a left button event so the cursor is
         # moved to the location of the pointer.
         event = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
                             Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
     QPlainTextEdit.mousePressEvent(self, event)
Example #4
0
    def mousePressEvent(self, event: QMouseEvent):
        # key == 1 left; key == 2 right

        pos_rel_app = event.pos()
        key = event.button()

        pos_rel_map = pos_rel_app.x() - self.mapLabel.x(), pos_rel_app.y() - self.mapLabel.y()
        if 0 < pos_rel_map[0] < self.mapLabel.width() and 0 < pos_rel_map[1] < self.mapLabel.height():
            if key == 1:
                self.obj_by_click(pos_rel_map)
            elif key == 2:
                self.obj_by_click(pos_rel_map, True)
Example #5
0
 def mouse_move(self, ev: QMouseEvent):
     if self.state == STATE.NORMAL:
         return
     pos = ev.pos()
     valid, relative_pos = self.pos_in_img_area(pos)
     if valid:
         relative_pos = (int(relative_pos[0] / self.scale),
                         int(relative_pos[1] / self.scale))
         if self.state == STATE.DRAW_RECTANGLE:
             self.draw_rect(self.start_point, relative_pos)
             if self.labelimg is not None:
                 pic = self.draw_points()
                 self.show_pic(file_name=None, content=pic)
             else:
                 self.show_pic(file_name=None, content=self.panel_pic)
         elif self.state == STATE.DRAW_POLYGON:
             pass
         elif self.state == STATE.DRAW_ELLIPSE:
             pass
         else:
             raise NotImplementedError()
Example #6
0
 def mouseMoveEvent(self, event: QMouseEvent):
     if self.__mouse_press_pos is not None:
         global_position = event.globalPos()
         diff = global_position - self.__mouse_press_pos
         if self.__rubber_band.isVisible():
             self.__rubber_band.setGeometry(
                 QRect(self.mapFromGlobal(self.__mouse_press_pos),
                       event.pos()).normalized())
             # Add to selection if inside rubber band remove otherwise
             for widget in self.__model_widget_map.values():
                 if self.__rubber_band.geometry().contains(
                         widget.geometry()):
                     self.__add_selection(widget)
                 else:
                     self.__remove_selection(widget)
         else:
             self.setCursor(QtGui.QCursor(QtCore.Qt.ClosedHandCursor))
             self.__grid_offset += diff
             self.__grid.set_offset(self.__grid_offset)
             self.__grid_widget.set_offset(self.__grid_offset)
             self.__grid_widget.repaint()
             self.__model.move_graph_relative(diff.x(), diff.y())
             self.__mouse_press_pos = global_position
Example #7
0
 def mouseMoveEvent(self, _event: QMouseEvent):
     point = self.chart().mapToValue(_event.pos())
     index = round(point.x())
     self.wizard.mouseMove(index)
Example #8
0
 def mouse_moved(self, event: Qt.QMouseEvent) -> None:
     if not event.buttons() & Qt.Qt.LeftButton:
         self.update_labels(event.pos())
Example #9
0
 def mouseMoveEvent(self, e: QMouseEvent):
     # self.diff_pos = e.pos() - self.diff_pos
     # print(diff+self.pos())
     mouse_pos = self.pos() + e.pos()
     self.move(mouse_pos - self.tmp_pos)
Example #10
0
 def mousePressEvent(self, e: QMouseEvent):
     self.tmp_pos = e.pos()
 def mouse_released(self, event: Qt.QMouseEvent) -> None:
     if event.buttons() == Qt.Qt.RightButton:
         self.tracking = True
     self.update_labels(event.pos())
 def mouse_moved(self, event: Qt.QMouseEvent) -> None:
     if self.tracking and not event.buttons():
         self.update_labels(event.pos())
Example #13
0
 def mouse_release(self, ev: QMouseEvent):
     if self.state == STATE.NORMAL:
         return
     if ev.button() == Qt.LeftButton:
         if self.state == STATE.DRAW_RECTANGLE:
             pos = ev.pos()
             valid, relative_pos = self.pos_in_img_area(pos)
             self.logger.debug(valid)
             if valid:
                 self.logger.debug(relative_pos)
                 self.end_point = (int(relative_pos[0] / self.scale),
                                   int(relative_pos[1] / self.scale))
     elif ev.button() == Qt.RightButton:
         if self.state == STATE.NORMAL:
             return
         if self.state == STATE.DRAW_RECTANGLE:
             if self.start_point is None or self.end_point is None:
                 return
             pos = ev.pos()
             valid, relative_pos = self.pos_in_img_area(pos)
             if valid:
                 click_pos = (int(relative_pos[0] / self.scale),
                              int(relative_pos[1] / self.scale))
                 min_x, max_x = min(self.start_point[0],
                                    self.end_point[0]), max(
                                        self.start_point[0],
                                        self.end_point[0])
                 min_y, max_y = min(self.start_point[1],
                                    self.end_point[1]), max(
                                        self.start_point[1],
                                        self.end_point[1])
                 self.logger.debug(click_pos)
                 if min_x <= click_pos[0] <= max_x and min_y <= click_pos[
                         1] <= max_y:
                     pixel_value = self.origin_img[click_pos[1],
                                                   click_pos[0], 0]
                     low, high = pixel_value + \
                         self.pixel_range[0], pixel_value + \
                         self.pixel_range[1]
                     selected_area = self.origin_img[min_y:max_y + 1,
                                                     min_x:max_x + 1, 0]
                     x, y = np.where(
                         (selected_area >= low) * (selected_area <= high))
                     x = x + min_y
                     y = y + min_x
                     self.labelimg[x, y] = 1
                     pic = self.draw_points()
                     self.show_pic(file_name=None, content=pic)
                     self.histroty.append((x, y))
                     self.modified = True
         elif self.state == STATE.DRAW_POLYGON:
             if self.polygon_points is None or self.polygon_points[
                     'finish'] is False:
                 return
             pos = ev.pos()
             valid, relative_pos = self.pos_in_img_area(pos)
             if valid:
                 click_pos = (int(relative_pos[0] / self.scale),
                              int(relative_pos[1] / self.scale))
                 self.logger.debug(click_pos)
                 x_pos = np.array(
                     [item[0] for item in self.polygon_points['points']])
                 y_pos = np.array(
                     [item[1] for item in self.polygon_points['points']])
                 min_x, max_x = x_pos.min(), x_pos.max()
                 min_y, max_y = y_pos.min(), y_pos.max()
                 p = np.array(self.polygon_points['points']).reshape(
                     [1, len(self.polygon_points['points']), 2])
                 p[0, :, 0] -= min_x
                 p[0, :, 1] -= min_y
                 mask = np.zeros([max_y - min_y + 1, max_x - min_x + 1],
                                 np.uint8)
                 mask = cv.fillPoly(mask, p, 1)
                 pixel_value = self.origin_img[click_pos[1], click_pos[0],
                                               0]
                 low, high = pixel_value + \
                     self.pixel_range[0], pixel_value + self.pixel_range[1]
                 selected_img = self.origin_img[min_y:max_y + 1,
                                                min_x:max_x + 1, 0]
                 x, y = np.where(
                     (selected_img >= low) * (selected_img <= high) * mask)
                 x = x + min_y
                 y = y + min_x
                 self.labelimg[x, y] = 1
                 pic = self.draw_points()
                 self.show_pic(file_name=None, content=pic)
                 self.histroty.append((x, y))
                 self.modified = True
         elif self.state == STATE.DRAW_ELLIPSE:
             if self.ellipse_points is None or len(
                     self.ellipse_points['points']
             ) < 3 or self.ellipse_points['info'] is None:
                 return
             pos = ev.pos()
             valid, relative_pos = self.pos_in_img_area(pos)
             if valid:
                 click_pos = (int(relative_pos[0] / self.scale),
                              int(relative_pos[1] / self.scale))
                 self.logger.debug(click_pos)
                 center, r, theta = self.ellipse_points['info']
                 theta = int(np.around(theta))
                 p = cv.ellipse2Poly(center, r, theta, 0, 360, 1)
                 num_p = p.shape[0]
                 p = p.reshape((1, num_p, 2))
                 min_x, max_x = np.min(p[0, :, 0]), np.max(p[0, :, 0])
                 min_y, max_y = np.min(p[0, :, 1]), np.max(p[0, :, 1])
                 p[0, :, 0] -= min_x
                 p[0, :, 1] -= min_y
                 mask = np.zeros((max_y - min_y + 1, max_x - min_x + 1),
                                 np.uint8)
                 mask = cv.fillPoly(mask, p, 1)
                 pixel_value = self.origin_img[click_pos[1], click_pos[0],
                                               0]
                 low, high = pixel_value + \
                     self.pixel_range[0], pixel_value + self.pixel_range[1]
                 selected_img = self.origin_img[min_y:max_y + 1,
                                                min_x:max_x + 1, 0]
                 x, y = np.where(
                     (selected_img >= low) * (selected_img <= high) * mask)
                 x = x + min_y
                 y = y + min_x
                 self.labelimg[x, y] = 1
                 pic = self.draw_points()
                 self.show_pic(file_name=None, content=pic)
                 self.histroty.append((x, y))
                 self.modified = True
                 self.saved = False
Example #14
0
 def mouse_pressed(self, ev: QMouseEvent):
     if self.state == STATE.NORMAL:
         return
     if ev.button() == Qt.LeftButton:
         pos = ev.pos()
         valid, relative_pos = self.pos_in_img_area(pos)
         self.logger.debug(valid)
         if valid:
             self.logger.debug(relative_pos)
             point = (int(relative_pos[0] / self.scale),
                      int(relative_pos[1] / self.scale))
             if self.state == STATE.DRAW_RECTANGLE:
                 self.start_point = point
                 self.end_point = None
                 self.logger.debug(self.start_point)
             elif self.state == STATE.DRAW_POLYGON:
                 if self.polygon_points is None or self.polygon_points[
                         'finish'] is True:
                     self.polygon_points = {
                         'finish': False,
                         'points': [point]
                     }
                 else:
                     p1 = np.array([
                         self.polygon_points['points'][0][0] * self.scale,
                         self.polygon_points['points'][0][1] * self.scale
                     ])
                     p2 = np.array(
                         [point[0] * self.scale, point[1] * self.scale])
                     dis = np.linalg.norm(p1 - p2, 2)
                     if dis < 10:
                         self.polygon_points['finish'] = True
                         self.draw_lines(self.polygon_points['points'],
                                         True)
                     else:
                         self.polygon_points['points'].append(point)
                         self.draw_lines(self.polygon_points['points'],
                                         False)
                     if self.labelimg is not None:
                         pic = self.draw_points()
                         self.show_pic(file_name=None, content=pic)
                     else:
                         self.show_pic(file_name=None,
                                       content=self.panel_pic)
             elif self.state == STATE.DRAW_ELLIPSE:
                 if self.ellipse_points is None:
                     self.ellipse_points = {'points': [point], 'info': None}
                 elif len(self.ellipse_points['points']) == 1:
                     self.ellipse_points['points'].append(point)
                     self.draw_lines(self.ellipse_points['points'], False)
                     if self.labelimg is not None:
                         pic = self.draw_points()
                         self.show_pic(file_name=None, content=pic)
                     else:
                         self.show_pic(file_name=None,
                                       content=self.panel_pic)
                 elif len(self.ellipse_points['points']) == 2:
                     self.ellipse_points['points'].append(point)
                     self.ellipse_points['info'] = self.draw_ellipse(
                         self.ellipse_points['points'])
                     if self.labelimg is not None:
                         pic = self.draw_points()
                         self.show_pic(file_name=None, content=pic)
                     else:
                         self.show_pic(file_name=None,
                                       content=self.panel_pic)
                 else:
                     self.ellipse_points = {'points': [point], 'info': None}
             else:
                 raise NotImplementedError()
     elif ev.button() == Qt.RightButton:
         pass
Example #15
0
 def mouseDoubleClickEvent(self, event: QMouseEvent):
     if event.buttons() == Qt.LeftButton:
         grid_pos = self.__grid.get_grid_position(event.pos())
         self.__controller.create_node(grid_pos.x(), grid_pos.y())