- style = wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS |
- wxNO_FULL_REPAINT_ON_RESIZE)
-
- # Setup our menu bar.
-
- menuBar = wxMenuBar()
-
- self.fileMenu = wxMenu()
- self.fileMenu.Append(wxID_NEW, "New\tCTRL-N")
- self.fileMenu.Append(wxID_OPEN, "Open...\tCTRL-O")
- self.fileMenu.Append(wxID_CLOSE, "Close\tCTRL-W")
- self.fileMenu.AppendSeparator()
- self.fileMenu.Append(wxID_SAVE, "Save\tCTRL-S")
- self.fileMenu.Append(wxID_SAVEAS, "Save As...")
- self.fileMenu.Append(wxID_REVERT, "Revert...")
- self.fileMenu.AppendSeparator()
- self.fileMenu.Append(wxID_EXIT, "Quit\tCTRL-Q")
-
- menuBar.Append(self.fileMenu, "File")
-
- self.editMenu = wxMenu()
- self.editMenu.Append(menu_UNDO, "Undo\tCTRL-Z")
- self.editMenu.AppendSeparator()
- self.editMenu.Append(menu_SELECT_ALL, "Select All\tCTRL-A")
- self.editMenu.AppendSeparator()
- self.editMenu.Append(menu_DUPLICATE, "Duplicate\tCTRL-D")
- self.editMenu.Append(menu_EDIT_TEXT, "Edit...\tCTRL-E")
- self.editMenu.Append(menu_DELETE, "Delete\tDEL")
-
- menuBar.Append(self.editMenu, "Edit")
-
- self.toolsMenu = wxMenu()
- self.toolsMenu.Append(menu_SELECT, "Selection", kind=wxITEM_CHECK)
- self.toolsMenu.Append(menu_LINE, "Line", kind=wxITEM_CHECK)
- self.toolsMenu.Append(menu_RECT, "Rectangle", kind=wxITEM_CHECK)
- self.toolsMenu.Append(menu_ELLIPSE, "Ellipse", kind=wxITEM_CHECK)
- self.toolsMenu.Append(menu_TEXT, "Text", kind=wxITEM_CHECK)
-
- menuBar.Append(self.toolsMenu, "Tools")
-
- self.objectMenu = wxMenu()
- self.objectMenu.Append(menu_MOVE_FORWARD, "Move Forward")
- self.objectMenu.Append(menu_MOVE_TO_FRONT, "Move to Front\tCTRL-F")
- self.objectMenu.Append(menu_MOVE_BACKWARD, "Move Backward")
- self.objectMenu.Append(menu_MOVE_TO_BACK, "Move to Back\tCTRL-B")
-
- menuBar.Append(self.objectMenu, "Object")
-
- self.helpMenu = wxMenu()
- self.helpMenu.Append(menu_ABOUT, "About pySketch...")
-
- menuBar.Append(self.helpMenu, "Help")
-
- self.SetMenuBar(menuBar)
-
- # Create our toolbar.
-
- self.toolbar = self.CreateToolBar(wxTB_HORIZONTAL |
- wxNO_BORDER | wxTB_FLAT)
-
- self.toolbar.AddSimpleTool(wxID_NEW,
- wxBitmap("images/new.bmp",
- wxBITMAP_TYPE_BMP),
- "New")
- self.toolbar.AddSimpleTool(wxID_OPEN,
- wxBitmap("images/open.bmp",
- wxBITMAP_TYPE_BMP),
- "Open")
- self.toolbar.AddSimpleTool(wxID_SAVE,
- wxBitmap("images/save.bmp",
- wxBITMAP_TYPE_BMP),
- "Save")
- self.toolbar.AddSeparator()
- self.toolbar.AddSimpleTool(menu_UNDO,
- wxBitmap("images/undo.bmp",
- wxBITMAP_TYPE_BMP),
- "Undo")
- self.toolbar.AddSeparator()
- self.toolbar.AddSimpleTool(menu_DUPLICATE,
- wxBitmap("images/duplicate.bmp",
- wxBITMAP_TYPE_BMP),
- "Duplicate")
- self.toolbar.AddSeparator()
- self.toolbar.AddSimpleTool(menu_MOVE_FORWARD,
- wxBitmap("images/moveForward.bmp",
- wxBITMAP_TYPE_BMP),
- "Move Forward")
- self.toolbar.AddSimpleTool(menu_MOVE_BACKWARD,
- wxBitmap("images/moveBack.bmp",
- wxBITMAP_TYPE_BMP),
- "Move Backward")
-
- self.toolbar.Realize()
-
- # Associate each menu/toolbar item with the method that handles that
- # item.
-
- EVT_MENU(self, wxID_NEW, self.doNew)
- EVT_MENU(self, wxID_OPEN, self.doOpen)
- EVT_MENU(self, wxID_CLOSE, self.doClose)
- EVT_MENU(self, wxID_SAVE, self.doSave)
- EVT_MENU(self, wxID_SAVEAS, self.doSaveAs)
- EVT_MENU(self, wxID_REVERT, self.doRevert)
- EVT_MENU(self, wxID_EXIT, self.doExit)
-
- EVT_MENU(self, menu_UNDO, self.doUndo)
- EVT_MENU(self, menu_SELECT_ALL, self.doSelectAll)
- EVT_MENU(self, menu_DUPLICATE, self.doDuplicate)
- EVT_MENU(self, menu_EDIT_TEXT, self.doEditText)
- EVT_MENU(self, menu_DELETE, self.doDelete)
-
- EVT_MENU(self, menu_SELECT, self.doChooseSelectTool)
- EVT_MENU(self, menu_LINE, self.doChooseLineTool)
- EVT_MENU(self, menu_RECT, self.doChooseRectTool)
- EVT_MENU(self, menu_ELLIPSE, self.doChooseEllipseTool)
- EVT_MENU(self, menu_TEXT, self.doChooseTextTool)
-
- EVT_MENU(self, menu_MOVE_FORWARD, self.doMoveForward)
- EVT_MENU(self, menu_MOVE_TO_FRONT, self.doMoveToFront)
- EVT_MENU(self, menu_MOVE_BACKWARD, self.doMoveBackward)
- EVT_MENU(self, menu_MOVE_TO_BACK, self.doMoveToBack)
-
- EVT_MENU(self, menu_ABOUT, self.doShowAbout)
-
- # Install our own method to handle closing the window. This allows us
- # to ask the user if he/she wants to save before closing the window, as
- # well as keeping track of which windows are currently open.
-
- EVT_CLOSE(self, self.doClose)
-
- # Install our own method for handling keystrokes. We use this to let
- # the user move the selected object(s) around using the arrow keys.
-
- EVT_CHAR_HOOK(self, self.onKeyEvent)
-
- # Setup our top-most panel. This holds the entire contents of the
- # window, excluding the menu bar.
-
- self.topPanel = wxPanel(self, -1, style=wxSIMPLE_BORDER)
-
- # Setup our tool palette, with all our drawing tools and option icons.
-
- self.toolPalette = wxBoxSizer(wxVERTICAL)
-
- self.selectIcon = ToolPaletteIcon(self.topPanel, id_SELECT,
- "select", "Selection Tool")
- self.lineIcon = ToolPaletteIcon(self.topPanel, id_LINE,
- "line", "Line Tool")
- self.rectIcon = ToolPaletteIcon(self.topPanel, id_RECT,
- "rect", "Rectangle Tool")
- self.ellipseIcon = ToolPaletteIcon(self.topPanel, id_ELLIPSE,
- "ellipse", "Ellipse Tool")
- self.textIcon = ToolPaletteIcon(self.topPanel, id_TEXT,
- "text", "Text Tool")
-
- toolSizer = wxGridSizer(0, 2, 5, 5)
- toolSizer.Add(self.selectIcon)
- toolSizer.Add(0, 0) # Gap to make tool icons line up nicely.
- toolSizer.Add(self.lineIcon)
- toolSizer.Add(self.rectIcon)
- toolSizer.Add(self.ellipseIcon)
- toolSizer.Add(self.textIcon)
-
- self.optionIndicator = ToolOptionIndicator(self.topPanel)
- self.optionIndicator.SetToolTip(
- wxToolTip("Shows Current Pen/Fill/Line Size Settings"))
-
- optionSizer = wxBoxSizer(wxHORIZONTAL)
-
- self.penOptIcon = ToolPaletteIcon(self.topPanel, id_PEN_OPT,
- "penOpt", "Set Pen Colour")
- self.fillOptIcon = ToolPaletteIcon(self.topPanel, id_FILL_OPT,
- "fillOpt", "Set Fill Colour")
- self.lineOptIcon = ToolPaletteIcon(self.topPanel, id_LINE_OPT,
- "lineOpt", "Set Line Size")
-
- margin = wxLEFT | wxRIGHT
- optionSizer.Add(self.penOptIcon, 0, margin, 1)
- optionSizer.Add(self.fillOptIcon, 0, margin, 1)
- optionSizer.Add(self.lineOptIcon, 0, margin, 1)
-
- margin = wxTOP | wxLEFT | wxRIGHT | wxALIGN_CENTRE
- self.toolPalette.Add(toolSizer, 0, margin, 5)
- self.toolPalette.Add(0, 0, 0, margin, 5) # Spacer.
- self.toolPalette.Add(self.optionIndicator, 0, margin, 5)
- self.toolPalette.Add(optionSizer, 0, margin, 5)
+ style = wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS |
+ wxNO_FULL_REPAINT_ON_RESIZE)
+
+ # Setup our menu bar.
+
+ menuBar = wxMenuBar()
+
+ self.fileMenu = wxMenu()
+ self.fileMenu.Append(wxID_NEW, "New\tCTRL-N")
+ self.fileMenu.Append(wxID_OPEN, "Open...\tCTRL-O")
+ self.fileMenu.Append(wxID_CLOSE, "Close\tCTRL-W")
+ self.fileMenu.AppendSeparator()
+ self.fileMenu.Append(wxID_SAVE, "Save\tCTRL-S")
+ self.fileMenu.Append(wxID_SAVEAS, "Save As...")
+ self.fileMenu.Append(wxID_REVERT, "Revert...")
+ self.fileMenu.AppendSeparator()
+ self.fileMenu.Append(wxID_EXIT, "Quit\tCTRL-Q")
+
+ menuBar.Append(self.fileMenu, "File")
+
+ self.editMenu = wxMenu()
+ self.editMenu.Append(menu_UNDO, "Undo\tCTRL-Z")
+ self.editMenu.AppendSeparator()
+ self.editMenu.Append(menu_SELECT_ALL, "Select All\tCTRL-A")
+ self.editMenu.AppendSeparator()
+ self.editMenu.Append(menu_DUPLICATE, "Duplicate\tCTRL-D")
+ self.editMenu.Append(menu_EDIT_TEXT, "Edit...\tCTRL-E")
+ self.editMenu.Append(menu_DELETE, "Delete\tDEL")
+
+ menuBar.Append(self.editMenu, "Edit")
+
+ self.toolsMenu = wxMenu()
+ self.toolsMenu.Append(menu_SELECT, "Selection", kind=wxITEM_CHECK)
+ self.toolsMenu.Append(menu_LINE, "Line", kind=wxITEM_CHECK)
+ self.toolsMenu.Append(menu_RECT, "Rectangle", kind=wxITEM_CHECK)
+ self.toolsMenu.Append(menu_ELLIPSE, "Ellipse", kind=wxITEM_CHECK)
+ self.toolsMenu.Append(menu_TEXT, "Text", kind=wxITEM_CHECK)
+
+ menuBar.Append(self.toolsMenu, "Tools")
+
+ self.objectMenu = wxMenu()
+ self.objectMenu.Append(menu_MOVE_FORWARD, "Move Forward")
+ self.objectMenu.Append(menu_MOVE_TO_FRONT, "Move to Front\tCTRL-F")
+ self.objectMenu.Append(menu_MOVE_BACKWARD, "Move Backward")
+ self.objectMenu.Append(menu_MOVE_TO_BACK, "Move to Back\tCTRL-B")
+
+ menuBar.Append(self.objectMenu, "Object")
+
+ self.helpMenu = wxMenu()
+ self.helpMenu.Append(menu_ABOUT, "About pySketch...")
+
+ menuBar.Append(self.helpMenu, "Help")
+
+ self.SetMenuBar(menuBar)
+
+ # Create our toolbar.
+
+ self.toolbar = self.CreateToolBar(wxTB_HORIZONTAL |
+ wxNO_BORDER | wxTB_FLAT)
+
+ self.toolbar.AddSimpleTool(wxID_NEW,
+ wxBitmap("images/new.bmp",
+ wxBITMAP_TYPE_BMP),
+ "New")
+ self.toolbar.AddSimpleTool(wxID_OPEN,
+ wxBitmap("images/open.bmp",
+ wxBITMAP_TYPE_BMP),
+ "Open")
+ self.toolbar.AddSimpleTool(wxID_SAVE,
+ wxBitmap("images/save.bmp",
+ wxBITMAP_TYPE_BMP),
+ "Save")
+ self.toolbar.AddSeparator()
+ self.toolbar.AddSimpleTool(menu_UNDO,
+ wxBitmap("images/undo.bmp",
+ wxBITMAP_TYPE_BMP),
+ "Undo")
+ self.toolbar.AddSeparator()
+ self.toolbar.AddSimpleTool(menu_DUPLICATE,
+ wxBitmap("images/duplicate.bmp",
+ wxBITMAP_TYPE_BMP),
+ "Duplicate")
+ self.toolbar.AddSeparator()
+ self.toolbar.AddSimpleTool(menu_MOVE_FORWARD,
+ wxBitmap("images/moveForward.bmp",
+ wxBITMAP_TYPE_BMP),
+ "Move Forward")
+ self.toolbar.AddSimpleTool(menu_MOVE_BACKWARD,
+ wxBitmap("images/moveBack.bmp",
+ wxBITMAP_TYPE_BMP),
+ "Move Backward")
+
+ self.toolbar.Realize()
+
+ # Associate each menu/toolbar item with the method that handles that
+ # item.
+
+ EVT_MENU(self, wxID_NEW, self.doNew)
+ EVT_MENU(self, wxID_OPEN, self.doOpen)
+ EVT_MENU(self, wxID_CLOSE, self.doClose)
+ EVT_MENU(self, wxID_SAVE, self.doSave)
+ EVT_MENU(self, wxID_SAVEAS, self.doSaveAs)
+ EVT_MENU(self, wxID_REVERT, self.doRevert)
+ EVT_MENU(self, wxID_EXIT, self.doExit)
+
+ EVT_MENU(self, menu_UNDO, self.doUndo)
+ EVT_MENU(self, menu_SELECT_ALL, self.doSelectAll)
+ EVT_MENU(self, menu_DUPLICATE, self.doDuplicate)
+ EVT_MENU(self, menu_EDIT_TEXT, self.doEditText)
+ EVT_MENU(self, menu_DELETE, self.doDelete)
+
+ EVT_MENU(self, menu_SELECT, self.doChooseSelectTool)
+ EVT_MENU(self, menu_LINE, self.doChooseLineTool)
+ EVT_MENU(self, menu_RECT, self.doChooseRectTool)
+ EVT_MENU(self, menu_ELLIPSE, self.doChooseEllipseTool)
+ EVT_MENU(self, menu_TEXT, self.doChooseTextTool)
+
+ EVT_MENU(self, menu_MOVE_FORWARD, self.doMoveForward)
+ EVT_MENU(self, menu_MOVE_TO_FRONT, self.doMoveToFront)
+ EVT_MENU(self, menu_MOVE_BACKWARD, self.doMoveBackward)
+ EVT_MENU(self, menu_MOVE_TO_BACK, self.doMoveToBack)
+
+ EVT_MENU(self, menu_ABOUT, self.doShowAbout)
+
+ # Install our own method to handle closing the window. This allows us
+ # to ask the user if he/she wants to save before closing the window, as
+ # well as keeping track of which windows are currently open.
+
+ EVT_CLOSE(self, self.doClose)
+
+ # Install our own method for handling keystrokes. We use this to let
+ # the user move the selected object(s) around using the arrow keys.
+
+ EVT_CHAR_HOOK(self, self.onKeyEvent)
+
+ # Setup our top-most panel. This holds the entire contents of the
+ # window, excluding the menu bar.
+
+ self.topPanel = wxPanel(self, -1, style=wxSIMPLE_BORDER)
+
+ # Setup our tool palette, with all our drawing tools and option icons.
+
+ self.toolPalette = wxBoxSizer(wxVERTICAL)
+
+ self.selectIcon = ToolPaletteIcon(self.topPanel, id_SELECT,
+ "select", "Selection Tool")
+ self.lineIcon = ToolPaletteIcon(self.topPanel, id_LINE,
+ "line", "Line Tool")
+ self.rectIcon = ToolPaletteIcon(self.topPanel, id_RECT,
+ "rect", "Rectangle Tool")
+ self.ellipseIcon = ToolPaletteIcon(self.topPanel, id_ELLIPSE,
+ "ellipse", "Ellipse Tool")
+ self.textIcon = ToolPaletteIcon(self.topPanel, id_TEXT,
+ "text", "Text Tool")
+
+ toolSizer = wxGridSizer(0, 2, 5, 5)
+ toolSizer.Add(self.selectIcon)
+ toolSizer.Add((0, 0)) # Gap to make tool icons line up nicely.
+ toolSizer.Add(self.lineIcon)
+ toolSizer.Add(self.rectIcon)
+ toolSizer.Add(self.ellipseIcon)
+ toolSizer.Add(self.textIcon)
+
+ self.optionIndicator = ToolOptionIndicator(self.topPanel)
+ self.optionIndicator.SetToolTip(
+ wxToolTip("Shows Current Pen/Fill/Line Size Settings"))
+
+ optionSizer = wxBoxSizer(wxHORIZONTAL)
+
+ self.penOptIcon = ToolPaletteIcon(self.topPanel, id_PEN_OPT,
+ "penOpt", "Set Pen Colour")
+ self.fillOptIcon = ToolPaletteIcon(self.topPanel, id_FILL_OPT,
+ "fillOpt", "Set Fill Colour")
+ self.lineOptIcon = ToolPaletteIcon(self.topPanel, id_LINE_OPT,
+ "lineOpt", "Set Line Size")
+
+ margin = wxLEFT | wxRIGHT
+ optionSizer.Add(self.penOptIcon, 0, margin, 1)
+ optionSizer.Add(self.fillOptIcon, 0, margin, 1)
+ optionSizer.Add(self.lineOptIcon, 0, margin, 1)
+
+ margin = wxTOP | wxLEFT | wxRIGHT | wxALIGN_CENTRE
+ self.toolPalette.Add(toolSizer, 0, margin, 5)
+ self.toolPalette.Add((0, 0), 0, margin, 5) # Spacer.
+ self.toolPalette.Add(self.optionIndicator, 0, margin, 5)
+ self.toolPalette.Add(optionSizer, 0, margin, 5)