def __init__(self, parent, id_, wsize, title): """Initialiaze the Frame and Event Handlers. @param wsize: Windows initial size @param title: Windows Title """ wx.Frame.__init__(self, parent, id_, title, size=wsize, style=wx.DEFAULT_FRAME_STYLE) self._mgr = wx.aui.AuiManager(flags=wx.aui.AUI_MGR_DEFAULT | \ wx.aui.AUI_MGR_TRANSPARENT_DRAG | \ wx.aui.AUI_MGR_TRANSPARENT_HINT) self._mgr.SetManagedWindow(self) viewmgr.PerspectiveManager.__init__(self, self._mgr, \ CONFIG['CACHE_DIR']) # Setup app icon and title self.SetTitle() util.SetWindowIcon(self) # Attributes self.LOG = wx.GetApp().GetLog() self._exiting = False self._handlers = dict(menu=list(), ui=list()) #---- Sizers to hold subapplets ----# self.sizer = wx.BoxSizer(wx.VERTICAL) #---- Setup File History ----# self.filehistory = wx.FileHistory(_PGET('FHIST_LVL', 'int', 5)) #---- Status bar on bottom of window ----# self.SetStatusBar(ed_statbar.EdStatBar(self)) #---- End Statusbar Setup ----# #---- Notebook that contains the editting buffers ----# edit_pane = wx.Panel(self) self.nb = ed_pages.EdPages(edit_pane, wx.ID_ANY) edit_pane.nb = self.nb self.sizer.Add(self.nb, 1, wx.EXPAND) edit_pane.SetSizer(self.sizer) self._mgr.AddPane(edit_pane, wx.aui.AuiPaneInfo(). \ Name("EditPane").Center().Layer(1).Dockable(False). \ CloseButton(False).MaximizeButton(False). \ CaptionVisible(False)) #---- Command Bar ----# self._cmdbar = ed_cmdbar.CommandBar(edit_pane, ID_COMMAND_BAR) self._cmdbar.Hide() #---- Setup Toolbar ----# self.SetToolBar(ed_toolbar.EdToolBar(self)) self.GetToolBar().Show(_PGET('TOOLBAR')) #---- End Toolbar Setup ----# #---- Menus ----# menbar = ed_menu.EdMenuBar() # Todo this should not be hard coded menbar.GetMenuByName("view").InsertMenu(5, ID_PERSPECTIVES, _("Perspectives"), self.GetPerspectiveControls()) ## Setup additional menu items self.filehistory.UseMenu(menbar.GetMenuByName("filehistory")) menbar.GetMenuByName("settings").AppendMenu(ID_LEXER, _("Lexers"), syntax.GenLexerMenu(), _("Manually Set a Lexer/Syntax")) # On mac, do this to make help menu appear in correct location # Note it must be done before setting the menu bar and after the # menus have been created. if wx.Platform == '__WXMAC__': wx.GetApp().SetMacHelpMenuTitleName(_("&Help")) #---- Menu Bar ----# self.SetMenuBar(menbar) #---- Actions to take on menu events ----# # Collect Menu Event handler pairs self._handlers['menu'].extend([# File Menu (ID_NEW, self.OnNew), (ID_OPEN, self.OnOpen), (ID_CLOSE, self.OnClosePage), (ID_CLOSEALL, self.OnClosePage), (ID_SAVE, self.OnSave), (ID_SAVEAS, self.OnSaveAs), (ID_SAVEALL, self.OnSave), (ID_SAVE_PROFILE, self.OnSaveProfile), (ID_LOAD_PROFILE, self.OnLoadProfile), (ID_EXIT, wx.GetApp().OnExit), (ID_PRINT, self.OnPrint), (ID_PRINT_PRE, self.OnPrint), (ID_PRINT_SU, self.OnPrint), # Edit Menu (ID_FIND, self.nb.FindService.OnShowFindDlg), (ID_FIND_REPLACE, self.nb.FindService.OnShowFindDlg), (ID_QUICK_FIND, self.OnCommandBar), (ID_PREF, OnPreferences), # View Menu (ID_GOTO_LINE, self.OnCommandBar), (ID_GOTO_MBRACE, self.DispatchToControl), (ID_VIEW_TOOL, self.OnViewTb), # Format Menu (ID_FONT, self.OnFont), # Tool Menu (ID_COMMAND, self.OnCommandBar), (ID_STYLE_EDIT, self.OnStyleEdit), (ID_PLUGMGR, self.OnPluginMgr), # Help Menu (ID_ABOUT, OnAbout), (ID_HOMEPAGE, self.OnHelp), (ID_DOCUMENTATION, self.OnHelp), (ID_TRANSLATE, self.OnHelp), (ID_CONTACT, self.OnHelp)]) self._handlers['menu'].extend([(l_id, self.DispatchToControl) for l_id in syntax.SyntaxIds()]) # Extra menu handlers (need to work these into above system yet) self.Bind(wx.EVT_MENU, self.DispatchToControl) self.Bind(wx.EVT_MENU, self.OnGenerate) self.Bind(wx.EVT_MENU_RANGE, self.OnFileHistory, id=wx.ID_FILE1, id2=wx.ID_FILE9) # Update UI Handlers self._handlers['ui'].extend([# Edit Menu (ID_COPY, self.OnUpdateClipboardUI), (ID_CUT, self.OnUpdateClipboardUI), (ID_PASTE, self.OnUpdateClipboardUI), (ID_UNDO, self.OnUpdateClipboardUI), (ID_REDO, self.OnUpdateClipboardUI), # Format Menu (ID_INDENT, self.OnUpdateFormatUI), (ID_USE_SOFTTABS, self.OnUpdateFormatUI), (ID_TO_UPPER, self.OnUpdateFormatUI), (ID_TO_LOWER, self.OnUpdateFormatUI), (ID_WORD_WRAP, self.OnUpdateFormatUI), (ID_EOL_MAC, self.OnUpdateFormatUI), (ID_EOL_WIN, self.OnUpdateFormatUI), (ID_EOL_UNIX, self.OnUpdateFormatUI), # Settings Menu (ID_AUTOCOMP, self.OnUpdateSettingsUI), (ID_AUTOINDENT, self.OnUpdateSettingsUI), (ID_SYNTAX, self.OnUpdateSettingsUI), (ID_FOLDING, self.OnUpdateSettingsUI), (ID_BRACKETHL, self.OnUpdateSettingsUI), # View Menu (ID_ZOOM_NORMAL, self.OnUpdateViewUI), (ID_ZOOM_IN, self.OnUpdateViewUI), (ID_ZOOM_OUT, self.OnUpdateViewUI), (ID_GOTO_MBRACE, self.OnUpdateViewUI), (ID_HLCARET_LINE, self.OnUpdateViewUI), (ID_VIEW_TOOL, self.OnUpdateViewUI), (ID_SHOW_WS, self.OnUpdateViewUI), (ID_SHOW_EDGE, self.OnUpdateViewUI), (ID_SHOW_EOL, self.OnUpdateViewUI), (ID_SHOW_LN, self.OnUpdateViewUI), (ID_INDENT_GUIDES, self.OnUpdateViewUI) ]) # Lexer Menu self._handlers['ui'].extend([(l_id, self.OnUpdateLexerUI) for l_id in syntax.SyntaxIds()]) # Perspectives self._handlers['ui'].extend(self.GetPersectiveHandlers()) #---- End Menu Setup ----# #---- Other Event Handlers ----# # Frame self.Bind(wx.EVT_ACTIVATE, self.OnActivate) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Bind(ed_event.EVT_STATUS, self.OnStatus) # Find Dialog self.Bind(wx.EVT_FIND, self.nb.FindService.OnFind) self.Bind(wx.EVT_FIND_NEXT, self.nb.FindService.OnFind) self.Bind(wx.EVT_FIND_REPLACE, self.nb.FindService.OnFind) self.Bind(wx.EVT_FIND_REPLACE_ALL, self.nb.FindService.OnFind) self.Bind(wx.EVT_FIND_CLOSE, self.nb.FindService.OnFindClose) #---- End other event actions ----# #---- Final Setup Calls ----# self.LoadFileHistory(_PGET('FHIST_LVL', fmt='int')) # Call add on plugins self.LOG("[ed_main][info] Loading MainWindow Plugins") plgmgr = wx.GetApp().GetPluginManager() addons = MainWindowAddOn(plgmgr) addons.Init(self) self._handlers['menu'].extend(addons.GetEventHandlers()) self._handlers['ui'].extend(addons.GetEventHandlers(ui_evt=True)) self._shelf = iface.Shelf(plgmgr) self._shelf.Init(self) self._handlers['ui'].extend(self._shelf.GetUiHandlers()) self.LOG("[ed_main][info] Loading Generator plugins") generator.Generator(plgmgr).InstallMenu(menbar.GetMenuByName("tools")) # Set Perspective self.SetPerspective(_PGET('DEFAULT_VIEW')) self._mgr.Update()
def __init__(self, parent, id_, wsize, title): """Initialiaze the Frame and Event Handlers. @param wsize: Windows initial size @param title: Windows Title """ wx.Frame.__init__(self, parent, id_, title, size=wsize, style=wx.DEFAULT_FRAME_STYLE) self._mgr = wx.aui.AuiManager(flags=wx.aui.AUI_MGR_DEFAULT | \ wx.aui.AUI_MGR_TRANSPARENT_DRAG | \ wx.aui.AUI_MGR_TRANSPARENT_HINT) self._mgr.SetManagedWindow(self) viewmgr.PerspectiveManager.__init__(self, self._mgr, \ CONFIG['CACHE_DIR']) # Setup app icon and title self.SetTitle() util.SetWindowIcon(self) # Check if user wants Metal Style under OS X # NOTE: soon to be deprecated if wx.Platform == '__WXMAC__' and _PGET('METAL'): self.SetExtraStyle(wx.FRAME_EX_METAL) # Attributes self.LOG = wx.GetApp().GetLog() self._handlers = dict(menu=list(), ui=list()) #---- Sizers to hold subapplets ----# self.sizer = wx.BoxSizer(wx.VERTICAL) #---- Setup File History ----# self.filehistory = wx.FileHistory(_PGET('FHIST_LVL', 'int', 5)) #---- Status bar on bottom of window ----# self.CreateStatusBar(3, style=wx.ST_SIZEGRIP) self.SetStatusWidths([-1, 120, 155]) #---- End Statusbar Setup ----# #---- Notebook that contains the editting buffers ----# edit_pane = wx.Panel(self) self.nb = ed_pages.EdPages(edit_pane, wx.ID_ANY) edit_pane.nb = self.nb self.sizer.Add(self.nb, 1, wx.EXPAND) edit_pane.SetSizer(self.sizer) self._mgr.AddPane(edit_pane, wx.aui.AuiPaneInfo(). \ Name("EditPane").Center().Layer(1).Dockable(False). \ CloseButton(False).MaximizeButton(False). \ CaptionVisible(False)) #---- Command Bar ----# self._cmdbar = ed_cmdbar.CommandBar(edit_pane, ID_COMMAND_BAR) self._cmdbar.Hide() #---- Setup Toolbar ----# self.SetToolBar(ed_toolbar.EdToolBar(self)) if not _PGET('TOOLBAR'): self.GetToolBar().Hide() #---- End Toolbar Setup ----# #---- Menus ----# menbar = ed_menu.EdMenuBar() self._menus = dict(file=menbar.GetMenuByName("file"), edit=menbar.GetMenuByName("edit"), view=menbar.GetMenuByName("view"), viewedit=menbar.GetMenuByName("viewedit"), format=menbar.GetMenuByName("format"), settings=menbar.GetMenuByName("settings"), tools=menbar.GetMenuByName("tools"), lineformat=menbar.GetMenuByName("lineformat"), language=syntax.GenLexerMenu()) # Todo this should not be hard coded self._menus['view'].InsertMenu(5, ID_PERSPECTIVES, _("Perspectives"), self.GetPerspectiveControls()) ## Setup additional menu items self.filehistory.UseMenu(menbar.GetMenuByName("filehistory")) self._menus['settings'].AppendMenu(ID_LEXER, _("Lexers"), self._menus['language'], _("Manually Set a Lexer/Syntax")) # On mac, do this to make help menu appear in correct location # Note it must be done before setting the menu bar and after the # menus have been created. if wx.Platform == '__WXMAC__': wx.GetApp().SetMacHelpMenuTitleName(_("Help")) #---- Menu Bar ----# self.SetMenuBar(menbar) #---- Actions to take on menu events ----# self.Bind(wx.EVT_MENU_OPEN, self.UpdateMenu) if wx.Platform == '__WXGTK__': self.Bind(wx.EVT_MENU_HIGHLIGHT, \ self.OnMenuHighlight, id=ID_LEXER) self.Bind(wx.EVT_MENU_HIGHLIGHT, \ self.OnMenuHighlight, id=ID_EOL_MODE) # Collect Menu Event handler pairs self._handlers['menu'].extend([ # File Menu (ID_NEW, self.OnNew), (ID_OPEN, self.OnOpen), (ID_CLOSE, self.OnClosePage), (ID_CLOSE_WINDOW, self.OnClose), (ID_CLOSEALL, self.OnClosePage), (ID_SAVE, self.OnSave), (ID_SAVEAS, self.OnSaveAs), (ID_SAVEALL, self.OnSave), (ID_SAVE_PROFILE, self.OnSaveProfile), (ID_LOAD_PROFILE, self.OnLoadProfile), (ID_EXIT, wx.GetApp().OnExit), (ID_PRINT, self.OnPrint), (ID_PRINT_PRE, self.OnPrint), (ID_PRINT_SU, self.OnPrint), # Edit Menu (ID_FIND, self.nb.FindService.OnShowFindDlg), (ID_FIND_REPLACE, self.nb.FindService.OnShowFindDlg), (ID_QUICK_FIND, self.OnCommandBar), (ID_PREF, self.OnPreferences), # View Menu (ID_GOTO_LINE, self.OnCommandBar), (ID_VIEW_TOOL, self.OnViewTb), # Format Menu (ID_FONT, self.OnFont), # Tool Menu (ID_COMMAND, self.OnCommandBar), (ID_STYLE_EDIT, self.OnStyleEdit), (ID_PLUGMGR, self.OnPluginMgr), # Help Menu (ID_ABOUT, self.OnAbout), (ID_HOMEPAGE, self.OnHelp), (ID_DOCUMENTATION, self.OnHelp), (ID_CONTACT, self.OnHelp) ]) self._handlers['menu'].extend([(l_id, self.DispatchToControl) for l_id in syntax.SyntaxIds()]) # Extra menu handlers (need to work these into above system yet self.Bind(wx.EVT_MENU, self.DispatchToControl) self.Bind(wx.EVT_MENU, self.OnGenerate) self.Bind(wx.EVT_MENU_RANGE, self.OnFileHistory, id=wx.ID_FILE1, id2=wx.ID_FILE9) #---- End Menu Setup ----# #---- Other Event Handlers ----# # Frame self.Bind(wx.EVT_ACTIVATE, self.OnActivate) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Bind(ed_event.EVT_STATUS, self.OnStatus) # Find Dialog self.Bind(wx.EVT_FIND, self.nb.FindService.OnFind) self.Bind(wx.EVT_FIND_NEXT, self.nb.FindService.OnFind) self.Bind(wx.EVT_FIND_REPLACE, self.nb.FindService.OnFind) self.Bind(wx.EVT_FIND_REPLACE_ALL, self.nb.FindService.OnFind) self.Bind(wx.EVT_FIND_CLOSE, self.nb.FindService.OnFindClose) #---- End other event actions ----# #---- Final Setup Calls ----# self._exiting = False self.LoadFileHistory(_PGET('FHIST_LVL', fmt='int')) self.UpdateToolBar() # Call add on plugins self.LOG("[main][info] Loading MainWindow Plugins ") plgmgr = wx.GetApp().GetPluginManager() addons = MainWindowAddOn(plgmgr) addons.Init(self) self._handlers['menu'].extend(addons.GetEventHandlers()) self._handlers['ui'].extend(addons.GetEventHandlers(ui_evt=True)) self._shelf = iface.Shelf(plgmgr) self._shelf.Init(self) self.LOG("[main][info] Loading Generator plugins") generator.Generator(plgmgr).InstallMenu(self._menus['tools']) # Set Perspective self.SetPerspective(_PGET('DEFAULT_VIEW')) self._mgr.Update()