+ def __init__(self, parent, id, title, fileName=None):
+ """ Standard constructor.
+
+ 'parent', 'id' and 'title' are all passed to the standard wx.Frame
+ constructor. 'fileName' is the name and path of a saved file to
+ load into this frame, if any.
+ """
+ wx.Frame.__init__(self, parent, id, title,
+ style = wx.DEFAULT_FRAME_STYLE | wx.WANTS_CHARS |
+ wx.NO_FULL_REPAINT_ON_RESIZE)
+
+ # Setup our menu bar.
+ menuBar = wx.MenuBar()
+
+ self.fileMenu = wx.Menu()
+ self.fileMenu.Append(wx.ID_NEW, "New\tCtrl-N", "Create a new document")
+ self.fileMenu.Append(wx.ID_OPEN, "Open...\tCtrl-O", "Open an existing document")
+ self.fileMenu.Append(wx.ID_CLOSE, "Close\tCtrl-W")
+ self.fileMenu.AppendSeparator()
+ self.fileMenu.Append(wx.ID_SAVE, "Save\tCtrl-S")
+ self.fileMenu.Append(wx.ID_SAVEAS, "Save As...")
+ self.fileMenu.Append(wx.ID_REVERT, "Revert...")
+ self.fileMenu.AppendSeparator()
+ self.fileMenu.Append(wx.ID_EXIT, "Quit\tCtrl-Q")
+
+ menuBar.Append(self.fileMenu, "File")
+
+ self.editMenu = wx.Menu()
+ self.editMenu.Append(wx.ID_UNDO, "Undo\tCtrl-Z")
+ self.editMenu.Append(wx.ID_REDO, "Redo\tCtrl-Y")
+ self.editMenu.AppendSeparator()
+ self.editMenu.Append(wx.ID_SELECTALL, "Select All\tCtrl-A")
+ self.editMenu.AppendSeparator()
+ self.editMenu.Append(menu_DUPLICATE, "Duplicate\tCtrl-D")
+ self.editMenu.Append(menu_EDIT_PROPS,"Edit...\tCtrl-E", "Edit object properties")
+ self.editMenu.Append(wx.ID_CLEAR, "Delete\tDel")
+
+ menuBar.Append(self.editMenu, "Edit")
+
+ self.viewMenu = wx.Menu()
+ self.viewMenu.Append(menu_DC, "Normal quality",
+ "Normal rendering using wx.DC",
+ kind=wx.ITEM_RADIO)
+ self.viewMenu.Append(menu_GCDC,"High quality",
+ "Anti-aliased rendering using wx.GCDC",
+ kind=wx.ITEM_RADIO)
+
+ menuBar.Append(self.viewMenu, "View")
+
+ self.toolsMenu = wx.Menu()
+ self.toolsMenu.Append(id_SELECT, "Selection", kind=wx.ITEM_RADIO)
+ self.toolsMenu.Append(id_LINE, "Line", kind=wx.ITEM_RADIO)
+ self.toolsMenu.Append(id_POLYGON, "Polygon", kind=wx.ITEM_RADIO)
+ self.toolsMenu.Append(id_SCRIBBLE,"Scribble", kind=wx.ITEM_RADIO)
+ self.toolsMenu.Append(id_RECT, "Rectangle", kind=wx.ITEM_RADIO)
+ self.toolsMenu.Append(id_ELLIPSE, "Ellipse", kind=wx.ITEM_RADIO)
+ self.toolsMenu.Append(id_TEXT, "Text", kind=wx.ITEM_RADIO)
+
+ menuBar.Append(self.toolsMenu, "Tools")
+
+ self.objectMenu = wx.Menu()
+ 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 = wx.Menu()
+ self.helpMenu.Append(menu_ABOUT, "About pySketch...")
+
+ menuBar.Append(self.helpMenu, "Help")
+
+ self.SetMenuBar(menuBar)
+
+ # Create our statusbar
+
+ self.CreateStatusBar()
+
+ # Create our toolbar.
+
+ tsize = (15,15)
+ self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
+
+ artBmp = wx.ArtProvider.GetBitmap
+ self.toolbar.AddSimpleTool(
+ wx.ID_NEW, artBmp(wx.ART_NEW, wx.ART_TOOLBAR, tsize), "New")
+ self.toolbar.AddSimpleTool(
+ wx.ID_OPEN, artBmp(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize), "Open")
+ self.toolbar.AddSimpleTool(
+ wx.ID_SAVE, artBmp(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize), "Save")
+ self.toolbar.AddSimpleTool(
+ wx.ID_SAVEAS, artBmp(wx.ART_FILE_SAVE_AS, wx.ART_TOOLBAR, tsize),
+ "Save As...")
+ #-------
+ self.toolbar.AddSeparator()
+ self.toolbar.AddSimpleTool(
+ wx.ID_UNDO, artBmp(wx.ART_UNDO, wx.ART_TOOLBAR, tsize), "Undo")
+ self.toolbar.AddSimpleTool(
+ wx.ID_REDO, artBmp(wx.ART_REDO, wx.ART_TOOLBAR, tsize), "Redo")
+ self.toolbar.AddSeparator()
+ self.toolbar.AddSimpleTool(
+ menu_DUPLICATE, wx.Bitmap("images/duplicate.bmp", wx.BITMAP_TYPE_BMP),
+ "Duplicate")
+ #-------
+ self.toolbar.AddSeparator()
+ self.toolbar.AddSimpleTool(
+ menu_MOVE_FORWARD, wx.Bitmap("images/moveForward.bmp", wx.BITMAP_TYPE_BMP),
+ "Move Forward")
+ self.toolbar.AddSimpleTool(
+ menu_MOVE_BACKWARD, wx.Bitmap("images/moveBack.bmp", wx.BITMAP_TYPE_BMP),
+ "Move Backward")
+
+ self.toolbar.Realize()
+
+ # Associate menu/toolbar items with their handlers.
+ menuHandlers = [
+ (wx.ID_NEW, self.doNew),
+ (wx.ID_OPEN, self.doOpen),
+ (wx.ID_CLOSE, self.doClose),
+ (wx.ID_SAVE, self.doSave),
+ (wx.ID_SAVEAS, self.doSaveAs),
+ (wx.ID_REVERT, self.doRevert),
+ (wx.ID_EXIT, self.doExit),
+
+ (wx.ID_UNDO, self.doUndo),
+ (wx.ID_REDO, self.doRedo),
+ (wx.ID_SELECTALL, self.doSelectAll),
+ (menu_DUPLICATE, self.doDuplicate),
+ (menu_EDIT_PROPS, self.doEditObject),
+ (wx.ID_CLEAR, self.doDelete),
+
+ (id_SELECT, self.onChooseTool, self.updChooseTool),
+ (id_LINE, self.onChooseTool, self.updChooseTool),
+ (id_POLYGON, self.onChooseTool, self.updChooseTool),
+ (id_SCRIBBLE,self.onChooseTool, self.updChooseTool),
+ (id_RECT, self.onChooseTool, self.updChooseTool),
+ (id_ELLIPSE, self.onChooseTool, self.updChooseTool),
+ (id_TEXT, self.onChooseTool, self.updChooseTool),
+
+ (menu_DC, self.doChooseQuality),
+ (menu_GCDC, self.doChooseQuality),
+
+ (menu_MOVE_FORWARD, self.doMoveForward),
+ (menu_MOVE_TO_FRONT, self.doMoveToFront),
+ (menu_MOVE_BACKWARD, self.doMoveBackward),
+ (menu_MOVE_TO_BACK, self.doMoveToBack),
+
+ (menu_ABOUT, self.doShowAbout)]
+ for combo in menuHandlers:
+ id, handler = combo[:2]
+ self.Bind(wx.EVT_MENU, handler, id = id)
+ if len(combo)>2:
+ self.Bind(wx.EVT_UPDATE_UI, combo[2], id = id)
+
+ # 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.
+
+ self.Bind(wx.EVT_CLOSE, 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.
+
+ self.Bind(wx.EVT_CHAR_HOOK, self.onKeyEvent)
+
+ # Setup our top-most panel. This holds the entire contents of the
+ # window, excluding the menu bar.
+
+ self.topPanel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
+
+ # Setup our tool palette, with all our drawing tools and option icons.
+
+ self.toolPalette = wx.BoxSizer(wx.VERTICAL)
+
+ self.selectIcon = ToolPaletteToggle(self.topPanel, id_SELECT,
+ "select", "Selection Tool", mode=wx.ITEM_RADIO)
+ self.lineIcon = ToolPaletteToggle(self.topPanel, id_LINE,
+ "line", "Line Tool", mode=wx.ITEM_RADIO)
+ self.polygonIcon = ToolPaletteToggle(self.topPanel, id_POLYGON,
+ "polygon", "Polygon Tool", mode=wx.ITEM_RADIO)
+ self.scribbleIcon = ToolPaletteToggle(self.topPanel, id_SCRIBBLE,
+ "scribble", "Scribble Tool", mode=wx.ITEM_RADIO)
+ self.rectIcon = ToolPaletteToggle(self.topPanel, id_RECT,
+ "rect", "Rectangle Tool", mode=wx.ITEM_RADIO)
+ self.ellipseIcon = ToolPaletteToggle(self.topPanel, id_ELLIPSE,
+ "ellipse", "Ellipse Tool", mode=wx.ITEM_RADIO)
+ self.textIcon = ToolPaletteToggle(self.topPanel, id_TEXT,
+ "text", "Text Tool", mode=wx.ITEM_RADIO)
+
+ # Create the tools
+ self.tools = {
+ 'select' : (self.selectIcon, SelectDrawingTool()),
+ 'line' : (self.lineIcon, LineDrawingTool()),
+ 'polygon' : (self.polygonIcon, PolygonDrawingTool()),
+ 'scribble': (self.scribbleIcon, ScribbleDrawingTool()),
+ 'rect' : (self.rectIcon, RectDrawingTool()),
+ 'ellipse' : (self.ellipseIcon, EllipseDrawingTool()),
+ 'text' : (self.textIcon, TextDrawingTool())
+ }
+
+
+ toolSizer = wx.GridSizer(0, 2, 5, 5)
+ toolSizer.Add(self.selectIcon)
+ toolSizer.Add(self.lineIcon)
+ toolSizer.Add(self.rectIcon)
+ toolSizer.Add(self.ellipseIcon)
+ toolSizer.Add(self.polygonIcon)
+ toolSizer.Add(self.scribbleIcon)
+ toolSizer.Add(self.textIcon)
+
+ self.optionIndicator = ToolOptionIndicator(self.topPanel)
+ self.optionIndicator.SetToolTip(
+ wx.ToolTip("Shows Current Pen/Fill/Line Size Settings"))
+
+ optionSizer = wx.BoxSizer(wx.HORIZONTAL)
+
+ self.penOptIcon = ToolPaletteButton(self.topPanel, id_PEN_OPT,
+ "penOpt", "Set Pen Colour",)
+ self.fillOptIcon = ToolPaletteButton(self.topPanel, id_FILL_OPT,
+ "fillOpt", "Set Fill Colour")
+ self.lineOptIcon = ToolPaletteButton(self.topPanel, id_LINE_OPT,
+ "lineOpt", "Set Line Size")