本文整理汇总了Python中document.Document.new_shape方法的典型用法代码示例。如果您正苦于以下问题:Python Document.new_shape方法的具体用法?Python Document.new_shape怎么用?Python Document.new_shape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类document.Document
的用法示例。
在下文中一共展示了Document.new_shape方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDeselectsWhenClickingElsewhere
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import new_shape [as 别名]
def testDeselectsWhenClickingElsewhere(self):
document = Document()
document.new_shape()
document.current_shape.append_point((0, 0))
tool = SelectTool(document)
_perform_click(tool, 0, 0)
_perform_click(tool, 1000, 0) # Click far away
self.assertTrue(document.selected_point_index is None)
示例2: testSelectsWhenMouseClicked
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import new_shape [as 别名]
def testSelectsWhenMouseClicked(self):
document = Document()
document.new_shape()
document.current_shape.append_point((0, 0))
tool = SelectTool(document)
self.assertTrue(document.selected_point_index is None)
_perform_click(tool, 0, 0)
self.assertTrue(document.selected_point_index == 0)
示例3: Canvas
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import new_shape [as 别名]
class Canvas(QGraphicsView):
def __init__(self):
self._scene = QGraphicsScene()
QGraphicsView.__init__(self, self._scene)
self._document = Document()
self._document.changed.connect(self._update_scene)
self.use_tool(PenTool)
self.setMouseTracking(True)
def use_tool(self, tool_class):
"""Instantiates tool_class and uses it as the current tool."""
self._tool = tool_class(self._document)
self._tool.needs_repaint.connect(self._update)
def new_shape(self):
self._document.new_shape()
def delete_selection(self):
self._document.delete_selection()
if not self._document.current_shape:
self._document.delete_current_shape()
def _update(self):
self.update()
def _update_scene(self):
self._scene.clear()
for shape in self._document.shapes:
self._scene.addPath(shape.make_painter_path())
def _call_tool(self, method_name, *args):
method = getattr(self._tool, method_name, None)
if method:
method(*args)
def _map_event(self, qt_event):
"""Take a QMouseEvent and return a MouseEvent in scene space."""
point = self.mapToScene(qt_event.x(), qt_event.y())
return MouseEvent((_round_to_half(point.x()), _round_to_half(point.y())))
def mouseMoveEvent(self, event):
self._call_tool("mouse_move_event", self._map_event(event))
def mousePressEvent(self, event):
self._call_tool("mouse_press_event", self._map_event(event))
def mouseReleaseEvent(self, event):
self._call_tool("mouse_release_event", self._map_event(event))
def paintEvent(self, event):
QGraphicsView.paintEvent(self, event)
self._call_tool("paint_event", self)
示例4: testRedundantNewShapeCreatesOnlyOneShape
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import new_shape [as 别名]
def testRedundantNewShapeCreatesOnlyOneShape(self):
document = Document()
document.new_shape()
document.new_shape()
self.assertEqual(document.shape_count, 1)
示例5: testNewShape
# 需要导入模块: from document import Document [as 别名]
# 或者: from document.Document import new_shape [as 别名]
def testNewShape(self):
document = Document()
shape = document.new_shape()
self.assertTrue(shape is not None)
self.assertEqual(document.shape_count, 1)