예제 #1
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self._create_actions()
        self._create_toolbar()
        self._canvas = Canvas()
        self._canvas.scale(16, 16)
        self.setCentralWidget(self._canvas)

    def _create_actions(self):
        self._delete_action = QAction("Delete", None)
        self._delete_action.setShortcuts(QKeySequence.Delete)
        self._delete_action.triggered.connect(self._delete)

        self._select_action = QAction("Select", None)
        self._select_action.setCheckable(True)
        self._select_action.triggered.connect(self._use_select_tool)

        self._pen_action = QAction("Pen", None)
        self._pen_action.setCheckable(True)
        self._pen_action.setChecked(True)
        self._pen_action.triggered.connect(self._use_pen_tool)

        self._new_shape_action = QAction("New Shape", None)
        self._new_shape_action.triggered.connect(self._new_shape)

        self._tool_group = QActionGroup(None)
        self._tool_group.addAction(self._select_action)
        self._tool_group.addAction(self._pen_action)

    def _create_toolbar(self):
        toolbar = self.addToolBar("Tools")
        toolbar.addAction(self._delete_action)
        toolbar.addAction(self._select_action)
        toolbar.addAction(self._pen_action)
        toolbar.addAction(self._new_shape_action)

    def _use_select_tool(self):
        self._canvas.use_tool(SelectTool)

    def _use_pen_tool(self):
        self._canvas.use_tool(PenTool)

    def _new_shape(self):
        self._canvas.new_shape()

    def _delete(self):
        self._canvas.delete_selection()